Skip to content

Commit fd55045

Browse files
Merge pull request #6199 from nextcloud/bugfix/6050/handleAvatarClickHardening
Harden the profile implementation
2 parents c7e1259 + bfa7e08 commit fd55045

2 files changed

Lines changed: 23 additions & 37 deletions

File tree

app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,11 +817,12 @@ class ChatActivity :
817817
value = profileSheetMessageId?.let { id -> chatViewModel.getMessageById(id).first() }
818818
}
819819
profileSheetMessage
820-
?.takeIf { it.actorType != Participant.ActorType.FEDERATED.toString() }
820+
?.takeIf { it.actorType.equals("users") }
821821
?.let { msg ->
822+
val actorId = msg.actorId ?: return@let
822823
conversationUser?.let { user ->
823824
ProfileModalBottomSheet(
824-
actorId = msg.actorId!!,
825+
actorId = actorId,
825826
user = user,
826827
ncApiCoroutines = ncApiCoroutines,
827828
onTalkTo = { actorId -> startDirectChat(actorId) },
@@ -927,7 +928,7 @@ class ChatActivity :
927928
val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(
928929
version = apiVersion,
929930
baseUrl = user.baseUrl!!,
930-
roomType = "1",
931+
roomType = ROOM_TYPE_ONE_TO_ONE,
931932
invite = actorId
932933
)
933934
val roomOverall = ncApiCoroutines.createRoom(

app/src/main/java/com/nextcloud/talk/chat/ui/ProfileModalBottomSheet.kt

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ private fun iconResForAppId(appId: String?): Int? =
7171
else -> null
7272
}
7373

74+
@Suppress("TooGenericExceptionCaught")
7475
@OptIn(ExperimentalMaterial3Api::class)
7576
@Composable
7677
fun ProfileModalBottomSheet(
@@ -80,32 +81,7 @@ fun ProfileModalBottomSheet(
8081
onTalkTo: (actorId: String) -> Unit,
8182
onDismiss: () -> Unit
8283
) {
83-
val sheetState = rememberModalBottomSheetState()
84-
ModalBottomSheet(
85-
onDismissRequest = onDismiss,
86-
sheetState = sheetState,
87-
containerColor = MaterialTheme.colorScheme.surfaceContainerLow
88-
) {
89-
ProfileSheetContent(
90-
actorId = actorId,
91-
user = user,
92-
ncApiCoroutines = ncApiCoroutines,
93-
onTalkTo = onTalkTo,
94-
onDismiss = onDismiss
95-
)
96-
}
97-
}
98-
99-
@Suppress("TooGenericExceptionCaught")
100-
@Composable
101-
internal fun ProfileSheetContent(
102-
actorId: String,
103-
user: User,
104-
ncApiCoroutines: NcApiCoroutines,
105-
onTalkTo: (actorId: String) -> Unit,
106-
onDismiss: () -> Unit
107-
) {
108-
var displayName by remember { mutableStateOf("") }
84+
var displayName by remember { mutableStateOf<String?>(null) }
10985
var actions by remember { mutableStateOf<List<HoverCardAction>>(emptyList()) }
11086
val context = LocalContext.current
11187
val credentials = remember(user) { ApiUtils.getCredentials(user.username, user.token) }
@@ -116,22 +92,31 @@ internal fun ProfileSheetContent(
11692
credentials!!,
11793
ApiUtils.getUrlForHoverCard(user.baseUrl!!, actorId)
11894
)
119-
displayName = result.ocs!!.data!!.displayName!!
12095
actions = result.ocs!!.data!!.actions!!.filter { allowedAppIds.contains(it.appId) }
96+
displayName = result.ocs!!.data!!.displayName!!
12197
} catch (e: Exception) {
12298
Log.e(TAG, "Failed to load hover card for $actorId", e)
12399
onDismiss()
124100
}
125101
}
126102

127-
ProfileSheetLayout(
128-
displayName = displayName,
129-
actions = actions,
130-
onActionClick = { action ->
131-
onDismiss()
132-
handleAction(action, actorId, context, onTalkTo)
103+
if (displayName != null) {
104+
val sheetState = rememberModalBottomSheetState()
105+
ModalBottomSheet(
106+
onDismissRequest = onDismiss,
107+
sheetState = sheetState,
108+
containerColor = MaterialTheme.colorScheme.surfaceContainerLow
109+
) {
110+
ProfileSheetLayout(
111+
displayName = displayName!!,
112+
actions = actions,
113+
onActionClick = { action ->
114+
onDismiss()
115+
handleAction(action, actorId, context, onTalkTo)
116+
}
117+
)
133118
}
134-
)
119+
}
135120
}
136121

137122
@Composable

0 commit comments

Comments
 (0)