-
Notifications
You must be signed in to change notification settings - Fork 19
/
ConversationSheetState.kt
138 lines (126 loc) · 5.51 KB
/
ConversationSheetState.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*
*/
package com.wire.android.ui.common.bottomsheet.conversation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.res.stringResource
import com.wire.android.R
import com.wire.android.ui.home.conversationslist.model.ConversationItem
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.conversation.MutedConversationStatus
import com.wire.kalium.logic.data.id.ConversationId
class ConversationSheetState(
conversationSheetContent: ConversationSheetContent? = null,
conversationOptionNavigation: ConversationOptionNavigation = ConversationOptionNavigation.Home
) {
val startOptionNavigation = conversationOptionNavigation
var conversationSheetContent: ConversationSheetContent? by mutableStateOf(conversationSheetContent)
var currentOptionNavigation: ConversationOptionNavigation by mutableStateOf(conversationOptionNavigation)
val conversationId: ConversationId?
get() = conversationSheetContent?.conversationId
fun muteConversation(mutedConversationStatus: MutedConversationStatus) {
conversationSheetContent = conversationSheetContent?.copy(mutingConversationState = mutedConversationStatus)
}
fun toMutingNotificationOption() {
currentOptionNavigation = ConversationOptionNavigation.MutingNotificationOption
}
fun toHome() {
currentOptionNavigation = ConversationOptionNavigation.Home
}
}
@Composable
fun rememberConversationSheetState(
conversationItem: ConversationItem,
conversationOptionNavigation: ConversationOptionNavigation
): ConversationSheetState {
val conversationSheetContent: ConversationSheetContent = when (conversationItem) {
is ConversationItem.GroupConversation -> {
with(conversationItem) {
ConversationSheetContent(
conversationId = conversationId,
title = groupName.ifEmpty { stringResource(id = R.string.member_name_deleted_label) },
mutingConversationState = mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Group(
conversationId = conversationId,
isCreator = isSelfUserCreator
),
isTeamConversation = teamId != null,
selfRole = selfMemberRole,
isArchived = conversationItem.isArchived
)
}
}
is ConversationItem.PrivateConversation -> {
with(conversationItem) {
ConversationSheetContent(
conversationId = conversationId,
title = if (conversationInfo.isSenderUnavailable) {
stringResource(id = R.string.username_unavailable_label)
} else conversationInfo.name,
mutingConversationState = mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Private(
userAvatarData.asset,
userId,
blockingState
),
isTeamConversation = isTeamConversation,
selfRole = Conversation.Member.Role.Member,
isArchived = conversationItem.isArchived
)
}
}
is ConversationItem.ConnectionConversation -> {
with(conversationItem) {
ConversationSheetContent(
conversationId = conversationId,
title = conversationInfo.name,
mutingConversationState = mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Connection(
userAvatarData.asset
),
isTeamConversation = isTeamConversation,
selfRole = Conversation.Member.Role.Member,
isArchived = conversationItem.isArchived
)
}
}
}
return remember(conversationItem, conversationOptionNavigation) {
ConversationSheetState(
conversationSheetContent = conversationSheetContent,
conversationOptionNavigation = conversationOptionNavigation
)
}
}
@Composable
fun rememberConversationSheetState(
conversationSheetContent: ConversationSheetContent?,
conversationOptionNavigation: ConversationOptionNavigation = ConversationOptionNavigation.Home
): ConversationSheetState {
return remember(conversationSheetContent) {
ConversationSheetState(
conversationSheetContent = conversationSheetContent,
conversationOptionNavigation = conversationOptionNavigation
)
}
}