mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 17:27:45 +00:00
Disappearing messages job update
This commit is contained in:
parent
304bf42c0d
commit
92b30739f0
@ -206,6 +206,12 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
|
|||||||
return messageDB.getMessageServerHashes(messageIDs)
|
return messageDB.getMessageServerHashes(messageIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getMessageTimestampForServerHash(serverHash: String): Long? {
|
||||||
|
return DatabaseComponent.get(context).lokiMessageDatabase().getMessageIdForServerHash(serverHash)?.let {
|
||||||
|
DatabaseComponent.get(context).mmsSmsDatabase().getMessage(it)?.timestamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getDatabaseAttachment(attachmentId: Long): DatabaseAttachment? {
|
override fun getDatabaseAttachment(attachmentId: Long): DatabaseAttachment? {
|
||||||
val attachmentDatabase = DatabaseComponent.get(context).attachmentDatabase()
|
val attachmentDatabase = DatabaseComponent.get(context).attachmentDatabase()
|
||||||
return attachmentDatabase.getAttachment(AttachmentId(attachmentId, 0))
|
return attachmentDatabase.getAttachment(AttachmentId(attachmentId, 0))
|
||||||
|
@ -197,4 +197,9 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab
|
|||||||
database.update(messageThreadMappingTable, contentValues, "$threadID = ?", arrayOf(legacyThreadId.toString()))
|
database.update(messageThreadMappingTable, contentValues, "$threadID = ?", arrayOf(legacyThreadId.toString()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getMessageIdForServerHash(serverHash: String): Long? {
|
||||||
|
return readableDatabase.get(messageHashTable, "$serverHash = ?", arrayOf(serverHash)) { cursor ->
|
||||||
|
cursor.getLong(messageID)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -81,6 +81,12 @@ public class MmsSmsDatabase extends Database {
|
|||||||
super(context, databaseHelper);
|
super(context, databaseHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable MessageRecord getMessage(long messageId) {
|
||||||
|
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.ID + " = " + messageId, null, null)) {
|
||||||
|
return readerFor(cursor).getNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable MessageRecord getMessageForTimestamp(long timestamp) {
|
public @Nullable MessageRecord getMessageForTimestamp(long timestamp) {
|
||||||
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
||||||
MmsSmsDatabase.Reader reader = readerFor(cursor);
|
MmsSmsDatabase.Reader reader = readerFor(cursor);
|
||||||
|
@ -990,7 +990,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
|||||||
val smsDb = DatabaseComponent.get(context).smsDatabase()
|
val smsDb = DatabaseComponent.get(context).smsDatabase()
|
||||||
smsDb.readerFor(smsDb.expirationNotStartedMessages).use { reader ->
|
smsDb.readerFor(smsDb.expirationNotStartedMessages).use { reader ->
|
||||||
while (reader.next != null) {
|
while (reader.next != null) {
|
||||||
if (reader.current.id in messageIds) {
|
if (messageIds.isEmpty() || reader.current.id in messageIds) {
|
||||||
expiringMessages.add(reader.current.id to reader.current.expiresIn)
|
expiringMessages.add(reader.current.id to reader.current.expiresIn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -998,7 +998,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
|||||||
val mmsDb = DatabaseComponent.get(context).mmsDatabase()
|
val mmsDb = DatabaseComponent.get(context).mmsDatabase()
|
||||||
mmsDb.expireNotStartedMessages.use { reader ->
|
mmsDb.expireNotStartedMessages.use { reader ->
|
||||||
while (reader.next != null) {
|
while (reader.next != null) {
|
||||||
if (reader.current.id in messageIds) {
|
if (messageIds.isEmpty() || reader.current.id in messageIds) {
|
||||||
expiringMessages.add(reader.current.id to reader.current.expiresIn)
|
expiringMessages.add(reader.current.id to reader.current.expiresIn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ interface MessageDataProvider {
|
|||||||
fun updateMessageAsDeleted(timestamp: Long, author: String)
|
fun updateMessageAsDeleted(timestamp: Long, author: String)
|
||||||
fun getServerHashForMessage(messageID: Long): String?
|
fun getServerHashForMessage(messageID: Long): String?
|
||||||
fun getServerHashForMessages(messageIDs: List<Long>): List<Pair<Long, String?>>
|
fun getServerHashForMessages(messageIDs: List<Long>): List<Pair<Long, String?>>
|
||||||
|
fun getMessageTimestampForServerHash(serverHash: String): Long?
|
||||||
fun getDatabaseAttachment(attachmentId: Long): DatabaseAttachment?
|
fun getDatabaseAttachment(attachmentId: Long): DatabaseAttachment?
|
||||||
fun getAttachmentStream(attachmentId: Long): SessionServiceAttachmentStream?
|
fun getAttachmentStream(attachmentId: Long): SessionServiceAttachmentStream?
|
||||||
fun getAttachmentPointer(attachmentId: Long): SessionServiceAttachmentPointer?
|
fun getAttachmentPointer(attachmentId: Long): SessionServiceAttachmentPointer?
|
||||||
|
@ -202,6 +202,6 @@ interface StorageProtocol {
|
|||||||
fun blockedContacts(): List<Recipient>
|
fun blockedContacts(): List<Recipient>
|
||||||
fun getExpirationConfiguration(threadId: Long): ExpirationConfiguration?
|
fun getExpirationConfiguration(threadId: Long): ExpirationConfiguration?
|
||||||
fun setExpirationConfiguration(config: ExpirationConfiguration)
|
fun setExpirationConfiguration(config: ExpirationConfiguration)
|
||||||
fun getExpiringMessages(messageIds: List<Long>): List<Pair<Long, Long>>
|
fun getExpiringMessages(messageIds: List<Long> = emptyList()): List<Pair<Long, Long>>
|
||||||
fun updateDisappearingState(address: String, disappearingState: Recipient.DisappearingState)
|
fun updateDisappearingState(address: String, disappearingState: Recipient.DisappearingState)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import org.session.libsession.messaging.messages.ExpirationConfiguration
|
|||||||
import org.session.libsession.messaging.utilities.Data
|
import org.session.libsession.messaging.utilities.Data
|
||||||
|
|
||||||
class DisappearingMessagesJob(
|
class DisappearingMessagesJob(
|
||||||
val messageIds: List<Long> = listOf(),
|
val messageIds: List<Long> = emptyList(),
|
||||||
val startedAtMs: Long = 0,
|
val startedAtMs: Long = 0,
|
||||||
val threadId: Long = 0
|
val threadId: Long = 0
|
||||||
) : Job {
|
) : Job {
|
||||||
|
@ -10,7 +10,7 @@ import org.session.libsession.snode.SnodeAPI
|
|||||||
import org.session.libsession.utilities.Address
|
import org.session.libsession.utilities.Address
|
||||||
|
|
||||||
class SyncedExpiriesJob(
|
class SyncedExpiriesJob(
|
||||||
val messageIds: List<Long> = listOf(),
|
val messageIds: List<Long> = emptyList(),
|
||||||
val startedAtMs: Long = 0,
|
val startedAtMs: Long = 0,
|
||||||
val threadId: Long = 0
|
val threadId: Long = 0
|
||||||
) : Job {
|
) : Job {
|
||||||
|
@ -121,14 +121,16 @@ private fun MessageReceiver.handleCallMessage(message: CallMessage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun MessageReceiver.handleSyncedExpiriesMessage(message: SyncedExpiriesMessage) {
|
private fun MessageReceiver.handleSyncedExpiriesMessage(message: SyncedExpiriesMessage) {
|
||||||
val storage = MessagingModuleConfiguration.shared.storage
|
val module = MessagingModuleConfiguration.shared
|
||||||
val userPublicKey = storage.getUserPublicKey() ?: return
|
val userPublicKey = module.storage.getUserPublicKey() ?: return
|
||||||
if (userPublicKey != message.sender) return
|
if (userPublicKey != message.sender) return
|
||||||
message.conversationExpiries.forEach { (syncTarget, syncedExpiries) ->
|
message.conversationExpiries.forEach { (syncTarget, syncedExpiries) ->
|
||||||
val config = storage.getExpirationConfiguration(storage.getOrCreateThreadIdFor(syncTarget)) ?: return@forEach
|
val config = module.storage.getExpirationConfiguration(module.storage.getOrCreateThreadIdFor(syncTarget)) ?: return@forEach
|
||||||
syncedExpiries.forEach { syncedExpiry ->
|
syncedExpiries.forEach { syncedExpiry ->
|
||||||
val startedAtMs = syncedExpiry.expirationTimestamp!! - config.durationSeconds * 1000
|
module.messageDataProvider.getMessageTimestampForServerHash(syncedExpiry.serverHash!!)?.let { timestamp ->
|
||||||
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(startedAtMs, syncTarget, System.currentTimeMillis())
|
val startedAtMs = syncedExpiry.expirationTimestamp!! - config.durationSeconds * 1000
|
||||||
|
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(timestamp, syncTarget, startedAtMs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -388,6 +390,7 @@ fun MessageReceiver.handleVisibleMessage(message: VisibleMessage,
|
|||||||
storage.persist(message, quoteModel, linkPreviews, message.groupPublicKey, openGroupID,
|
storage.persist(message, quoteModel, linkPreviews, message.groupPublicKey, openGroupID,
|
||||||
attachments, runIncrement, runThreadUpdate
|
attachments, runIncrement, runThreadUpdate
|
||||||
) ?: return null
|
) ?: return null
|
||||||
|
JobQueue.shared.add(DisappearingMessagesJob())
|
||||||
val openGroupServerID = message.openGroupServerMessageID
|
val openGroupServerID = message.openGroupServerMessageID
|
||||||
if (openGroupServerID != null) {
|
if (openGroupServerID != null) {
|
||||||
val isSms = !(message.isMediaMessage() || attachments.isNotEmpty())
|
val isSms = !(message.isMediaMessage() || attachments.isNotEmpty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user