Unverified Commit c654a070 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge pull request #1959 from shubhsherl/I_1395

[NEW] Group chats by favorites
parents 92d3243b 85740ad5
...@@ -36,15 +36,30 @@ class RoomUiModelMapper( ...@@ -36,15 +36,30 @@ class RoomUiModelMapper(
grouped: Boolean = false, grouped: Boolean = false,
showLastMessage: Boolean = true showLastMessage: Boolean = true
): List<ItemHolder<*>> { ): List<ItemHolder<*>> {
val list = ArrayList<ItemHolder<*>>(rooms.size + 4) val list = ArrayList<ItemHolder<*>>(rooms.size + 5)
var lastType: String? = null var lastType: String? = null
rooms.forEach { room -> if (grouped) {
if (grouped && lastType != room.chatRoom.type) { val favRooms = rooms.filter { it.chatRoom.favorite == true }
val unfavRooms = rooms.filterNot { it.chatRoom.favorite == true }
if (favRooms.isNotEmpty()) {
list.add(HeaderItemHolder(context.resources.getString(R.string.header_favorite)))
}
favRooms.forEach { room ->
list.add(RoomItemHolder(map(room, showLastMessage)))
}
unfavRooms.forEach { room ->
if (lastType != room.chatRoom.type) {
list.add(HeaderItemHolder(roomType(room.chatRoom.type))) list.add(HeaderItemHolder(roomType(room.chatRoom.type)))
} }
list.add(RoomItemHolder(map(room, showLastMessage))) list.add(RoomItemHolder(map(room, showLastMessage)))
lastType = room.chatRoom.type lastType = room.chatRoom.type
} }
} else {
rooms.forEach { room ->
list.add(RoomItemHolder(map(room, showLastMessage)))
}
}
return list return list
} }
...@@ -108,6 +123,7 @@ class RoomUiModelMapper( ...@@ -108,6 +123,7 @@ class RoomUiModelMapper(
val type = roomTypeOf(type) val type = roomTypeOf(type)
val status = chatRoom.status?.let { userStatusOf(it) } val status = chatRoom.status?.let { userStatusOf(it) }
val roomName = mapName(name, fullname) val roomName = mapName(name, fullname)
val favorite = favorite
val timestamp = mapDate(lastMessageTimestamp ?: updatedAt) val timestamp = mapDate(lastMessageTimestamp ?: updatedAt)
val avatar = if (type is RoomType.DirectMessage) { val avatar = if (type is RoomType.DirectMessage) {
serverUrl.avatarUrl(name) serverUrl.avatarUrl(name)
...@@ -140,6 +156,7 @@ class RoomUiModelMapper( ...@@ -140,6 +156,7 @@ class RoomUiModelMapper(
date = timestamp, date = timestamp,
unread = unread, unread = unread,
mentions = hasMentions, mentions = hasMentions,
favorite = favorite,
alert = isUnread, alert = isUnread,
lastMessage = lastMessageMarkdown, lastMessage = lastMessageMarkdown,
status = status, status = status,
...@@ -157,6 +174,7 @@ class RoomUiModelMapper( ...@@ -157,6 +174,7 @@ class RoomUiModelMapper(
private fun roomType(type: String): String { private fun roomType(type: String): String {
val resources = context.resources val resources = context.resources
return when (type) { return when (type) {
RoomType.CHANNEL -> resources.getString(R.string.header_channel) RoomType.CHANNEL -> resources.getString(R.string.header_channel)
RoomType.PRIVATE_GROUP -> resources.getString(R.string.header_private_groups) RoomType.PRIVATE_GROUP -> resources.getString(R.string.header_private_groups)
......
...@@ -12,6 +12,7 @@ data class RoomUiModel( ...@@ -12,6 +12,7 @@ data class RoomUiModel(
val date: CharSequence? = null, val date: CharSequence? = null,
val unread: String? = null, val unread: String? = null,
val alert: Boolean = false, val alert: Boolean = false,
val favorite: Boolean? = false,
val mentions: Boolean = false, val mentions: Boolean = false,
val lastMessage: CharSequence? = null, val lastMessage: CharSequence? = null,
val status: UserStatus? = null, val status: UserStatus? = null,
......
...@@ -324,6 +324,7 @@ ...@@ -324,6 +324,7 @@
<string name="chatroom_header">Kopf</string> <string name="chatroom_header">Kopf</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">Räume</string> <string name="header_channel">Räume</string>
<string name="header_private_groups">Private Räume</string> <string name="header_private_groups">Private Räume</string>
<string name="header_direct_messages">Direkt Nachrichten</string> <string name="header_direct_messages">Direkt Nachrichten</string>
......
...@@ -315,6 +315,7 @@ ...@@ -315,6 +315,7 @@
<string name="chatroom_header">Cabezazo</string> <string name="chatroom_header">Cabezazo</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">Canales</string> <string name="header_channel">Canales</string>
<string name="header_private_groups">Grupos privados</string> <string name="header_private_groups">Grupos privados</string>
<string name="header_direct_messages">Mensajes directos</string> <string name="header_direct_messages">Mensajes directos</string>
......
...@@ -318,6 +318,7 @@ ...@@ -318,6 +318,7 @@
<string name="chatroom_header">سرپیام</string> <string name="chatroom_header">سرپیام</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">کانال‌ها</string> <string name="header_channel">کانال‌ها</string>
<string name="header_private_groups">گروه‌های خصوصی</string> <string name="header_private_groups">گروه‌های خصوصی</string>
<string name="header_direct_messages">پیام‌های خصوصی</string> <string name="header_direct_messages">پیام‌های خصوصی</string>
......
...@@ -319,6 +319,7 @@ ...@@ -319,6 +319,7 @@
<string name="chatroom_header">Entête</string> <string name="chatroom_header">Entête</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">Salons</string> <string name="header_channel">Salons</string>
<string name="header_private_groups">Groupes privés</string> <string name="header_private_groups">Groupes privés</string>
<string name="header_direct_messages">Messages directs</string> <string name="header_direct_messages">Messages directs</string>
......
...@@ -319,6 +319,7 @@ ...@@ -319,6 +319,7 @@
<string name="chatroom_header">हैडर</string> <string name="chatroom_header">हैडर</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">चैनलों</string> <string name="header_channel">चैनलों</string>
<string name="header_private_groups">निजी समूहों</string> <string name="header_private_groups">निजी समूहों</string>
<string name="header_direct_messages">प्रत्यक्ष संदेश</string> <string name="header_direct_messages">प्रत्यक्ष संदेश</string>
......
...@@ -315,6 +315,7 @@ ...@@ -315,6 +315,7 @@
<string name="chatroom_header">Intestazione</string> <string name="chatroom_header">Intestazione</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">Canali</string> <string name="header_channel">Canali</string>
<string name="header_private_groups">Gruppi Privati</string> <string name="header_private_groups">Gruppi Privati</string>
<string name="header_direct_messages">Messaggi Diretti</string> <string name="header_direct_messages">Messaggi Diretti</string>
......
...@@ -319,6 +319,7 @@ ...@@ -319,6 +319,7 @@
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">チャンネル</string> <string name="header_channel">チャンネル</string>
<string name="header_private_groups">プライベートグループ</string> <string name="header_private_groups">プライベートグループ</string>
<string name="header_direct_messages">ダイレクトメッセージ</string> <string name="header_direct_messages">ダイレクトメッセージ</string>
......
...@@ -317,6 +317,7 @@ ...@@ -317,6 +317,7 @@
<string name="chatroom_header">Cabeçalho</string> <string name="chatroom_header">Cabeçalho</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favoritos</string>
<string name="header_channel">Canais</string> <string name="header_channel">Canais</string>
<string name="header_private_groups">Grupos Privados</string> <string name="header_private_groups">Grupos Privados</string>
<string name="header_direct_messages">Mensagens diretas</string> <string name="header_direct_messages">Mensagens diretas</string>
......
...@@ -315,6 +315,7 @@ ...@@ -315,6 +315,7 @@
<string name="chatroom_header">Заголовок</string> <string name="chatroom_header">Заголовок</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">Каналы</string> <string name="header_channel">Каналы</string>
<string name="header_private_groups">Приватные каналы</string> <string name="header_private_groups">Приватные каналы</string>
<string name="header_direct_messages">Личная переписка</string> <string name="header_direct_messages">Личная переписка</string>
......
...@@ -320,6 +320,7 @@ ...@@ -320,6 +320,7 @@
<string name="chatroom_header">Başlık</string> <string name="chatroom_header">Başlık</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">Kanallar</string> <string name="header_channel">Kanallar</string>
<string name="header_private_groups">Gizli Gruplar</string> <string name="header_private_groups">Gizli Gruplar</string>
<string name="header_direct_messages">Direkt Mesajlar</string> <string name="header_direct_messages">Direkt Mesajlar</string>
......
...@@ -316,6 +316,7 @@ ...@@ -316,6 +316,7 @@
<string name="chatroom_header">Заголовок</string> <string name="chatroom_header">Заголовок</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">Канали</string> <string name="header_channel">Канали</string>
<string name="header_private_groups">Приватні канали</string> <string name="header_private_groups">Приватні канали</string>
<string name="header_direct_messages">Особисті повідомлення</string> <string name="header_direct_messages">Особисті повідомлення</string>
......
...@@ -315,6 +315,7 @@ ...@@ -315,6 +315,7 @@
<string name="chatroom_header">头部</string> <string name="chatroom_header">头部</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string><!-- TODO - Add proper translation -->
<string name="header_channel">频道</string> <string name="header_channel">频道</string>
<string name="header_private_groups">私人组</string> <string name="header_private_groups">私人组</string>
<string name="header_direct_messages">直接对话</string> <string name="header_direct_messages">直接对话</string>
......
...@@ -331,6 +331,7 @@ https://github.com/RocketChat/java-code-styles/blob/master/CODING_STYLE.md#strin ...@@ -331,6 +331,7 @@ https://github.com/RocketChat/java-code-styles/blob/master/CODING_STYLE.md#strin
<string name="chatroom_header">Header</string> <string name="chatroom_header">Header</string>
<!--ChatRooms Headers--> <!--ChatRooms Headers-->
<string name="header_favorite">Favorites</string>
<string name="header_channel">Channels</string> <string name="header_channel">Channels</string>
<string name="header_private_groups">Private Groups</string> <string name="header_private_groups">Private Groups</string>
<string name="header_direct_messages">Direct Messages</string> <string name="header_direct_messages">Direct Messages</string>
......
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