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

Merge pull request #1410 from RocketChat/new/star-unstar-chatroom

[NEW] Favorite/Unfavorite chatroom
parents 847d6e6f 3cc4aa53
......@@ -51,6 +51,7 @@ class ChatRoomNavigator(internal val activity: ChatRoomActivity) {
chatRoomLastSeen: Long,
isChatRoomSubscribed: Boolean,
isChatRoomCreator: Boolean,
isChatRoomFavorite: Boolean,
chatRoomMessage: String
) {
activity.startActivity(
......@@ -62,6 +63,7 @@ class ChatRoomNavigator(internal val activity: ChatRoomActivity) {
chatRoomLastSeen,
isChatRoomSubscribed,
isChatRoomCreator,
isChatRoomFavorite,
chatRoomMessage
)
)
......
......@@ -62,6 +62,7 @@ import chat.rocket.core.internal.rest.unpinMessage
import chat.rocket.core.internal.rest.unstarMessage
import chat.rocket.core.internal.rest.updateMessage
import chat.rocket.core.internal.rest.uploadFile
import chat.rocket.core.internal.rest.favorite
import chat.rocket.core.model.ChatRoomRole
import chat.rocket.core.model.Command
import chat.rocket.core.model.Message
......@@ -723,6 +724,25 @@ class ChatRoomPresenter @Inject constructor(
}
}
fun toggleFavoriteChatRoom(roomId: String, isFavorite: Boolean) {
launchUI(strategy) {
try {
// Note that if it is favorite then the user wants to unfavorite - and vice versa.
retryIO("favorite($roomId, $isFavorite)") {
client.favorite(roomId, !isFavorite)
}
view.showFavoriteIcon(!isFavorite)
} catch (e: RocketChatException) {
Timber.e(e, "Error while trying to favorite/unfavorite chat room.")
e.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
}
}
}
fun toMembersList(chatRoomId: String) =
navigator.toMembersList(chatRoomId)
......@@ -785,6 +805,7 @@ class ChatRoomPresenter @Inject constructor(
chatRoomLastSeen = it.lastSeen ?: -1,
chatRoomName = roomName,
isChatRoomCreator = false,
isChatRoomFavorite = false,
isChatRoomReadOnly = false,
isChatRoomSubscribed = it.open,
chatRoomMessage = message
......
......@@ -12,6 +12,13 @@ import chat.rocket.core.model.ChatRoom
interface ChatRoomView : LoadingView, MessageView {
/**
* Shows the Favorite/Unfavorite chat room icon.
*
* @param isFavorite Shows the favorite icon if true, otherwise shows the unfavorite icon.
*/
fun showFavoriteIcon(isFavorite: Boolean)
/**
* Shows the chat room messages.
*
......
......@@ -27,20 +27,22 @@ fun Context.chatRoomIntent(
chatRoomId: String,
chatRoomName: String,
chatRoomType: String,
isChatRoomReadOnly: Boolean,
isReadOnly: Boolean,
chatRoomLastSeen: Long,
isChatRoomSubscribed: Boolean = true,
isChatRoomCreator: Boolean = false,
isSubscribed: Boolean = true,
isCreator: Boolean = false,
isFavorite: Boolean = false,
chatRoomMessage: String? = null
): Intent {
return Intent(this, ChatRoomActivity::class.java).apply {
putExtra(INTENT_CHAT_ROOM_ID, chatRoomId)
putExtra(INTENT_CHAT_ROOM_NAME, chatRoomName)
putExtra(INTENT_CHAT_ROOM_TYPE, chatRoomType)
putExtra(INTENT_CHAT_ROOM_IS_READ_ONLY, isChatRoomReadOnly)
putExtra(INTENT_CHAT_ROOM_IS_READ_ONLY, isReadOnly)
putExtra(INTENT_CHAT_ROOM_LAST_SEEN, chatRoomLastSeen)
putExtra(INTENT_CHAT_IS_SUBSCRIBED, isChatRoomSubscribed)
putExtra(INTENT_CHAT_ROOM_IS_CREATOR, isChatRoomCreator)
putExtra(INTENT_CHAT_IS_SUBSCRIBED, isSubscribed)
putExtra(INTENT_CHAT_ROOM_IS_CREATOR, isCreator)
putExtra(INTENT_CHAT_ROOM_IS_FAVORITE, isFavorite)
putExtra(INTENT_CHAT_ROOM_MESSAGE, chatRoomMessage)
}
}
......@@ -50,6 +52,7 @@ private const val INTENT_CHAT_ROOM_NAME = "chat_room_name"
private const val INTENT_CHAT_ROOM_TYPE = "chat_room_type"
private const val INTENT_CHAT_ROOM_IS_READ_ONLY = "chat_room_is_read_only"
private const val INTENT_CHAT_ROOM_IS_CREATOR = "chat_room_is_creator"
private const val INTENT_CHAT_ROOM_IS_FAVORITE = "chat_room_is_favorite"
private const val INTENT_CHAT_ROOM_LAST_SEEN = "chat_room_last_seen"
private const val INTENT_CHAT_IS_SUBSCRIBED = "is_chat_room_subscribed"
private const val INTENT_CHAT_ROOM_MESSAGE = "chat_room_message"
......@@ -89,13 +92,15 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector {
val chatRoomType = intent.getStringExtra(INTENT_CHAT_ROOM_TYPE)
requireNotNull(chatRoomType) { "no chat_room_type provided in Intent extras" }
val isChatRoomReadOnly = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_READ_ONLY, true)
val isReadOnly = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_READ_ONLY, true)
val isChatRoomCreator = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_CREATOR, false)
val isCreator = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_CREATOR, false)
val isFavorite = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_FAVORITE, false)
val chatRoomLastSeen = intent.getLongExtra(INTENT_CHAT_ROOM_LAST_SEEN, -1)
val isChatRoomSubscribed = intent.getBooleanExtra(INTENT_CHAT_IS_SUBSCRIBED, true)
val isSubscribed = intent.getBooleanExtra(INTENT_CHAT_IS_SUBSCRIBED, true)
val chatRoomMessage = intent.getStringExtra(INTENT_CHAT_ROOM_MESSAGE)
......@@ -104,8 +109,15 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector {
if (supportFragmentManager.findFragmentByTag(TAG_CHAT_ROOM_FRAGMENT) == null) {
addFragment(TAG_CHAT_ROOM_FRAGMENT, R.id.fragment_container) {
newInstance(
chatRoomId, chatRoomName, chatRoomType, isChatRoomReadOnly, chatRoomLastSeen,
isChatRoomSubscribed, isChatRoomCreator, chatRoomMessage
chatRoomId,
chatRoomName,
chatRoomType,
isReadOnly,
chatRoomLastSeen,
isSubscribed,
isCreator,
isFavorite,
chatRoomMessage
)
}
}
......
......@@ -76,10 +76,11 @@ fun newInstance(
chatRoomId: String,
chatRoomName: String,
chatRoomType: String,
isChatRoomReadOnly: Boolean,
isReadOnly: Boolean,
chatRoomLastSeen: Long,
isSubscribed: Boolean = true,
isChatRoomCreator: Boolean = false,
isCreator: Boolean = false,
isFavorite: Boolean = false,
chatRoomMessage: String? = null
): Fragment {
return ChatRoomFragment().apply {
......@@ -87,10 +88,11 @@ fun newInstance(
putString(BUNDLE_CHAT_ROOM_ID, chatRoomId)
putString(BUNDLE_CHAT_ROOM_NAME, chatRoomName)
putString(BUNDLE_CHAT_ROOM_TYPE, chatRoomType)
putBoolean(BUNDLE_IS_CHAT_ROOM_READ_ONLY, isChatRoomReadOnly)
putBoolean(BUNDLE_IS_CHAT_ROOM_READ_ONLY, isReadOnly)
putLong(BUNDLE_CHAT_ROOM_LAST_SEEN, chatRoomLastSeen)
putBoolean(BUNDLE_CHAT_ROOM_IS_SUBSCRIBED, isSubscribed)
putBoolean(BUNDLE_CHAT_ROOM_IS_CREATOR, isChatRoomCreator)
putBoolean(BUNDLE_CHAT_ROOM_IS_CREATOR, isCreator)
putBoolean(BUNDLE_CHAT_ROOM_IS_FAVORITE, isFavorite)
putString(BUNDLE_CHAT_ROOM_MESSAGE, chatRoomMessage)
}
}
......@@ -104,8 +106,16 @@ private const val REQUEST_CODE_FOR_PERFORM_SAF = 42
private const val BUNDLE_CHAT_ROOM_LAST_SEEN = "chat_room_last_seen"
private const val BUNDLE_CHAT_ROOM_IS_SUBSCRIBED = "chat_room_is_subscribed"
private const val BUNDLE_CHAT_ROOM_IS_CREATOR = "chat_room_is_creator"
private const val BUNDLE_CHAT_ROOM_IS_FAVORITE = "chat_room_is_favorite"
private const val BUNDLE_CHAT_ROOM_MESSAGE = "chat_room_message"
private const val MENU_ACTION_FAVORITE_UNFAVORITE_CHAT = 1
private const val MENU_ACTION_MEMBER = 2
private const val MENU_ACTION_MENTIONS = 3
private const val MENU_ACTION_PINNED_MESSAGES = 4
private const val MENU_ACTION_FAVORITE_MESSAGES = 5
private const val MENU_ACTION_FILES = 6
class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiReactionListener {
@Inject
......@@ -118,8 +128,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
private lateinit var chatRoomType: String
private var chatRoomMessage: String? = null
private var isSubscribed: Boolean = true
private var isChatRoomReadOnly: Boolean = false
private var isChatRoomCreator: Boolean = false
private var isReadOnly: Boolean = false
private var isCreator: Boolean = false
private var isFavorite: Boolean = false
private var isBroadcastChannel: Boolean = false
private lateinit var emojiKeyboardPopup: EmojiKeyboardPopup
private var chatRoomLastSeen: Long = -1
......@@ -158,10 +169,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
chatRoomId = bundle.getString(BUNDLE_CHAT_ROOM_ID)
chatRoomName = bundle.getString(BUNDLE_CHAT_ROOM_NAME)
chatRoomType = bundle.getString(BUNDLE_CHAT_ROOM_TYPE)
isChatRoomReadOnly = bundle.getBoolean(BUNDLE_IS_CHAT_ROOM_READ_ONLY)
isReadOnly = bundle.getBoolean(BUNDLE_IS_CHAT_ROOM_READ_ONLY)
isSubscribed = bundle.getBoolean(BUNDLE_CHAT_ROOM_IS_SUBSCRIBED)
chatRoomLastSeen = bundle.getLong(BUNDLE_CHAT_ROOM_LAST_SEEN)
isChatRoomCreator = bundle.getBoolean(BUNDLE_CHAT_ROOM_IS_CREATOR)
isCreator = bundle.getBoolean(BUNDLE_CHAT_ROOM_IS_CREATOR)
isFavorite = bundle.getBoolean(BUNDLE_CHAT_ROOM_IS_FAVORITE)
chatRoomMessage = bundle.getString(BUNDLE_CHAT_ROOM_MESSAGE)
} else {
requireNotNull(bundle) { "no arguments supplied when the fragment was instantiated" }
......@@ -221,33 +233,83 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.chatroom_actions, menu)
menu.findItem(R.id.action_members_list)?.isVisible = !isBroadcastChannel
override fun onPrepareOptionsMenu(menu: Menu) {
menu.clear()
if (isFavorite) {
menu.add(
Menu.NONE,
MENU_ACTION_FAVORITE_UNFAVORITE_CHAT,
Menu.NONE,
R.string.title_unfavorite_chat
)
.setIcon(R.drawable.ic_star_yellow_24dp)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
} else {
menu.add(
Menu.NONE,
MENU_ACTION_FAVORITE_UNFAVORITE_CHAT,
Menu.NONE,
R.string.title_favorite_chat
)
.setIcon(R.drawable.ic_star_border_white_24dp)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
}
menu.add(
Menu.NONE,
MENU_ACTION_MEMBER,
Menu.NONE,
R.string.title_members_list
)
menu.add(
Menu.NONE,
MENU_ACTION_MENTIONS,
Menu.NONE,
R.string.msg_mentions
)
menu.add(
Menu.NONE,
MENU_ACTION_PINNED_MESSAGES,
Menu.NONE,
R.string.title_pinned_messages
)
menu.add(
Menu.NONE,
MENU_ACTION_FAVORITE_MESSAGES,
Menu.NONE,
R.string.title_favorite_messages
)
menu.add(
Menu.NONE,
MENU_ACTION_FILES,
Menu.NONE,
R.string.title_files
)
super.onPrepareOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_members_list -> {
presenter.toMembersList(chatRoomId)
}
R.id.action_mentions -> {
presenter.toMentions(chatRoomId)
}
R.id.action_pinned_messages -> {
presenter.toPinnedMessageList(chatRoomId)
}
R.id.action_favorite_messages -> {
presenter.toFavoriteMessageList(chatRoomId)
}
R.id.action_files -> {
presenter.toFileList(chatRoomId)
MENU_ACTION_FAVORITE_UNFAVORITE_CHAT -> {
presenter.toggleFavoriteChatRoom(chatRoomId, isFavorite)
}
MENU_ACTION_MEMBER -> presenter.toMembersList(chatRoomId)
MENU_ACTION_MENTIONS -> presenter.toMentions(chatRoomId)
MENU_ACTION_PINNED_MESSAGES -> presenter.toPinnedMessageList(chatRoomId)
MENU_ACTION_FAVORITE_MESSAGES -> presenter.toFavoriteMessageList(chatRoomId)
MENU_ACTION_FILES -> presenter.toFileList(chatRoomId)
}
return true
}
override fun showFavoriteIcon(isFavorite: Boolean) {
this.isFavorite = isFavorite
activity?.invalidateOptionsMenu()
}
override fun showMessages(dataSet: List<BaseUiModel<*>>) {
ui {
// track the message sent immediately after the current message
......@@ -666,7 +728,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
private fun setupMessageComposer(canPost: Boolean) {
if (isChatRoomReadOnly && !canPost) {
if (isReadOnly && !canPost) {
text_room_is_read_only.isVisible = true
input_container.isVisible = false
} else if (!isSubscribed && roomTypeOf(chatRoomType) !is RoomType.DirectMessage) {
......
......@@ -60,9 +60,17 @@ class ChatRoomsPresenter @Inject constructor(
} else {
id
}
val isChatRoomOwner = ownerId == myself.id || isDirectMessage
navigator.toChatRoom(id, roomName, type, readonly ?: false,
lastSeen ?: -1, open, isChatRoomOwner)
navigator.toChatRoom(
chatRoomId = id,
chatRoomName = roomName,
chatRoomType = type,
isReadOnly = readonly ?: false,
chatRoomLastSeen = lastSeen ?: -1,
isSubscribed = open,
isCreator = ownerId == myself.id || isDirectMessage,
isFavorite = favorite ?: false
)
}
}
}
......
......@@ -41,20 +41,22 @@ class MainNavigator(internal val activity: MainActivity) {
chatRoomId: String,
chatRoomName: String,
chatRoomType: String,
isChatRoomReadOnly: Boolean,
isReadOnly: Boolean,
chatRoomLastSeen: Long,
isChatRoomSubscribed: Boolean,
isChatRoomCreator: Boolean
isSubscribed: Boolean,
isCreator: Boolean,
isFavorite: Boolean
) {
activity.startActivity(
activity.chatRoomIntent(
chatRoomId,
chatRoomName,
chatRoomType,
isChatRoomReadOnly,
isReadOnly,
chatRoomLastSeen,
isChatRoomSubscribed,
isChatRoomCreator
isSubscribed,
isCreator,
isFavorite
)
)
activity.overridePendingTransition(R.anim.open_enter, R.anim.open_exit)
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M22,9.24l-7.19,-0.62L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21 12,17.27 18.18,21l-1.63,-7.03L22,9.24zM12,15.4l-3.76,2.27 1,-4.28 -3.32,-2.88 4.38,-0.38L12,6.1l1.71,4.04 4.38,0.38 -3.32,2.88 1,4.28L12,15.4z" />
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFF59D"
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_members_list"
android:title="@string/title_members_list"
android:showAsAction="never" />
<item
android:id="@+id/action_mentions"
android:title="@string/msg_mentions"
app:showAsAction="never" />
<item
android:id="@+id/action_pinned_messages"
android:title="@string/title_pinned_messages"
android:showAsAction="never" />
<item
android:id="@+id/action_favorite_messages"
android:title="@string/title_favorite_messages"
android:showAsAction="never" />
<item
android:id="@+id/action_files"
android:title="@string/msg_files"
android:showAsAction="never" />
</menu>
\ No newline at end of file
......@@ -188,6 +188,11 @@
// TODO: Add proper translation.
<string name="permission_starring_not_allowed">Starring is not allowed</string>
<!-- Favorite/Unfavorite chat room -->
<!-- TODO Add proper translation-->
<string name="title_favorite_chat">Favorite chat</string>
<string name="title_unfavorite_chat">Unfavorite chat</string>
<!-- Members List -->
<string name="title_members_list">Miembros</string>
......@@ -210,7 +215,7 @@
<!-- Files -->
<!-- TODO Add proper translation-->
<string name="msg_files">Files</string>
<string name="title_files">Files</string>
<string name="title_files_total">Files (%d)</string>
<string name="msg_no_files">No files</string>
<string name="msg_all_files_appear_here">All the files appear here</string>
......
......@@ -189,6 +189,11 @@
// TODO: Add proper translation.
<string name="permission_starring_not_allowed">Starring is not allowed</string>
<!-- Favorite/Unfavorite chat room -->
<!-- TODO Add proper translation-->
<string name="title_favorite_chat">Favorite chat</string>
<string name="title_unfavorite_chat">Unfavorite chat</string>
<!-- Members List -->
<string name="title_members_list">Membres</string>
......@@ -211,7 +216,7 @@
<!-- Files -->
<!-- TODO Add proper translation-->
<string name="msg_files">Files</string>
<string name="title_files">Files</string>
<string name="title_files_total">Files (%d)</string>
<string name="msg_no_files">No files</string>
<string name="msg_all_files_appear_here">All the files appear here</string>
......
......@@ -175,6 +175,11 @@
<string name="permission_pinning_not_allowed">पिनि करने की अनुमति नहीं है</string>
<string name="permission_starring_not_allowed">तारांकित की अनुमति नहीं है</string>
<!-- Favorite/Unfavorite chat room -->
<!-- TODO Add proper translation-->
<string name="title_favorite_chat">Favorite chat</string>
<string name="title_unfavorite_chat">Unfavorite chat</string>
<!-- Members List -->
<string name="title_members_list">सदस्य</string>
......@@ -195,7 +200,7 @@
<string name="no_favorite_description">सभी पसंदीदा संदेश यहां\nदिखाई देते हैं</string>
<!-- Files -->
<string name="msg_files">फ़ाइलें</string>
<string name="title_files">फ़ाइलें</string>
<string name="title_files_total">फ़ाइलें (%d)</string>
<string name="msg_no_files">कोई फाइल नहीं है</string>
<string name="msg_all_files_appear_here">सभी फाइलें यहां दिखाई देती हैं</string>
......
......@@ -172,6 +172,10 @@
<string name="permission_pinning_not_allowed">Pinagem não permitida</string>
<string name="permission_starring_not_allowed">Favoritar não permitido</string>
<!-- Favorite/Unfavorite chat room -->
<string name="title_favorite_chat">Favoritar canal</string>
<string name="title_unfavorite_chat">Desfavoritar canal</string>
<!-- Members List -->
<string name="title_members_list">Membros</string>
......@@ -191,7 +195,7 @@
<string name="no_favorite_description">Todas mensagens favoritas\naparecerão aqui</string>
<!-- Files -->
<string name="msg_files">Arquivos</string>
<string name="title_files">Arquivos</string>
<string name="title_files_total">Arquivos (%d)</string>
<string name="msg_no_files">Nenhum arquivo</string>
<string name="msg_all_files_appear_here">Todos arquivos aparecerão aqui</string>
......
......@@ -168,6 +168,11 @@
<string name="permission_pinning_not_allowed">Прикрепление запрещено</string>
<string name="permission_starring_not_allowed">Отмечивание запрещено</string>
<!-- Favorite/Unfavorite chat room -->
<!-- TODO Add proper translation-->
<string name="title_favorite_chat">Favorite chat</string>
<string name="title_unfavorite_chat">Unfavorite chat</string>
<!-- Members List -->
<string name="title_members_list">Пользователи</string>
......@@ -187,7 +192,7 @@
<string name="no_favorite_description">Все избранные сообщения\nотображаются здесь</string>
<!-- Files -->
<string name="msg_files">Файлы</string>
<string name="title_files">Файлы</string>
<string name="title_files_total">Файлы (%d)</string>
<string name="msg_no_files">Нет файлов</string>
<string name="msg_all_files_appear_here">Все файлы отображаются здесь</string>
......
......@@ -171,6 +171,10 @@
<string name="permission_pinning_not_allowed">Pinning is not allowed</string>
<string name="permission_starring_not_allowed">Starring is not allowed</string>
<!-- Favorite/Unfavorite chat room -->
<string name="title_favorite_chat">Favorite chat</string>
<string name="title_unfavorite_chat">Unfavorite chat</string>
<!-- Members List -->
<string name="title_members_list">Members</string>
......@@ -190,7 +194,7 @@
<string name="no_favorite_description">All the favorite messages\nappear here</string>
<!-- Files -->
<string name="msg_files">Files</string>
<string name="title_files">Files</string>
<string name="title_files_total">Files (%d)</string>
<string name="msg_no_files">No files</string>
<string name="msg_all_files_appear_here">All the files appear here</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