Fix group expiration update config messages

This commit is contained in:
Andrew 2024-04-18 13:40:02 +09:30
parent 207da18115
commit 0ba18dcd46
2 changed files with 37 additions and 58 deletions

View File

@ -31,6 +31,7 @@ import org.session.libsession.messaging.utilities.UpdateMessageData;
import org.session.libsession.utilities.IdentityKeyMismatch; import org.session.libsession.utilities.IdentityKeyMismatch;
import org.session.libsession.utilities.NetworkFailure; import org.session.libsession.utilities.NetworkFailure;
import org.session.libsession.utilities.recipients.Recipient; import org.session.libsession.utilities.recipients.Recipient;
import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -120,7 +121,8 @@ public abstract class MessageRecord extends DisplayRecord {
return new SpannableString(UpdateMessageBuilder.INSTANCE.buildGroupUpdateMessage(context, updateMessageData, getIndividualRecipient().getAddress().serialize(), isOutgoing())); return new SpannableString(UpdateMessageBuilder.INSTANCE.buildGroupUpdateMessage(context, updateMessageData, getIndividualRecipient().getAddress().serialize(), isOutgoing()));
} else if (isExpirationTimerUpdate()) { } else if (isExpirationTimerUpdate()) {
int seconds = (int) (getExpiresIn() / 1000); int seconds = (int) (getExpiresIn() / 1000);
return new SpannableString(UpdateMessageBuilder.INSTANCE.buildExpirationTimerMessage(context, seconds, getRecipient(), getIndividualRecipient().getAddress().serialize(), isOutgoing(), getTimestamp(), expireStarted)); boolean isGroup = DatabaseComponent.get(context).threadDatabase().getRecipientForThreadId(getThreadId()).isGroupRecipient();
return new SpannableString(UpdateMessageBuilder.INSTANCE.buildExpirationTimerMessage(context, seconds, isGroup, getIndividualRecipient().getAddress().serialize(), isOutgoing(), getTimestamp(), expireStarted));
} else if (isDataExtractionNotification()) { } else if (isDataExtractionNotification()) {
if (isScreenshotNotification()) return new SpannableString((UpdateMessageBuilder.INSTANCE.buildDataExtractionMessage(context, DataExtractionNotificationInfoMessage.Kind.SCREENSHOT, getIndividualRecipient().getAddress().serialize()))); if (isScreenshotNotification()) return new SpannableString((UpdateMessageBuilder.INSTANCE.buildDataExtractionMessage(context, DataExtractionNotificationInfoMessage.Kind.SCREENSHOT, getIndividualRecipient().getAddress().serialize())));
else if (isMediaSavedNotification()) return new SpannableString((UpdateMessageBuilder.INSTANCE.buildDataExtractionMessage(context, DataExtractionNotificationInfoMessage.Kind.MEDIA_SAVED, getIndividualRecipient().getAddress().serialize()))); else if (isMediaSavedNotification()) return new SpannableString((UpdateMessageBuilder.INSTANCE.buildDataExtractionMessage(context, DataExtractionNotificationInfoMessage.Kind.MEDIA_SAVED, getIndividualRecipient().getAddress().serialize())));

View File

@ -11,9 +11,10 @@ import org.session.libsession.messaging.calls.CallMessageType.CALL_MISSED
import org.session.libsession.messaging.calls.CallMessageType.CALL_OUTGOING import org.session.libsession.messaging.calls.CallMessageType.CALL_OUTGOING
import org.session.libsession.messaging.contacts.Contact import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage
import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage.Kind.MEDIA_SAVED
import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage.Kind.SCREENSHOT
import org.session.libsession.utilities.ExpirationUtil import org.session.libsession.utilities.ExpirationUtil
import org.session.libsession.utilities.getExpirationTypeDisplayValue import org.session.libsession.utilities.getExpirationTypeDisplayValue
import org.session.libsession.utilities.recipients.Recipient
import org.session.libsession.utilities.truncateIdForDisplay import org.session.libsession.utilities.truncateIdForDisplay
object UpdateMessageBuilder { object UpdateMessageBuilder {
@ -30,47 +31,35 @@ object UpdateMessageBuilder {
else getSenderName(senderId!!) else getSenderName(senderId!!)
return when (updateData) { return when (updateData) {
is UpdateMessageData.Kind.GroupCreation -> if (isOutgoing) { is UpdateMessageData.Kind.GroupCreation -> {
context.getString(R.string.MessageRecord_you_created_a_new_group) if (isOutgoing) context.getString(R.string.MessageRecord_you_created_a_new_group)
} else { else context.getString(R.string.MessageRecord_s_added_you_to_the_group, senderName)
context.getString(R.string.MessageRecord_s_added_you_to_the_group, senderName)
} }
is UpdateMessageData.Kind.GroupNameChange -> if (isOutgoing) { is UpdateMessageData.Kind.GroupNameChange -> {
context.getString(R.string.MessageRecord_you_renamed_the_group_to_s, updateData.name) if (isOutgoing) context.getString(R.string.MessageRecord_you_renamed_the_group_to_s, updateData.name)
} else { else context.getString(R.string.MessageRecord_s_renamed_the_group_to_s, senderName, updateData.name)
context.getString(R.string.MessageRecord_s_renamed_the_group_to_s, senderName, updateData.name)
} }
is UpdateMessageData.Kind.GroupMemberAdded -> { is UpdateMessageData.Kind.GroupMemberAdded -> {
val members = updateData.updatedMembers.joinToString(", ", transform = ::getSenderName) val members = updateData.updatedMembers.joinToString(", ", transform = ::getSenderName)
if (isOutgoing) { if (isOutgoing) context.getString(R.string.MessageRecord_you_added_s_to_the_group, members)
context.getString(R.string.MessageRecord_you_added_s_to_the_group, members) else context.getString(R.string.MessageRecord_s_added_s_to_the_group, senderName, members)
} else {
context.getString(R.string.MessageRecord_s_added_s_to_the_group, senderName, members)
}
} }
is UpdateMessageData.Kind.GroupMemberRemoved -> { is UpdateMessageData.Kind.GroupMemberRemoved -> {
val userPublicKey = storage.getUserPublicKey()!! val userPublicKey = storage.getUserPublicKey()!!
// 1st case: you are part of the removed members // 1st case: you are part of the removed members
return if (userPublicKey in updateData.updatedMembers) { return if (userPublicKey in updateData.updatedMembers) {
if (isOutgoing) { if (isOutgoing) context.getString(R.string.MessageRecord_left_group)
context.getString(R.string.MessageRecord_left_group) else context.getString(R.string.MessageRecord_you_were_removed_from_the_group)
} else {
context.getString(R.string.MessageRecord_you_were_removed_from_the_group)
}
} else { } else {
// 2nd case: you are not part of the removed members // 2nd case: you are not part of the removed members
val members = updateData.updatedMembers.joinToString(", ", transform = ::getSenderName) val members = updateData.updatedMembers.joinToString(", ", transform = ::getSenderName)
if (isOutgoing) { if (isOutgoing) context.getString(R.string.MessageRecord_you_removed_s_from_the_group, members)
context.getString(R.string.MessageRecord_you_removed_s_from_the_group, members) else context.getString(R.string.MessageRecord_s_removed_s_from_the_group, senderName, members)
} else {
context.getString(R.string.MessageRecord_s_removed_s_from_the_group, senderName, members)
}
} }
} }
is UpdateMessageData.Kind.GroupMemberLeft -> if (isOutgoing) { is UpdateMessageData.Kind.GroupMemberLeft -> {
context.getString(R.string.MessageRecord_left_group) if (isOutgoing) context.getString(R.string.MessageRecord_left_group)
} else { else context.getString(R.string.ConversationItem_group_action_left, senderName)
context.getString(R.string.ConversationItem_group_action_left, senderName)
} }
else -> return "" else -> return ""
} }
@ -79,7 +68,7 @@ object UpdateMessageBuilder {
fun buildExpirationTimerMessage( fun buildExpirationTimerMessage(
context: Context, context: Context,
duration: Long, duration: Long,
recipient: Recipient, isGroup: Boolean,
senderId: String? = null, senderId: String? = null,
isOutgoing: Boolean = false, isOutgoing: Boolean = false,
timestamp: Long, timestamp: Long,
@ -88,40 +77,28 @@ object UpdateMessageBuilder {
if (!isOutgoing && senderId == null) return "" if (!isOutgoing && senderId == null) return ""
val senderName = if (isOutgoing) context.getString(R.string.MessageRecord_you) else getSenderName(senderId!!) val senderName = if (isOutgoing) context.getString(R.string.MessageRecord_you) else getSenderName(senderId!!)
return if (duration <= 0) { return if (duration <= 0) {
if (isOutgoing) { if (isOutgoing) context.getString(if (isGroup) R.string.MessageRecord_you_turned_off_disappearing_messages else R.string.MessageRecord_you_turned_off_disappearing_messages_1_on_1)
context.getString(if (recipient.is1on1) R.string.MessageRecord_you_turned_off_disappearing_messages_1_on_1 else R.string.MessageRecord_you_turned_off_disappearing_messages) else context.getString(if (isGroup) R.string.MessageRecord_s_turned_off_disappearing_messages else R.string.MessageRecord_s_turned_off_disappearing_messages_1_on_1, senderName)
} else {
context.getString(if (recipient.is1on1) R.string.MessageRecord_s_turned_off_disappearing_messages_1_on_1 else R.string.MessageRecord_s_turned_off_disappearing_messages, senderName)
}
} else { } else {
val time = ExpirationUtil.getExpirationDisplayValue(context, duration.toInt()) val time = ExpirationUtil.getExpirationDisplayValue(context, duration.toInt())
val action = context.getExpirationTypeDisplayValue(timestamp == expireStarted) val action = context.getExpirationTypeDisplayValue(timestamp == expireStarted)
if (isOutgoing) { if (isOutgoing) context.getString(
context.getString( if (isGroup) R.string.MessageRecord_you_set_messages_to_disappear_s_after_s else R.string.MessageRecord_you_set_messages_to_disappear_s_after_s_1_on_1,
if (recipient.is1on1) R.string.MessageRecord_you_set_messages_to_disappear_s_after_s_1_on_1 else R.string.MessageRecord_you_set_messages_to_disappear_s_after_s, time,
time, action
action ) else context.getString(
) if (isGroup) R.string.MessageRecord_s_set_messages_to_disappear_s_after_s else R.string.MessageRecord_s_set_messages_to_disappear_s_after_s_1_on_1,
} else { senderName,
context.getString( time,
if (recipient.is1on1) R.string.MessageRecord_s_set_messages_to_disappear_s_after_s_1_on_1 else R.string.MessageRecord_s_set_messages_to_disappear_s_after_s, action
senderName, )
time,
action
)
}
} }
} }
fun buildDataExtractionMessage(context: Context, kind: DataExtractionNotificationInfoMessage.Kind, senderId: String? = null): String { fun buildDataExtractionMessage(context: Context, kind: DataExtractionNotificationInfoMessage.Kind, senderId: String? = null) = when (kind) {
val senderName = getSenderName(senderId!!) SCREENSHOT -> R.string.MessageRecord_s_took_a_screenshot
return when (kind) { MEDIA_SAVED -> R.string.MessageRecord_media_saved_by_s
DataExtractionNotificationInfoMessage.Kind.SCREENSHOT -> }.let { context.getString(it, getSenderName(senderId!!)) }
context.getString(R.string.MessageRecord_s_took_a_screenshot, senderName)
DataExtractionNotificationInfoMessage.Kind.MEDIA_SAVED ->
context.getString(R.string.MessageRecord_media_saved_by_s, senderName)
}
}
fun buildCallMessage(context: Context, type: CallMessageType, sender: String): String = fun buildCallMessage(context: Context, type: CallMessageType, sender: String): String =
when (type) { when (type) {