diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/GroupMemberDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/GroupMemberDatabase.kt index 878b8a1c09..ce2e2eba8d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/GroupMemberDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/GroupMemberDatabase.kt @@ -3,9 +3,9 @@ package org.thoughtcrime.securesms.database import android.content.ContentValues import android.content.Context import android.database.Cursor -import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.session.libsession.messaging.open_groups.GroupMember import org.session.libsession.messaging.open_groups.GroupMemberRole +import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper class GroupMemberDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) { @@ -69,4 +69,16 @@ class GroupMemberDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab } } + fun clearGroupMemberRoles(groupId: String) { + writableDatabase.beginTransaction() + try { + val query = "$GROUP_ID = ?" + val args = arrayOf(groupId) + writableDatabase.delete(TABLE_NAME, query, args) + writableDatabase.setTransactionSuccessful() + } finally { + writableDatabase.endTransaction() + } + } + } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index ef14ed83e4..9c2cf5e9d8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -324,7 +324,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, return getAllOpenGroups().values.firstOrNull { it.server == server && it.room == room } } - override fun addGroupMember(member: GroupMember) { + override fun clearGroupMemberRoles(groupId: String) { + DatabaseComponent.get(context).groupMemberDatabase().clearGroupMemberRoles(groupId) + } + + override fun addGroupMemberRole(member: GroupMember) { DatabaseComponent.get(context).groupMemberDatabase().addGroupMember(member) } diff --git a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt index 8d9273a063..7dbea4deb5 100644 --- a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt +++ b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt @@ -71,7 +71,8 @@ interface StorageProtocol { fun hasBackgroundGroupAddJob(groupJoinUrl: String): Boolean fun setOpenGroupServerMessageID(messageID: Long, serverID: Long, threadID: Long, isSms: Boolean) fun getOpenGroup(room: String, server: String): OpenGroup? - fun addGroupMember(member: GroupMember) + fun addGroupMemberRole(member: GroupMember) + fun clearGroupMemberRoles(groupId: String) // Open Group Public Keys fun getOpenGroupPublicKey(server: String): String? diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt index 5a681594d0..7bb00f8f35 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt @@ -134,18 +134,20 @@ class OpenGroupPoller(private val server: String, private val executorService: S storage.setUserCount(roomToken, server, pollInfo.activeUsers) // - Moderators + storage.clearGroupMemberRoles(groupId) + pollInfo.details?.moderators?.forEach { - storage.addGroupMember(GroupMember(groupId, it, GroupMemberRole.MODERATOR)) + storage.addGroupMemberRole(GroupMember(groupId, it, GroupMemberRole.MODERATOR)) } pollInfo.details?.hiddenModerators?.forEach { - storage.addGroupMember(GroupMember(groupId, it, GroupMemberRole.HIDDEN_MODERATOR)) + storage.addGroupMemberRole(GroupMember(groupId, it, GroupMemberRole.HIDDEN_MODERATOR)) } // - Admins pollInfo.details?.admins?.forEach { - storage.addGroupMember(GroupMember(groupId, it, GroupMemberRole.ADMIN)) + storage.addGroupMemberRole(GroupMember(groupId, it, GroupMemberRole.ADMIN)) } pollInfo.details?.hiddenAdmins?.forEach { - storage.addGroupMember(GroupMember(groupId, it, GroupMemberRole.HIDDEN_ADMIN)) + storage.addGroupMemberRole(GroupMember(groupId, it, GroupMemberRole.HIDDEN_ADMIN)) } } diff --git a/libsession/src/main/java/org/session/libsession/utilities/recipients/Recipient.java b/libsession/src/main/java/org/session/libsession/utilities/recipients/Recipient.java index d6b7938e83..a72c5d2af5 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/recipients/Recipient.java +++ b/libsession/src/main/java/org/session/libsession/utilities/recipients/Recipient.java @@ -224,6 +224,7 @@ public class Recipient implements RecipientModifiedListener { Recipient.this.profileSharing = result.profileSharing; Recipient.this.unidentifiedAccessMode = result.unidentifiedAccessMode; Recipient.this.forceSmsSelection = result.forceSmsSelection; + Recipient.this.notifyType = result.notifyType; Recipient.this.participants.clear(); Recipient.this.participants.addAll(result.participants);