Using member names in the control messages wherever possible (#914)

pull/1709/head
SessionHero01 2 months ago committed by GitHub
parent f8a6ad05b0
commit 0956d65808
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -36,6 +36,7 @@ import org.session.libsession.utilities.IdentityKeyMismatch;
import org.session.libsession.utilities.NetworkFailure;
import org.session.libsession.utilities.ThemeUtil;
import org.session.libsession.utilities.recipients.Recipient;
import org.session.libsignal.utilities.AccountId;
import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
import network.loki.messenger.R;
@ -137,12 +138,15 @@ public abstract class MessageRecord extends DisplayRecord {
public CharSequence getDisplayBody(@NonNull Context context) {
if (isGroupUpdateMessage()) {
UpdateMessageData updateMessageData = getGroupUpdateMessage();
if (updateMessageData == null) {
Recipient groupRecipient = DatabaseComponent.get(context).threadDatabase().getRecipientForThreadId(getThreadId());
if (updateMessageData == null || groupRecipient == null || !groupRecipient.isGroupV2Recipient()) {
return "";
}
SpannableString text = new SpannableString(UpdateMessageBuilder.buildGroupUpdateMessage(
context,
new AccountId(groupRecipient.getAddress().serialize()),
updateMessageData,
MessagingModuleConfiguration.getShared().getConfigFactory(),
isOutgoing(),

@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
@ -25,6 +26,7 @@ import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn
import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_HIDDEN
import org.session.libsession.utilities.ConfigUpdateNotification
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.database.DatabaseContentProviders
import org.thoughtcrime.securesms.database.ThreadDatabase
@ -33,7 +35,6 @@ import org.thoughtcrime.securesms.dependencies.ConfigFactory
import org.thoughtcrime.securesms.sskenvironment.TypingStatusRepository
import org.thoughtcrime.securesms.util.observeChanges
import javax.inject.Inject
import dagger.hilt.android.qualifiers.ApplicationContext as ApplicationContextQualifier
@HiltViewModel
class HomeViewModel @Inject constructor(
@ -116,9 +117,10 @@ class HomeViewModel @Inject constructor(
.flowOn(Dispatchers.IO)
@OptIn(FlowPreview::class)
private fun reloadTriggersAndContentChanges() = merge(
private fun reloadTriggersAndContentChanges(): Flow<*> = merge(
manualReloadTrigger,
contentResolver.observeChanges(DatabaseContentProviders.ConversationList.CONTENT_URI)
contentResolver.observeChanges(DatabaseContentProviders.ConversationList.CONTENT_URI),
configFactory.configUpdateNotifications.filterIsInstance<ConfigUpdateNotification.GroupConfigsUpdated>()
)
.debounce(CHANGE_NOTIFICATION_DEBOUNCE_MILLS)
.onStart { emit(Unit) }

@ -2,6 +2,7 @@ package org.session.libsession.messaging.utilities
import android.content.Context
import com.squareup.phrase.Phrase
import network.loki.messenger.libsession_util.getOrNull
import org.session.libsession.R
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.calls.CallMessageType
@ -37,9 +38,15 @@ object UpdateMessageBuilder {
?.displayName(Contact.ContactContext.REGULAR)
?: truncateIdForDisplay(senderId)
private fun getGroupMemberName(groupId: AccountId, memberId: String) =
storage.getContactWithAccountID(memberId)?.displayName(Contact.ContactContext.REGULAR)
?: MessagingModuleConfiguration.shared.configFactory.withGroupConfigs(groupId) { it.groupMembers.getOrNull(memberId)?.name }
?: truncateIdForDisplay(memberId)
@JvmStatic
fun buildGroupUpdateMessage(
context: Context,
groupId: AccountId,
updateMessageData: UpdateMessageData,
configFactory: ConfigFactoryProtocol,
isOutgoing: Boolean,
@ -79,19 +86,19 @@ object UpdateMessageBuilder {
}
1 -> {
Phrase.from(context, R.string.legacyGroupMemberNew)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.format()
}
2 -> {
Phrase.from(context, R.string.legacyGroupMemberTwoNew)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(OTHER_NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(1)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.put(OTHER_NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(1)))
.format()
}
else -> {
val newMemberCountMinusOne = newMemberCount - 1
Phrase.from(context, R.string.legacyGroupMemberNewMultiple)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.put(COUNT_KEY, newMemberCountMinusOne)
.format()
}
@ -119,14 +126,14 @@ object UpdateMessageBuilder {
"" // Return an empty string - we don't want to show the error in the conversation
}
1 -> Phrase.from(context, R.string.groupRemoved)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.format()
2 -> Phrase.from(context, R.string.groupRemovedTwo)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(OTHER_NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(1)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.put(OTHER_NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(1)))
.format()
else -> Phrase.from(context, R.string.groupRemovedMultiple)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.put(COUNT_KEY, updateData.updatedMembers.size - 1)
.format()
}
@ -143,14 +150,14 @@ object UpdateMessageBuilder {
"" // Return an empty string - we don't want to show the error in the conversation
}
1 -> Phrase.from(context, R.string.groupRemoved)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.format()
2 -> Phrase.from(context, R.string.groupRemovedTwo)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(OTHER_NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(1)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.put(OTHER_NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(1)))
.format()
else -> Phrase.from(context, R.string.groupRemovedMultiple)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.put(COUNT_KEY, updateData.updatedMembers.size - 1)
.format()
}
@ -166,14 +173,14 @@ object UpdateMessageBuilder {
"" // Return an empty string - we don't want to show the error in the conversation
}
1 -> Phrase.from(context, R.string.groupMemberLeft)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.format()
2 -> Phrase.from(context, R.string.groupMemberLeftTwo)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(OTHER_NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(1)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.put(OTHER_NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(1)))
.format()
else -> Phrase.from(context, R.string.groupMemberLeftMultiple)
.put(NAME_KEY, getSenderName(updateData.updatedMembers.elementAt(0)))
.put(NAME_KEY, getGroupMemberName(groupId, updateData.updatedMembers.elementAt(0)))
.put(COUNT_KEY, updateData.updatedMembers.size - 1)
.format()
}
@ -288,7 +295,7 @@ object UpdateMessageBuilder {
}
is UpdateMessageData.Kind.GroupInvitation -> {
val approved = configFactory.getGroup(AccountId(updateData.groupAccountId))?.invited == false
val inviterName = updateData.invitingAdminName?.takeIf { it.isNotEmpty() } ?: getSenderName(updateData.invitingAdminId)
val inviterName = updateData.invitingAdminName?.takeIf { it.isNotEmpty() } ?: getGroupMemberName(groupId, updateData.invitingAdminId)
return if (!approved) {
Phrase.from(context, R.string.messageRequestGroupInvite)
.put(NAME_KEY, inviterName)
@ -314,7 +321,7 @@ object UpdateMessageBuilder {
}
}
fun Context.youOrSender(sessionId: String) = if (storage.getUserPublicKey() == sessionId) getString(R.string.you) else getSenderName(sessionId)
private fun Context.youOrSender(sessionId: String) = if (storage.getUserPublicKey() == sessionId) getString(R.string.you) else getSenderName(sessionId)
fun buildExpirationTimerMessage(
context: Context,

Loading…
Cancel
Save