on master help sign in
Add contact added date tracking for sorting contacts without messages
commit6cd8d15a01c4e6cf9fcf2c562865866756056ce7 authoriko <mail@iko.soy> dateSun 19 Apr 2026, 14:55 (6 months ago) parentd6c4b4e
3 files changed+20−8
client/App.fs+2−1 client/Store.fs+17−6 client/ViewConversations.fs+1−1
client/App.fs+2−1
@@ -60,7 +60,8 @@ module App =
6060 Nickname = nickname
6161 DisplayName = ""
6262 Bio = ""
63− Photo = None }
63+ Photo = None
64+ AddedDate = System.DateTimeOffset.UtcNow }
6465
6566 let private withProfile (p: Profile) (c: Contact) =
6667 { c with
client/Store.fs+17−6
@@ -13,7 +13,8 @@ module Store =
1313 Nickname: string
1414 DisplayName: string
1515 Bio: string
16− Photo: byte[] option }
16+ Photo: byte[] option
17+ AddedDate: DateTimeOffset }
1718
1819 type Profile =
1920 { DisplayName: string
@@ -75,7 +76,8 @@ module Store =
7576 Nickname = rd.ReadString "Nickname"
7677 DisplayName = rd.ReadString "DisplayName"
7778 Bio = rd.ReadString "Bio"
78− Photo = rd.ReadBytesOption "Photo" }
79+ Photo = rd.ReadBytesOption "Photo"
80+ AddedDate = rd.ReadInt64 "AddedDateUnix" |> DateTimeOffset.FromUnixTimeMilliseconds }
7981
8082 let private readMessage (rd: IDataReader) : ChatMessage =
8183 let isOutgoing = rd.ReadBoolean "IsOutgoing"
@@ -108,9 +110,17 @@ module Store =
108110
109111 conn
110112 |> Db.newCommand
111− "CREATE TABLE IF NOT EXISTS contacts (Pubkey TEXT PRIMARY KEY, Nickname TEXT NOT NULL DEFAULT '', DisplayName TEXT NOT NULL DEFAULT '', Bio TEXT NOT NULL DEFAULT '', Photo BLOB)"
113+ "CREATE TABLE IF NOT EXISTS contacts (Pubkey TEXT PRIMARY KEY, Nickname TEXT NOT NULL DEFAULT '', DisplayName TEXT NOT NULL DEFAULT '', Bio TEXT NOT NULL DEFAULT '', Photo BLOB, AddedDateUnix INTEGER NOT NULL DEFAULT 0)"
112114 |> Db.exec
113115
116+ // Migration: add AddedDateUnix to existing contacts tables
117+ try
118+ conn
119+ |> Db.newCommand "ALTER TABLE contacts ADD COLUMN AddedDateUnix INTEGER NOT NULL DEFAULT 0"
120+ |> Db.exec
121+ with _ ->
122+ ()
123+
114124 conn
115125 |> Db.newCommand
116126 "CREATE TABLE IF NOT EXISTS messages (Id TEXT PRIMARY KEY, ConversationId TEXT NOT NULL, Body TEXT NOT NULL DEFAULT '', TimestampUnix INTEGER NOT NULL, IsOutgoing INTEGER NOT NULL DEFAULT 0, Status INTEGER NOT NULL DEFAULT 0)"
@@ -234,7 +244,7 @@ module Store =
234244 | Some(serverUrl, pollCursor) ->
235245 let contacts =
236246 conn
237− |> Db.newCommand "SELECT Pubkey, Nickname, DisplayName, Bio, Photo FROM contacts"
247+ |> Db.newCommand "SELECT Pubkey, Nickname, DisplayName, Bio, Photo, AddedDateUnix FROM contacts"
238248 |> Db.query readContact
239249 |> List.map (fun c -> c.Pubkey, c)
240250 |> Map.ofList
@@ -268,7 +278,7 @@ module Store =
268278 for c in data.Contacts.Values do
269279 conn
270280 |> Db.newCommand
271− "INSERT OR REPLACE INTO contacts (Pubkey, Nickname, DisplayName, Bio, Photo) VALUES (@Pubkey, @Nickname, @DisplayName, @Bio, @Photo)"
281+ "INSERT OR REPLACE INTO contacts (Pubkey, Nickname, DisplayName, Bio, Photo, AddedDateUnix) VALUES (@Pubkey, @Nickname, @DisplayName, @Bio, @Photo, @AddedDateUnix)"
272282 |> Db.setParams
273283 [ "Pubkey", SqlType.String c.Pubkey
274284 "Nickname", SqlType.String c.Nickname
@@ -277,7 +287,8 @@ module Store =
277287 "Photo",
278288 (match c.Photo with
279289 | Some bytes -> SqlType.Bytes bytes
280− | None -> SqlType.Null) ]
290+ | None -> SqlType.Null)
291+ "AddedDateUnix", SqlType.Int64(c.AddedDate.ToUnixTimeMilliseconds()) ]
281292 |> Db.exec
282293
283294 for KeyValue(convId, msgs) in data.Messages do
client/ViewConversations.fs+1−1
@@ -21,7 +21,7 @@ module ViewConversations =
2121 messagesFor c.Pubkey model.Messages
2222 |> List.tryLast
2323 |> Option.map (fun m -> m.Timestamp)
24− |> Option.defaultValue System.DateTimeOffset.MinValue)
24+ |> Option.defaultValue c.AddedDate)
2525
2626 let content =
2727 if contacts.IsEmpty then