Skip to content

Commit

Permalink
[PBE-3848] add additional option over message xml compose for user bl…
Browse files Browse the repository at this point in the history
…ocking (#5289)

* Add the API to block/unblock users and expose it via chat client

* Use `Date` instead of raw `String` for dates.

* Remove list as response and add single `UserBlock` instead for both block and unblock

* Add block/unblock support into `MessageListController`

* Api & Spotless

* Api & Spotless after merge

* Add option to block user in the menu items of a message both in compose and xml

* Remove useless bool check for capability
  • Loading branch information
aleksandar-apostolov authored Jun 18, 2024
1 parent 215be11 commit 9e0a8ef
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import io.getstream.chat.android.models.ChannelCapabilities
import io.getstream.chat.android.models.Message
import io.getstream.chat.android.models.SyncStatus
import io.getstream.chat.android.models.User
import io.getstream.chat.android.ui.common.state.messages.BlockUser
import io.getstream.chat.android.ui.common.state.messages.Copy
import io.getstream.chat.android.ui.common.state.messages.Delete
import io.getstream.chat.android.ui.common.state.messages.Edit
Expand Down Expand Up @@ -242,6 +243,17 @@ public fun defaultMessageOptionsState(
} else {
null
},
if (!isOwnMessage) {
MessageOptionItemState(
title = R.string.stream_compose_block_user,
iconPainter = painterResource(R.drawable.stream_compose_ic_clear),
action = BlockUser(selectedMessage),
iconColor = ChatTheme.colors.textLowEmphasis,
titleColor = ChatTheme.colors.textHighEmphasis,
)
} else {
null
},
if (visibility.isDeleteMessageVisible && isDeleteMessagePossible) {
MessageOptionItemState(
title = R.string.stream_compose_delete_message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<string name="stream_compose_quoted_message_file_tag">File</string>

<!-- Selected Message Menu -->
<string name="stream_compose_block_user">Block user</string>
<string name="stream_compose_resend_message">Resend</string>
<string name="stream_compose_reply">Reply</string>
<string name="stream_compose_thread_reply">Thread reply</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public final class io/getstream/chat/android/ui/common/feature/messages/list/Mes
public synthetic fun <init> (Ljava/lang/String;Lio/getstream/chat/android/ui/common/helper/ClipboardHandler;ZLjava/lang/String;Ljava/lang/String;ILio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/client/setup/state/ClientState;Lio/getstream/chat/android/ui/common/state/messages/list/DeletedMessageVisibility;ZLio/getstream/chat/android/ui/common/state/messages/list/MessageFooterVisibility;ZLio/getstream/chat/android/ui/common/feature/messages/list/DateSeparatorHandler;Lio/getstream/chat/android/ui/common/feature/messages/list/DateSeparatorHandler;Lio/getstream/chat/android/ui/common/feature/messages/list/MessagePositionHandler;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun banUser (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;)V
public static synthetic fun banUser$default (Lio/getstream/chat/android/ui/common/feature/messages/list/MessageListController;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;ILjava/lang/Object;)V
public final fun blockUser (Ljava/lang/String;)V
public final fun clearNewMessageState ()V
public final fun deleteMessage (Lio/getstream/chat/android/models/Message;Z)V
public static synthetic fun deleteMessage$default (Lio/getstream/chat/android/ui/common/feature/messages/list/MessageListController;Lio/getstream/chat/android/models/Message;ZILjava/lang/Object;)V
Expand Down Expand Up @@ -202,6 +203,7 @@ public final class io/getstream/chat/android/ui/common/feature/messages/list/Mes
public final fun shadowBanUser (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;)V
public static synthetic fun shadowBanUser$default (Lio/getstream/chat/android/ui/common/feature/messages/list/MessageListController;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;ILjava/lang/Object;)V
public final fun unbanUser (Ljava/lang/String;)V
public final fun unblockUser (Ljava/lang/String;)V
public final fun unmuteUser (Lio/getstream/chat/android/models/User;)V
public final fun unmuteUser (Ljava/lang/String;)V
public final fun unpinMessage (Lio/getstream/chat/android/models/Message;)V
Expand Down Expand Up @@ -517,6 +519,18 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Vi
public fun toString ()Ljava/lang/String;
}

public final class io/getstream/chat/android/ui/common/state/messages/BlockUser : io/getstream/chat/android/ui/common/state/messages/MessageAction {
public static final field $stable I
public fun <init> (Lio/getstream/chat/android/models/Message;)V
public final fun component1 ()Lio/getstream/chat/android/models/Message;
public final fun copy (Lio/getstream/chat/android/models/Message;)Lio/getstream/chat/android/ui/common/state/messages/BlockUser;
public static synthetic fun copy$default (Lio/getstream/chat/android/ui/common/state/messages/BlockUser;Lio/getstream/chat/android/models/Message;ILjava/lang/Object;)Lio/getstream/chat/android/ui/common/state/messages/BlockUser;
public fun equals (Ljava/lang/Object;)Z
public fun getMessage ()Lio/getstream/chat/android/models/Message;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class io/getstream/chat/android/ui/common/state/messages/Copy : io/getstream/chat/android/ui/common/state/messages/MessageAction {
public static final field $stable I
public fun <init> (Lio/getstream/chat/android/models/Message;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import io.getstream.chat.android.state.extensions.loadOlderMessages
import io.getstream.chat.android.state.extensions.watchChannelAsState
import io.getstream.chat.android.state.plugin.state.channel.thread.ThreadState
import io.getstream.chat.android.ui.common.helper.ClipboardHandler
import io.getstream.chat.android.ui.common.state.messages.BlockUser
import io.getstream.chat.android.ui.common.state.messages.Copy
import io.getstream.chat.android.ui.common.state.messages.Delete
import io.getstream.chat.android.ui.common.state.messages.MarkAsUnread
Expand Down Expand Up @@ -1431,6 +1432,7 @@ public class MessageListController(
is Delete, is FlagMessage -> {
_messageActions.value = _messageActions.value + messageAction
}
is BlockUser -> blockUser(messageAction.message.user.id)
is Copy -> copyMessage(messageAction.message)
is React -> reactToMessage(messageAction.reaction, messageAction.message)
is Pin -> updateMessagePin(messageAction.message)
Expand Down Expand Up @@ -1873,6 +1875,32 @@ public class MessageListController(
})
}

/**
* Block a user. Unlike ban the block is not channel related but rather directly to the user.
*
* @param userId the id of the user that will be blocked.
*/
public fun blockUser(userId: String) {
chatClient.blockUser(userId).enqueue(onError = { error ->
onActionResult(error) {
ErrorEvent.BlockUserError(it)
}
})
}

/**
* Unblock a user.
*
* @param userId the id of the user that will be unblocked.
*/
public fun unblockUser(userId: String) {
chatClient.unblockUser(userId).enqueue(onError = { error ->
onActionResult(error) {
ErrorEvent.BlockUserError(it)
}
})
}

/**
* Executes one of the actions for the given ephemeral giphy message.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public data class Flag(
override val message: Message,
) : MessageAction()

/**
* Block the sender of the message.
*/
public data class BlockUser(override val message: Message) : MessageAction()

/**
* User-customizable action, with any number of extra properties.
*
Expand All @@ -121,5 +126,6 @@ public fun MessageAction.updateMessage(message: Message): MessageAction {
is Delete -> copy(message = message)
is Flag -> copy(message = message)
is CustomAction -> copy(message = message)
is BlockUser -> copy(message = message)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,7 @@ public final class io/getstream/chat/android/ui/feature/messages/list/MessageLis
public final fun setMessageRetryHandler (Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$MessageRetryHandler;)V
public final fun setMessageRetryListener (Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$MessageRetryListener;)V
public final fun setMessageUnpinHandler (Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$MessageUnpinHandler;)V
public final fun setMessageUserBlockHandler (Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$MessageUserBlockHandler;)V
public final fun setMessageViewHolderFactory (Lio/getstream/chat/android/ui/feature/messages/list/adapter/MessageListItemViewHolderFactory;)V
public final fun setModeratedMessageHandler (Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$ModeratedMessageOptionHandler;)V
public final fun setModeratedMessageLongClickListener (Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$ModeratedMessageLongClickListener;)V
Expand Down Expand Up @@ -2267,6 +2268,10 @@ public abstract interface class io/getstream/chat/android/ui/feature/messages/li
public abstract fun onMessageUnpin (Lio/getstream/chat/android/models/Message;)V
}

public abstract interface class io/getstream/chat/android/ui/feature/messages/list/MessageListView$MessageUserBlockHandler {
public abstract fun onUserBlocked (Lio/getstream/chat/android/models/Message;)V
}

public final class io/getstream/chat/android/ui/feature/messages/list/MessageListView$MessagesStart : java/lang/Enum {
public static final field BOTTOM Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$MessagesStart;
public static final field TOP Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$MessagesStart;
Expand Down Expand Up @@ -2389,7 +2394,7 @@ public abstract interface class io/getstream/chat/android/ui/feature/messages/li

public final class io/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle : io/getstream/chat/android/ui/helper/ViewStyle {
public static final field Companion Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle$Companion;
public fun <init> (Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZ)V
public fun <init> (Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZ)V
public final fun component1 ()Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;
public final fun component10 ()I
public final fun component11 ()Z
Expand All @@ -2408,29 +2413,29 @@ public final class io/getstream/chat/android/ui/feature/messages/list/MessageLis
public final fun component23 ()Z
public final fun component24 ()I
public final fun component25 ()Z
public final fun component26 ()Z
public final fun component26 ()I
public final fun component27 ()Z
public final fun component28 ()Z
public final fun component29 ()Z
public final fun component3 ()Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;
public final fun component30 ()Z
public final fun component31 ()Lio/getstream/chat/android/ui/font/TextStyle;
public final fun component32 ()Lio/getstream/chat/android/ui/font/TextStyle;
public final fun component33 ()I
public final fun component34 ()I
public final fun component35 ()Lio/getstream/chat/android/ui/font/TextStyle;
public final fun component31 ()Z
public final fun component32 ()Z
public final fun component33 ()Lio/getstream/chat/android/ui/font/TextStyle;
public final fun component34 ()Lio/getstream/chat/android/ui/font/TextStyle;
public final fun component35 ()I
public final fun component36 ()I
public final fun component37 ()Lio/getstream/chat/android/ui/font/TextStyle;
public final fun component38 ()I
public final fun component39 ()I
public final fun component39 ()Lio/getstream/chat/android/ui/font/TextStyle;
public final fun component4 ()Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;
public final fun component40 ()I
public final fun component41 ()I
public final fun component42 ()I
public final fun component43 ()I
public final fun component44 ()Z
public final fun component44 ()I
public final fun component45 ()I
public final fun component46 ()I
public final fun component46 ()Z
public final fun component47 ()I
public final fun component48 ()I
public final fun component49 ()I
Expand All @@ -2442,17 +2447,21 @@ public final class io/getstream/chat/android/ui/feature/messages/list/MessageLis
public final fun component54 ()I
public final fun component55 ()I
public final fun component56 ()I
public final fun component57 ()Z
public final fun component58 ()Z
public final fun component57 ()I
public final fun component58 ()I
public final fun component59 ()Z
public final fun component6 ()Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;
public final fun component60 ()Z
public final fun component7 ()Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;
public final fun component8 ()Z
public final fun component9 ()I
public final fun copy (Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZ)Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;
public static synthetic fun copy$default (Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZIILjava/lang/Object;)Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;
public final fun copy (Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZ)Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;
public static synthetic fun copy$default (Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZIILjava/lang/Object;)Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;
public fun equals (Ljava/lang/Object;)Z
public final fun getAudioRecordPlayerViewStyle ()Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;
public final fun getBackgroundColor ()I
public final fun getBlockUserEnabled ()Z
public final fun getBlockUserIcon ()I
public final fun getCopyIcon ()I
public final fun getCopyTextEnabled ()Z
public final fun getDeleteConfirmationEnabled ()Z
Expand Down Expand Up @@ -4264,6 +4273,17 @@ public final class io/getstream/chat/android/ui/viewmodel/messages/MessageListVi
public fun toString ()Ljava/lang/String;
}

public final class io/getstream/chat/android/ui/viewmodel/messages/MessageListViewModel$Event$BlockUser : io/getstream/chat/android/ui/viewmodel/messages/MessageListViewModel$Event {
public fun <init> (Ljava/lang/String;)V
public final fun component1 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;)Lio/getstream/chat/android/ui/viewmodel/messages/MessageListViewModel$Event$BlockUser;
public static synthetic fun copy$default (Lio/getstream/chat/android/ui/viewmodel/messages/MessageListViewModel$Event$BlockUser;Ljava/lang/String;ILjava/lang/Object;)Lio/getstream/chat/android/ui/viewmodel/messages/MessageListViewModel$Event$BlockUser;
public fun equals (Ljava/lang/Object;)Z
public final fun getUserId ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class io/getstream/chat/android/ui/viewmodel/messages/MessageListViewModel$Event$BottomEndRegionReached : io/getstream/chat/android/ui/viewmodel/messages/MessageListViewModel$Event {
public fun <init> (Ljava/lang/String;)V
public final fun component1 ()Ljava/lang/String;
Expand Down
Loading

0 comments on commit 9e0a8ef

Please sign in to comment.