Fix improperly caching notifyType on Recipients (#965)

* fix: perform clear member roles before setting new roles to clear out old members

* fix: hopefully add somewhere notifyType wasn't being carried over

fixes #945
This commit is contained in:
Harris 2022-09-13 14:15:35 +10:00 committed by GitHub
parent 7d186c198e
commit 29124f36b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 7 deletions

View File

@ -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()
}
}
}

View File

@ -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)
}

View File

@ -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?

View File

@ -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))
}
}

View File

@ -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);