Commit 5ca833b7 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Fix chat list now showing.

parent 25efdb18
...@@ -18,7 +18,7 @@ android { ...@@ -18,7 +18,7 @@ android {
applicationId "chat.rocket.android" applicationId "chat.rocket.android"
minSdkVersion versions.minSdk minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk targetSdkVersion versions.targetSdk
versionCode 2060 versionCode 2061
versionName "3.3.0" versionName "3.3.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"formatVersion": 1, "formatVersion": 1,
"database": { "database": {
"version": 11, "version": 11,
"identityHash": "fb9f1c815809b0217d326452aeb34e92", "identityHash": "1984b5661945bd83607d9a7043ed87b0",
"entities": [ "entities": [
{ {
"tableName": "users", "tableName": "users",
...@@ -1013,7 +1013,7 @@ ...@@ -1013,7 +1013,7 @@
}, },
{ {
"tableName": "reactions", "tableName": "reactions",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`reaction` TEXT NOT NULL, `messageId` TEXT NOT NULL, `count` INTEGER NOT NULL, `usernames` TEXT NOT NULL, PRIMARY KEY(`reaction`), FOREIGN KEY(`messageId`) REFERENCES `messages`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`reaction` TEXT NOT NULL, `messageId` TEXT NOT NULL, `count` INTEGER NOT NULL, `usernames` TEXT NOT NULL, `names` TEXT NOT NULL, PRIMARY KEY(`reaction`), FOREIGN KEY(`messageId`) REFERENCES `messages`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [ "fields": [
{ {
"fieldPath": "reaction", "fieldPath": "reaction",
...@@ -1038,6 +1038,12 @@ ...@@ -1038,6 +1038,12 @@
"columnName": "usernames", "columnName": "usernames",
"affinity": "TEXT", "affinity": "TEXT",
"notNull": true "notNull": true
},
{
"fieldPath": "names",
"columnName": "names",
"affinity": "TEXT",
"notNull": true
} }
], ],
"primaryKey": { "primaryKey": {
...@@ -1099,7 +1105,7 @@ ...@@ -1099,7 +1105,7 @@
], ],
"setupQueries": [ "setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"fb9f1c815809b0217d326452aeb34e92\")" "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"1984b5661945bd83607d9a7043ed87b0\")"
] ]
} }
} }
\ No newline at end of file
This diff is collapsed.
...@@ -472,18 +472,20 @@ class UiModelMapper @Inject constructor( ...@@ -472,18 +472,20 @@ class UiModelMapper @Inject constructor(
val list = mutableListOf<ReactionUiModel>() val list = mutableListOf<ReactionUiModel>()
val customEmojis = EmojiRepository.getCustomEmojis() val customEmojis = EmojiRepository.getCustomEmojis()
it.getShortNames().forEach { shortname -> it.getShortNames().forEach { shortname ->
val usernames = it.getUsernames(shortname).orEmpty() it.getUsernames(shortname)?.let { usernames ->
val count = usernames.size val count = usernames.size
val custom = customEmojis.firstOrNull { emoji -> emoji.shortname == shortname } val custom = customEmojis.firstOrNull { emoji -> emoji.shortname == shortname }
list.add( list.add(
ReactionUiModel(messageId = message.id, ReactionUiModel(messageId = message.id,
shortname = shortname, shortname = shortname,
unicode = EmojiParser.parse(context, shortname), unicode = EmojiParser.parse(context, shortname),
count = count, count = count,
usernames = usernames, usernames = usernames,
url = custom?.url, url = custom?.url,
isCustom = custom != null) isCustom = custom != null)
) )
}
} }
list list
} }
......
...@@ -101,9 +101,11 @@ class RoomUiModelMapper( ...@@ -101,9 +101,11 @@ class RoomUiModelMapper(
avatar = serverUrl.avatarUrl(name!!, isGroupOrChannel = true), avatar = serverUrl.avatarUrl(name!!, isGroupOrChannel = true),
lastMessage = if (showLastMessage) { lastMessage = if (showLastMessage) {
mapLastMessage( mapLastMessage(
lastMessage?.sender?.id, lastMessage?.sender?.username, lastMessage?.sender?.id,
lastMessage?.sender?.name, lastMessage?.message, lastMessage?.sender?.username,
isDirectMessage = type is RoomType.DirectMessage lastMessage?.sender?.name,
lastMessage?.message,
isDirectMessage = type is RoomType.DirectMessage
) )
} else { } else {
null null
......
...@@ -31,7 +31,6 @@ import chat.rocket.core.model.ChatRoom ...@@ -31,7 +31,6 @@ import chat.rocket.core.model.ChatRoom
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import chat.rocket.core.model.Myself import chat.rocket.core.model.Myself
import chat.rocket.core.model.Room import chat.rocket.core.model.Room
import chat.rocket.core.model.attachment.Attachment
import chat.rocket.core.model.userId import chat.rocket.core.model.userId
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
...@@ -237,7 +236,8 @@ class DatabaseManager(val context: Application, val serverUrl: String) { ...@@ -237,7 +236,8 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
reaction, reaction,
message.id, message.id,
size, size,
reactionValue.joinToString() reactionValue.first.joinToString(),
reactionValue.second.joinToString()
) )
) )
} }
...@@ -383,17 +383,14 @@ class DatabaseManager(val context: Application, val serverUrl: String) { ...@@ -383,17 +383,14 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
} }
} }
private fun mapLastMessageText(message: Message?): String? = message?.run { private fun mapLastMessageText(message: Message?): String? = message?.let { lastMessage ->
if (this.message.isEmpty() && attachments?.isNotEmpty() == true) { if (lastMessage.message.isEmpty() && lastMessage.attachments?.isNotEmpty() == true) {
message.attachments?.let { mapAttachmentText(it[0]) } context.getString(R.string.msg_sent_attachment)
} else { } else {
this.message lastMessage.message
} }
} }
private fun mapAttachmentText(attachment: Attachment): String =
context.getString(R.string.msg_sent_attachment)
private suspend fun updateSubscription(data: Subscription): ChatRoomEntity? { private suspend fun updateSubscription(data: Subscription): ChatRoomEntity? {
return retryDB("getRoom(${data.roomId}") { chatRoomDao().getSync(data.roomId) }?.let { current -> return retryDB("getRoom(${data.roomId}") { chatRoomDao().getSync(data.roomId) }?.let { current ->
with(data) { with(data) {
......
...@@ -19,13 +19,20 @@ import chat.rocket.android.emoji.internal.db.StringListConverter ...@@ -19,13 +19,20 @@ import chat.rocket.android.emoji.internal.db.StringListConverter
@Database( @Database(
entities = [ entities = [
UserEntity::class, ChatRoomEntity::class, MessageEntity::class, UserEntity::class,
MessageFavoritesRelation::class, MessageMentionsRelation::class, ChatRoomEntity::class,
MessageChannels::class, AttachmentEntity::class, MessageEntity::class,
AttachmentFieldEntity::class, AttachmentActionEntity::class, UrlEntity::class, MessageFavoritesRelation::class,
ReactionEntity::class, MessagesSync::class MessageMentionsRelation::class,
MessageChannels::class,
AttachmentEntity::class,
AttachmentFieldEntity::class,
AttachmentActionEntity::class,
UrlEntity::class,
ReactionEntity::class,
MessagesSync::class
], ],
version = 11, version = 12,
exportSchema = true exportSchema = true
) )
@TypeConverters(StringListConverter::class) @TypeConverters(StringListConverter::class)
......
...@@ -8,11 +8,13 @@ import androidx.room.Relation ...@@ -8,11 +8,13 @@ import androidx.room.Relation
interface BaseMessageEntity interface BaseMessageEntity
@Entity(tableName = "messages", @Entity(
foreignKeys = [ tableName = "messages",
ForeignKey(entity = UserEntity::class, parentColumns = ["id"], childColumns = ["senderId"]), foreignKeys = [
ForeignKey(entity = UserEntity::class, parentColumns = ["id"], childColumns = ["editedBy"]) ForeignKey(entity = UserEntity::class, parentColumns = ["id"], childColumns = ["senderId"]),
]) ForeignKey(entity = UserEntity::class, parentColumns = ["id"], childColumns = ["editedBy"])
]
)
data class MessageEntity( data class MessageEntity(
@PrimaryKey val id: String, @PrimaryKey val id: String,
val roomId: String, val roomId: String,
...@@ -33,36 +35,47 @@ data class MessageEntity( ...@@ -33,36 +35,47 @@ data class MessageEntity(
val unread: Boolean? = null val unread: Boolean? = null
) : BaseMessageEntity ) : BaseMessageEntity
@Entity(tableName = "message_favorites", @Entity(
primaryKeys = ["messageId", "userId"], tableName = "message_favorites",
foreignKeys = [ primaryKeys = ["messageId", "userId"],
ForeignKey(entity = MessageEntity::class, parentColumns = ["id"], foreignKeys = [
childColumns = ["messageId"], onDelete = ForeignKey.CASCADE), ForeignKey(
ForeignKey(entity = UserEntity::class, parentColumns = ["id"], childColumns = ["userId"]) entity = MessageEntity::class, parentColumns = ["id"],
]) childColumns = ["messageId"], onDelete = ForeignKey.CASCADE
),
ForeignKey(entity = UserEntity::class, parentColumns = ["id"], childColumns = ["userId"])
]
)
data class MessageFavoritesRelation( data class MessageFavoritesRelation(
val messageId: String, val messageId: String,
val userId: String val userId: String
) : BaseMessageEntity ) : BaseMessageEntity
@Entity(tableName = "message_mentions", @Entity(
primaryKeys = ["messageId", "userId"], tableName = "message_mentions",
foreignKeys = [ primaryKeys = ["messageId", "userId"],
ForeignKey(entity = MessageEntity::class, parentColumns = ["id"], foreignKeys = [
childColumns = ["messageId"], onDelete = ForeignKey.CASCADE), ForeignKey(
ForeignKey(entity = UserEntity::class, parentColumns = ["id"], childColumns = ["userId"]) entity = MessageEntity::class, parentColumns = ["id"],
]) childColumns = ["messageId"], onDelete = ForeignKey.CASCADE
),
ForeignKey(entity = UserEntity::class, parentColumns = ["id"], childColumns = ["userId"])
]
)
data class MessageMentionsRelation( data class MessageMentionsRelation(
val messageId: String, val messageId: String,
val userId: String val userId: String
) : BaseMessageEntity ) : BaseMessageEntity
@Entity(tableName = "message_channels", @Entity(
primaryKeys = ["messageId", "roomId"], tableName = "message_channels",
foreignKeys = [ primaryKeys = ["messageId", "roomId"],
ForeignKey(entity = MessageEntity::class, parentColumns = ["id"], foreignKeys = [
childColumns = ["messageId"], onDelete = ForeignKey.CASCADE) ForeignKey(
] entity = MessageEntity::class, parentColumns = ["id"],
childColumns = ["messageId"], onDelete = ForeignKey.CASCADE
)
]
) )
data class MessageChannels( data class MessageChannels(
val messageId: String, val messageId: String,
...@@ -95,8 +108,6 @@ data class PartialMessage( ...@@ -95,8 +108,6 @@ data class PartialMessage(
override fun toString(): String { override fun toString(): String {
return "PartialMessage(message=$message, senderName=$senderName, senderUsername=$senderUsername, editName=$editName, editUsername=$editUsername, urls=$urls, attachments=$attachments, reactions=$reactions, channels=$channels)" return "PartialMessage(message=$message, senderName=$senderName, senderUsername=$senderUsername, editName=$editName, editUsername=$editUsername, urls=$urls, attachments=$attachments, reactions=$reactions, channels=$channels)"
} }
} }
data class FullMessage( data class FullMessage(
......
...@@ -5,18 +5,22 @@ import androidx.room.ForeignKey ...@@ -5,18 +5,22 @@ import androidx.room.ForeignKey
import androidx.room.Index import androidx.room.Index
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
@Entity(tableName = "reactions", @Entity(
foreignKeys = [ tableName = "reactions",
ForeignKey(entity = MessageEntity::class, parentColumns = ["id"], foreignKeys = [
childColumns = ["messageId"], onDelete = ForeignKey.CASCADE) ForeignKey(
], entity = MessageEntity::class,
indices = [ parentColumns = ["id"],
Index(value = ["messageId"]) childColumns = ["messageId"],
] onDelete = ForeignKey.CASCADE
)
],
indices = [Index(value = ["messageId"])]
) )
data class ReactionEntity( data class ReactionEntity(
@PrimaryKey val reaction: String, @PrimaryKey val reaction: String,
val messageId: String, val messageId: String,
val count: Int, val count: Int,
val usernames: String val usernames: String,
val names: String
) : BaseMessageEntity ) : BaseMessageEntity
\ No newline at end of file
...@@ -89,7 +89,8 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) { ...@@ -89,7 +89,8 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
val map = Reactions() val map = Reactions()
reactions.forEach { reaction -> reactions.forEach { reaction ->
val usernames = reaction.usernames.split(",").map { it.trim() } val usernames = reaction.usernames.split(",").map { it.trim() }
map[reaction.reaction] = usernames val names = reaction.names.split(",").map { it.trim() }
map[reaction.reaction] = Pair(usernames, names)
} }
return map return map
......
...@@ -56,7 +56,7 @@ ext { ...@@ -56,7 +56,7 @@ ext {
glide : '4.8.0', glide : '4.8.0',
glideTransformations : '4.0.0', glideTransformations : '4.0.0',
jitsi : '+', // TODO Avoid using + (https://github.com/jitsi/jitsi-meet/issues/3987) jitsi : '1.21.0',
// For testing // For testing
junit : '4.12', junit : '4.12',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment