expiration timer messages generation updated

This commit is contained in:
Brice-W
2021-03-23 09:58:17 +11:00
parent 0578195d61
commit 28cecc0236
9 changed files with 56 additions and 21 deletions

View File

@@ -10,15 +10,15 @@ import java.util.LinkedList;
public class OutgoingExpirationUpdateMessage extends OutgoingSecureMediaMessage {
public OutgoingExpirationUpdateMessage(Recipient recipient, long sentTimeMillis, long expiresIn) {
super(recipient, "", new LinkedList<Attachment>(), sentTimeMillis,
public OutgoingExpirationUpdateMessage(Recipient recipient, String body, long sentTimeMillis, long expiresIn) {
super(recipient, body, new LinkedList<Attachment>(), sentTimeMillis,
DistributionTypes.CONVERSATION, expiresIn, null, Collections.emptyList(),
Collections.emptyList());
}
public static OutgoingExpirationUpdateMessage from(ExpirationTimerUpdate message,
Recipient recipient) {
return new OutgoingExpirationUpdateMessage(recipient, message.getSentTimestamp(), message.getDuration() * 1000);
Recipient recipient, String body) {
return new OutgoingExpirationUpdateMessage(recipient, body, message.getSentTimestamp(), message.getDuration() * 1000);
}
@Override

View File

@@ -1,19 +1,23 @@
package org.session.libsession.messaging.utilities
import android.content.Context
import android.text.SpannableString
import org.session.libsession.R
import org.session.libsession.messaging.MessagingConfiguration
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsession.utilities.ExpirationUtil
import org.session.libsignal.service.api.messages.SignalServiceGroup
import org.session.libsignal.service.internal.push.SignalServiceProtos
object UpdateMessageBuilder {
fun buildGroupUpdateMessage(context: Context, groupInfo: SignalServiceGroup, sender: String, isOutgoing: Boolean = false): String {
fun buildGroupUpdateMessage(context: Context, groupInfo: SignalServiceGroup, sender: String? = null, isOutgoing: Boolean = false): String {
val updateType = groupInfo.type
val senderName: String = if (!isOutgoing) {
MessagingConfiguration.shared.storage.getDisplayNameForRecipient(sender) ?: sender
} else { sender }
var message: String = ""
if (!isOutgoing && sender == null) return message
val senderName: String? = if (!isOutgoing) {
MessagingConfiguration.shared.storage.getDisplayNameForRecipient(sender!!) ?: sender
} else { sender }
when (updateType) {
SignalServiceGroup.Type.NEW_GROUP -> {
message = if (isOutgoing) {
@@ -40,13 +44,25 @@ object UpdateMessageBuilder {
}
}
SignalServiceGroup.Type.MEMBER_REMOVED -> {
val members = groupInfo.members.get().joinToString(", ") {
MessagingConfiguration.shared.storage.getDisplayNameForRecipient(it) ?: it
}
message = if (isOutgoing) {
context.getString(R.string.MessageRecord_you_removed_s_from_the_group, members)
val storage = MessagingConfiguration.shared.storage
val userPublicKey = storage.getUserPublicKey()!!
// 1st case: you are part of the removed members
message = if (userPublicKey in groupInfo.members.get()) {
if (isOutgoing) {
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_s_removed_s_from_the_group, senderName, members)
// 2nd case: you are not part of the removed members
val members = groupInfo.members.get().joinToString(", ") {
storage.getDisplayNameForRecipient(it) ?: it
}
if (isOutgoing) {
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)
}
}
}
SignalServiceGroup.Type.QUIT -> {
@@ -63,8 +79,20 @@ object UpdateMessageBuilder {
return message
}
fun buildExpirationTimerMessage(): String {
return ""
fun buildExpirationTimerMessage(context: Context, duration: Int, sender: String? = null, isOutgoing: Boolean = false): String {
val seconds = (duration!! / 1000)
if (!isOutgoing && sender == null) return ""
val senderName: String? = if (!isOutgoing) {
MessagingConfiguration.shared.storage.getDisplayNameForRecipient(sender!!) ?: sender
} else { sender }
return if (seconds <= 0) {
if (isOutgoing) context.getString(R.string.MessageRecord_you_disabled_disappearing_messages)
else context.getString(R.string.MessageRecord_s_disabled_disappearing_messages, senderName)
} else {
val time = ExpirationUtil.getExpirationDisplayValue(context, seconds)
if (isOutgoing)context.getString(R.string.MessageRecord_you_set_disappearing_message_time_to_s, time)
else context.getString(R.string.MessageRecord_s_set_disappearing_message_time_to_s, senderName, time)
}
}
fun buildDataExtractionMessage(): String {

View File

@@ -495,6 +495,7 @@
<string name="MessageRecord_s_added_s_to_the_group">%1$s added %2$s to the group.</string>
<string name="MessageRecord_you_removed_s_from_the_group">You removed %1$s from the group.</string>
<string name="MessageRecord_s_removed_s_from_the_group">%1$s removed %2$s from the group.</string>
<string name="MessageRecord_you_were_removed_from_the_group">You were removed from the group.</string>
<string name="MessageRecord_you_called">You called</string>
<string name="MessageRecord_called_you">Contact called</string>
<string name="MessageRecord_missed_call">Missed call</string>