mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Start disappearing message timer on read sync messages
Fixes #5733 // FREEBIE
This commit is contained in:
parent
8b9e0b7ab8
commit
68b48ebe00
@ -486,10 +486,11 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setTimestampRead(SyncMessageId messageId) {
|
||||
MmsAddressDatabase addressDatabase = DatabaseFactory.getMmsAddressDatabase(context);
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
Cursor cursor = null;
|
||||
public List<Pair<Long, Long>> setTimestampRead(SyncMessageId messageId, long expireStarted) {
|
||||
MmsAddressDatabase addressDatabase = DatabaseFactory.getMmsAddressDatabase(context);
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
List<Pair<Long, Long>> expiring = new LinkedList<>();
|
||||
Cursor cursor = null;
|
||||
|
||||
try {
|
||||
cursor = database.query(TABLE_NAME, new String[] {ID, THREAD_ID, MESSAGE_BOX}, DATE_SENT + " = ?", new String[] {String.valueOf(messageId.getTimetamp())}, null, null, null, null);
|
||||
@ -503,11 +504,19 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
String theirAddress = canonicalizeNumberOrGroup(context, storedAddress);
|
||||
|
||||
if (ourAddress.equals(theirAddress) || GroupUtil.isEncodedGroup(theirAddress)) {
|
||||
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
||||
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
|
||||
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
||||
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
|
||||
long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(EXPIRES_IN));
|
||||
|
||||
database.execSQL("UPDATE " + TABLE_NAME + " SET " + READ + " = 1 WHERE " + ID + " = ?",
|
||||
new String[] {String.valueOf(id)});
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(READ, 1);
|
||||
|
||||
if (expiresIn > 0) {
|
||||
values.put(EXPIRE_STARTED, expireStarted);
|
||||
expiring.add(new Pair<>(id, expiresIn));
|
||||
}
|
||||
|
||||
database.update(TABLE_NAME, values, ID_WHERE, new String[]{String.valueOf(id)});
|
||||
|
||||
DatabaseFactory.getThreadDatabase(context).updateReadState(threadId);
|
||||
notifyConversationListeners(threadId);
|
||||
@ -521,6 +530,8 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return expiring;
|
||||
}
|
||||
|
||||
public void setAllMessagesRead() {
|
||||
|
@ -348,12 +348,13 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setTimestampRead(SyncMessageId messageId) {
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
Cursor cursor = null;
|
||||
public List<Pair<Long, Long>> setTimestampRead(SyncMessageId messageId, long expireStarted) {
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
List<Pair<Long, Long>> expiring = new LinkedList<>();
|
||||
Cursor cursor = null;
|
||||
|
||||
try {
|
||||
cursor = database.query(TABLE_NAME, new String[] {ID, THREAD_ID, ADDRESS, TYPE},
|
||||
cursor = database.query(TABLE_NAME, new String[] {ID, THREAD_ID, ADDRESS, TYPE, EXPIRES_IN},
|
||||
DATE_SENT + " = ?", new String[] {String.valueOf(messageId.getTimetamp())},
|
||||
null, null, null, null);
|
||||
|
||||
@ -363,11 +364,18 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
String ourAddress = canonicalizeNumber(context, cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS)));
|
||||
|
||||
if (ourAddress.equals(theirAddress)) {
|
||||
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
|
||||
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
||||
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
|
||||
long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(EXPIRES_IN));
|
||||
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(READ, 1);
|
||||
|
||||
if (expiresIn > 0) {
|
||||
contentValues.put(EXPIRE_STARTED, expireStarted);
|
||||
expiring.add(new Pair<>(id, expiresIn));
|
||||
}
|
||||
|
||||
database.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {cursor.getLong(cursor.getColumnIndexOrThrow(ID)) + ""});
|
||||
|
||||
DatabaseFactory.getThreadDatabase(context).updateReadState(threadId);
|
||||
@ -380,6 +388,8 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
} finally {
|
||||
if (cursor != null) cursor.close();
|
||||
}
|
||||
|
||||
return expiring;
|
||||
}
|
||||
|
||||
public void setAllMessagesRead() {
|
||||
|
@ -151,7 +151,7 @@ public class PushDecryptJob extends ContextJob {
|
||||
|
||||
if (syncMessage.getSent().isPresent()) handleSynchronizeSentMessage(masterSecret, envelope, syncMessage.getSent().get(), smsMessageId);
|
||||
else if (syncMessage.getRequest().isPresent()) handleSynchronizeRequestMessage(masterSecret, syncMessage.getRequest().get());
|
||||
else if (syncMessage.getRead().isPresent()) handleSynchronizeReadMessage(masterSecret, syncMessage.getRead().get());
|
||||
else if (syncMessage.getRead().isPresent()) handleSynchronizeReadMessage(masterSecret, syncMessage.getRead().get(), envelope.getTimestamp());
|
||||
else Log.w(TAG, "Contains no known sync types...");
|
||||
}
|
||||
|
||||
@ -295,11 +295,24 @@ public class PushDecryptJob extends ContextJob {
|
||||
}
|
||||
|
||||
private void handleSynchronizeReadMessage(@NonNull MasterSecretUnion masterSecret,
|
||||
@NonNull List<ReadMessage> readMessages)
|
||||
@NonNull List<ReadMessage> readMessages,
|
||||
long envelopeTimestamp)
|
||||
{
|
||||
for (ReadMessage readMessage : readMessages) {
|
||||
DatabaseFactory.getSmsDatabase(context).setTimestampRead(new SyncMessageId(readMessage.getSender(), readMessage.getTimestamp()));
|
||||
DatabaseFactory.getMmsDatabase(context).setTimestampRead(new SyncMessageId(readMessage.getSender(), readMessage.getTimestamp()));
|
||||
List<Pair<Long, Long>> expiringText = DatabaseFactory.getSmsDatabase(context).setTimestampRead(new SyncMessageId(readMessage.getSender(), readMessage.getTimestamp()), envelopeTimestamp);
|
||||
List<Pair<Long, Long>> expiringMedia = DatabaseFactory.getMmsDatabase(context).setTimestampRead(new SyncMessageId(readMessage.getSender(), readMessage.getTimestamp()), envelopeTimestamp);
|
||||
|
||||
for (Pair<Long, Long> expiringMessage : expiringText) {
|
||||
ApplicationContext.getInstance(context)
|
||||
.getExpiringMessageManager()
|
||||
.scheduleDeletion(expiringMessage.first, false, envelopeTimestamp, expiringMessage.second);
|
||||
}
|
||||
|
||||
for (Pair<Long, Long> expiringMessage : expiringMedia) {
|
||||
ApplicationContext.getInstance(context)
|
||||
.getExpiringMessageManager()
|
||||
.scheduleDeletion(expiringMessage.first, true, envelopeTimestamp, expiringMessage.second);
|
||||
}
|
||||
}
|
||||
|
||||
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull());
|
||||
|
Loading…
x
Reference in New Issue
Block a user