Skip to content

Commit cd244ea

Browse files
committed
feat(fc/conversation): add block user control
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent bc5c591 commit cd244ea

19 files changed

Lines changed: 685 additions & 88 deletions

File tree

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/chat/conversation/ConversationViewModel.kt

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/chat/conversation/MessageActionContextSheet.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ internal data class MessageActionContextSheet(val actions: List<MessageControlAc
4040
action.name
4141
)
4242

43+
is MessageControlAction.BlockUser -> stringResource(
44+
R.string.action_blockUser,
45+
action.name
46+
)
47+
48+
49+
is MessageControlAction.UnblockUser -> stringResource(
50+
R.string.action_unblockUser,
51+
action.name
52+
)
53+
54+
4355
is MessageControlAction.ReportUserForMessage -> stringResource(R.string.action_report)
4456
is MessageControlAction.MuteUser -> stringResource(
4557
R.string.action_muteUser,

flipchatApp/src/main/res/values/strings.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
<string name="error_title_failedToMuteUser">Something Went Wrong</string>
5151
<string name="error_description_failedToMuteUser">This user\'s could not be muted. Please check your network connection and try again</string>
5252

53+
<string name="error_title_failedToBlockUser">Something Went Wrong</string>
54+
<string name="error_description_failedToBlockUser">This user could not be block. Please check your network connection and try again</string>
55+
56+
<string name="error_title_failedToUnblockUser">Something Went Wrong</string>
57+
<string name="error_description_failedToUnblockUser">This user could not be unblocked. Please check your network connection and try again</string>
58+
59+
5360
<string name="error_title_failedToMuteChat">Something Went Wrong</string>
5461
<string name="error_description_failedToMuteChat">Please check your network connection and try again</string>
5562

@@ -103,6 +110,10 @@
103110
<string name="action_mute">Mute</string>
104111
<string name="action_muteUser">Mute %1$s</string>
105112

113+
<string name="title_blockUserInRoom">Block %1$s?</string>
114+
<string name="subtitle_blockUserInRoom">All messages from this user will be hidden</string>
115+
<string name="action_block">Block</string>
116+
106117
<string name="title_reportUserForMessage">Report</string>
107118
<string name="subtitle_reportUserForMessage">This message will be forwarded to Flipchat. This contact will not be notified</string>
108119
<string name="action_report">Report</string>
@@ -114,6 +125,9 @@
114125

115126
<string name="action_copyMessage">Copy</string>
116127
<string name="action_deleteMessage">Delete</string>
128+
<string name="action_blockUser">Block User</string>
129+
<string name="action_blockUserByName">Block %1$s</string>
130+
<string name="action_unblockUser">Unblock %1$s</string>
117131
<string name="action_removeUser">Remove %1$s</string>
118132
<string name="action_reportUser">Report %1$s</string>
119133

libs/models/src/main/kotlin/com/getcode/model/chat/Sender.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package com.getcode.model.chat
33
import com.getcode.model.ID
44

55
data class Sender(
6-
val id: ID?,
7-
val profileImage: String?,
8-
val displayName: String?,
9-
val isHost: Boolean,
10-
val isSelf: Boolean
6+
val id: ID? = null,
7+
val profileImage: String? = null,
8+
val displayName: String? = null,
9+
val isHost: Boolean = false,
10+
val isSelf: Boolean = false,
11+
val isBlocked: Boolean = false,
1112
)

services/flipchat/chat/src/main/kotlin/xyz/flipchat/services/domain/model/chat/ConversationMember.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ data class ConversationMember(
2727
@ColumnInfo(defaultValue = "false")
2828
val isMuted: Boolean,
2929
@ColumnInfo(defaultValue = "false")
30-
val isFullMember: Boolean
30+
val isFullMember: Boolean,
31+
@ColumnInfo(defaultValue = "false")
32+
val isBlocked: Boolean
3133
) {
3234
@Ignore
3335
val id: ID = Base58.decode(memberIdBase58).toList()

services/flipchat/chat/src/main/kotlin/xyz/flipchat/services/internal/data/mapper/ConversationMemberMapper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class ConversationMemberMapper @Inject constructor(): Mapper<Pair<ID, Member>, C
1717
imageUri = member.identity?.imageUrl,
1818
isHost = member.isModerator,
1919
isMuted = member.isMuted,
20-
isFullMember = !member.isSpectator
20+
isFullMember = !member.isSpectator,
21+
isBlocked = false // local set only right now
2122
)
2223
}
2324
}

services/flipchat/chat/src/main/kotlin/xyz/flipchat/services/internal/db/ConversationMemberDao.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ interface ConversationMemberDao {
6767
unmuteMember(conversationId.base58, memberId.base58)
6868
}
6969

70+
@Query("UPDATE members SET isBlocked = 1 WHERE memberIdBase58 = :memberId")
71+
suspend fun blockMember(memberId: String)
72+
suspend fun blockMember(memberId: ID) {
73+
blockMember(memberId.base58)
74+
}
75+
76+
@Query("UPDATE members SET isBlocked = 0 WHERE memberIdBase58 = :memberId")
77+
suspend fun unblockMember(memberId: String)
78+
suspend fun unblockMember(memberId: ID) {
79+
unblockMember(memberId.base58)
80+
}
81+
7082
@Query("DELETE FROM members")
7183
fun clearMembers()
7284
}

0 commit comments

Comments
 (0)