|
|
@ -4,52 +4,51 @@ import android.content.Context
|
|
|
|
import org.session.libsession.R
|
|
|
|
import org.session.libsession.R
|
|
|
|
import org.session.libsession.messaging.MessagingModuleConfiguration
|
|
|
|
import org.session.libsession.messaging.MessagingModuleConfiguration
|
|
|
|
import org.session.libsession.messaging.calls.CallMessageType
|
|
|
|
import org.session.libsession.messaging.calls.CallMessageType
|
|
|
|
|
|
|
|
import org.session.libsession.messaging.calls.CallMessageType.CALL_FIRST_MISSED
|
|
|
|
|
|
|
|
import org.session.libsession.messaging.calls.CallMessageType.CALL_INCOMING
|
|
|
|
|
|
|
|
import org.session.libsession.messaging.calls.CallMessageType.CALL_MISSED
|
|
|
|
|
|
|
|
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.utilities.ExpirationUtil
|
|
|
|
import org.session.libsession.utilities.ExpirationUtil
|
|
|
|
import org.session.libsession.utilities.truncateIdForDisplay
|
|
|
|
import org.session.libsession.utilities.truncateIdForDisplay
|
|
|
|
|
|
|
|
|
|
|
|
object UpdateMessageBuilder {
|
|
|
|
object UpdateMessageBuilder {
|
|
|
|
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun getSenderName(senderId: String) = storage.getContactWithSessionID(senderId)
|
|
|
|
|
|
|
|
?.displayName(Contact.ContactContext.REGULAR)
|
|
|
|
|
|
|
|
?: truncateIdForDisplay(senderId)
|
|
|
|
|
|
|
|
|
|
|
|
fun buildGroupUpdateMessage(context: Context, updateMessageData: UpdateMessageData, senderId: String? = null, isOutgoing: Boolean = false): String {
|
|
|
|
fun buildGroupUpdateMessage(context: Context, updateMessageData: UpdateMessageData, senderId: String? = null, isOutgoing: Boolean = false): String {
|
|
|
|
var message = ""
|
|
|
|
val updateData = updateMessageData.kind
|
|
|
|
val updateData = updateMessageData.kind ?: return message
|
|
|
|
if (updateData == null || !isOutgoing && senderId == null) return ""
|
|
|
|
if (!isOutgoing && senderId == null) return message
|
|
|
|
val senderName: String = if (isOutgoing) context.getString(R.string.MessageRecord_you)
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
|
|
|
else getSenderName(senderId!!)
|
|
|
|
val senderName: String = if (!isOutgoing) {
|
|
|
|
|
|
|
|
storage.getContactWithSessionID(senderId!!)?.displayName(Contact.ContactContext.REGULAR) ?: truncateIdForDisplay(senderId)
|
|
|
|
|
|
|
|
} else { context.getString(R.string.MessageRecord_you) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when (updateData) {
|
|
|
|
return when (updateData) {
|
|
|
|
is UpdateMessageData.Kind.GroupCreation -> {
|
|
|
|
is UpdateMessageData.Kind.GroupCreation -> if (isOutgoing) {
|
|
|
|
message = if (isOutgoing) {
|
|
|
|
context.getString(R.string.MessageRecord_you_created_a_new_group)
|
|
|
|
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 -> {
|
|
|
|
is UpdateMessageData.Kind.GroupNameChange -> if (isOutgoing) {
|
|
|
|
message = if (isOutgoing) {
|
|
|
|
context.getString(R.string.MessageRecord_you_renamed_the_group_to_s, updateData.name)
|
|
|
|
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(", ") {
|
|
|
|
val members = updateData.updatedMembers.joinToString(", ", transform = ::getSenderName)
|
|
|
|
storage.getContactWithSessionID(it)?.displayName(Contact.ContactContext.REGULAR) ?: it
|
|
|
|
if (isOutgoing) {
|
|
|
|
}
|
|
|
|
|
|
|
|
message = 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 {
|
|
|
|
} else {
|
|
|
|
context.getString(R.string.MessageRecord_s_added_s_to_the_group, senderName, members)
|
|
|
|
context.getString(R.string.MessageRecord_s_added_s_to_the_group, senderName, members)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is UpdateMessageData.Kind.GroupMemberRemoved -> {
|
|
|
|
is UpdateMessageData.Kind.GroupMemberRemoved -> {
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
|
|
|
|
|
|
|
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
|
|
|
|
message = 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 {
|
|
|
|
} else {
|
|
|
@ -57,9 +56,7 @@ object UpdateMessageBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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(", ") {
|
|
|
|
val members = updateData.updatedMembers.joinToString(", ", transform = ::getSenderName)
|
|
|
|
storage.getContactWithSessionID(it)?.displayName(Contact.ContactContext.REGULAR) ?: it
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
} else {
|
|
|
@ -67,22 +64,19 @@ object UpdateMessageBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is UpdateMessageData.Kind.GroupMemberLeft -> {
|
|
|
|
is UpdateMessageData.Kind.GroupMemberLeft -> if (isOutgoing) {
|
|
|
|
message = if (isOutgoing) {
|
|
|
|
context.getString(R.string.MessageRecord_left_group)
|
|
|
|
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 ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return message
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun buildExpirationTimerMessage(context: Context, duration: Long, senderId: String? = null, isOutgoing: Boolean = false): String {
|
|
|
|
fun buildExpirationTimerMessage(context: Context, duration: Long, senderId: String? = null, isOutgoing: Boolean = false): String {
|
|
|
|
if (!isOutgoing && senderId == null) return ""
|
|
|
|
if (!isOutgoing && senderId == null) return ""
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
|
|
|
val senderName: String = if (!isOutgoing) {
|
|
|
|
val senderName: String? = if (!isOutgoing) {
|
|
|
|
getSenderName(senderId!!)
|
|
|
|
storage.getContactWithSessionID(senderId!!)?.displayName(Contact.ContactContext.REGULAR) ?: truncateIdForDisplay(senderId)
|
|
|
|
|
|
|
|
} else { context.getString(R.string.MessageRecord_you) }
|
|
|
|
} else { context.getString(R.string.MessageRecord_you) }
|
|
|
|
return if (duration <= 0) {
|
|
|
|
return if (duration <= 0) {
|
|
|
|
if (isOutgoing) context.getString(R.string.MessageRecord_you_disabled_disappearing_messages)
|
|
|
|
if (isOutgoing) context.getString(R.string.MessageRecord_you_disabled_disappearing_messages)
|
|
|
@ -95,8 +89,7 @@ object UpdateMessageBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun buildDataExtractionMessage(context: Context, kind: DataExtractionNotificationInfoMessage.Kind, senderId: String? = null): String {
|
|
|
|
fun buildDataExtractionMessage(context: Context, kind: DataExtractionNotificationInfoMessage.Kind, senderId: String? = null): String {
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
|
|
|
val senderName = getSenderName(senderId!!)
|
|
|
|
val senderName = storage.getContactWithSessionID(senderId!!)?.displayName(Contact.ContactContext.REGULAR) ?: truncateIdForDisplay(senderId)
|
|
|
|
|
|
|
|
return when (kind) {
|
|
|
|
return when (kind) {
|
|
|
|
DataExtractionNotificationInfoMessage.Kind.SCREENSHOT ->
|
|
|
|
DataExtractionNotificationInfoMessage.Kind.SCREENSHOT ->
|
|
|
|
context.getString(R.string.MessageRecord_s_took_a_screenshot, senderName)
|
|
|
|
context.getString(R.string.MessageRecord_s_took_a_screenshot, senderName)
|
|
|
@ -105,18 +98,12 @@ object UpdateMessageBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun buildCallMessage(context: Context, type: CallMessageType, sender: String): String {
|
|
|
|
fun buildCallMessage(context: Context, type: CallMessageType, sender: String): String =
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
|
|
|
when (type) {
|
|
|
|
val senderName = storage.getContactWithSessionID(sender)?.displayName(Contact.ContactContext.REGULAR) ?: sender
|
|
|
|
CALL_INCOMING -> R.string.MessageRecord_s_called_you
|
|
|
|
return when (type) {
|
|
|
|
CALL_OUTGOING -> R.string.MessageRecord_called_s
|
|
|
|
CallMessageType.CALL_MISSED ->
|
|
|
|
CALL_MISSED, CALL_FIRST_MISSED -> R.string.MessageRecord_missed_call_from
|
|
|
|
context.getString(R.string.MessageRecord_missed_call_from, senderName)
|
|
|
|
}.let {
|
|
|
|
CallMessageType.CALL_INCOMING ->
|
|
|
|
context.getString(it, storage.getContactWithSessionID(sender)?.displayName(Contact.ContactContext.REGULAR) ?: sender)
|
|
|
|
context.getString(R.string.MessageRecord_s_called_you, senderName)
|
|
|
|
|
|
|
|
CallMessageType.CALL_OUTGOING ->
|
|
|
|
|
|
|
|
context.getString(R.string.MessageRecord_called_s, senderName)
|
|
|
|
|
|
|
|
CallMessageType.CALL_FIRST_MISSED ->
|
|
|
|
|
|
|
|
context.getString(R.string.MessageRecord_missed_call_from, senderName)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|