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
}