@@ -197,6 +197,8 @@ class ConversationViewModel @Inject constructor(
197197 data class RemoveUser (val conversationId : ID , val userId : ID ) : Event
198198 data class ReportUser (val userId : ID , val messageId : ID ) : Event
199199 data class MuteUser (val conversationId : ID , val userId : ID ) : Event
200+ data class BlockUser (val userId : ID ) : Event
201+ data class UnblockUser (val userId : ID ) : Event
200202
201203 data object OnUserTypingStarted : Event
202204 data object OnUserTypingStopped : Event
@@ -517,6 +519,38 @@ class ConversationViewModel @Inject constructor(
517519 )
518520 .launchIn(viewModelScope)
519521
522+ eventFlow
523+ .filterIsInstance<Event .BlockUser >()
524+ .map { it.userId }
525+ .map { roomController.blockUser(it) }
526+ .onResult(
527+ onError = {
528+ TopBarManager .showMessage(
529+ TopBarManager .TopBarMessage (
530+ title = resources.getString(R .string.error_title_failedToBlockUser),
531+ message = resources.getString(R .string.error_description_failedToBlockUser)
532+ )
533+ )
534+ }
535+ )
536+ .launchIn(viewModelScope)
537+
538+ eventFlow
539+ .filterIsInstance<Event .UnblockUser >()
540+ .map { it.userId }
541+ .map { roomController.unblockUser(it) }
542+ .onResult(
543+ onError = {
544+ TopBarManager .showMessage(
545+ TopBarManager .TopBarMessage (
546+ title = resources.getString(R .string.error_title_failedToUnblockUser),
547+ message = resources.getString(R .string.error_description_failedToUnblockUser)
548+ )
549+ )
550+ }
551+ )
552+ .launchIn(viewModelScope)
553+
520554 eventFlow
521555 .filterIsInstance<Event .CopyMessage >()
522556 .map { it.text }
@@ -687,6 +721,7 @@ class ConversationViewModel @Inject constructor(
687721 },
688722 displayName = it.member?.memberName ? : " Deleted" ,
689723 isSelf = it.content.isFromSelf,
724+ isBlocked = it.member?.isBlocked == true ,
690725 isHost = it.message.senderId == currentState.hostId && ! contents.isFromSelf,
691726 )
692727 )
@@ -711,6 +746,7 @@ class ConversationViewModel @Inject constructor(
711746 displayName = member?.memberName ? : " Deleted" ,
712747 isSelf = contents.isFromSelf,
713748 isHost = message.senderId == currentState.hostId && ! contents.isFromSelf,
749+ isBlocked = member?.isBlocked == true ,
714750 ),
715751 originalMessage = anchor,
716752 messageControls = MessageControls (
@@ -777,6 +813,7 @@ class ConversationViewModel @Inject constructor(
777813 displayName = member?.memberName ? : " Deleted" ,
778814 isSelf = contents.isFromSelf,
779815 isHost = message.senderId == stateFlow.value.hostId && ! contents.isFromSelf,
816+ isBlocked = member?.isBlocked == true
780817 )
781818 val anchor = MessageReplyAnchor (message.id, sender, contents)
782819 dispatchEvent(Event .ReplyTo (anchor))
@@ -824,6 +861,25 @@ class ConversationViewModel @Inject constructor(
824861 }
825862
826863 if (! contents.isFromSelf) {
864+ if (member?.isBlocked != null ) {
865+ if (member.isBlocked) {
866+ add(
867+ MessageControlAction .UnblockUser (member.memberName.orEmpty()) {
868+ dispatchEvent(Event .UnblockUser (member.id))
869+ }
870+ )
871+ } else {
872+ add(
873+ MessageControlAction .BlockUser (member.memberName.orEmpty()) {
874+ confirmUserBlock(
875+ user = member.memberName,
876+ userId = message.senderId,
877+ )
878+ }
879+ )
880+ }
881+ }
882+
827883 add(
828884 MessageControlAction .ReportUserForMessage (member?.memberName.orEmpty()) {
829885 confirmUserReport(
@@ -885,6 +941,25 @@ class ConversationViewModel @Inject constructor(
885941 )
886942 }
887943
944+ private fun confirmUserBlock (user : String? , userId : ID ) {
945+ BottomBarManager .showMessage(
946+ BottomBarManager .BottomBarMessage (
947+ title = resources.getString(
948+ R .string.title_blockUserInRoom,
949+ user.orEmpty().ifEmpty { " User" },
950+ ),
951+ subtitle = resources.getString(R .string.subtitle_blockUserInRoom, user.orEmpty()),
952+ positiveText = resources.getString(R .string.action_blockUser, user.orEmpty()),
953+ negativeText = " " ,
954+ tertiaryText = resources.getString(R .string.action_cancel),
955+ onPositive = { dispatchEvent(Event .BlockUser (userId)) },
956+ onNegative = { },
957+ type = BottomBarManager .BottomBarMessageType .DESTRUCTIVE ,
958+ showScrim = true ,
959+ )
960+ )
961+ }
962+
888963 private fun confirmUserReport (user : String? , userId : ID , messageId : ID ) {
889964 BottomBarManager .showMessage(
890965 BottomBarManager .BottomBarMessage (
@@ -1011,6 +1086,8 @@ class ConversationViewModel @Inject constructor(
10111086 is Event .RemoveUser ,
10121087 is Event .ReportUser ,
10131088 is Event .MuteUser ,
1089+ is Event .BlockUser ,
1090+ is Event .UnblockUser ,
10141091 is Event .Resumed ,
10151092 is Event .Stopped ,
10161093 is Event .LookupRoom ,
0 commit comments