-
Notifications
You must be signed in to change notification settings - Fork 19
/
ConversationItem.kt
122 lines (110 loc) 路 4.5 KB
/
ConversationItem.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
/*
* 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.home.conversationslist.model
import com.wire.android.model.UserAvatarData
import com.wire.android.ui.home.conversations.model.UILastMessageContent
import com.wire.android.ui.home.conversationslist.common.UserInfoLabel
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.conversation.MutedConversationStatus
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.TeamId
import com.wire.kalium.logic.data.user.ConnectionState
import com.wire.kalium.logic.data.user.OtherUser
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.type.isTeammate
sealed class ConversationItem {
abstract val conversationId: ConversationId
abstract val mutedStatus: MutedConversationStatus
abstract val isLegalHold: Boolean
abstract val lastMessageContent: UILastMessageContent?
abstract val badgeEventType: BadgeEventType
abstract val teamId: TeamId?
abstract val isArchived: Boolean
val isTeamConversation get() = teamId != null
data class GroupConversation(
val groupName: String,
val hasOnGoingCall: Boolean = false,
val isSelfUserCreator: Boolean = false,
val selfMemberRole: Conversation.Member.Role?,
val isSelfUserMember: Boolean = true,
override val conversationId: ConversationId,
override val mutedStatus: MutedConversationStatus,
override val isLegalHold: Boolean = false,
override val lastMessageContent: UILastMessageContent?,
override val badgeEventType: BadgeEventType,
override val teamId: TeamId?,
override val isArchived: Boolean,
) : ConversationItem()
data class PrivateConversation(
val userAvatarData: UserAvatarData,
val conversationInfo: ConversationInfo,
val userId: UserId,
val blockingState: BlockingState,
override val conversationId: ConversationId,
override val mutedStatus: MutedConversationStatus,
override val isLegalHold: Boolean = false,
override val lastMessageContent: UILastMessageContent?,
override val badgeEventType: BadgeEventType,
override val teamId: TeamId?,
override val isArchived: Boolean
) : ConversationItem()
data class ConnectionConversation(
val userAvatarData: UserAvatarData,
val conversationInfo: ConversationInfo,
override val conversationId: ConversationId,
override val mutedStatus: MutedConversationStatus,
override val isLegalHold: Boolean = false,
override val lastMessageContent: UILastMessageContent?,
override val badgeEventType: BadgeEventType,
override val isArchived: Boolean = false,
) : ConversationItem() {
override val teamId: TeamId? = null
}
}
data class ConversationInfo(
val name: String,
val membership: Membership = Membership.None,
val isSenderUnavailable: Boolean = false
)
enum class BlockingState {
CAN_NOT_BE_BLOCKED, // we should not be able to block our own team-members
BLOCKED,
NOT_BLOCKED
}
val OtherUser.BlockState: BlockingState
get() =
when {
userType.isTeammate() -> BlockingState.CAN_NOT_BE_BLOCKED
connectionStatus == ConnectionState.BLOCKED -> BlockingState.BLOCKED
else -> BlockingState.NOT_BLOCKED
}
fun ConversationItem.PrivateConversation.toUserInfoLabel() =
UserInfoLabel(
labelName = conversationInfo.name,
isLegalHold = isLegalHold,
membership = conversationInfo.membership,
unavailable = conversationInfo.isSenderUnavailable
)
fun ConversationItem.ConnectionConversation.toUserInfoLabel() =
UserInfoLabel(
labelName = conversationInfo.name,
isLegalHold = isLegalHold,
membership = conversationInfo.membership
)