@ -77,6 +77,25 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab
database . endTransaction ( )
}
fun deleteMessages ( messageIDs : List < Long > ) {
val database = databaseHelper . writableDatabase
database . beginTransaction ( )
database . delete (
messageIDTable ,
" ${Companion.messageID} IN ( ${messageIDs.map { "?" } .joinToString( " , " )}) " ,
messageIDs . map { " $it " } . toTypedArray ( )
)
database . delete (
messageThreadMappingTable ,
" ${Companion.messageID} IN ( ${messageIDs.map { "?" } .joinToString( " , " )}) " ,
messageIDs . map { " $it " } . toTypedArray ( )
)
database . setTransactionSuccessful ( )
database . endTransaction ( )
}
/ * *
* @return pair of sms or mms table - specific ID and whether it is in SMS table
* /
@ -96,6 +115,37 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab
}
}
fun getMessageIDs ( serverIDs : List < Long > , threadID : Long ) : Pair < List < Long > , List < Long > > {
val database = databaseHelper . readableDatabase
// Retrieve the message ids
val messageIdCursor = database
. rawQuery (
"""
SELECT $ { messageThreadMappingTable } . $ { messageID } , $ { messageIDTable } . $ { messageType }
FROM $ { messageThreadMappingTable }
JOIN $ { messageIDTable } ON $ { messageIDTable } . message _id = $ { messageThreadMappingTable } . $ { messageID }
WHERE (
$ { messageThreadMappingTable } . $ { Companion . threadID } = $ threadID AND
$ { messageThreadMappingTable } . $ { Companion . serverID } IN ( $ { serverIDs . joinToString ( " , " ) } )
)
"""
)
val smsMessageIds : MutableList < Long > = mutableListOf ( )
val mmsMessageIds : MutableList < Long > = mutableListOf ( )
while ( messageIdCursor . moveToNext ( ) ) {
if ( messageIdCursor . getInt ( 1 ) == SMS _TYPE ) {
smsMessageIds . add ( messageIdCursor . getLong ( 0 ) )
}
else {
mmsMessageIds . add ( messageIdCursor . getLong ( 0 ) )
}
}
return Pair ( smsMessageIds , mmsMessageIds )
}
override fun setServerID ( messageID : Long , serverID : Long , isSms : Boolean ) {
val database = databaseHelper . writableDatabase
val contentValues = ContentValues ( 3 )
@ -183,6 +233,15 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab
database . delete ( messageHashTable , " ${Companion.messageID} = ? " , arrayOf ( messageID . toString ( ) ) )
}
fun deleteMessageServerHashes ( messageIDs : List < Long > ) {
val database = databaseHelper . writableDatabase
database . delete (
messageHashTable ,
" ${Companion.messageID} IN ( ${messageIDs.map { "?" } .joinToString( " , " )}) " ,
messageIDs . map { " $it " } . toTypedArray ( )
)
}
fun migrateThreadId ( legacyThreadId : Long , newThreadId : Long ) {
val database = databaseHelper . writableDatabase
val contentValues = ContentValues ( 1 )