mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-18 07:14:01 +00:00
feat: add basic contact logic for setting local contact state. Need to implement handling properly
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user