6open Microsoft.Maui.Storage
12 { [<BsonId>] Pubkey: string
18 Timestamp: DateTimeOffset
22 { Contacts: Contact list
23 Messages: Map<string, ChatMessage list>
28 type private MessageDoc =
29 { [<BsonId>] Id: string
30 ConversationId: string
36 type private SettingsDoc =
37 { [<BsonId>] Id: string
41 let private toChatMessage (d: MessageDoc) : ChatMessage =
42 { Id = d.Id; Body = d.Body; Timestamp = DateTimeOffset.FromUnixTimeSeconds d.TimestampUnix; IsOutgoing = d.IsOutgoing }
44 let private toMessageDoc convId (m: ChatMessage) : MessageDoc =
45 { Id = m.Id; ConversationId = convId; Body = m.Body; TimestampUnix = m.Timestamp.ToUnixTimeSeconds(); IsOutgoing = m.IsOutgoing }
47 let private openDb () =
48 new LiteDatabase(Path.Combine(FileSystem.AppDataDirectory, "skrepka.db"))
53 SecureStorage.Default.GetAsync("identity_privkey")
57 SecureStorage.Default.GetAsync("identity_pubkey")
63 { Crypto.Identity.PrivKey = Convert.FromBase64String pk
64 Crypto.Identity.PubKeyHex = pub })
65 (Option.ofObj privKeyB64)
66 (Option.ofObj pubKeyHex)
69 let saveIdentity (identity: Crypto.Identity) =
71 do! SecureStorage.Default.SetAsync("identity_privkey", Convert.ToBase64String identity.PrivKey) |> Async.AwaitTask
72 do! SecureStorage.Default.SetAsync("identity_pubkey", identity.PubKeyHex) |> Async.AwaitTask
75 let loadData () : Data option =
78 let settings = db.GetCollection<SettingsDoc>("settings").FindById(BsonValue "settings")
80 match settings |> Option.ofObj with
83 let contacts = db.GetCollection<Contact>("contacts").FindAll() |> Seq.toList
86 db.GetCollection<MessageDoc>("messages").FindAll()
87 |> Seq.groupBy _.ConversationId
88 |> Seq.map (fun (convId, docs) ->
89 convId, docs |> Seq.map toChatMessage |> Seq.sortBy _.Timestamp |> Seq.toList)
95 ServerUrl = settings.ServerUrl
96 PollCursor = settings.PollCursor }
100 let saveData (data: Data) =
103 let contacts = db.GetCollection<Contact>("contacts")
104 let messages = db.GetCollection<MessageDoc>("messages")
105 let settings = db.GetCollection<SettingsDoc>("settings")
107 for c in data.Contacts do
108 contacts.Upsert c |> ignore
111 |> Map.iter (fun convId msgs ->
113 messages.Upsert(toMessageDoc convId m) |> ignore)
117 ServerUrl = data.ServerUrl
118 PollCursor = data.PollCursor }
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list