diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 51f343a57..e2fb846ab 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -477,6 +477,10 @@ public interface NcApi { @Url String url, @Field("lastReadMessage") int lastReadMessage); + // Url is: /api/{apiVersion}/chat/{token}/read + @DELETE + Observable markRoomAsUnread(@Header("Authorization") String authorization, @Url String url); + /* Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /listed-room */ diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 11fb1eef3..2d2b07a0d 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -3028,7 +3028,7 @@ class ChatController(args: Bundle) : if (chatMessage!!.previousMessageId > NO_PREVIOUS_MESSAGE_ID) { ncApi.setChatReadMarker( credentials, - ApiUtils.getUrlForSetChatReadMarker( + ApiUtils.getUrlForChatReadMarker( ApiUtils.getChatApiVersion(conversationUser, intArrayOf(ApiUtils.APIv1)), conversationUser?.baseUrl, roomToken diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/ConversationOperationEnum.kt b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/ConversationOperationEnum.kt index 45c20b032..1e5979d7b 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/ConversationOperationEnum.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/ConversationOperationEnum.kt @@ -25,6 +25,7 @@ enum class ConversationOperationEnum { OPS_CODE_GET_AND_JOIN_ROOM, OPS_CODE_INVITE_USERS, OPS_CODE_MARK_AS_READ, + OPS_CODE_MARK_AS_UNREAD, OPS_CODE_REMOVE_FAVORITE, OPS_CODE_ADD_FAVORITE, OPS_CODE_JOIN_ROOM diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.kt b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.kt index 1fde700a1..7f71f8b9b 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.kt @@ -214,6 +214,7 @@ class OperationsMenuController(args: Bundle) : BaseController( ConversationOperationEnum.OPS_CODE_GET_AND_JOIN_ROOM -> operationGetAndJoinRoom() ConversationOperationEnum.OPS_CODE_INVITE_USERS -> operationInviteUsers() ConversationOperationEnum.OPS_CODE_MARK_AS_READ -> operationMarkAsRead() + ConversationOperationEnum.OPS_CODE_MARK_AS_UNREAD -> operationMarkAsUnread() ConversationOperationEnum.OPS_CODE_REMOVE_FAVORITE, ConversationOperationEnum.OPS_CODE_ADD_FAVORITE -> operationToggleFavorite() ConversationOperationEnum.OPS_CODE_JOIN_ROOM -> operationJoinRoom() @@ -249,7 +250,7 @@ class OperationsMenuController(args: Bundle) : BaseController( private fun operationMarkAsRead() { ncApi.setChatReadMarker( credentials, - ApiUtils.getUrlForSetChatReadMarker( + ApiUtils.getUrlForChatReadMarker( chatApiVersion(), currentUser!!.baseUrl, conversation!!.token @@ -262,6 +263,21 @@ class OperationsMenuController(args: Bundle) : BaseController( .subscribe(GenericOperationsObserver()) } + private fun operationMarkAsUnread() { + ncApi.markRoomAsUnread( + credentials, + ApiUtils.getUrlForChatReadMarker( + chatApiVersion(), + currentUser!!.baseUrl, + conversation!!.token + ) + ) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .retry(1) + .subscribe(GenericOperationsObserver()) + } + private fun operationRenameRoom() { ncApi.renameRoom( credentials, diff --git a/app/src/main/java/com/nextcloud/talk/receivers/MarkAsReadReceiver.kt b/app/src/main/java/com/nextcloud/talk/receivers/MarkAsReadReceiver.kt index 7426293aa..9486804cd 100644 --- a/app/src/main/java/com/nextcloud/talk/receivers/MarkAsReadReceiver.kt +++ b/app/src/main/java/com/nextcloud/talk/receivers/MarkAsReadReceiver.kt @@ -83,7 +83,7 @@ class MarkAsReadReceiver : BroadcastReceiver() { private fun markAsRead() { val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token) val apiVersion = ApiUtils.getChatApiVersion(currentUser, intArrayOf(1)) - val url = ApiUtils.getUrlForSetChatReadMarker( + val url = ApiUtils.getUrlForChatReadMarker( apiVersion, currentUser.baseUrl, roomToken diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt index 8dd0caf72..abc87eaf6 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt @@ -42,6 +42,7 @@ import com.nextcloud.talk.controllers.ConversationsListController import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum.OPS_CODE_ADD_FAVORITE import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum.OPS_CODE_MARK_AS_READ +import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum.OPS_CODE_MARK_AS_UNREAD import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum.OPS_CODE_REMOVE_FAVORITE import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum.OPS_CODE_RENAME_ROOM import com.nextcloud.talk.controllers.bottomsheet.EntryMenuController @@ -118,6 +119,10 @@ class ConversationsListBottomDialog( conversation.unreadMessages > 0 && CapabilitiesUtilNew.canSetChatReadMarker(currentUser) ) + binding.conversationOperationMarkAsUnread.visibility = setVisibleIf( + conversation.unreadMessages <= 0 && CapabilitiesUtilNew.canMarkRoomAsUnread(currentUser) + ) + binding.conversationOperationRename.visibility = setVisibleIf( conversation.isNameEditable(currentUser) ) @@ -185,6 +190,10 @@ class ConversationsListBottomDialog( binding.conversationOperationMarkAsRead.setOnClickListener { executeOperationsMenuController(OPS_CODE_MARK_AS_READ) } + + binding.conversationOperationMarkAsUnread.setOnClickListener { + executeOperationsMenuController(OPS_CODE_MARK_AS_UNREAD) + } } private fun executeOperationsMenuController(operation: ConversationOperationEnum) { diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index 9e1d9868b..fe40815d9 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -429,7 +429,7 @@ public class ApiUtils { "/hovercard/v1/" + userId; } - public static String getUrlForSetChatReadMarker(int version, String baseUrl, String roomToken) { + public static String getUrlForChatReadMarker(int version, String baseUrl, String roomToken) { return getUrlForChat(version, baseUrl, roomToken) + "/read"; } diff --git a/app/src/main/java/com/nextcloud/talk/utils/database/user/CapabilitiesUtilNew.kt b/app/src/main/java/com/nextcloud/talk/utils/database/user/CapabilitiesUtilNew.kt index cb7d93e33..97a30404e 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/database/user/CapabilitiesUtilNew.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/database/user/CapabilitiesUtilNew.kt @@ -51,6 +51,10 @@ object CapabilitiesUtilNew { return hasSpreedFeatureCapability(user, "chat-read-marker") } + fun canMarkRoomAsUnread(user: User): Boolean { + return hasSpreedFeatureCapability(user, "chat-unread") + } + @JvmStatic fun hasSpreedFeatureCapability(user: User?, capabilityName: String): Boolean { if (user?.capabilities?.spreedCapability?.features != null) { diff --git a/app/src/main/res/layout/dialog_conversation_operations.xml b/app/src/main/res/layout/dialog_conversation_operations.xml index 0a023f6c1..7e05f329f 100644 --- a/app/src/main/res/layout/dialog_conversation_operations.xml +++ b/app/src/main/res/layout/dialog_conversation_operations.xml @@ -136,6 +136,36 @@ android:textSize="@dimen/bottom_sheet_text_size" /> + + + + + + +