From 845ea16415f435f8cd3e14ef315ee0c9738e71f7 Mon Sep 17 00:00:00 2001 From: Brice Date: Tue, 19 Jan 2021 11:39:45 +1100 Subject: [PATCH] impl of missing methods in DatabaseAttachmentProvider --- .../attachments/DatabaseAttachmentProvider.kt | 25 ++++++++----------- .../database/MessageDataProvider.kt | 6 +---- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt b/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt index 1684359a54..5f4a989f75 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt @@ -8,8 +8,6 @@ import org.session.libsession.messaging.sending_receiving.attachments.* import org.session.libsession.messaging.threads.Address import org.session.libsignal.libsignal.util.guava.Optional import org.session.libsignal.service.api.messages.SignalServiceAttachment -import org.session.libsignal.service.api.messages.SignalServiceAttachmentPointer -import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper @@ -28,10 +26,6 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper) return databaseAttachment.toAttachmentStream(context) } - override fun getAttachmentPointer(attachmentID: String): SignalServiceAttachmentPointer? { - TODO("Not yet implemented") - } - override fun getAttachmentPointer(attachmentId: Long): SessionServiceAttachmentPointer? { val attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context) val databaseAttachment = attachmentDatabase.getAttachment(AttachmentId(attachmentId, 0)) ?: return null @@ -50,15 +44,18 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper) } override fun getMessageForQuote(timestamp: Long, author: Address): Long? { - TODO("Not yet implemented") + val messagingDatabase = DatabaseFactory.getMmsSmsDatabase(context) + return messagingDatabase.getMessageFor(timestamp, author)?.id } - override fun getAttachmentsWithLinkPreviewFor(messageID: Long): List { - TODO("Not yet implemented") + override fun getAttachmentsAndLinkPreviewFor(messageID: Long): List { + val attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context) + return attachmentDatabase.getAttachmentsForMessage(messageID) } override fun getMessageBodyFor(messageID: Long): String { - TODO("Not yet implemented") + val messagingDatabase = DatabaseFactory.getSmsDatabase(context) + return messagingDatabase.getMessage(messageID).body } override fun insertAttachment(messageId: Long, attachmentId: Long, stream: InputStream) { @@ -72,13 +69,13 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper) } override fun getMessageID(serverID: Long): Long? { - TODO("Not yet implemented") + val openGroupMessagingDatabase = DatabaseFactory.getLokiMessageDatabase(context) + return openGroupMessagingDatabase.getMessageID(serverID) } override fun deleteMessage(messageID: Long) { - TODO("Not yet implemented") - //val publicChatAPI = ApplicationContext.getInstance(context).publicChatAPI - //publicChatAPI?.deleteMessage(messageID) + val messagingDatabase = DatabaseFactory.getSmsDatabase(context) + messagingDatabase.deleteMessage(messageID) } } diff --git a/libsession/src/main/java/org/session/libsession/database/MessageDataProvider.kt b/libsession/src/main/java/org/session/libsession/database/MessageDataProvider.kt index 874f8662df..27518b8d34 100644 --- a/libsession/src/main/java/org/session/libsession/database/MessageDataProvider.kt +++ b/libsession/src/main/java/org/session/libsession/database/MessageDataProvider.kt @@ -10,10 +10,6 @@ import java.io.InputStream interface MessageDataProvider { - //fun getAttachment(attachmentId: Long): SignalServiceAttachmentStream? - - fun getAttachmentPointer(attachmentID: String): SignalServiceAttachmentPointer? - fun getMessageID(serverID: Long): Long? fun deleteMessage(messageID: Long) @@ -32,7 +28,7 @@ interface MessageDataProvider { // Quotes fun getMessageForQuote(timestamp: Long, author: Address): Long? - fun getAttachmentsWithLinkPreviewFor(messageID: Long): List + fun getAttachmentsAndLinkPreviewFor(messageID: Long): List fun getMessageBodyFor(messageID: Long): String } \ No newline at end of file