on master help sign in
Add contact added date tracking for sorting contacts without messages
6cd8d15iko
client/App.fs+2−1
@@ -60,7 +60,8 @@ module App =
60 Nickname = nickname
60 Nickname = nickname
61 DisplayName = ""
61 DisplayName = ""
62 Bio = ""
62 Bio = ""
63− Photo = None }
63+ Photo = None
64+ AddedDate = System.DateTimeOffset.UtcNow }
64
65
65 let private withProfile (p: Profile) (c: Contact) =
66 let private withProfile (p: Profile) (c: Contact) =
66 { c with
67 { c with
client/Store.fs+17−6
@@ -13,7 +13,8 @@ module Store =
13 Nickname: string
13 Nickname: string
14 DisplayName: string
14 DisplayName: string
15 Bio: string
15 Bio: string
16− Photo: byte[] option }
16+ Photo: byte[] option
17+ AddedDate: DateTimeOffset }
17
18
18 type Profile =
19 type Profile =
19 { DisplayName: string
20 { DisplayName: string
@@ -75,7 +76,8 @@ module Store =
75 Nickname = rd.ReadString "Nickname"
76 Nickname = rd.ReadString "Nickname"
76 DisplayName = rd.ReadString "DisplayName"
77 DisplayName = rd.ReadString "DisplayName"
77 Bio = rd.ReadString "Bio"
78 Bio = rd.ReadString "Bio"
78− Photo = rd.ReadBytesOption "Photo" }
79+ Photo = rd.ReadBytesOption "Photo"
80+ AddedDate = rd.ReadInt64 "AddedDateUnix" |> DateTimeOffset.FromUnixTimeMilliseconds }
79
81
80 let private readMessage (rd: IDataReader) : ChatMessage =
82 let private readMessage (rd: IDataReader) : ChatMessage =
81 let isOutgoing = rd.ReadBoolean "IsOutgoing"
83 let isOutgoing = rd.ReadBoolean "IsOutgoing"
@@ -108,9 +110,17 @@ module Store =
108
110
109 conn
111 conn
110 |> Db.newCommand
112 |> 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)"
112 |> Db.exec
114 |> Db.exec
113
115
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+
114 conn
124 conn
115 |> Db.newCommand
125 |> Db.newCommand
116 "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)"
126 "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 =
234 | Some(serverUrl, pollCursor) ->
244 | Some(serverUrl, pollCursor) ->
235 let contacts =
245 let contacts =
236 conn
246 conn
237− |> Db.newCommand "SELECT Pubkey, Nickname, DisplayName, Bio, Photo FROM contacts"
247+ |> Db.newCommand "SELECT Pubkey, Nickname, DisplayName, Bio, Photo, AddedDateUnix FROM contacts"
238 |> Db.query readContact
248 |> Db.query readContact
239 |> List.map (fun c -> c.Pubkey, c)
249 |> List.map (fun c -> c.Pubkey, c)
240 |> Map.ofList
250 |> Map.ofList
@@ -268,7 +278,7 @@ module Store =
268 for c in data.Contacts.Values do
278 for c in data.Contacts.Values do
269 conn
279 conn
270 |> Db.newCommand
280 |> 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)"
272 |> Db.setParams
282 |> Db.setParams
273 [ "Pubkey", SqlType.String c.Pubkey
283 [ "Pubkey", SqlType.String c.Pubkey
274 "Nickname", SqlType.String c.Nickname
284 "Nickname", SqlType.String c.Nickname
@@ -277,7 +287,8 @@ module Store =
277 "Photo",
287 "Photo",
278 (match c.Photo with
288 (match c.Photo with
279 | Some bytes -> SqlType.Bytes bytes
289 | Some bytes -> SqlType.Bytes bytes
280− | None -> SqlType.Null) ]
290+ | None -> SqlType.Null)
291+ "AddedDateUnix", SqlType.Int64(c.AddedDate.ToUnixTimeMilliseconds()) ]
281 |> Db.exec
292 |> Db.exec
282
293
283 for KeyValue(convId, msgs) in data.Messages do
294 for KeyValue(convId, msgs) in data.Messages do
client/ViewConversations.fs+1−1
@@ -21,7 +21,7 @@ module ViewConversations =
21 messagesFor c.Pubkey model.Messages
21 messagesFor c.Pubkey model.Messages
22 |> List.tryLast
22 |> List.tryLast
23 |> Option.map (fun m -> m.Timestamp)
23 |> Option.map (fun m -> m.Timestamp)
24− |> Option.defaultValue System.DateTimeOffset.MinValue)
24+ |> Option.defaultValue c.AddedDate)
25
25
26 let content =
26 let content =
27 if contacts.IsEmpty then
27 if contacts.IsEmpty then