mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 20:57:41 +00:00
new approach in update saving
This commit is contained in:
@@ -5,10 +5,12 @@ import static org.session.libsignal.service.internal.push.SignalServiceProtos.Gr
|
||||
public class IncomingGroupMessage extends IncomingTextMessage {
|
||||
|
||||
private final String groupID;
|
||||
private final boolean updateMessage;
|
||||
|
||||
public IncomingGroupMessage(IncomingTextMessage base, String groupID, String body) {
|
||||
public IncomingGroupMessage(IncomingTextMessage base, String groupID, String body, boolean updateMessage) {
|
||||
super(base, body);
|
||||
this.groupID = groupID;
|
||||
this.updateMessage = updateMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -16,4 +18,6 @@ public class IncomingGroupMessage extends IncomingTextMessage {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isUpdateMessage() { return updateMessage; }
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package org.session.libsession.messaging.messages.signal;
|
||||
|
||||
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
|
||||
import org.session.libsession.messaging.threads.DistributionTypes;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
@@ -8,18 +7,15 @@ import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
||||
// TODO this class could be deleted if its usage in MmsDatabase.getOutgoingMessage is replaced by something elsex
|
||||
public class OutgoingExpirationUpdateMessage extends OutgoingSecureMediaMessage {
|
||||
|
||||
public OutgoingExpirationUpdateMessage(Recipient recipient, long sentTimeMillis, long expiresIn) {
|
||||
super(recipient, "", new LinkedList<Attachment>(), sentTimeMillis,
|
||||
DistributionTypes.CONVERSATION, expiresIn, true, null, Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
}
|
||||
private final String groupId;
|
||||
|
||||
public static OutgoingExpirationUpdateMessage from(ExpirationTimerUpdate message,
|
||||
Recipient recipient) {
|
||||
return new OutgoingExpirationUpdateMessage(recipient, message.getSentTimestamp(), message.getDuration() * 1000);
|
||||
public OutgoingExpirationUpdateMessage(Recipient recipient, long sentTimeMillis, long expiresIn, String groupId) {
|
||||
super(recipient, "", new LinkedList<Attachment>(), sentTimeMillis,
|
||||
DistributionTypes.CONVERSATION, expiresIn, null, Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,4 +23,13 @@ public class OutgoingExpirationUpdateMessage extends OutgoingSecureMediaMessage
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGroup() {
|
||||
return groupId != null;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -20,23 +20,7 @@ import java.util.List;
|
||||
public class OutgoingGroupMediaMessage extends OutgoingSecureMediaMessage {
|
||||
|
||||
private final String groupID;
|
||||
|
||||
public OutgoingGroupMediaMessage(@NonNull Recipient recipient,
|
||||
@NonNull String body,
|
||||
@Nullable String groupId,
|
||||
@NonNull List<Attachment> avatar,
|
||||
long sentTimeMillis,
|
||||
long expiresIn,
|
||||
@Nullable QuoteModel quote,
|
||||
@NonNull List<Contact> contacts,
|
||||
@NonNull List<LinkPreview> previews)
|
||||
throws IOException
|
||||
{
|
||||
super(recipient, body, avatar, sentTimeMillis,
|
||||
DistributionTypes.CONVERSATION, expiresIn, false, quote, contacts, previews);
|
||||
|
||||
this.groupID = groupId;
|
||||
}
|
||||
private final boolean isUpdateMessage;
|
||||
|
||||
public OutgoingGroupMediaMessage(@NonNull Recipient recipient,
|
||||
@NonNull String body,
|
||||
@@ -44,7 +28,7 @@ public class OutgoingGroupMediaMessage extends OutgoingSecureMediaMessage {
|
||||
@Nullable final Attachment avatar,
|
||||
long sentTime,
|
||||
long expireIn,
|
||||
boolean expirationUpdate,
|
||||
boolean updateMessage,
|
||||
@Nullable QuoteModel quote,
|
||||
@NonNull List<Contact> contacts,
|
||||
@NonNull List<LinkPreview> previews)
|
||||
@@ -52,9 +36,10 @@ public class OutgoingGroupMediaMessage extends OutgoingSecureMediaMessage {
|
||||
super(recipient, body,
|
||||
new LinkedList<Attachment>() {{if (avatar != null) add(avatar);}},
|
||||
sentTime,
|
||||
DistributionTypes.CONVERSATION, expireIn, expirationUpdate, quote, contacts, previews);
|
||||
DistributionTypes.CONVERSATION, expireIn, quote, contacts, previews);
|
||||
|
||||
this.groupID = groupId;
|
||||
this.isUpdateMessage = updateMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,4 +50,8 @@ public class OutgoingGroupMediaMessage extends OutgoingSecureMediaMessage {
|
||||
public String getGroupId() {
|
||||
return groupID;
|
||||
}
|
||||
|
||||
public boolean isUpdateMessage() {
|
||||
return isUpdateMessage;
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,6 @@ public class OutgoingMediaMessage {
|
||||
private final int distributionType;
|
||||
private final int subscriptionId;
|
||||
private final long expiresIn;
|
||||
private final boolean expirationUpdate;
|
||||
private final QuoteModel outgoingQuote;
|
||||
|
||||
private final List<NetworkFailure> networkFailures = new LinkedList<>();
|
||||
@@ -37,7 +36,6 @@ public class OutgoingMediaMessage {
|
||||
public OutgoingMediaMessage(Recipient recipient, String message,
|
||||
List<Attachment> attachments, long sentTimeMillis,
|
||||
int subscriptionId, long expiresIn,
|
||||
boolean expirationUpdate,
|
||||
int distributionType,
|
||||
@Nullable QuoteModel outgoingQuote,
|
||||
@NonNull List<Contact> contacts,
|
||||
@@ -52,7 +50,6 @@ public class OutgoingMediaMessage {
|
||||
this.attachments = attachments;
|
||||
this.subscriptionId = subscriptionId;
|
||||
this.expiresIn = expiresIn;
|
||||
this.expirationUpdate = expirationUpdate;
|
||||
this.outgoingQuote = outgoingQuote;
|
||||
|
||||
this.contacts.addAll(contacts);
|
||||
@@ -69,7 +66,6 @@ public class OutgoingMediaMessage {
|
||||
this.sentTimeMillis = that.sentTimeMillis;
|
||||
this.subscriptionId = that.subscriptionId;
|
||||
this.expiresIn = that.expiresIn;
|
||||
this.expirationUpdate = that.expirationUpdate;
|
||||
this.outgoingQuote = that.outgoingQuote;
|
||||
|
||||
this.identityKeyMismatches.addAll(that.identityKeyMismatches);
|
||||
@@ -89,7 +85,7 @@ public class OutgoingMediaMessage {
|
||||
previews = Collections.singletonList(linkPreview);
|
||||
}
|
||||
return new OutgoingMediaMessage(recipient, message.getText(), attachments, message.getSentTimestamp(), -1,
|
||||
recipient.getExpireMessages() * 1000, false, DistributionTypes.DEFAULT, outgoingQuote, Collections.emptyList(),
|
||||
recipient.getExpireMessages() * 1000, DistributionTypes.DEFAULT, outgoingQuote, Collections.emptyList(),
|
||||
previews, Collections.emptyList(), Collections.emptyList());
|
||||
}
|
||||
|
||||
@@ -113,7 +109,7 @@ public class OutgoingMediaMessage {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isExpirationUpdate() { return expirationUpdate; }
|
||||
public boolean isExpirationUpdate() { return false; }
|
||||
|
||||
public long getSentTimeMillis() {
|
||||
return sentTimeMillis;
|
||||
|
@@ -19,12 +19,11 @@ public class OutgoingSecureMediaMessage extends OutgoingMediaMessage {
|
||||
long sentTimeMillis,
|
||||
int distributionType,
|
||||
long expiresIn,
|
||||
boolean expirationUpdate,
|
||||
@Nullable QuoteModel quote,
|
||||
@NonNull List<Contact> contacts,
|
||||
@NonNull List<LinkPreview> previews)
|
||||
{
|
||||
super(recipient, body, attachments, sentTimeMillis, -1, expiresIn, expirationUpdate, distributionType, quote, contacts, previews, Collections.emptyList(), Collections.emptyList());
|
||||
super(recipient, body, attachments, sentTimeMillis, -1, expiresIn, distributionType, quote, contacts, previews, Collections.emptyList(), Collections.emptyList());
|
||||
}
|
||||
|
||||
public OutgoingSecureMediaMessage(OutgoingMediaMessage base) {
|
||||
|
@@ -1,17 +1,15 @@
|
||||
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
|
||||
|
||||
object UpdateMessageBuilder {
|
||||
|
||||
fun buildGroupUpdateMessage(context: Context, groupInfo: SignalServiceGroup, sender: String? = null, isOutgoing: Boolean = false): String {
|
||||
val updateType = groupInfo.type
|
||||
fun buildGroupUpdateMessage(context: Context, updateData: UpdateMessageData, sender: String? = null, isOutgoing: Boolean = false): String {
|
||||
val updateType = updateData.type
|
||||
var message: String = ""
|
||||
if (!isOutgoing && sender == null) return message
|
||||
val senderName: String? = if (!isOutgoing) {
|
||||
@@ -28,13 +26,13 @@ object UpdateMessageBuilder {
|
||||
}
|
||||
SignalServiceGroup.Type.NAME_CHANGE -> {
|
||||
message = if (isOutgoing) {
|
||||
context.getString(R.string.MessageRecord_you_renamed_the_group_to_s, groupInfo.name.get())
|
||||
context.getString(R.string.MessageRecord_you_renamed_the_group_to_s, updateData.groupName)
|
||||
} else {
|
||||
context.getString(R.string.MessageRecord_s_renamed_the_group_to_s, senderName, groupInfo.name.get())
|
||||
context.getString(R.string.MessageRecord_s_renamed_the_group_to_s, senderName, updateData.groupName)
|
||||
}
|
||||
}
|
||||
SignalServiceGroup.Type.MEMBER_ADDED -> {
|
||||
val members = groupInfo.members.get().joinToString(", ") {
|
||||
val members = updateData.updatedMembers.joinToString(", ") {
|
||||
MessagingConfiguration.shared.storage.getDisplayNameForRecipient(it) ?: it
|
||||
}
|
||||
message = if (isOutgoing) {
|
||||
@@ -47,7 +45,7 @@ object UpdateMessageBuilder {
|
||||
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()) {
|
||||
message = if (userPublicKey in updateData.updatedMembers) {
|
||||
if (isOutgoing) {
|
||||
context.getString(R.string.MessageRecord_left_group)
|
||||
} else {
|
||||
@@ -55,7 +53,7 @@ object UpdateMessageBuilder {
|
||||
}
|
||||
} else {
|
||||
// 2nd case: you are not part of the removed members
|
||||
val members = groupInfo.members.get().joinToString(", ") {
|
||||
val members = updateData.updatedMembers.joinToString(", ") {
|
||||
storage.getDisplayNameForRecipient(it) ?: it
|
||||
}
|
||||
if (isOutgoing) {
|
||||
@@ -94,14 +92,8 @@ object UpdateMessageBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO one this is merged in
|
||||
//TODO do this when the current update is merged
|
||||
fun buildDataExtractionMessage(): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
/*TODO retro compatibilite old update messages (MessageRecord)
|
||||
ThreadRecord to display specific messages? (hard unless we can get the incoming / outgoing messages)
|
||||
Clean code (comments, logs...)
|
||||
Delete OutgoingExpirationUpdateMessage (check how its used in MmsDatabase l.520 to save messages and how to do the same when getting messages from db without breaking it)
|
||||
*/
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package org.session.libsession.messaging.utilities
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException
|
||||
import org.session.libsignal.service.api.messages.SignalServiceGroup
|
||||
import org.session.libsignal.utilities.JsonUtil
|
||||
import org.session.libsignal.utilities.logging.Log
|
||||
import java.util.*
|
||||
|
||||
// class used to save update messages details
|
||||
class UpdateMessageData () {
|
||||
|
||||
var type: SignalServiceGroup.Type = SignalServiceGroup.Type.UNKNOWN
|
||||
var groupName: String? = null
|
||||
var updatedMembers: Collection<String> = Collections.emptyList()
|
||||
|
||||
constructor(type: SignalServiceGroup.Type, groupName: String?, updatedMembers: Collection<String>): this() {
|
||||
this.type = type
|
||||
this.groupName = groupName
|
||||
this.updatedMembers = updatedMembers
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TAG = UpdateMessageData::class.simpleName
|
||||
|
||||
fun buildGroupUpdate(type: SignalServiceGroup.Type, name: String, members: Collection<String>): UpdateMessageData {
|
||||
return when(type) {
|
||||
SignalServiceGroup.Type.NAME_CHANGE -> UpdateMessageData(type, name, Collections.emptyList())
|
||||
SignalServiceGroup.Type.MEMBER_ADDED -> UpdateMessageData(type,null, members)
|
||||
SignalServiceGroup.Type.MEMBER_REMOVED -> UpdateMessageData(type,null, members)
|
||||
else -> UpdateMessageData(type,null, Collections.emptyList())
|
||||
}
|
||||
}
|
||||
|
||||
fun fromJSON(json: String): UpdateMessageData {
|
||||
return try {
|
||||
JsonUtil.fromJson(json, UpdateMessageData::class.java)
|
||||
} catch (e: JsonParseException) {
|
||||
Log.e(TAG, "${e.message}")
|
||||
UpdateMessageData(SignalServiceGroup.Type.UNKNOWN, null, Collections.emptyList())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun toJSON(): String {
|
||||
return JsonUtil.toJson(this)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user