mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 02:55:23 +00:00
fix: handling user group updates bug fix for closed groups instead of all groups
This commit is contained in:
parent
0fc5675e42
commit
61e8935725
@ -55,7 +55,7 @@ class NewConversationHomeFragment : Fragment() {
|
|||||||
val displayName = contact?.displayName(Contact.ContactContext.REGULAR) ?: sessionId
|
val displayName = contact?.displayName(Contact.ContactContext.REGULAR) ?: sessionId
|
||||||
ContactListItem.Contact(it, displayName)
|
ContactListItem.Contact(it, displayName)
|
||||||
}.sortedBy { it.displayName }
|
}.sortedBy { it.displayName }
|
||||||
.groupBy { if (PublicKeyValidation.isValid(it.displayName)) unknownSectionTitle else it.displayName.first().uppercase() }
|
.groupBy { if (PublicKeyValidation.isValid(it.displayName)) unknownSectionTitle else it.displayName.firstOrNull()?.uppercase() ?: unknownSectionTitle }
|
||||||
.toMutableMap()
|
.toMutableMap()
|
||||||
contactGroups.remove(unknownSectionTitle)?.let { contactGroups.put(unknownSectionTitle, it) }
|
contactGroups.remove(unknownSectionTitle)?.let { contactGroups.put(unknownSectionTitle, it) }
|
||||||
adapter.items = contactGroups.flatMap { entry -> listOf(ContactListItem.Header(entry.key)) + entry.value }
|
adapter.items = contactGroups.flatMap { entry -> listOf(ContactListItem.Header(entry.key)) + entry.value }
|
||||||
|
@ -411,7 +411,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper, private val configF
|
|||||||
val toAddCommunities = communities.filter { it.community.fullUrl() !in existingCommunities.map { it.value.joinURL } }
|
val toAddCommunities = communities.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 existingClosedGroups = getAllGroups()
|
val existingClosedGroups = getAllGroups().filter { it.isClosedGroup }
|
||||||
val lgcIds = lgc.map { it.sessionId }
|
val lgcIds = lgc.map { it.sessionId }
|
||||||
val toDeleteClosedGroups = existingClosedGroups.filter { group ->
|
val toDeleteClosedGroups = existingClosedGroups.filter { group ->
|
||||||
GroupUtil.doubleDecodeGroupId(group.encodedId) !in lgcIds
|
GroupUtil.doubleDecodeGroupId(group.encodedId) !in lgcIds
|
||||||
@ -1062,6 +1062,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper, private val configF
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun deleteConversation(threadID: Long) {
|
override fun deleteConversation(threadID: Long) {
|
||||||
|
// TODO: delete from either contacts / convo volatile or the closed groups
|
||||||
val threadDB = DatabaseComponent.get(context).threadDatabase()
|
val threadDB = DatabaseComponent.get(context).threadDatabase()
|
||||||
threadDB.deleteConversation(threadID)
|
threadDB.deleteConversation(threadID)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import network.loki.messenger.libsession_util.UserProfile
|
|||||||
import org.session.libsession.utilities.ConfigFactoryProtocol
|
import org.session.libsession.utilities.ConfigFactoryProtocol
|
||||||
import org.session.libsession.utilities.ConfigFactoryUpdateListener
|
import org.session.libsession.utilities.ConfigFactoryUpdateListener
|
||||||
import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage
|
import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage
|
||||||
|
import org.session.libsignal.utilities.Log
|
||||||
import org.thoughtcrime.securesms.database.ConfigDatabase
|
import org.thoughtcrime.securesms.database.ConfigDatabase
|
||||||
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
|
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
@ -130,15 +131,19 @@ class ConfigFactory(private val context: Context,
|
|||||||
|
|
||||||
override fun persist(forConfigObject: ConfigBase) {
|
override fun persist(forConfigObject: ConfigBase) {
|
||||||
factoryExecutor.submit {
|
factoryExecutor.submit {
|
||||||
listeners.forEach { listener ->
|
try {
|
||||||
listener.notifyUpdates(forConfigObject)
|
listeners.forEach { listener ->
|
||||||
}
|
listener.notifyUpdates(forConfigObject)
|
||||||
when (forConfigObject) {
|
}
|
||||||
is UserProfile -> persistUserConfigDump()
|
when (forConfigObject) {
|
||||||
is Contacts -> persistContactsConfigDump()
|
is UserProfile -> persistUserConfigDump()
|
||||||
is ConversationVolatileConfig -> persistConvoVolatileConfigDump()
|
is Contacts -> persistContactsConfigDump()
|
||||||
is UserGroupsConfig -> persistUserGroupsConfigDump()
|
is ConversationVolatileConfig -> persistConvoVolatileConfigDump()
|
||||||
else -> throw UnsupportedOperationException("Can't support type of ${forConfigObject::class.simpleName} yet")
|
is UserGroupsConfig -> persistUserGroupsConfigDump()
|
||||||
|
else -> throw UnsupportedOperationException("Can't support type of ${forConfigObject::class.simpleName} yet")
|
||||||
|
}
|
||||||
|
} catch (e: Exception){
|
||||||
|
Log.e("Loki-DBG", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import org.session.libsession.messaging.sending_receiving.pollers.OpenGroupPolle
|
|||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
import org.session.libsignal.utilities.ThreadUtils
|
import org.session.libsignal.utilities.ThreadUtils
|
||||||
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
||||||
|
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
object OpenGroupManager {
|
object OpenGroupManager {
|
||||||
@ -101,6 +102,7 @@ object OpenGroupManager {
|
|||||||
|
|
||||||
fun delete(server: String, room: String, context: Context) {
|
fun delete(server: String, room: String, context: Context) {
|
||||||
val storage = MessagingModuleConfiguration.shared.storage
|
val storage = MessagingModuleConfiguration.shared.storage
|
||||||
|
val configFactory = MessagingModuleConfiguration.shared.configFactory
|
||||||
val threadDB = DatabaseComponent.get(context).threadDatabase()
|
val threadDB = DatabaseComponent.get(context).threadDatabase()
|
||||||
val openGroupID = "$server.$room"
|
val openGroupID = "$server.$room"
|
||||||
val threadID = GroupManager.getOpenGroupThreadID(openGroupID, context)
|
val threadID = GroupManager.getOpenGroupThreadID(openGroupID, context)
|
||||||
@ -116,6 +118,7 @@ object OpenGroupManager {
|
|||||||
pollers.remove(server)
|
pollers.remove(server)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
configFactory.userGroups?.eraseCommunity(server, room)
|
||||||
// Delete
|
// Delete
|
||||||
storage.removeLastDeletionServerID(room, server)
|
storage.removeLastDeletionServerID(room, server)
|
||||||
storage.removeLastMessageServerID(room, server)
|
storage.removeLastMessageServerID(room, server)
|
||||||
@ -124,8 +127,9 @@ object OpenGroupManager {
|
|||||||
val lokiThreadDB = DatabaseComponent.get(context).lokiThreadDatabase()
|
val lokiThreadDB = DatabaseComponent.get(context).lokiThreadDatabase()
|
||||||
lokiThreadDB.removeOpenGroupChat(threadID)
|
lokiThreadDB.removeOpenGroupChat(threadID)
|
||||||
ThreadUtils.queue {
|
ThreadUtils.queue {
|
||||||
threadDB.deleteConversation(threadID) // Must be invoked on a background thread
|
storage.deleteConversation(threadID) // Must be invoked on a background thread
|
||||||
GroupManager.deleteGroup(groupID, context) // Must be invoked on a background thread
|
GroupManager.deleteGroup(groupID, context) // Must be invoked on a background thread
|
||||||
|
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,10 +626,12 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
} else {
|
} else {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
storage.deleteConversation(threadID)
|
storage.deleteConversation(threadID)
|
||||||
|
// Update the badge count
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
ApplicationContext.getInstance(context).messageNotifier.updateNotification(context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Update the badge count
|
|
||||||
ApplicationContext.getInstance(context).messageNotifier.updateNotification(context)
|
|
||||||
// Notify the user
|
// Notify the user
|
||||||
val toastMessage = if (recipient.isGroupRecipient) R.string.MessageRecord_left_group else R.string.activity_home_conversation_deleted_message
|
val toastMessage = if (recipient.isGroupRecipient) R.string.MessageRecord_left_group else R.string.activity_home_conversation_deleted_message
|
||||||
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show()
|
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show()
|
||||||
|
@ -115,12 +115,13 @@ JNIEXPORT void JNICALL
|
|||||||
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_set__Lnetwork_loki_messenger_libsession_1util_util_GroupInfo_2(
|
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_set__Lnetwork_loki_messenger_libsession_1util_util_GroupInfo_2(
|
||||||
JNIEnv *env, jobject thiz, jobject group_info) {
|
JNIEnv *env, jobject thiz, jobject group_info) {
|
||||||
auto conf = ptrToUserGroups(env, thiz);
|
auto conf = ptrToUserGroups(env, thiz);
|
||||||
auto communityInfo = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$CommunityGroupInfo");
|
auto community_info = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$CommunityGroupInfo");
|
||||||
auto legacyInfo = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$LegacyGroupInfo");
|
auto legacy_info = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$LegacyGroupInfo");
|
||||||
if (env->GetObjectClass(group_info) == communityInfo) {
|
auto object_class = env->GetObjectClass(group_info);
|
||||||
|
if (env->IsSameObject(community_info, object_class)) {
|
||||||
auto deserialized = deserialize_community_info(env, group_info, conf);
|
auto deserialized = deserialize_community_info(env, group_info, conf);
|
||||||
conf->set(deserialized);
|
conf->set(deserialized);
|
||||||
} else if (env->GetObjectClass(group_info) == legacyInfo) {
|
} else if (env->IsSameObject(legacy_info, object_class)) {
|
||||||
auto deserialized = deserialize_legacy_group_info(env, group_info, conf);
|
auto deserialized = deserialize_legacy_group_info(env, group_info, conf);
|
||||||
conf->set(deserialized);
|
conf->set(deserialized);
|
||||||
}
|
}
|
||||||
@ -214,15 +215,34 @@ Java_network_loki_messenger_libsession_1util_UserGroupsConfig_allLegacyGroupInfo
|
|||||||
jobject legacy_stack = iterator_as_java_stack(env, conf->begin_legacy_groups(), conf->end());
|
jobject legacy_stack = iterator_as_java_stack(env, conf->begin_legacy_groups(), conf->end());
|
||||||
return legacy_stack;
|
return legacy_stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT jboolean JNICALL
|
JNIEXPORT jboolean JNICALL
|
||||||
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseCommunity(JNIEnv *env,
|
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseCommunity__Lnetwork_loki_messenger_libsession_1util_util_BaseCommunityInfo_2(JNIEnv *env,
|
||||||
jobject thiz,
|
jobject thiz,
|
||||||
jobject base_community_info) {
|
jobject base_community_info) {
|
||||||
auto conf = ptrToUserGroups(env, thiz);
|
auto conf = ptrToUserGroups(env, thiz);
|
||||||
auto base_community = util::deserialize_base_community(env, base_community_info);
|
auto base_community = util::deserialize_base_community(env, base_community_info);
|
||||||
return conf->erase_community(base_community.base_url(),base_community.room());
|
return conf->erase_community(base_community.base_url(),base_community.room());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT jboolean JNICALL
|
||||||
|
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseCommunity__Ljava_lang_String_2Ljava_lang_String_2(
|
||||||
|
JNIEnv *env, jobject thiz, jstring server, jstring room) {
|
||||||
|
auto conf = ptrToUserGroups(env, thiz);
|
||||||
|
auto server_bytes = env->GetStringUTFChars(server, nullptr);
|
||||||
|
auto room_bytes = env->GetStringUTFChars(room, nullptr);
|
||||||
|
auto community = conf->get_community(server_bytes, room_bytes);
|
||||||
|
bool deleted = false;
|
||||||
|
if (community) {
|
||||||
|
deleted = conf->erase(*community);
|
||||||
|
}
|
||||||
|
env->ReleaseStringUTFChars(server, server_bytes);
|
||||||
|
env->ReleaseStringUTFChars(room, room_bytes);
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT jboolean JNICALL
|
JNIEXPORT jboolean JNICALL
|
||||||
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseLegacyGroup(JNIEnv *env,
|
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseLegacyGroup(JNIEnv *env,
|
||||||
|
@ -159,6 +159,7 @@ class UserGroupsConfig(pointer: Long): ConfigBase(pointer) {
|
|||||||
external fun set(groupInfo: GroupInfo)
|
external fun set(groupInfo: GroupInfo)
|
||||||
external fun erase(communityInfo: GroupInfo)
|
external fun erase(communityInfo: GroupInfo)
|
||||||
external fun eraseCommunity(baseCommunityInfo: BaseCommunityInfo): Boolean
|
external fun eraseCommunity(baseCommunityInfo: BaseCommunityInfo): Boolean
|
||||||
|
external fun eraseCommunity(server: String, room: String): Boolean
|
||||||
external fun eraseLegacyGroup(sessionId: String): Boolean
|
external fun eraseLegacyGroup(sessionId: String): Boolean
|
||||||
external fun sizeCommunityInfo(): Int
|
external fun sizeCommunityInfo(): Int
|
||||||
external fun sizeLegacyGroupInfo(): Int
|
external fun sizeLegacyGroupInfo(): Int
|
||||||
|
Loading…
Reference in New Issue
Block a user