mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 19:43:38 +00:00
handle home screen update for unsend request
This commit is contained in:
parent
8b6b02911f
commit
9ab285c3be
@ -178,11 +178,18 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
|
||||
DatabaseFactory.getLokiMessageDatabase(context).deleteMessageServerHash(messageID)
|
||||
}
|
||||
|
||||
override fun updateMessageAsDeleted(messageID: Long) {
|
||||
val smsDatabase = DatabaseFactory.getSmsDatabase(context)
|
||||
override fun updateMessageAsDeleted(timestamp: Long, author: String) {
|
||||
val database = DatabaseFactory.getMmsSmsDatabase(context)
|
||||
val address = Address.fromSerialized(author)
|
||||
val message = database.getMessageFor(timestamp, address)!!
|
||||
if (message.isMms) {
|
||||
val mmsDatabase = DatabaseFactory.getMmsDatabase(context)
|
||||
smsDatabase.markAsDeleted(messageID)
|
||||
mmsDatabase.markAsDeleted(messageID)
|
||||
mmsDatabase.markAsDeleted(message.id, message.isRead)
|
||||
} else {
|
||||
val smsDatabase = DatabaseFactory.getSmsDatabase(context)
|
||||
smsDatabase.markAsDeleted(message.id, message.isRead)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun getServerHashForMessage(messageID: Long): String? {
|
||||
|
@ -38,7 +38,7 @@ public abstract class MessagingDatabase extends Database implements MmsSmsColumn
|
||||
public abstract void markAsSent(long messageId, boolean secure);
|
||||
public abstract void markUnidentified(long messageId, boolean unidentified);
|
||||
|
||||
public abstract void markAsDeleted(long messageId);
|
||||
public abstract void markAsDeleted(long messageId, boolean read);
|
||||
|
||||
public void addMismatchedIdentity(long messageId, Address address, IdentityKey identityKey) {
|
||||
try {
|
||||
|
@ -392,7 +392,7 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAsDeleted(long messageId) {
|
||||
public void markAsDeleted(long messageId, boolean read) {
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(READ, 1);
|
||||
@ -403,6 +403,7 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
ThreadUtils.queue(() -> attachmentDatabase.deleteAttachmentsForMessage(messageId));
|
||||
|
||||
long threadId = getThreadIdForMessage(messageId);
|
||||
if (!read) { DatabaseFactory.getThreadDatabase(context).decrementUnread(threadId, 1); }
|
||||
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_DELETED_TYPE, Optional.of(threadId));
|
||||
notifyConversationListeners(threadId);
|
||||
}
|
||||
|
@ -129,7 +129,9 @@ public class MmsSmsDatabase extends Database {
|
||||
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
||||
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
||||
|
||||
return queryTables(PROJECTION, selection, order, "1");
|
||||
// FIXME: Not sure if this will cause any performance issues
|
||||
// return queryTables(PROJECTION, selection, order, "1");
|
||||
return queryTables(PROJECTION, selection, order, null);
|
||||
}
|
||||
|
||||
public long getLastMessageID(long threadId) {
|
||||
|
@ -184,12 +184,14 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAsDeleted(long messageId) {
|
||||
public void markAsDeleted(long messageId, boolean read) {
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(READ, 1);
|
||||
contentValues.put(BODY, "");
|
||||
database.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(messageId)});
|
||||
long threadId = getThreadIdForMessage(messageId);
|
||||
if (!read) { DatabaseFactory.getThreadDatabase(context).decrementUnread(threadId, 1); }
|
||||
updateTypeBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_DELETED_TYPE);
|
||||
}
|
||||
|
||||
|
@ -294,6 +294,14 @@ public class ThreadDatabase extends Database {
|
||||
String.valueOf(threadId)});
|
||||
}
|
||||
|
||||
public void decrementUnread(long threadId, int amount) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
db.execSQL("UPDATE " + TABLE_NAME + " SET " + READ + " = 0, " +
|
||||
UNREAD_COUNT + " = " + UNREAD_COUNT + " - ? WHERE " + ID + " = ?",
|
||||
new String[] {String.valueOf(amount),
|
||||
String.valueOf(threadId)});
|
||||
}
|
||||
|
||||
public void setDistributionType(long threadId, int distributionType) {
|
||||
ContentValues contentValues = new ContentValues(1);
|
||||
contentValues.put(TYPE, distributionType);
|
||||
@ -536,9 +544,14 @@ public class ThreadDatabase extends Database {
|
||||
|
||||
try {
|
||||
reader = mmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId));
|
||||
MessageRecord record;
|
||||
|
||||
if (reader != null && (record = reader.getNext()) != null) {
|
||||
MessageRecord record = null;
|
||||
if (reader != null) {
|
||||
record = reader.getNext();
|
||||
while (record != null && record.isDeleted()) {
|
||||
record = reader.getNext();
|
||||
}
|
||||
}
|
||||
if (record != null && !record.isDeleted()) {
|
||||
updateThread(threadId, count, getFormattedBodyFor(record), getAttachmentUriFor(record),
|
||||
record.getTimestamp(), record.getDeliveryStatus(), record.getDeliveryReceiptCount(),
|
||||
record.getType(), unarchive, record.getExpiresIn(), record.getReadReceiptCount());
|
||||
|
@ -13,7 +13,7 @@ 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 updateMessageAsDeleted(timestamp: Long, author: String)
|
||||
fun getServerHashForMessage(messageID: Long): String?
|
||||
fun getDatabaseAttachment(attachmentId: Long): DatabaseAttachment?
|
||||
fun getAttachmentStream(attachmentId: Long): SessionServiceAttachmentStream?
|
||||
|
@ -157,13 +157,12 @@ fun MessageReceiver.handleUnsendRequest(message: UnsendRequest) {
|
||||
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)
|
||||
messageDataProvider.updateMessageAsDeleted(timestamp, author)
|
||||
}
|
||||
//endregion
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user