mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-19 19:38:45 +00:00
WIP: message receiver handler for unsend request
This commit is contained in:
parent
2cb91c3a0e
commit
bf83f9b391
@ -177,6 +177,14 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
|
||||
DatabaseFactory.getLokiMessageDatabase(context).deleteMessage(messageID, isSms)
|
||||
}
|
||||
|
||||
override fun updateMessageAsDeleted(messageID: Long) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getServerHashForMessage(messageID: Long): String? {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getDatabaseAttachment(attachmentId: Long): DatabaseAttachment? {
|
||||
val attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context)
|
||||
return attachmentDatabase.getAttachment(AttachmentId(attachmentId, 0))
|
||||
|
@ -49,6 +49,7 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
private final long expireStarted;
|
||||
private final boolean unidentified;
|
||||
public final long id;
|
||||
public final boolean deleted;
|
||||
|
||||
public abstract boolean isMms();
|
||||
public abstract boolean isMmsNotification();
|
||||
@ -71,6 +72,7 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
this.expiresIn = expiresIn;
|
||||
this.expireStarted = expireStarted;
|
||||
this.unidentified = unidentified;
|
||||
this.deleted = false;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
@ -103,7 +105,9 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
|
||||
@Override
|
||||
public SpannableString getDisplayBody(@NonNull Context context) {
|
||||
if (isGroupUpdateMessage()) {
|
||||
if (this.deleted) {
|
||||
return new SpannableString("This message has been deleted."); // TODO: localize
|
||||
} else if (isGroupUpdateMessage()) {
|
||||
UpdateMessageData updateMessageData = UpdateMessageData.Companion.fromJSON(getBody());
|
||||
return new SpannableString(UpdateMessageBuilder.INSTANCE.buildGroupUpdateMessage(context, updateMessageData, getIndividualRecipient().getAddress().serialize(), isOutgoing()));
|
||||
} else if (isExpirationTimerUpdate()) {
|
||||
|
@ -13,6 +13,8 @@ interface MessageDataProvider {
|
||||
fun getMessageID(serverID: Long): Long?
|
||||
fun getMessageID(serverId: Long, threadId: Long): Pair<Long, Boolean>?
|
||||
fun deleteMessage(messageID: Long, isSms: Boolean)
|
||||
fun updateMessageAsDeleted(messageID: Long)
|
||||
fun getServerHashForMessage(messageID: Long): String?
|
||||
fun getDatabaseAttachment(attachmentId: Long): DatabaseAttachment?
|
||||
fun getAttachmentStream(attachmentId: Long): SessionServiceAttachmentStream?
|
||||
fun getAttachmentPointer(attachmentId: Long): SessionServiceAttachmentPointer?
|
||||
|
@ -94,6 +94,7 @@ object MessageReceiver {
|
||||
DataExtractionNotification.fromProto(proto) ?:
|
||||
ExpirationTimerUpdate.fromProto(proto) ?:
|
||||
ConfigurationMessage.fromProto(proto) ?:
|
||||
UnsendRequest.fromProto(proto) ?:
|
||||
VisibleMessage.fromProto(proto) ?: throw Error.UnknownMessage
|
||||
// Ignore self send if needed
|
||||
if (!message.isSelfSendValid && sender == userPublicKey) throw Error.SelfSend
|
||||
|
@ -14,6 +14,7 @@ import org.session.libsession.messaging.sending_receiving.link_preview.LinkPrevi
|
||||
import org.session.libsession.messaging.sending_receiving.notifications.PushNotificationAPI
|
||||
import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPollerV2
|
||||
import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel
|
||||
import org.session.libsession.snode.SnodeAPI
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.GroupRecord
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
@ -49,6 +50,7 @@ fun MessageReceiver.handle(message: Message, proto: SignalServiceProtos.Content,
|
||||
is ExpirationTimerUpdate -> handleExpirationTimerUpdate(message)
|
||||
is DataExtractionNotification -> handleDataExtractionNotification(message)
|
||||
is ConfigurationMessage -> handleConfigurationMessage(message)
|
||||
is UnsendRequest -> handleUnsendRequest(message)
|
||||
is VisibleMessage -> handleVisibleMessage(message, proto, openGroupID)
|
||||
}
|
||||
}
|
||||
@ -145,6 +147,24 @@ private fun handleConfigurationMessage(message: ConfigurationMessage) {
|
||||
}
|
||||
storage.addContacts(message.contacts)
|
||||
}
|
||||
|
||||
fun MessageReceiver.handleUnsendRequest(message: UnsendRequest) {
|
||||
if (message.sender != message.author) { return }
|
||||
val context = MessagingModuleConfiguration.shared.context
|
||||
val storage = MessagingModuleConfiguration.shared.storage
|
||||
val messageDataProvider = MessagingModuleConfiguration.shared.messageDataProvider
|
||||
val timestamp = message.timestamp ?: return
|
||||
val author = message.author ?: return
|
||||
val messageIdToDelete = storage.getMessageIdInDatabase(timestamp, author) ?: return
|
||||
if (!messageDataProvider.isOutgoingMessage(messageIdToDelete)) {
|
||||
// TODO: Mark this message as read
|
||||
// TODO: Cancel the notification of this message
|
||||
}
|
||||
messageDataProvider.getServerHashForMessage(messageIdToDelete)?.let { serverHash ->
|
||||
SnodeAPI.deleteMessage(author, listOf(serverHash))
|
||||
}
|
||||
messageDataProvider.updateMessageAsDeleted(messageIdToDelete)
|
||||
}
|
||||
//endregion
|
||||
|
||||
// region Visible Messages
|
||||
|
Loading…
x
Reference in New Issue
Block a user