mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-22 21:15:30 +03:00
Merge pull request #2743 from nextcloud/feature/noid/markRoomAdUnread
Add ability to mark a room as unread
This commit is contained in:
commit
2d369d89c9
9 changed files with 68 additions and 4 deletions
|
@ -477,6 +477,10 @@ public interface NcApi {
|
|||
@Url String url,
|
||||
@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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -136,6 +136,36 @@
|
|||
android:textSize="@dimen/bottom_sheet_text_size" />
|
||||
</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
|
||||
android:id="@+id/conversation_operation_rename"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in a new issue