implementation of persistAttachments + refactoring

This commit is contained in:
Brice
2021-01-29 11:16:53 +11:00
parent ebad701378
commit 49f3e0cfca
7 changed files with 44 additions and 11 deletions

View File

@@ -438,6 +438,30 @@ public class AttachmentDatabase extends Database {
return insertedAttachments;
}
/**
* Insert attachments in database and return the IDs of the inserted attachments
*
* @param mmsId message ID
* @param attachments attachments to persist
* @return IDs of the persisted attachments
* @throws MmsException
*/
@NonNull List<Long> insertAttachments(long mmsId, @NonNull List<Attachment> attachments)
throws MmsException
{
Log.d(TAG, "insertParts(" + attachments.size() + ")");
List<Long> insertedAttachmentsIDs = new LinkedList<>();
for (Attachment attachment : attachments) {
AttachmentId attachmentId = insertAttachment(mmsId, attachment, attachment.isQuote());
insertedAttachmentsIDs.add(attachmentId.getRowId());
Log.i(TAG, "Inserted attachment at ID: " + attachmentId);
}
return insertedAttachmentsIDs;
}
public @NonNull Attachment updateAttachmentData(@NonNull Attachment attachment,
@NonNull MediaStream mediaStream)
throws MmsException

View File

@@ -81,8 +81,10 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
return registrationID
}
override fun persist(attachments: List<Attachment>): List<Long> {
TODO("Not yet implemented")
override fun persistAttachments(messageId: Long, attachments: List<Attachment>): List<Long> {
val database = DatabaseFactory.getAttachmentDatabase(context)
val databaseAttachments = attachments.map { it.toDatabaseAttachment() }
return database.insertAttachments(messageId, databaseAttachments)
}
override fun persist(message: VisibleMessage, quotes: QuoteModel?, linkPreview: List<LinkPreview?>, groupPublicKey: String?, openGroupID: String?): Long? {
@@ -127,7 +129,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
// JOBS
override fun persist(job: Job) {
override fun persistJob(job: Job) {
DatabaseFactory.getSessionJobDatabase(context).persistJob(job)
}