...
 
Commits (2)
......@@ -38,6 +38,7 @@ class AvatarHelperTest {
bufferId = BufferId(0),
networkId = NetworkId(0),
currentBufferId = BufferId(0),
currentBufferType = Buffer_Type.of(),
sender = "justJanne",
senderPrefixes = "",
realName = "Janne Mareike Koschinski <janne@kuschku.de>",
......@@ -79,6 +80,7 @@ class AvatarHelperTest {
bufferId = BufferId(0),
networkId = NetworkId(0),
currentBufferId = BufferId(0),
currentBufferType = Buffer_Type.of(),
sender = "jwheare!sid2@irccloud.com",
senderPrefixes = "",
realName = "James Wheare",
......@@ -120,6 +122,7 @@ class AvatarHelperTest {
bufferId = BufferId(0),
networkId = NetworkId(0),
currentBufferId = BufferId(0),
currentBufferType = Buffer_Type.of(),
sender = "jwheare!sid2@irccloud.com",
senderPrefixes = "",
realName = "James Wheare",
......
......@@ -44,7 +44,7 @@ interface MessageDao {
@Query("SELECT * FROM message WHERE bufferId = :bufferId ORDER BY messageId ASC")
fun _findByBufferId(bufferId: BufferId_Type): List<MessageData>
@Query("SELECT * FROM message WHERE (bufferId = :bufferId AND type & ~ :type > 0 AND ignored = 0) OR (networkId = :networkId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showUserNotices != 0) OR (bufferId = :serverBufferId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showServerNotices != 0) OR (bufferId = :serverBufferId AND type & 4096 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showErrors != 0) ORDER BY messageId DESC")
@Query("SELECT * FROM message WHERE (bufferId = :bufferId AND type & ~ :type > 0 AND ignored = 0) OR (networkId = :networkId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND currentBufferType = 4 AND :showUserNotices != 0) OR (bufferId = :serverBufferId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND currentBufferType = 1 AND :showServerNotices != 0) OR (bufferId = :serverBufferId AND type & 4096 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showErrors != 0) ORDER BY messageId DESC")
fun _findByBufferIdPaged(networkId: NetworkId_Type, serverBufferId: BufferId_Type,
bufferId: BufferId_Type, type: Int,
showUserNotices: Boolean, showServerNotices: Boolean,
......@@ -59,7 +59,7 @@ interface MessageDao {
@Query("SELECT messageId FROM message WHERE bufferId = :bufferId ORDER BY messageId ASC LIMIT 1")
fun _firstMsgId(bufferId: BufferId_Type): Flowable<MsgId_Type>
@Query("SELECT messageId FROM message WHERE (bufferId = :bufferId AND type & ~ :type > 0 AND ignored = 0) OR (networkId = :networkId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showUserNotices != 0) OR (bufferId = :serverBufferId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showServerNotices != 0) OR (bufferId = :serverBufferId AND type & 4096 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showErrors != 0) ORDER BY messageId ASC LIMIT 1")
@Query("SELECT messageId FROM message WHERE (bufferId = :bufferId AND type & ~ :type > 0 AND ignored = 0) OR (networkId = :networkId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND currentBufferType = 4 AND :showUserNotices != 0) OR (bufferId = :serverBufferId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND currentBufferType = 1 AND :showServerNotices != 0) OR (bufferId = :serverBufferId AND type & 4096 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showErrors != 0) ORDER BY messageId ASC LIMIT 1")
fun _firstVisibleMsgId(networkId: NetworkId_Type, serverBufferId: BufferId_Type,
bufferId: BufferId_Type, type: Int,
showUserNotices: Boolean, showServerNotices: Boolean,
......@@ -68,7 +68,7 @@ interface MessageDao {
@Query("SELECT * FROM message WHERE bufferId = :bufferId ORDER BY messageId ASC LIMIT 1")
fun _findFirstByBufferId(bufferId: BufferId_Type): MessageData?
@Query("SELECT EXISTS(SELECT 1 FROM message WHERE (bufferId = :bufferId AND type & ~ :type > 0 AND ignored = 0) OR (networkId = :networkId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showUserNotices != 0) OR (bufferId = :serverBufferId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showServerNotices != 0) OR (bufferId = :serverBufferId AND type & 4096 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showErrors != 0))")
@Query("SELECT EXISTS(SELECT 1 FROM message WHERE (bufferId = :bufferId AND type & ~ :type > 0 AND ignored = 0) OR (networkId = :networkId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND currentBufferType = 4 AND :showUserNotices != 0) OR (bufferId = :serverBufferId AND type & 2 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND currentBufferType = 1 AND :showServerNotices != 0) OR (bufferId = :serverBufferId AND type & 4096 > 0 AND ignored = 0 AND currentBufferId = :bufferId AND :showErrors != 0))")
fun _hasVisibleMessages(networkId: NetworkId_Type, serverBufferId: BufferId_Type,
bufferId: BufferId_Type, type: Int,
showUserNotices: Boolean, showServerNotices: Boolean,
......
......@@ -30,7 +30,7 @@ import de.kuschku.quasseldroid.persistence.models.*
import de.kuschku.quasseldroid.persistence.util.MessageTypeConverter
@Database(entities = [MessageData::class, Filtered::class, SslValidityWhitelistEntry::class, SslHostnameWhitelistEntry::class, NotificationData::class],
version = 20)
version = 21)
@TypeConverters(MessageTypeConverter::class)
abstract class QuasselDatabase : RoomDatabase() {
abstract fun message(): MessageDao
......@@ -164,6 +164,12 @@ abstract class QuasselDatabase : RoomDatabase() {
database.execSQL("CREATE INDEX index_message_currentBufferId ON message(currentBufferId);")
database.execSQL("CREATE INDEX index_message_networkId ON message(networkId);")
}
},
object : Migration(20, 21) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE message ADD currentBufferType INT DEFAULT 0 NOT NULL;")
database.execSQL("CREATE INDEX index_message_currentBufferType ON message(currentBufferType);")
}
}
).build()
}
......
......@@ -28,7 +28,14 @@ import de.kuschku.libquassel.protocol.*
import org.threeten.bp.Instant
import java.io.Serializable
@Entity(tableName = "message", indices = [Index("bufferId"), Index("ignored"), Index("currentBufferId"), Index("networkId")])
@Entity(tableName = "message",
indices = [
Index("bufferId"),
Index("ignored"),
Index("currentBufferId"),
Index("currentBufferType"),
Index("networkId")
])
data class MessageData(
@PrimaryKey
@ColumnInfo(name = "messageId")
......@@ -40,6 +47,7 @@ data class MessageData(
var rawBufferId: BufferId_Type,
@ColumnInfo(name = "currentBufferId")
var rawCurrentBufferId: BufferId_Type,
var currentBufferType: Buffer_Types,
@ColumnInfo(name = "networkId")
var rawNetworkId: NetworkId_Type,
var sender: String,
......@@ -65,6 +73,7 @@ data class MessageData(
type: Message_Types,
flag: Message_Flags,
bufferId: BufferId,
currentBufferType: Buffer_Types,
networkId: NetworkId,
currentBufferId: BufferId,
sender: String,
......@@ -80,6 +89,7 @@ data class MessageData(
flag,
bufferId.id,
currentBufferId.id,
currentBufferType,
networkId.id,
sender,
senderPrefixes,
......
......@@ -20,13 +20,11 @@
package de.kuschku.quasseldroid.persistence.util
import de.kuschku.libquassel.protocol.BufferId
import de.kuschku.libquassel.protocol.Buffer_Type
import de.kuschku.libquassel.protocol.Message
import de.kuschku.libquassel.protocol.NetworkId
import de.kuschku.libquassel.quassel.syncables.IgnoreListManager
import de.kuschku.libquassel.session.BacklogStorage
import de.kuschku.libquassel.session.ISession
import de.kuschku.libquassel.util.flag.hasFlag
import de.kuschku.quasseldroid.persistence.db.QuasselDatabase
import de.kuschku.quasseldroid.persistence.models.MessageData
import io.reactivex.subjects.BehaviorSubject
......@@ -55,10 +53,8 @@ class QuasselBacklogStorage(private val db: QuasselDatabase) : BacklogStorage {
type = it.type,
flag = it.flag,
bufferId = it.bufferInfo.bufferId,
currentBufferId =
if (it.bufferInfo.type.hasFlag(Buffer_Type.QueryBuffer) ||
it.bufferInfo.type.hasFlag(Buffer_Type.StatusBuffer)) currentBuffer.value
else BufferId(0),
currentBufferId = currentBuffer.value,
currentBufferType = it.bufferInfo.type,
networkId = it.bufferInfo.networkId,
sender = it.sender,
senderPrefixes = it.senderPrefixes,
......