feat: add user config integrated into config sync

This commit is contained in:
0x330a
2023-08-03 17:37:21 +10:00
parent 06c0ab3080
commit 8db92cc55c
13 changed files with 120 additions and 37 deletions

View File

@@ -182,7 +182,7 @@ interface StorageProtocol {
fun setContact(contact: Contact)
fun getRecipientForThread(threadId: Long): Recipient?
fun getRecipientSettings(address: Address): RecipientSettings?
fun addLibSessionContacts(contacts: List<LibSessionContact>)
fun addLibSessionContacts(contacts: List<LibSessionContact>, timestamp: Long)
fun addContacts(contacts: List<ConfigurationMessage.Contact>)
// Attachments
@@ -229,7 +229,7 @@ interface StorageProtocol {
fun updateDisappearingState(threadID: Long, disappearingState: Recipient.DisappearingState)
// Shared configs
fun notifyConfigUpdates(forConfigObject: ConfigBase)
fun notifyConfigUpdates(forConfigObject: ConfigBase, messageTimestamp: Long)
fun conversationInConfig(publicKey: String?, groupPublicKey: String?, openGroupId: String?, visibleOnly: Boolean): Boolean
fun canPerformConfigChange(variant: String, publicKey: String, changeTimestampMs: Long): Boolean
}

View File

@@ -65,11 +65,13 @@ abstract class Message {
if (config.isEnabled && config.expiryMode != null) {
expirationTimer = config.expiryMode.expirySeconds.toInt()
lastDisappearingMessageChangeTimestamp = config.updatedTimestampMs
config.expiryMode.let { expiryMode ->
when (expiryMode) {
is ExpiryMode.AfterSend -> expirationType = ExpirationType.DELETE_AFTER_SEND
is ExpiryMode.AfterRead -> expirationType = ExpirationType.DELETE_AFTER_READ
ExpiryMode.NONE -> { /* do nothing */ }
if (ExpirationConfiguration.isNewConfigEnabled) {
config.expiryMode.let { expiryMode ->
when (expiryMode) {
is ExpiryMode.AfterSend -> expirationType = ExpirationType.DELETE_AFTER_SEND
is ExpiryMode.AfterRead -> expirationType = ExpirationType.DELETE_AFTER_READ
ExpiryMode.NONE -> { /* do nothing */ }
}
}
}
}

View File

@@ -3,8 +3,8 @@ package org.session.libsession.messaging.messages.control
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.messages.ExpirationConfiguration
import org.session.libsession.messaging.messages.visible.VisibleMessage
import org.session.libsignal.utilities.Log
import org.session.libsignal.protos.SignalServiceProtos
import org.session.libsignal.utilities.Log
class ExpirationTimerUpdate() : ControlMessage() {
/** In the case of a sync message, the public key of the person the message was targeted at.
@@ -26,7 +26,9 @@ class ExpirationTimerUpdate() : ControlMessage() {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
val dataMessageProto = if (proto.hasDataMessage()) proto.dataMessage else return null
val isExpirationTimerUpdate = dataMessageProto.flags.and(SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0
val isExpirationTimerUpdate = dataMessageProto.flags.and(
SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE
) != 0
if (!isExpirationTimerUpdate) return null
val syncTarget = dataMessageProto.syncTarget
val duration = if (proto.hasExpirationTimer()) proto.expirationTimer else dataMessageProto.expireTimer

View File

@@ -69,7 +69,7 @@ fun MessageReceiver.handle(message: Message, proto: SignalServiceProtos.Content,
// Do nothing if the message was outdated
if (MessageReceiver.messageIsOutdated(message, threadId, openGroupID)) { return }
MessageReceiver.updateExpiryIfNeeded(message, proto, openGroupID, )
MessageReceiver.updateExpiryIfNeeded(message, proto, openGroupID)
when (message) {
is ReadReceipt -> handleReadReceipt(message)
is TypingIndicator -> handleTypingIndicator(message)

View File

@@ -19,5 +19,5 @@ interface ConfigFactoryProtocol {
}
interface ConfigFactoryUpdateListener {
fun notifyUpdates(forConfigObject: ConfigBase)
fun notifyUpdates(forConfigObject: ConfigBase, messageTimestamp: Long)
}

View File

@@ -1,6 +1,5 @@
package org.session.libsession.utilities
import network.loki.messenger.libsession_util.util.GroupInfo
import org.session.libsignal.messages.SignalServiceGroup
import org.session.libsignal.utilities.Hex
import java.io.IOException
@@ -104,6 +103,11 @@ object GroupUtil {
return Hex.toStringCondensed(getDecodedGroupIDAsData(getDecodedGroupID(groupID)))
}
@JvmStatic
fun addressToGroupSessionId(address: Address): String {
return doubleDecodeGroupId(address.toGroupString())
}
fun createConfigMemberMap(
members: Collection<String>,
admins: Collection<String>