mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-11 18:54:21 +00:00
expiration timer messages generation updated
This commit is contained in:
parent
0578195d61
commit
28cecc0236
@ -89,6 +89,7 @@ import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate;
|
|||||||
import org.session.libsession.messaging.messages.visible.VisibleMessage;
|
import org.session.libsession.messaging.messages.visible.VisibleMessage;
|
||||||
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
|
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
|
||||||
import org.session.libsession.messaging.threads.DistributionTypes;
|
import org.session.libsession.messaging.threads.DistributionTypes;
|
||||||
|
import org.session.libsession.messaging.utilities.UpdateMessageBuilder;
|
||||||
import org.session.libsession.utilities.GroupUtil;
|
import org.session.libsession.utilities.GroupUtil;
|
||||||
import org.session.libsession.utilities.MediaTypes;
|
import org.session.libsession.utilities.MediaTypes;
|
||||||
import org.session.libsignal.libsignal.InvalidMessageException;
|
import org.session.libsignal.libsignal.InvalidMessageException;
|
||||||
@ -808,7 +809,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
DatabaseFactory.getRecipientDatabase(ConversationActivity.this).setExpireMessages(recipient, expirationTime);
|
DatabaseFactory.getRecipientDatabase(ConversationActivity.this).setExpireMessages(recipient, expirationTime);
|
||||||
ExpirationTimerUpdate message = new ExpirationTimerUpdate(expirationTime);
|
ExpirationTimerUpdate message = new ExpirationTimerUpdate(expirationTime);
|
||||||
message.setSentTimestamp(System.currentTimeMillis());
|
message.setSentTimestamp(System.currentTimeMillis());
|
||||||
OutgoingExpirationUpdateMessage outgoingMessage = OutgoingExpirationUpdateMessage.from(message, recipient);
|
String displayedMessage = UpdateMessageBuilder.INSTANCE.buildExpirationTimerMessage(getApplicationContext(), expirationTime, null, false);
|
||||||
|
OutgoingExpirationUpdateMessage outgoingMessage = OutgoingExpirationUpdateMessage.from(message, recipient, displayedMessage);
|
||||||
try {
|
try {
|
||||||
message.setId(DatabaseFactory.getMmsDatabase(ConversationActivity.this).insertMessageOutbox(outgoingMessage, getAllocatedThreadId(ConversationActivity.this), false, null));
|
message.setId(DatabaseFactory.getMmsDatabase(ConversationActivity.this).insertMessageOutbox(outgoingMessage, getAllocatedThreadId(ConversationActivity.this), false, null));
|
||||||
MessageSender.send(message, recipient.getAddress());
|
MessageSender.send(message, recipient.getAddress());
|
||||||
|
@ -175,7 +175,7 @@ public class ConversationUpdateItem extends LinearLayout
|
|||||||
icon.setImageResource(R.drawable.ic_group_grey600_24dp);
|
icon.setImageResource(R.drawable.ic_group_grey600_24dp);
|
||||||
icon.clearColorFilter();
|
icon.clearColorFilter();
|
||||||
|
|
||||||
GroupDescription.Companion.getDescription(getContext(), messageRecord.getBody()).addListener(this);
|
GroupDescription.Companion.getDescription(getContext(), messageRecord.getBody()).addListener(this); //TODO Brice: could be removed if GroupDescription is removed
|
||||||
body.setText(messageRecord.getDisplayBody(getContext()));
|
body.setText(messageRecord.getDisplayBody(getContext()));
|
||||||
|
|
||||||
title.setVisibility(GONE);
|
title.setVisibility(GONE);
|
||||||
|
@ -390,7 +390,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
|
|
||||||
values.put(REPLY_PATH_PRESENT, message.isReplyPathPresent());
|
values.put(REPLY_PATH_PRESENT, message.isReplyPathPresent());
|
||||||
values.put(SERVICE_CENTER, message.getServiceCenterAddress());
|
values.put(SERVICE_CENTER, message.getServiceCenterAddress());
|
||||||
values.put(BODY, message.getMessageBody());
|
values.put(BODY, message.getMessageBody()); //TODO Brice: is that encoded?
|
||||||
values.put(TYPE, type);
|
values.put(TYPE, type);
|
||||||
values.put(THREAD_ID, threadId);
|
values.put(THREAD_ID, threadId);
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import network.loki.messenger.R
|
|||||||
import org.session.libsignal.utilities.logging.Log
|
import org.session.libsignal.utilities.logging.Log
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
|
//TODO Brice: that class should be deprecated
|
||||||
class GroupDescription(context: Context, groupContext: SignalServiceProtos.GroupContext?) {
|
class GroupDescription(context: Context, groupContext: SignalServiceProtos.GroupContext?) {
|
||||||
private val context: Context
|
private val context: Context
|
||||||
private val groupContext: SignalServiceProtos.GroupContext?
|
private val groupContext: SignalServiceProtos.GroupContext?
|
||||||
|
@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.session.libsession.messaging.threads.Address;
|
import org.session.libsession.messaging.threads.Address;
|
||||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||||
|
import org.session.libsession.messaging.utilities.UpdateMessageBuilder;
|
||||||
import org.session.libsession.utilities.SSKEnvironment;
|
import org.session.libsession.utilities.SSKEnvironment;
|
||||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||||
import org.session.libsignal.service.api.messages.SignalServiceGroup;
|
import org.session.libsignal.service.api.messages.SignalServiceGroup;
|
||||||
@ -78,10 +79,11 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM
|
|||||||
GroupContext groupContext = content.getDataMessage().getGroup();
|
GroupContext groupContext = content.getDataMessage().getGroup();
|
||||||
groupInfo = Optional.of(new SignalServiceGroup(groupContext.getId().toByteArray(), SignalServiceGroup.GroupType.SIGNAL));
|
groupInfo = Optional.of(new SignalServiceGroup(groupContext.getId().toByteArray(), SignalServiceGroup.GroupType.SIGNAL));
|
||||||
}
|
}
|
||||||
|
String updateMessage = UpdateMessageBuilder.INSTANCE.buildExpirationTimerMessage(context, duration, senderPublicKey, false);
|
||||||
IncomingMediaMessage mediaMessage = new IncomingMediaMessage(address, content.getDataMessage().getTimestamp(), -1,
|
IncomingMediaMessage mediaMessage = new IncomingMediaMessage(address, content.getDataMessage().getTimestamp(), -1,
|
||||||
duration * 1000L, true,
|
duration * 1000L, true,
|
||||||
false,
|
false,
|
||||||
Optional.absent(),
|
Optional.of(updateMessage),
|
||||||
groupInfo,
|
groupInfo,
|
||||||
Optional.absent(),
|
Optional.absent(),
|
||||||
Optional.absent(),
|
Optional.absent(),
|
||||||
|
@ -501,6 +501,7 @@
|
|||||||
<string name="MessageRecord_s_added_s_to_the_group">%1$s added %2$s to the group.</string>
|
<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_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_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_you_called">You called</string>
|
||||||
<string name="MessageRecord_called_you">Contact called</string>
|
<string name="MessageRecord_called_you">Contact called</string>
|
||||||
<string name="MessageRecord_missed_call">Missed call</string>
|
<string name="MessageRecord_missed_call">Missed call</string>
|
||||||
|
@ -10,15 +10,15 @@ import java.util.LinkedList;
|
|||||||
|
|
||||||
public class OutgoingExpirationUpdateMessage extends OutgoingSecureMediaMessage {
|
public class OutgoingExpirationUpdateMessage extends OutgoingSecureMediaMessage {
|
||||||
|
|
||||||
public OutgoingExpirationUpdateMessage(Recipient recipient, long sentTimeMillis, long expiresIn) {
|
public OutgoingExpirationUpdateMessage(Recipient recipient, String body, long sentTimeMillis, long expiresIn) {
|
||||||
super(recipient, "", new LinkedList<Attachment>(), sentTimeMillis,
|
super(recipient, body, new LinkedList<Attachment>(), sentTimeMillis,
|
||||||
DistributionTypes.CONVERSATION, expiresIn, null, Collections.emptyList(),
|
DistributionTypes.CONVERSATION, expiresIn, null, Collections.emptyList(),
|
||||||
Collections.emptyList());
|
Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OutgoingExpirationUpdateMessage from(ExpirationTimerUpdate message,
|
public static OutgoingExpirationUpdateMessage from(ExpirationTimerUpdate message,
|
||||||
Recipient recipient) {
|
Recipient recipient, String body) {
|
||||||
return new OutgoingExpirationUpdateMessage(recipient, message.getSentTimestamp(), message.getDuration() * 1000);
|
return new OutgoingExpirationUpdateMessage(recipient, body, message.getSentTimestamp(), message.getDuration() * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
package org.session.libsession.messaging.utilities
|
package org.session.libsession.messaging.utilities
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.text.SpannableString
|
||||||
import org.session.libsession.R
|
import org.session.libsession.R
|
||||||
import org.session.libsession.messaging.MessagingConfiguration
|
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.api.messages.SignalServiceGroup
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
|
||||||
|
|
||||||
object UpdateMessageBuilder {
|
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 updateType = groupInfo.type
|
||||||
val senderName: String = if (!isOutgoing) {
|
|
||||||
MessagingConfiguration.shared.storage.getDisplayNameForRecipient(sender) ?: sender
|
|
||||||
} else { sender }
|
|
||||||
var message: String = ""
|
var message: String = ""
|
||||||
|
if (!isOutgoing && sender == null) return message
|
||||||
|
val senderName: String? = if (!isOutgoing) {
|
||||||
|
MessagingConfiguration.shared.storage.getDisplayNameForRecipient(sender!!) ?: sender
|
||||||
|
} else { sender }
|
||||||
|
|
||||||
when (updateType) {
|
when (updateType) {
|
||||||
SignalServiceGroup.Type.NEW_GROUP -> {
|
SignalServiceGroup.Type.NEW_GROUP -> {
|
||||||
message = if (isOutgoing) {
|
message = if (isOutgoing) {
|
||||||
@ -40,13 +44,25 @@ object UpdateMessageBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SignalServiceGroup.Type.MEMBER_REMOVED -> {
|
SignalServiceGroup.Type.MEMBER_REMOVED -> {
|
||||||
val members = groupInfo.members.get().joinToString(", ") {
|
val storage = MessagingConfiguration.shared.storage
|
||||||
MessagingConfiguration.shared.storage.getDisplayNameForRecipient(it) ?: it
|
val userPublicKey = storage.getUserPublicKey()!!
|
||||||
}
|
// 1st case: you are part of the removed members
|
||||||
message = if (isOutgoing) {
|
message = if (userPublicKey in groupInfo.members.get()) {
|
||||||
context.getString(R.string.MessageRecord_you_removed_s_from_the_group, members)
|
if (isOutgoing) {
|
||||||
|
context.getString(R.string.MessageRecord_left_group)
|
||||||
|
} else {
|
||||||
|
context.getString(R.string.MessageRecord_you_were_removed_from_the_group)
|
||||||
|
}
|
||||||
} else {
|
} 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 -> {
|
SignalServiceGroup.Type.QUIT -> {
|
||||||
@ -63,8 +79,20 @@ object UpdateMessageBuilder {
|
|||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildExpirationTimerMessage(): String {
|
fun buildExpirationTimerMessage(context: Context, duration: Int, sender: String? = null, isOutgoing: Boolean = false): String {
|
||||||
return ""
|
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 {
|
fun buildDataExtractionMessage(): String {
|
||||||
|
@ -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_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_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_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_you_called">You called</string>
|
||||||
<string name="MessageRecord_called_you">Contact called</string>
|
<string name="MessageRecord_called_you">Contact called</string>
|
||||||
<string name="MessageRecord_missed_call">Missed call</string>
|
<string name="MessageRecord_missed_call">Missed call</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user