Skip to content

Commit 09d2105

Browse files
committed
feat(fc): update protos; add mute user support for hosts
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent 2ed0bc4 commit 09d2105

File tree

20 files changed

+635
-88
lines changed

20 files changed

+635
-88
lines changed

definitions/flipchat/protos/src/main/proto/chat/v1/flipchat_service.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ service Chat {
4242
rpc SetCoverCharge(SetCoverChargeRequest) returns (SetCoverChargeResponse);
4343
// RemoveUser removes a user from a chat
4444
rpc RemoveUser(RemoveUserRequest) returns (RemoveUserResponse);
45+
// MuteUser mutes a user in the chat and removes their ability to send messages
46+
rpc MuteUser(MuteUserRequest) returns (MuteUserResponse);
4547
// ReportUser reports a user for a given message
4648
//
4749
// todo: might belong in a different service long-term
@@ -260,6 +262,18 @@ message RemoveUserResponse{
260262
DENIED = 1;
261263
}
262264
}
265+
message MuteUserRequest{
266+
common.v1.ChatId chat_id = 1;
267+
common.v1.UserId user_id = 2;
268+
common.v1.Auth auth = 3;
269+
}
270+
message MuteUserResponse{
271+
Result result = 1;
272+
enum Result {
273+
OK = 0;
274+
DENIED = 1;
275+
}
276+
}
263277
message ReportUserRequest{
264278
common.v1.UserId user_id = 1;
265279
messaging.v1.MessageId message_id = 2;
@@ -318,6 +332,8 @@ message Member {
318332
bool is_self = 4;
319333
// NOTE: We may switch to 'roles' in the future.
320334
bool is_host = 5;
335+
// Cant this user send messages in the chat?
336+
bool is_muted = 6;
321337
}
322338
message MemberIdentity {
323339
// If present, the display name of the user.

definitions/flipchat/protos/src/main/proto/messaging/v1/messaging_service.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ message SendMessageResponse {
8484
enum Result {
8585
OK = 0;
8686
DENIED = 1;
87-
INVALID_CONTENT_TYPE = 2;
8887
}
8988
// The chat message that was sent if the RPC was succesful, which includes
9089
// server-side metadata like the generated message ID and official timestamp

definitions/flipchat/protos/src/main/proto/push/v1/push_service.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ message DeleteTokenRequest {
3737
common.v1.Auth auth = 3;
3838
}
3939
message DeleteTokenResponse {
40+
Result result = 1;
41+
enum Result {
42+
OK = 0;
43+
}
4044
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ data class ConversationMessageIndice(
88
val message: ConversationMessage,
99
val sender: ConversationMember?,
1010
val messageContent: MessageContent,
11-
)
11+
)
12+
13+
sealed interface ChattableState {
14+
data object Unknown: ChattableState
15+
data object Enabled: ChattableState
16+
data object DisabledByMute: ChattableState
17+
}

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

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package xyz.flipchat.app.features.chat.conversation
55
import android.os.Parcelable
66
import android.widget.Toast
77
import androidx.activity.compose.BackHandler
8+
import androidx.compose.animation.AnimatedContent
89
import androidx.compose.animation.AnimatedVisibility
910
import androidx.compose.animation.core.Spring
1011
import androidx.compose.animation.core.spring
@@ -14,6 +15,7 @@ import androidx.compose.animation.scaleIn
1415
import androidx.compose.animation.scaleOut
1516
import androidx.compose.animation.slideInVertically
1617
import androidx.compose.animation.slideOutVertically
18+
import androidx.compose.animation.togetherWith
1719
import androidx.compose.foundation.ExperimentalFoundationApi
1820
import androidx.compose.foundation.background
1921
import androidx.compose.foundation.clickable
@@ -32,13 +34,15 @@ import androidx.compose.material.Divider
3234
import androidx.compose.material.Text
3335
import androidx.compose.runtime.Composable
3436
import androidx.compose.runtime.LaunchedEffect
37+
import androidx.compose.runtime.SideEffect
3538
import androidx.compose.runtime.collectAsState
3639
import androidx.compose.runtime.getValue
3740
import androidx.compose.ui.Alignment
3841
import androidx.compose.ui.Modifier
3942
import androidx.compose.ui.graphics.Color
4043
import androidx.compose.ui.platform.LocalContext
4144
import androidx.compose.ui.res.stringResource
45+
import androidx.compose.ui.text.style.TextAlign
4246
import androidx.compose.ui.util.fastForEachIndexed
4347
import androidx.lifecycle.Lifecycle
4448
import androidx.paging.compose.LazyPagingItems
@@ -67,7 +71,9 @@ import com.getcode.ui.components.chat.messagecontents.MessageControlAction
6771
import com.getcode.ui.components.chat.utils.ChatItem
6872
import com.getcode.ui.components.chat.utils.HandleMessageChanges
6973
import com.getcode.ui.theme.CodeScaffold
74+
import com.getcode.ui.utils.withTopBorder
7075
import com.getcode.util.formatDateRelatively
76+
import com.google.accompanist.systemuicontroller.rememberSystemUiController
7177
import kotlinx.coroutines.flow.filterIsInstance
7278
import kotlinx.coroutines.flow.launchIn
7379
import kotlinx.coroutines.flow.onEach
@@ -97,10 +103,12 @@ data class ConversationScreen(
97103
Lifecycle.Event.ON_RESUME -> {
98104
vm.dispatchEvent(ConversationViewModel.Event.ReopenStream)
99105
}
106+
100107
Lifecycle.Event.ON_STOP,
101108
Lifecycle.Event.ON_DESTROY -> {
102109
vm.dispatchEvent(ConversationViewModel.Event.CloseStream)
103110
}
111+
104112
else -> Unit
105113
}
106114
}
@@ -207,12 +215,12 @@ private fun ConversationScreenContent(
207215
messages: LazyPagingItems<ChatItem>,
208216
dispatchEvent: (ConversationViewModel.Event) -> Unit,
209217
) {
218+
val systemUiController = rememberSystemUiController()
210219
CodeScaffold(
211220
bottomBar = {
212221
Column(
213222
modifier = Modifier
214-
.imePadding()
215-
.navigationBarsPadding(),
223+
.imePadding(),
216224
verticalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x3),
217225
) {
218226
AnimatedVisibility(
@@ -230,12 +238,53 @@ private fun ConversationScreenContent(
230238
.padding(horizontal = CodeTheme.dimens.grid.x2)
231239
)
232240
}
233-
ChatInput(
234-
state = state.textFieldState,
235-
sendCashEnabled = false,
236-
onSendMessage = { dispatchEvent(ConversationViewModel.Event.SendMessage) },
237-
onSendCash = { dispatchEvent(ConversationViewModel.Event.SendCash) }
238-
)
241+
242+
AnimatedContent(
243+
targetState = state.chattableState,
244+
transitionSpec = {
245+
(slideInVertically(
246+
animationSpec = spring(
247+
dampingRatio = Spring.DampingRatioMediumBouncy,
248+
stiffness = Spring.StiffnessLow
249+
)
250+
) { it } + scaleIn() + fadeIn()).togetherWith(
251+
fadeOut() + scaleOut() + slideOutVertically { it }
252+
)
253+
},
254+
label = "chat input area"
255+
) {
256+
when (it) {
257+
ChattableState.DisabledByMute -> {
258+
Text(
259+
modifier = Modifier
260+
.fillMaxWidth()
261+
.background(CodeTheme.colors.secondary)
262+
.withTopBorder(color = CodeTheme.colors.dividerVariant)
263+
.padding(
264+
top = CodeTheme.dimens.grid.x1,
265+
bottom = CodeTheme.dimens.grid.x3
266+
).navigationBarsPadding(),
267+
textAlign = TextAlign.Center,
268+
text = stringResource(R.string.title_youHaveBeenMuted),
269+
style = CodeTheme.typography.textSmall,
270+
color = CodeTheme.colors.textSecondary
271+
)
272+
}
273+
274+
ChattableState.Enabled -> {
275+
ChatInput(
276+
modifier = Modifier.navigationBarsPadding(),
277+
state = state.textFieldState,
278+
sendCashEnabled = false,
279+
onSendMessage = { dispatchEvent(ConversationViewModel.Event.SendMessage) },
280+
onSendCash = { dispatchEvent(ConversationViewModel.Event.SendCash) }
281+
)
282+
}
283+
284+
ChattableState.Unknown -> Unit
285+
}
286+
287+
}
239288
}
240289
}
241290
) { padding ->
@@ -287,8 +336,16 @@ private data class MessageActionContextSheet(val actions: List<MessageControlAct
287336
text = when (action) {
288337
is MessageControlAction.Copy -> stringResource(R.string.action_copyMessage)
289338
is MessageControlAction.Delete -> stringResource(R.string.action_deleteMessage)
290-
is MessageControlAction.RemoveUser -> stringResource(R.string.action_removeUser, action.name)
339+
is MessageControlAction.RemoveUser -> stringResource(
340+
R.string.action_removeUser,
341+
action.name
342+
)
343+
291344
is MessageControlAction.ReportUserForMessage -> stringResource(R.string.action_report)
345+
is MessageControlAction.MuteUser -> stringResource(
346+
R.string.action_muteUser,
347+
action.name
348+
)
292349
},
293350
style = CodeTheme.typography.textMedium,
294351
modifier = Modifier

0 commit comments

Comments
 (0)