mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Switch to new group chat message deletion endpoint
This commit is contained in:
parent
fcefbac97b
commit
7273eb2774
@ -127,7 +127,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateGroupChatAuthTokenTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateLastMessageServerIDTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateFirstMessageServerIDTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateLastDeletionServerIDTableCommand());
|
||||
db.execSQL(LokiPreKeyBundleDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiPreKeyRecordDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiMessageDatabase.getCreateTableCommand());
|
||||
@ -489,7 +489,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
if (oldVersion < lokiV1) {
|
||||
db.execSQL(LokiAPIDatabase.getCreateGroupChatAuthTokenTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateLastMessageServerIDTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateFirstMessageServerIDTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateLastDeletionServerIDTableCommand());
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
@ -304,7 +304,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
else if (message.isGroupUpdate()) handleGroupMessage(content, message, smsMessageId);
|
||||
else if (message.isExpirationUpdate()) handleExpirationUpdate(content, message, smsMessageId);
|
||||
else if (isMediaMessage) handleMediaMessage(content, message, smsMessageId);
|
||||
else if (message.getBody().isPresent()) handleTextMessage(content, message, smsMessageId);
|
||||
else if (message.getBody().isPresent()) handleTextMessage(content, message, smsMessageId, Optional.absent());
|
||||
|
||||
if (message.getGroupInfo().isPresent() && groupDatabase.isUnknownGroup(GroupUtil.getEncodedId(message.getGroupInfo().get().getGroupId(), false))) {
|
||||
handleUnknownGroupMessage(content, message.getGroupInfo().get());
|
||||
@ -895,8 +895,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
}
|
||||
|
||||
public void handleTextMessage(@NonNull SignalServiceContent content,
|
||||
@NonNull SignalServiceDataMessage message,
|
||||
@NonNull Optional<Long> smsMessageId)
|
||||
@NonNull SignalServiceDataMessage message,
|
||||
@NonNull Optional<Long> smsMessageId,
|
||||
@Nullable Optional<Long> messageServerIDOrNull)
|
||||
throws StorageFailedException
|
||||
{
|
||||
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
|
||||
@ -928,6 +929,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
else threadId = null;
|
||||
|
||||
if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get());
|
||||
|
||||
if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) {
|
||||
long messageID = insertResult.get().getMessageId();
|
||||
long messageServerID = messageServerIDOrNull.get();
|
||||
DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID);
|
||||
}
|
||||
}
|
||||
|
||||
if (threadId != null) {
|
||||
|
@ -38,11 +38,11 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
private val lastMessageServerIDCacheIndex = "loki_api_last_message_server_id_cache_index"
|
||||
private val lastMessageServerID = "last_message_server_id"
|
||||
@JvmStatic val createLastMessageServerIDTableCommand = "CREATE TABLE $lastMessageServerIDCache ($lastMessageServerIDCacheIndex STRING PRIMARY KEY, $lastMessageServerID INTEGER DEFAULT 0);"
|
||||
// First message server ID cache
|
||||
private val firstMessageServerIDCache = "loki_api_first_message_server_id_cache"
|
||||
private val firstMessageServerIDCacheIndex = "loki_api_first_message_server_id_cache_index"
|
||||
private val firstMessageServerID = "first_message_server_id"
|
||||
@JvmStatic val createFirstMessageServerIDTableCommand = "CREATE TABLE $firstMessageServerIDCache ($firstMessageServerIDCacheIndex STRING PRIMARY KEY, $firstMessageServerID INTEGER DEFAULT 0);"
|
||||
// Last deletion server ID cache
|
||||
private val lastDeletionServerIDCache = "loki_api_last_deletion_server_id_cache"
|
||||
private val lastDeletionServerIDCacheIndex = "loki_api_last_deletion_server_id_cache_index"
|
||||
private val lastDeletionServerID = "last_deletion_server_id"
|
||||
@JvmStatic val createLastDeletionServerIDTableCommand = "CREATE TABLE $lastDeletionServerIDCache ($lastDeletionServerIDCacheIndex STRING PRIMARY KEY, $lastDeletionServerID INTEGER DEFAULT 0);"
|
||||
}
|
||||
|
||||
override fun getSwarmCache(hexEncodedPublicKey: String): Set<LokiAPITarget>? {
|
||||
@ -125,19 +125,19 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
database.insertOrUpdate(lastMessageServerIDCache, row, "$lastMessageServerIDCacheIndex = ?", wrap(index))
|
||||
}
|
||||
|
||||
override fun getFirstMessageServerID(group: Long, server: String): Long? {
|
||||
override fun getLastDeletionServerID(group: Long, server: String): Long? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
val index = "$server.$group"
|
||||
return database.get(firstMessageServerIDCache, "$firstMessageServerIDCacheIndex = ?", wrap(index)) { cursor ->
|
||||
cursor.getInt(firstMessageServerID)
|
||||
return database.get(lastDeletionServerIDCache, "$lastDeletionServerIDCacheIndex = ?", wrap(index)) { cursor ->
|
||||
cursor.getInt(lastDeletionServerID)
|
||||
}?.toLong()
|
||||
}
|
||||
|
||||
override fun setFirstMessageServerID(group: Long, server: String, newValue: Long) {
|
||||
override fun setLastDeletionServerID(group: Long, server: String, newValue: Long) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val index = "$server.$group"
|
||||
val row = wrap(mapOf( firstMessageServerIDCacheIndex to index, firstMessageServerID to newValue.toString() ))
|
||||
database.insertOrUpdate(firstMessageServerIDCache, row, "$firstMessageServerIDCacheIndex = ?", wrap(index))
|
||||
val row = wrap(mapOf( lastDeletionServerIDCacheIndex to index, lastDeletionServerID to newValue.toString() ))
|
||||
database.insertOrUpdate(lastDeletionServerIDCache, row, "$lastDeletionServerIDCacheIndex = ?", wrap(index))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class LokiGroupChatPoller(private val context: Context, private val group: LokiG
|
||||
|
||||
companion object {
|
||||
private val pollForNewMessagesInterval: Long = 4 * 1000
|
||||
private val pollForDeletedMessagesInterval: Long = 32 * 60 * 1000
|
||||
private val pollForDeletedMessagesInterval: Long = 20 * 1000
|
||||
}
|
||||
|
||||
fun startIfNeeded() {
|
||||
@ -70,7 +70,7 @@ class LokiGroupChatPoller(private val context: Context, private val group: LokiG
|
||||
val x2 = SignalServiceDataMessage(message.timestamp, x1, null, message.body)
|
||||
val senderDisplayName = "${message.displayName} (...${message.hexEncodedPublicKey.takeLast(8)})"
|
||||
val x3 = SignalServiceContent(x2, senderDisplayName, SignalServiceAddress.DEFAULT_DEVICE_ID, message.timestamp, false)
|
||||
PushDecryptJob(context).handleTextMessage(x3, x2, Optional.absent())
|
||||
PushDecryptJob(context).handleTextMessage(x3, x2, Optional.absent(), Optional.of(message.serverID))
|
||||
}
|
||||
}.fail {
|
||||
Log.d("Loki", "Failed to get messages for group chat with ID: ${group.serverID} on server: ${group.server}.")
|
||||
|
@ -67,7 +67,7 @@ class LokiRSSFeedPoller(private val context: Context, private val feed: LokiRSSF
|
||||
val x1 = SignalServiceGroup(SignalServiceGroup.Type.UPDATE, id, null, null, null)
|
||||
val x2 = SignalServiceDataMessage(timestamp, x1, null, body)
|
||||
val x3 = SignalServiceContent(x2, "Loki", SignalServiceAddress.DEFAULT_DEVICE_ID, timestamp, false)
|
||||
PushDecryptJob(context).handleTextMessage(x3, x2, Optional.absent())
|
||||
PushDecryptJob(context).handleTextMessage(x3, x2, Optional.absent(), Optional.absent())
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
Log.d("Loki", "Couldn't update RSS feed with ID: $feed.id.")
|
||||
|
Loading…
Reference in New Issue
Block a user