feat: add basic contact logic for setting local contact state. Need to implement handling properly

This commit is contained in:
0x330a
2023-02-23 17:19:03 +11:00
parent 164810e533
commit 8a000fe5a9
14 changed files with 100 additions and 33 deletions

View File

@@ -62,6 +62,25 @@ class Contacts(pointer: Long) : ConfigBase(pointer) {
external fun all(): List<Contact>
external fun set(contact: Contact)
external fun erase(sessionId: String): Boolean
/**
* Similar to [updateIfExists], but will create the underlying contact if it doesn't exist before passing to [updateFunction]
*/
fun upsertContact(sessionId: String, updateFunction: Contact.()->Unit) {
val contact = getOrConstruct(sessionId)
updateFunction(contact)
set(contact)
}
/**
* Updates the contact by sessionId with a given [updateFunction], and applies to the underlying config.
* the [updateFunction] doesn't run if there is no contact
*/
fun updateIfExists(sessionId: String, updateFunction: Contact.()->Unit) {
val contact = get(sessionId) ?: return
updateFunction(contact)
set(contact)
}
}
class UserProfile(pointer: Long) : ConfigBase(pointer) {