add open group through configuration message

This commit is contained in:
Ryan ZHAO 2021-02-09 13:16:33 +11:00
parent 5ceaf87ba9
commit c32c58eee7
4 changed files with 8 additions and 2 deletions

View File

@ -31,6 +31,7 @@ import org.session.libsignal.service.loki.api.opengroups.PublicChat
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase
import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities
import org.thoughtcrime.securesms.loki.utilities.get
import org.thoughtcrime.securesms.loki.utilities.getString
import org.thoughtcrime.securesms.mms.IncomingMediaMessage
@ -396,6 +397,10 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
return DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChats()
}
override fun addOpenGroup(server: String, channel: Long) {
OpenGroupUtilities.addGroup(context, server, channel)
}
override fun getAllGroups(): List<GroupRecord> {
return DatabaseFactory.getGroupDatabase(context).allGroups
}

View File

@ -27,7 +27,7 @@ object OpenGroupUtilities {
val groupID = PublicChat.getId(channel, url)
val threadID = GroupManager.getOpenGroupThreadID(groupID, context)
val openGroup = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(threadID)
if (openGroup != null) return openGroup
if (openGroup != null) { return openGroup }
// Add the new group.
val application = ApplicationContext.getInstance(context)

View File

@ -58,6 +58,7 @@ interface StorageProtocol {
fun getOpenGroup(threadID: String): OpenGroup?
fun getThreadID(openGroupID: String): String?
fun getAllOpenGroups(): Map<Long, PublicChat>
fun addOpenGroup(server: String, channel: Long)
// Open Group Public Keys
fun getOpenGroupPublicKey(server: String): String?

View File

@ -113,7 +113,7 @@ private fun MessageReceiver.handleConfigurationMessage(message: ConfigurationMes
val allOpenGroups = storage.getAllOpenGroups().map { it.value.server }
for (openGroup in message.openGroups) {
if (allOpenGroups.contains(openGroup)) continue
// TODO
storage.addOpenGroup(openGroup, 1)
}
}