More group renaming

This commit is contained in:
SessionHero01 2024-10-25 10:37:18 +11:00
parent e89cbdf029
commit 0518134c88
No known key found for this signature in database
9 changed files with 23 additions and 19 deletions

View File

@ -259,7 +259,7 @@ class ConfigToDatabaseSync @Inject constructor(
val toAddCommunities = userGroups.communityInfo.filter { it.community.fullUrl() !in existingCommunities.map { it.value.joinURL } } val toAddCommunities = userGroups.communityInfo.filter { it.community.fullUrl() !in existingCommunities.map { it.value.joinURL } }
val existingJoinUrls = existingCommunities.values.map { it.joinURL } val existingJoinUrls = existingCommunities.values.map { it.joinURL }
val existingLegacyClosedGroups = storage.getAllGroups(includeInactive = true).filter { it.isLegacyClosedGroup } val existingLegacyClosedGroups = storage.getAllGroups(includeInactive = true).filter { it.isLegacyGroup }
val lgcIds = userGroups.legacyGroupInfo.map { it.accountId } val lgcIds = userGroups.legacyGroupInfo.map { it.accountId }
val toDeleteLegacyClosedGroups = existingLegacyClosedGroups.filter { group -> val toDeleteLegacyClosedGroups = existingLegacyClosedGroups.filter { group ->
GroupUtil.doubleDecodeGroupId(group.encodedId) !in lgcIds GroupUtil.doubleDecodeGroupId(group.encodedId) !in lgcIds

View File

@ -182,8 +182,8 @@ object ConversationMenuHelper {
R.id.menu_block_delete -> { blockAndDelete(context, thread) } R.id.menu_block_delete -> { blockAndDelete(context, thread) }
R.id.menu_copy_account_id -> { copyAccountID(context, thread) } R.id.menu_copy_account_id -> { copyAccountID(context, thread) }
R.id.menu_copy_open_group_url -> { copyOpenGroupUrl(context, thread) } R.id.menu_copy_open_group_url -> { copyOpenGroupUrl(context, thread) }
R.id.menu_edit_group -> { editClosedGroup(context, thread) } R.id.menu_edit_group -> { editGroup(context, thread) }
R.id.menu_leave_group -> { return leaveClosedGroup(context, thread, threadID, factory, storage, groupManager) } R.id.menu_leave_group -> { return leaveGroup(context, thread, threadID, factory, storage, groupManager) }
R.id.menu_invite_to_open_group -> { inviteContacts(context, thread) } R.id.menu_invite_to_open_group -> { inviteContacts(context, thread) }
R.id.menu_unmute_notifications -> { unmute(context, thread) } R.id.menu_unmute_notifications -> { unmute(context, thread) }
R.id.menu_mute_notifications -> { mute(context, thread) } R.id.menu_mute_notifications -> { mute(context, thread) }
@ -316,7 +316,7 @@ object ConversationMenuHelper {
listener.copyOpenGroupUrl(thread) listener.copyOpenGroupUrl(thread)
} }
private fun editClosedGroup(context: Context, thread: Recipient) { private fun editGroup(context: Context, thread: Recipient) {
when { when {
thread.isGroupV2Recipient -> { thread.isGroupV2Recipient -> {
context.startActivity(EditGroupActivity.createIntent(context, thread.address.serialize())) context.startActivity(EditGroupActivity.createIntent(context, thread.address.serialize()))
@ -331,7 +331,7 @@ object ConversationMenuHelper {
} }
} }
fun leaveClosedGroup( fun leaveGroup(
context: Context, context: Context,
thread: Recipient, thread: Recipient,
threadID: Long, threadID: Long,
@ -346,7 +346,7 @@ object ConversationMenuHelper {
val accountID = TextSecurePreferences.getLocalNumber(context) val accountID = TextSecurePreferences.getLocalNumber(context)
val isCurrentUserAdmin = admins.any { it.toString() == accountID } val isCurrentUserAdmin = admins.any { it.toString() == accountID }
confirmAndLeaveClosedGroup( confirmAndLeaveGroup(
context = context, context = context,
groupName = group.title, groupName = group.title,
isAdmin = isCurrentUserAdmin, isAdmin = isCurrentUserAdmin,
@ -372,7 +372,7 @@ object ConversationMenuHelper {
val channel = Channel<Unit>() val channel = Channel<Unit>()
confirmAndLeaveClosedGroup( confirmAndLeaveGroup(
context = context, context = context,
groupName = name, groupName = name,
isAdmin = group.hasAdminKey(), isAdmin = group.hasAdminKey(),
@ -394,7 +394,7 @@ object ConversationMenuHelper {
return null return null
} }
private fun confirmAndLeaveClosedGroup( private fun confirmAndLeaveGroup(
context: Context, context: Context,
groupName: String, groupName: String,
isAdmin: Boolean, isAdmin: Boolean,

View File

@ -509,7 +509,7 @@ private fun MutableUserGroupsConfig.initFrom(storage: StorageProtocol) {
storage storage
.getAllGroups(includeInactive = false) .getAllGroups(includeInactive = false)
.asSequence().filter { it.isLegacyClosedGroup && it.isActive && it.members.size > 1 } .asSequence().filter { it.isLegacyGroup && it.isActive && it.members.size > 1 }
.mapNotNull { group -> .mapNotNull { group ->
val groupAddress = Address.fromSerialized(group.encodedId) val groupAddress = Address.fromSerialized(group.encodedId)
val groupPublicKey = GroupUtil.doubleDecodeGroupID(groupAddress.serialize()).toHexString() val groupPublicKey = GroupUtil.doubleDecodeGroupID(groupAddress.serialize()).toHexString()

View File

@ -34,7 +34,7 @@ object ClosedGroupManager {
} }
fun ConfigFactory.updateLegacyGroup(group: GroupRecord) { fun ConfigFactory.updateLegacyGroup(group: GroupRecord) {
if (!group.isLegacyClosedGroup) return if (!group.isLegacyGroup) return
val storage = MessagingModuleConfiguration.shared.storage val storage = MessagingModuleConfiguration.shared.storage
val threadId = storage.getThreadId(group.encodedId) ?: return val threadId = storage.getThreadId(group.encodedId) ?: return
val groupPublicKey = GroupUtil.doubleEncodeGroupID(group.getId()) val groupPublicKey = GroupUtil.doubleEncodeGroupID(group.getId())

View File

@ -583,8 +583,8 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
val threadID = thread.threadId val threadID = thread.threadId
val recipient = thread.recipient val recipient = thread.recipient
if (recipient.isGroupV2Recipient || recipient.isLegacyGroupRecipient) { if (recipient.isGroupRecipient) {
ConversationMenuHelper.leaveClosedGroup( ConversationMenuHelper.leaveGroup(
context = this, context = this,
thread = recipient, thread = recipient,
threadID = threadID, threadID = threadID,

View File

@ -89,7 +89,7 @@ private fun getHighlight(query: String?, toSearch: String): Spannable? {
fun ContentView.bindModel(query: String?, model: LegacyGroupConversation) { fun ContentView.bindModel(query: String?, model: LegacyGroupConversation) {
binding.searchResultProfilePicture.isVisible = true binding.searchResultProfilePicture.isVisible = true
binding.searchResultSubtitle.isVisible = model.groupRecord.isLegacyClosedGroup binding.searchResultSubtitle.isVisible = model.groupRecord.isLegacyGroup
binding.searchResultTimestamp.isVisible = false binding.searchResultTimestamp.isVisible = false
val threadRecipient = Recipient.from(binding.root.context, Address.fromSerialized(model.groupRecord.encodedId), false) val threadRecipient = Recipient.from(binding.root.context, Address.fromSerialized(model.groupRecord.encodedId), false)
binding.searchResultProfilePicture.update(threadRecipient) binding.searchResultProfilePicture.update(threadRecipient)
@ -99,7 +99,7 @@ fun ContentView.bindModel(query: String?, model: LegacyGroupConversation) {
val groupRecipients = model.groupRecord.members.map { Recipient.from(binding.root.context, it, false) } val groupRecipients = model.groupRecord.members.map { Recipient.from(binding.root.context, it, false) }
val membersString = groupRecipients.joinToString(transform = Recipient::getSearchName) val membersString = groupRecipients.joinToString(transform = Recipient::getSearchName)
if (model.groupRecord.isLegacyClosedGroup) { if (model.groupRecord.isLegacyGroup) {
binding.searchResultSubtitle.text = getHighlight(query, membersString) binding.searchResultSubtitle.text = getHighlight(query, membersString)
} }
} }

View File

@ -124,7 +124,7 @@ class ConfigurationMessage(var closedGroups: List<ClosedGroup>, var openGroups:
val profileKey = ProfileKeyUtil.getProfileKey(context) val profileKey = ProfileKeyUtil.getProfileKey(context)
val groups = storage.getAllGroups(includeInactive = false) val groups = storage.getAllGroups(includeInactive = false)
for (group in groups) { for (group in groups) {
if (group.isLegacyClosedGroup && group.isActive) { if (group.isLegacyGroup && group.isActive) {
if (!group.members.contains(Address.fromSerialized(storage.getUserPublicKey()!!))) continue if (!group.members.contains(Address.fromSerialized(storage.getUserPublicKey()!!))) continue
val groupPublicKey = GroupUtil.doubleDecodeGroupID(group.encodedId).toHexString() val groupPublicKey = GroupUtil.doubleDecodeGroupID(group.encodedId).toHexString()
val encryptionKeyPair = storage.getLatestClosedGroupEncryptionKeyPair(groupPublicKey) ?: continue val encryptionKeyPair = storage.getLatestClosedGroupEncryptionKeyPair(groupPublicKey) ?: continue
@ -137,7 +137,7 @@ class ConfigurationMessage(var closedGroups: List<ClosedGroup>, var openGroups:
) )
closedGroups.add(closedGroup) closedGroups.add(closedGroup)
} }
if (group.isOpenGroup) { if (group.isCommunity) {
val threadID = storage.getThreadId(group.encodedId) ?: continue val threadID = storage.getThreadId(group.encodedId) ?: continue
val openGroup = storage.getOpenGroup(threadID) val openGroup = storage.getOpenGroup(threadID)
val shareUrl = openGroup?.joinURL ?: continue val shareUrl = openGroup?.joinURL ?: continue

View File

@ -21,11 +21,11 @@ class GroupRecord(
} }
} }
val isOpenGroup: Boolean val isCommunity: Boolean
get() = Address.fromSerialized(encodedId).isCommunity get() = Address.fromSerialized(encodedId).isCommunity
val isLegacyClosedGroup: Boolean val isLegacyGroup: Boolean
get() = Address.fromSerialized(encodedId).isLegacyGroup get() = Address.fromSerialized(encodedId).isLegacyGroup
val isClosedGroupV2: Boolean val isGroupV2: Boolean
get() = Address.fromSerialized(encodedId).isGroupV2 get() = Address.fromSerialized(encodedId).isGroupV2
init { init {

View File

@ -480,6 +480,10 @@ public class Recipient implements RecipientModifiedListener {
return address.isLegacyGroup(); return address.isLegacyGroup();
} }
public boolean isGroupRecipient() {
return address.isGroup();
}
public boolean isGroupV2Recipient() { public boolean isGroupV2Recipient() {
return address.isGroupV2(); return address.isGroupV2();
} }