Merge pull request #2743 from nextcloud/feature/noid/markRoomAdUnread

Add ability to mark a room as unread
This commit is contained in:
Andy Scherzinger 2023-02-08 08:37:32 +01:00 committed by GitHub
commit 2d369d89c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 68 additions and 4 deletions

View file

@ -477,6 +477,10 @@ public interface NcApi {
@Url String url, @Url String url,
@Field("lastReadMessage") int lastReadMessage); @Field("lastReadMessage") int lastReadMessage);
// Url is: /api/{apiVersion}/chat/{token}/read
@DELETE
Observable<GenericOverall> markRoomAsUnread(@Header("Authorization") String authorization, @Url String url);
/* /*
Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /listed-room Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /listed-room
*/ */

View file

@ -3028,7 +3028,7 @@ class ChatController(args: Bundle) :
if (chatMessage!!.previousMessageId > NO_PREVIOUS_MESSAGE_ID) { if (chatMessage!!.previousMessageId > NO_PREVIOUS_MESSAGE_ID) {
ncApi.setChatReadMarker( ncApi.setChatReadMarker(
credentials, credentials,
ApiUtils.getUrlForSetChatReadMarker( ApiUtils.getUrlForChatReadMarker(
ApiUtils.getChatApiVersion(conversationUser, intArrayOf(ApiUtils.APIv1)), ApiUtils.getChatApiVersion(conversationUser, intArrayOf(ApiUtils.APIv1)),
conversationUser?.baseUrl, conversationUser?.baseUrl,
roomToken roomToken

View file

@ -25,6 +25,7 @@ enum class ConversationOperationEnum {
OPS_CODE_GET_AND_JOIN_ROOM, OPS_CODE_GET_AND_JOIN_ROOM,
OPS_CODE_INVITE_USERS, OPS_CODE_INVITE_USERS,
OPS_CODE_MARK_AS_READ, OPS_CODE_MARK_AS_READ,
OPS_CODE_MARK_AS_UNREAD,
OPS_CODE_REMOVE_FAVORITE, OPS_CODE_REMOVE_FAVORITE,
OPS_CODE_ADD_FAVORITE, OPS_CODE_ADD_FAVORITE,
OPS_CODE_JOIN_ROOM OPS_CODE_JOIN_ROOM

View file

@ -214,6 +214,7 @@ class OperationsMenuController(args: Bundle) : BaseController(
ConversationOperationEnum.OPS_CODE_GET_AND_JOIN_ROOM -> operationGetAndJoinRoom() ConversationOperationEnum.OPS_CODE_GET_AND_JOIN_ROOM -> operationGetAndJoinRoom()
ConversationOperationEnum.OPS_CODE_INVITE_USERS -> operationInviteUsers() ConversationOperationEnum.OPS_CODE_INVITE_USERS -> operationInviteUsers()
ConversationOperationEnum.OPS_CODE_MARK_AS_READ -> operationMarkAsRead() ConversationOperationEnum.OPS_CODE_MARK_AS_READ -> operationMarkAsRead()
ConversationOperationEnum.OPS_CODE_MARK_AS_UNREAD -> operationMarkAsUnread()
ConversationOperationEnum.OPS_CODE_REMOVE_FAVORITE, ConversationOperationEnum.OPS_CODE_REMOVE_FAVORITE,
ConversationOperationEnum.OPS_CODE_ADD_FAVORITE -> operationToggleFavorite() ConversationOperationEnum.OPS_CODE_ADD_FAVORITE -> operationToggleFavorite()
ConversationOperationEnum.OPS_CODE_JOIN_ROOM -> operationJoinRoom() ConversationOperationEnum.OPS_CODE_JOIN_ROOM -> operationJoinRoom()
@ -249,7 +250,7 @@ class OperationsMenuController(args: Bundle) : BaseController(
private fun operationMarkAsRead() { private fun operationMarkAsRead() {
ncApi.setChatReadMarker( ncApi.setChatReadMarker(
credentials, credentials,
ApiUtils.getUrlForSetChatReadMarker( ApiUtils.getUrlForChatReadMarker(
chatApiVersion(), chatApiVersion(),
currentUser!!.baseUrl, currentUser!!.baseUrl,
conversation!!.token conversation!!.token
@ -262,6 +263,21 @@ class OperationsMenuController(args: Bundle) : BaseController(
.subscribe(GenericOperationsObserver()) .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() { private fun operationRenameRoom() {
ncApi.renameRoom( ncApi.renameRoom(
credentials, credentials,

View file

@ -83,7 +83,7 @@ class MarkAsReadReceiver : BroadcastReceiver() {
private fun markAsRead() { private fun markAsRead() {
val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token) val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token)
val apiVersion = ApiUtils.getChatApiVersion(currentUser, intArrayOf(1)) val apiVersion = ApiUtils.getChatApiVersion(currentUser, intArrayOf(1))
val url = ApiUtils.getUrlForSetChatReadMarker( val url = ApiUtils.getUrlForChatReadMarker(
apiVersion, apiVersion,
currentUser.baseUrl, currentUser.baseUrl,
roomToken roomToken

View file

@ -42,6 +42,7 @@ import com.nextcloud.talk.controllers.ConversationsListController
import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum 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_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_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_REMOVE_FAVORITE
import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum.OPS_CODE_RENAME_ROOM import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum.OPS_CODE_RENAME_ROOM
import com.nextcloud.talk.controllers.bottomsheet.EntryMenuController import com.nextcloud.talk.controllers.bottomsheet.EntryMenuController
@ -118,6 +119,10 @@ class ConversationsListBottomDialog(
conversation.unreadMessages > 0 && CapabilitiesUtilNew.canSetChatReadMarker(currentUser) conversation.unreadMessages > 0 && CapabilitiesUtilNew.canSetChatReadMarker(currentUser)
) )
binding.conversationOperationMarkAsUnread.visibility = setVisibleIf(
conversation.unreadMessages <= 0 && CapabilitiesUtilNew.canMarkRoomAsUnread(currentUser)
)
binding.conversationOperationRename.visibility = setVisibleIf( binding.conversationOperationRename.visibility = setVisibleIf(
conversation.isNameEditable(currentUser) conversation.isNameEditable(currentUser)
) )
@ -185,6 +190,10 @@ class ConversationsListBottomDialog(
binding.conversationOperationMarkAsRead.setOnClickListener { binding.conversationOperationMarkAsRead.setOnClickListener {
executeOperationsMenuController(OPS_CODE_MARK_AS_READ) executeOperationsMenuController(OPS_CODE_MARK_AS_READ)
} }
binding.conversationOperationMarkAsUnread.setOnClickListener {
executeOperationsMenuController(OPS_CODE_MARK_AS_UNREAD)
}
} }
private fun executeOperationsMenuController(operation: ConversationOperationEnum) { private fun executeOperationsMenuController(operation: ConversationOperationEnum) {

View file

@ -429,7 +429,7 @@ public class ApiUtils {
"/hovercard/v1/" + userId; "/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"; return getUrlForChat(version, baseUrl, roomToken) + "/read";
} }

View file

@ -51,6 +51,10 @@ object CapabilitiesUtilNew {
return hasSpreedFeatureCapability(user, "chat-read-marker") return hasSpreedFeatureCapability(user, "chat-read-marker")
} }
fun canMarkRoomAsUnread(user: User): Boolean {
return hasSpreedFeatureCapability(user, "chat-unread")
}
@JvmStatic @JvmStatic
fun hasSpreedFeatureCapability(user: User?, capabilityName: String): Boolean { fun hasSpreedFeatureCapability(user: User?, capabilityName: String): Boolean {
if (user?.capabilities?.spreedCapability?.features != null) { if (user?.capabilities?.spreedCapability?.features != null) {

View file

@ -136,6 +136,36 @@
android:textSize="@dimen/bottom_sheet_text_size" /> android:textSize="@dimen/bottom_sheet_text_size" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/conversation_operation_mark_as_unread"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_item_height"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="@dimen/standard_padding"
android:paddingEnd="@dimen/standard_padding"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:src="@drawable/ic_eye_off"
app:tint="@color/high_emphasis_menu_icon" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:paddingStart="40dp"
android:paddingEnd="@dimen/zero"
android:text="@string/nc_mark_as_unread"
android:textAlignment="viewStart"
android:textColor="@color/high_emphasis_text"
android:textSize="@dimen/bottom_sheet_text_size" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/conversation_operation_rename" android:id="@+id/conversation_operation_rename"
android:layout_width="match_parent" android:layout_width="match_parent"