git » sdk » main » tree

[main] / borogove / Persistence.hx

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
package borogove;

import haxe.io.BytesData;
import borogove.Chat;
import borogove.ChatMessage;
import borogove.Message;
import thenshim.Promise;

#if cpp
import HaxeCBridge;
#end

#if !NO_OMEMO
import borogove.OMEMO;
using borogove.SignalProtocol;
#end

#if cpp
@:build(HaxeCBridge.expose())
@:build(HaxeSwiftBridge.expose())
#end
@:expose
interface Persistence {
	/**
		Get the last message in an account or chat that is is safe to sync forward from

		@param accountId the account whose state should be queried
		@param chatId chat to inspect, or null for the account-wide sync point
		@returns Promise resolving to the sync point or null
	**/
	public function syncPoint(accountId: String, chatId: Null<String>): Promise<Null<ChatMessage>>;

	/**
		Persist the current metadata for a set of Chats

		@param accountId the account that owns the Chats
		@param chats chats to write to storage
	**/
	public function storeChats(accountId: String, chats: Array<Chat>):Void;

	/**
		Load the stored Chats for an account

		@param accountId the account to load Chats for
		@returns Promise resolving to serialized chat records
	**/
	@HaxeCBridge.noemit
	public function getChats(accountId: String): Promise<Array<SerializedChat>>;

	/**
		Persist some members for a chat

		@param accountId the account that owns the chat
		@param chatId the chat whose members are being stored
		@param members members to write to storage
		@returns Promise resolving true when the write completes
	**/
	@HaxeCBridge.noemit
	public function storeMembers(accountId: String, chatId: String, members: Array<Member>): Promise<Bool>;

	/**
		Apply one or more member updates to stored chat membership state

		@param accountId the account that owns the chat
		@param chat the chat whose membership is being updated
		@param updates incremental member updates to apply
		@param isFullList true when updates represent the complete current affiliation list
		@returns Promise resolving to the updated members that should be surfaced to callers
	**/
	@HaxeCBridge.noemit
	public function storeMemberUpdates(accountId: String, chat: Chat, updates: Array<MemberUpdate>, isFullList: Bool): Promise<Array<Member>>;

	/**
		Clear cached member presence for one chat or an entire account

		@param accountId the account whose cached presence should be cleared
		@param chatId the chat to clear, or null to clear every chat in the account
		@returns Promise resolving true when the clear completes
	**/
	@HaxeCBridge.noemit
	public function clearMemberPresence(accountId: String, chatId: Null<String>): Promise<Bool>;

	/**
		Load some members for a chat

		@param accountId the account that owns the chat
		@param chat the chat to load members for
		@param forModerator true to include moderator-only rows such as banned occupants
		@returns Promise resolving to the members visible for the requested view
	**/
	@HaxeCBridge.noemit
	public function getMembers(accountId: String, chat: Chat, forModerator: Bool): Promise<Array<Member>>;

	/**
		Load detailed member records by ID

		@param accountId the account that owns the member records
		@param chat the chat context for any hydrated chat-specific metadata, or null when unavailable
		@param ids member IDs to look up
		@returns Promise resolving to an entry per requested ID, with null for unknown or incomplete members
	**/
	@HaxeCBridge.noemit
	public function getMemberDetails(accountId: String, chat: Null<Chat>, ids: Array<String>): Promise<Array<Null<Member>>>;

	/**
		Store a voice request by Jabber ID

		@param accountId the account that owns the member records
		@param chat the Channel the request is for
		@param jid the Jabber ID that is requesting / no longer requesting voice
		@returns Promise resolving to true
	**/
	@HaxeCBridge.noemit
	public function storeVoiceRequest(accountId: String, chat: Chat, jid: String, requesting: Bool): Promise<Bool>;

	/**
		List known voice requests

		@param accountId the account that owns the member records
		@param chat the Channels to look in
		@returns Promise resolving to the list of Members requesting voice
	**/
	@HaxeCBridge.noemit
	public function listVoiceRequests(accountId: String, chat: Chat): Promise<Array<Member>>;

	/**
		Load unread counters and most recent unread message per Chat

		@param accountId the account to load unread details for
		@param chats chats to inspect
		@returns Promise resolving to unread details for the requested chats
	**/
	@HaxeCBridge.noemit
	public function getChatsUnreadDetails(accountId: String, chats: Array<Chat>): Promise<Array<{ chatId: String, message: ChatMessage, unreadCount: Int }>>;

	/**
		Apply a reaction update to the stored message state

		@param accountId the account that owns the message
		@param update reaction update to apply
		@returns Promise resolving to the updated message or null if no message matched
	**/
	@HaxeCBridge.noemit
	public function storeReaction(accountId: String, update: ReactionUpdate): Promise<Null<ChatMessage>>;

	/**
		Persist one or more messages

		@param accountId the account that owns the messages
		@param message messages to store
		@returns Promise resolving to the stored message values
	**/
	public function storeMessages(accountId: String, message: Array<ChatMessage>): Promise<Array<ChatMessage>>;

	/**
		Replace the stored record for a message

		@param accountId the account that owns the message
		@param message message to write
	**/
	public function updateMessage(accountId: String, message: ChatMessage):Void;

	/**
		Update delivery state for a locally-created message

		@param accountId the account that owns the message
		@param localId local message ID to update
		@param status new delivery state
		@param statusText optional human-readable status detail
		@returns Promise resolving to the updated message
	**/
	public function updateMessageStatus(accountId: String, localId: String, status:borogove.Message.MessageStatus, statusText: Null<String>): Promise<ChatMessage>;

	/**
		Find a message by Chat ID and known IDs

		@param accountId the account that owns the message
		@param chatId Chat containing the message
		@param serverId authoritative server-assigned ID, if known
		@param localId client-assigned ID, if known
		@returns Promise resolving to the matching message or null
	**/
	public function getMessage(accountId: String, chatId: String, serverId: Null<String>, localId: Null<String>): Promise<Null<ChatMessage>>;

	/**
		Load messages older than a reference message

		@param accountId the account to load messages for
		@param chatId Chat to query
		@param before return messages older than this message, or start from the newest when null
		@returns Promise resolving to older messages
	**/
	public function getMessagesBefore(accountId: String, chatId: String, before: Null<ChatMessage>): Promise<Array<ChatMessage>>;

	/**
		Load messages newer than a reference message

		@param accountId the account to load messages for
		@param chatId Chat to query
		@param afterId return messages newer than this message, or start from the oldest when null
		@returns Promise resolving to newer messages
	**/
	public function getMessagesAfter(accountId: String, chatId: String, afterId: Null<ChatMessage>): Promise<Array<ChatMessage>>;

	/**
		Load messages surrounding a reference message

		@param accountId the account to load messages for
		@param around message to center the result set around
		@returns Promise resolving to nearby messages
	**/
	public function getMessagesAround(accountId: String, around: ChatMessage): Promise<Array<ChatMessage>>;

	/**
		Load messages with a particular delivery status

		@param accountId the account to load messages for
		@param status delivery status to match
		@returns Promise resolving to matching messages, oldest first
	**/
	@HaxeCBridge.noemit
	public function getMessagesByStatus(accountId: String, status:borogove.Message.MessageStatus): Promise<Array<ChatMessage>>;

	/**
		Check whether a media blob is already stored

		@param hash hash of the media we're looking for
		@returns Promise resolving to an ID when the media exists, null when it does not
	**/
	public function hasMedia(hash: Hash): Promise<Null<String>>;

	/**
		Store media bytes and any metadata needed to retrieve them later

		@param mime MIME type of the media
		@param source raw media bytes
		@returns Promise resolving to an ID for the stored media
	**/
	public function storeMedia(mime:String, source:Source): Promise<String>;

	/**
		Delete previously stored media

		@param hashAlgorithm hash algorithm for the content ID
		@param hash raw hash bytes
		@returns Promise resolving to true when removal succeeded
	**/
	public function removeMedia(hashAlgorithm:String, hash:BytesData): Promise<Bool>;

	/**
		Store service discovery capabilities for later reuse

		@param caps capabilities record to save
	**/
	@HaxeCBridge.noemit
	public function storeCaps(caps:Caps):Void;

	/**
		Load previously stored service discovery capabilities

		@param ver capability version hash
		@returns Promise resolving to the stored capability record or null
	**/
	@HaxeCBridge.noemit
	public function getCaps(ver:String): Promise<Null<Caps>>;

	/**
		Store login-related state for an account

		@param accountId the account to store login state for
		@param clientId negotiated client ID
		@param displayName last known display name
		@param rosterVer roster version string if known
		@param token persisted token or null to keep the current value
		@returns Promise resolving to true when store succeeded
	**/
	public function storeLogin(accountId:String, clientId:String, displayName:String, rosterVer: Null<String>, token:Null<String>): Promise<Bool>;

	/**
		Load persisted login-related state for an account

		@param accountId the account to load login state for
		@returns Promise resolving to stored login data
	**/
	@HaxeCBridge.noemit
	public function getLogin(accountId:String): Promise<{ clientId:Null<String>, token:Null<String>, fastCount: Int, displayName:Null<String>, rosterVer: Null<String> }>;

	/**
		Remove stored data for an account

		@param accountId the account to remove
		@param completely true to delete all account data, false to keep recoverable state
		@returns Promise resolving to true when removal succeeded
	**/
	public function removeAccount(accountId: String, completely:Bool): Promise<Bool>;

	/**
		List all accounts present in storage

		@returns Promise resolving to stored account IDs
	**/
	public function listAccounts(): Promise<Array<String>>;

	/**
		Store stream management resumption data for an account

		@param accountId the account to store resumption data for
		@param data stream management payload, or null to clear it
		@param sortId highest sortId ever seen by this stream
		@returns Promise resolving to true when store succeeded
	**/
	@HaxeCBridge.noemit
	public function storeStreamManagement(accountId:String, data:Null<BytesData>, sortId: String): Promise<Bool>;

	/**
		Load stream management resumption data for an account

		@param accountId the account to load resumption data for
		@returns Promise resolving to stored resumption data or null
	**/
	@HaxeCBridge.noemit
	public function getStreamManagement(accountId:String): Promise<{ sm: Null<BytesData>, sortId: String }>;

	/**
		Store metadata about a discovered service

		@param accountId the account that discovered the service
		@param serviceId ID of the service
		@param name advertised display name, if any
		@param node disco node, if any
		@param caps service capabilities
	**/
	@HaxeCBridge.noemit
	public function storeService(accountId:String, serviceId:String, name:Null<String>, node:Null<String>, caps:Caps):Void;

	/**
		Find known services that advertise a feature

		@param accountId the account to search services for
		@param feature disco feature to search for
		@returns Promise resolving to matching services
	**/
	@HaxeCBridge.noemit
	public function findServicesWithFeature(accountId:String, feature:String): Promise<Array<{serviceId:String, name:Null<String>, node:Null<String>, caps: Caps}>>;
#if !NO_OMEMO

	/**
		Load the local OMEMO device ID for an account
	**/
	public function getOmemoId(login:String): Promise<Null<Int>>;

	/**
		Store the local OMEMO device ID for an account
		@param accountId the account to store omemo id for
		@param omemoId the OMEMO device ID
		@returns Promise resolving to the stored device ID
	**/
	public function storeOmemoId(login:String, omemoId:Int):Promise<Int>;

	/**
		Store the local OMEMO identity key pair for an account
	**/
	public function storeOmemoIdentityKey(login:String, keypair:IdentityKeyPair):Promise<IdentityKeyPair>;

	/**
		Load the local OMEMO identity key pair for an account
	**/
	public function getOmemoIdentityKey(login:String): Promise<Null<IdentityKeyPair>>;

	/**
		Load the known OMEMO device list for a contact or account
	**/
	public function getOmemoDeviceList(identifier:String): Promise<Array<Int>>;

	/**
		Store the known OMEMO device list for a contact or account
	**/
	public function storeOmemoDeviceList(identifier:String, deviceIds:Array<Int>):Promise<Array<Int>>;

	/**
		Store an OMEMO pre-key
	**/
	public function storeOmemoPreKey(accountId:String, keyId:Int, keyPair:PreKeyPair):Promise<PreKeyPair>;

	/**
		Load an OMEMO pre-key
	**/
	public function getOmemoPreKey(accountId:String, keyId:Int): Promise<Null<PreKeyPair>>;

	/**
		Remove an OMEMO pre-key
	**/
	public function removeOmemoPreKey(accountId:String, keyId:Int):Promise<Bool>;

	/**
		Store an OMEMO signed pre-key
	**/
	public function storeOmemoSignedPreKey(login:String, signedPreKey:SignedPreKey):Promise<SignedPreKey>;

	/**
		Load an OMEMO signed pre-key
	**/
	public function getOmemoSignedPreKey(login:String, keyId:Int): Promise<Null<SignedPreKey>>;

	/**
		List available OMEMO pre-keys for an account
	**/
	public function getOmemoPreKeys(login:String): Promise<Array<PreKey>>;

	/**
		Store a trusted identity key for a remote OMEMO contact
	**/
	public function storeOmemoContactIdentityKey(account:String, address:String, identityKey:IdentityPublicKey):Promise<IdentityPublicKey>;

	/**
		Load a stored identity key for a remote OMEMO contact
	**/
	public function getOmemoContactIdentityKey(account:String, address:String): Promise<Null<IdentityPublicKey>>;

	/**
		Load a stored OMEMO session for a remote device
	**/
	public function getOmemoSession(account:String, address:String): Promise<Null<SignalSession>>;

	/**
		Store an OMEMO session for a remote device
	**/
	public function storeOmemoSession(account:String, address:String, session:SignalSession):Promise<SignalSession>;

	/**
		Remove a stored OMEMO session for a remote device
	**/
	public function removeOmemoSession(account:String, address:String):Promise<Bool>;

	/**
		Store extra metadata associated with an OMEMO session
	**/
	public function storeOmemoMetadata(account:String, address:String, metadata:OMEMOSessionMetadata):Promise<OMEMOSessionMetadata>;

	/**
		Load stored metadata associated with an OMEMO session
	**/
	public function getOmemoMetadata(account:String, address:String): Promise<Null<OMEMOSessionMetadata>>;
#end
}