Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class ChatViewModel @Inject constructor(
MutableStateFlow<SpaceInviteLinkAccessLevel>(SpaceInviteLinkAccessLevel.LinkDisabled())

private val syncStatus = MutableStateFlow<SyncStatus?>(null)
private val currentPermission = MutableStateFlow<SpaceMemberPermissions?>(null)
private val dateFormatter = SimpleDateFormat("d MMMM YYYY")
private val messageRateLimiter = MessageRateLimiter()

Expand All @@ -191,6 +192,7 @@ class ChatViewModel @Inject constructor(
spacePermissionProvider
.observe(vmParams.space)
.collect { permission ->
currentPermission.value = permission
if (permission?.isOwnerOrEditor() == true) {
if (chatBoxMode.value is ChatBoxMode.ReadOnly) {
chatBoxMode.value = ChatBoxMode.Default()
Expand All @@ -199,6 +201,21 @@ class ChatViewModel @Inject constructor(
chatBoxMode.value = ChatBoxMode.ReadOnly
}
canCreateInviteLink.value = permission?.isOwner() == true
// Update header with new permission if already set
val currentHeader = header.value
when (currentHeader) {
is HeaderView.Default -> {
header.value = currentHeader.copy(
canEdit = permission?.isOwnerOrEditor() == true
)
}
is HeaderView.ChatObject -> {
header.value = currentHeader.copy(
canEdit = permission?.isOwnerOrEditor() == true
)
}
else -> {}
}
}
}

Expand All @@ -211,6 +228,7 @@ class ChatViewModel @Inject constructor(
val notificationSetting = NotificationStateCalculator
.calculateChatNotificationState(chatSpace = view, chatId = vmParams.ctx)
.toNotificationSetting()
val canEdit = currentPermission.value?.isOwnerOrEditor() == true
getObject.async(
GetObject.Params(
target = vmParams.ctx,
Expand All @@ -223,7 +241,8 @@ class ChatViewModel @Inject constructor(
title = view.name.orEmpty(),
icon = view.spaceIcon(builder = urlBuilder),
isMuted = isMuted,
notificationSetting = notificationSetting
notificationSetting = notificationSetting,
canEdit = canEdit
)
} else {
// Chat object
Expand All @@ -241,7 +260,8 @@ class ChatViewModel @Inject constructor(
),
isMuted = isMuted,
notificationSetting = notificationSetting,
isPinned = isPinned
isPinned = isPinned,
canEdit = canEdit
)
}
}.onFailure {
Expand All @@ -251,7 +271,8 @@ class ChatViewModel @Inject constructor(
title = view.name.orEmpty(),
icon = view.spaceIcon(builder = urlBuilder),
isMuted = isMuted,
notificationSetting = notificationSetting
notificationSetting = notificationSetting,
canEdit = canEdit
)
}
}
Expand Down Expand Up @@ -2399,7 +2420,8 @@ class ChatViewModel @Inject constructor(
val isMuted: Boolean = false,
val showDropDownMenu: Boolean = true,
val showAddMembers: Boolean = true,
val notificationSetting: NotificationSetting = NotificationSetting.ALL
val notificationSetting: NotificationSetting = NotificationSetting.ALL,
val canEdit: Boolean = true
) : HeaderView()
data class ChatObject(
val icon: ObjectIcon,
Expand All @@ -2408,7 +2430,8 @@ class ChatViewModel @Inject constructor(
val showDropDownMenu: Boolean = true,
val showAddMembers: Boolean = false,
val notificationSetting: NotificationSetting = NotificationSetting.ALL,
val isPinned: Boolean = false
val isPinned: Boolean = false,
val canEdit: Boolean = true
) : HeaderView()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fun BoxScope.ChatMenu(
expanded: Boolean,
currentNotificationSetting: NotificationSetting,
isPinned: Boolean = false,
canEdit: Boolean = true,
onDismissRequest: () -> Unit,
onPropertiesClick: () -> Unit,
onEditInfoClick: () -> Unit,
Expand Down Expand Up @@ -96,32 +97,34 @@ fun BoxScope.ChatMenu(
// )
// Divider(paddingStart = 0.dp, paddingEnd = 0.dp)

// Edit Info
DropdownMenuItem(
content = {
ChatMenuItemContent(
text = stringResource(R.string.chat_edit_info),
iconRes = R.drawable.ic_edit_info_24
)
},
onClick = { onEditInfoClick() }
)
Divider(paddingStart = 0.dp, paddingEnd = 0.dp, height = 8.dp)
// Edit Info - only show if user can edit
if (canEdit) {
DropdownMenuItem(
content = {
ChatMenuItemContent(
text = stringResource(R.string.chat_edit_info),
iconRes = R.drawable.ic_edit_info_24
)
},
onClick = { onEditInfoClick() }
)
Divider(paddingStart = 0.dp, paddingEnd = 0.dp, height = 8.dp)

// Pin/Unpin
DropdownMenuItem(
content = {
ChatMenuItemContent(
text = stringResource(
if (isPinned) R.string.object_action_unpin
else R.string.object_action_pin
),
iconRes = R.drawable.ic_pin_24
)
},
onClick = { onPinClick() }
)
Divider(paddingStart = 0.dp, paddingEnd = 0.dp)
// Pin/Unpin - only show if user can edit
DropdownMenuItem(
content = {
ChatMenuItemContent(
text = stringResource(
if (isPinned) R.string.object_action_unpin
else R.string.object_action_pin
),
iconRes = R.drawable.ic_pin_24
)
},
onClick = { onPinClick() }
)
Divider(paddingStart = 0.dp, paddingEnd = 0.dp)
}

// Notifications - expandable
DropdownMenuItem(
Expand Down Expand Up @@ -192,17 +195,19 @@ fun BoxScope.ChatMenu(

Divider(paddingStart = 0.dp, paddingEnd = 0.dp)

// Move to Bin
DropdownMenuItem(
content = {
ChatMenuItemContent(
text = stringResource(R.string.chat_move_to_bin),
iconRes = R.drawable.ic_chat_menu_to_bin_24,
textColor = R.color.palette_system_red
)
},
onClick = { onMoveToBinClick() }
)
// Move to Bin - only show if user can edit
if (canEdit) {
DropdownMenuItem(
content = {
ChatMenuItemContent(
text = stringResource(R.string.chat_move_to_bin),
iconRes = R.drawable.ic_chat_menu_to_bin_24,
textColor = R.color.palette_system_red
)
},
onClick = { onMoveToBinClick() }
)
}
}
}
}
Expand Down Expand Up @@ -267,6 +272,7 @@ fun ChatMenuPreview() {
expanded = true,
currentNotificationSetting = NotificationSetting.ALL,
isPinned = false,
canEdit = true,
onDismissRequest = {},
onPropertiesClick = {},
onEditInfoClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ fun ChatTopToolbar(
expanded = showDropdownMenu,
currentNotificationSetting = header.notificationSetting,
isPinned = header.isPinned,
canEdit = header.canEdit,
onDismissRequest = {
showDropdownMenu = false
},
Expand Down
Loading