Skip to content

Commit b4cf74b

Browse files
Filter deactivated users in channel info view (#758)
1 parent 1f87f30 commit b4cf74b

11 files changed

+114
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
- Fix visibility of tabbar when reactions are shown [#750](https://github.com/GetStream/stream-chat-swiftui/pull/750)
88
### 🔄 Changed
99
- Only show "Pin/Unpin message" Action if user has permission [#749](https://github.com/GetStream/stream-chat-swiftui/pull/749)
10+
- Filter deactivated users in channel info view [#758](https://github.com/GetStream/stream-chat-swiftui/pull/758)
1011

1112
# [4.72.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.72.0)
1213
_February 04, 2025_

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoViewModel.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
6767
}) {
6868
return [otherParticipant]
6969
}
70+
71+
let participants = self.participants.filter { $0.isDeactivated == false }
7072

7173
if participants.count <= 6 {
7274
return participants
@@ -98,7 +100,8 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
98100
public var notDisplayedParticipantsCount: Int {
99101
let total = channel.memberCount
100102
let displayed = displayedParticipants.count
101-
return total - displayed
103+
let deactivated = participants.filter { $0.isDeactivated }.count
104+
return total - displayed - deactivated
102105
}
103106

104107
public var mutedText: String {
@@ -124,7 +127,8 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
124127
ParticipantInfo(
125128
chatUser: member,
126129
displayName: member.name ?? member.id,
127-
onlineInfoText: onlineInfo(for: member)
130+
onlineInfoText: onlineInfo(for: member),
131+
isDeactivated: member.isDeactivated
128132
)
129133
}
130134
}
@@ -198,7 +202,8 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
198202
ParticipantInfo(
199203
chatUser: member,
200204
displayName: member.name ?? member.id,
201-
onlineInfoText: onlineInfo(for: member)
205+
onlineInfoText: onlineInfo(for: member),
206+
isDeactivated: member.isDeactivated
202207
)
203208
}
204209
}
@@ -247,7 +252,8 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
247252
ParticipantInfo(
248253
chatUser: member,
249254
displayName: member.name ?? member.id,
250-
onlineInfoText: self.onlineInfo(for: member)
255+
onlineInfoText: self.onlineInfo(for: member),
256+
isDeactivated: member.isDeactivated
251257
)
252258
}
253259
if newMembers.count > self.participants.count {

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatInfoParticipantsView.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,17 @@ public struct ParticipantInfo: Identifiable {
4848
public let chatUser: ChatUser
4949
public let displayName: String
5050
public let onlineInfoText: String
51+
public let isDeactivated: Bool
5152

52-
public init(chatUser: ChatUser, displayName: String, onlineInfoText: String) {
53+
public init(
54+
chatUser: ChatUser,
55+
displayName: String,
56+
onlineInfoText: String,
57+
isDeactivated: Bool = false
58+
) {
5359
self.chatUser = chatUser
5460
self.displayName = displayName
5561
self.onlineInfoText = onlineInfoText
62+
self.isDeactivated = isDeactivated
5663
}
5764
}

StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChannelInfoMockUtils.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ struct ChannelInfoMockUtils {
1010
static func setupMockMembers(
1111
count: Int,
1212
currentUserId: String,
13-
onlineUserIndexes: [Int] = []
13+
onlineUserIndexes: [Int] = [],
14+
deactivatedUserIndexes: [Int] = []
1415
) -> [ChatChannelMember] {
1516
var activeMembers = [ChatChannelMember]()
1617
for i in 0..<count {
@@ -25,7 +26,8 @@ struct ChannelInfoMockUtils {
2526
let member: ChatChannelMember = .mock(
2627
id: id,
2728
name: "Test \(i)",
28-
isOnline: isOnline
29+
isOnline: isOnline,
30+
userDeactivatedAt: deactivatedUserIndexes.contains(i) ? Date() : nil
2931
)
3032
activeMembers.append(member)
3133
}

StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoView_Tests.swift

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@ class ChatChannelInfoView_Tests: StreamChatTestCase {
115115
// Then
116116
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
117117
}
118+
119+
func test_chatChannelInfoView_smallGroupDeactivatedSnapshot() {
120+
// Given
121+
let members = ChannelInfoMockUtils.setupMockMembers(
122+
count: 3,
123+
currentUserId: chatClient.currentUserId!,
124+
onlineUserIndexes: [0, 1],
125+
deactivatedUserIndexes: [2]
126+
)
127+
let group = ChatChannel.mock(
128+
cid: .unique,
129+
name: "Test Group",
130+
ownCapabilities: [.leaveChannel, .updateChannel],
131+
lastActiveMembers: members,
132+
memberCount: members.count
133+
)
134+
135+
// When
136+
let view = ChatChannelInfoView(channel: group)
137+
.applyDefaultSize()
138+
139+
// Then
140+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
141+
}
118142

119143
func test_chatChannelInfoView_groupExpandedSnapshot() {
120144
// Given
@@ -140,6 +164,56 @@ class ChatChannelInfoView_Tests: StreamChatTestCase {
140164
// Then
141165
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
142166
}
167+
168+
func test_chatChannelInfoView_groupCollapsedDeactivatedSnapshot() {
169+
// Given
170+
let members = ChannelInfoMockUtils.setupMockMembers(
171+
count: 8,
172+
currentUserId: chatClient.currentUserId!,
173+
onlineUserIndexes: [0, 1],
174+
deactivatedUserIndexes: [2, 3]
175+
)
176+
let group = ChatChannel.mock(
177+
cid: .unique,
178+
name: "Test Group",
179+
ownCapabilities: [.deleteChannel, .updateChannel],
180+
lastActiveMembers: members,
181+
memberCount: members.count
182+
)
183+
let viewModel = ChatChannelInfoViewModel(channel: group)
184+
185+
// When
186+
let view = ChatChannelInfoView(viewModel: viewModel)
187+
.applyDefaultSize()
188+
189+
// Then
190+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
191+
}
192+
193+
func test_chatChannelInfoView_groupCollapsedLargeDeactivatedSnapshot() {
194+
// Given
195+
let members = ChannelInfoMockUtils.setupMockMembers(
196+
count: 8,
197+
currentUserId: chatClient.currentUserId!,
198+
onlineUserIndexes: [0, 1],
199+
deactivatedUserIndexes: [5]
200+
)
201+
let group = ChatChannel.mock(
202+
cid: .unique,
203+
name: "Test Group",
204+
ownCapabilities: [.deleteChannel, .updateChannel],
205+
lastActiveMembers: members,
206+
memberCount: members.count
207+
)
208+
let viewModel = ChatChannelInfoViewModel(channel: group)
209+
210+
// When
211+
let view = ChatChannelInfoView(viewModel: viewModel)
212+
.applyDefaultSize()
213+
214+
// Then
215+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
216+
}
143217

144218
func test_chatChannelInfoView_navBarSnapshot() {
145219
// Given
Loading
Loading

StreamChatSwiftUITests/Tests/ChatChannel/MessageActionsViewModel_Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MessageActionsViewModel_Tests: StreamChatTestCase {
2020
text: "test",
2121
author: .mock(id: .unique)
2222
),
23-
channel: .mockDMChannel(),
23+
channel: .mockDMChannel(ownCapabilities: [.sendMessage, .uploadFile, .pinMessage]),
2424
chatClient: chatClient,
2525
onFinish: { _ in },
2626
onError: { _ in }

StreamChatSwiftUITests/Tests/ChatChannel/MessageActions_Tests.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MessageActions_Tests: StreamChatTestCase {
1010

1111
func test_messageActions_currentUserDefault() {
1212
// Given
13-
let channel = ChatChannel.mockDMChannel()
13+
let channel = mockDMChannel
1414
let message = ChatMessage.mock(
1515
id: .unique,
1616
cid: channel.cid,
@@ -42,7 +42,7 @@ class MessageActions_Tests: StreamChatTestCase {
4242

4343
func test_messageActions_otherUserDefault() {
4444
// Given
45-
let channel = ChatChannel.mockDMChannel()
45+
let channel = mockDMChannel
4646
let message = ChatMessage.mock(
4747
id: .unique,
4848
cid: channel.cid,
@@ -78,7 +78,7 @@ class MessageActions_Tests: StreamChatTestCase {
7878
chatClient: chatClient,
7979
utils: .init(messageListConfig: .init(userBlockingEnabled: true))
8080
)
81-
let channel = ChatChannel.mockDMChannel()
81+
let channel = mockDMChannel
8282
let message = ChatMessage.mock(
8383
id: .unique,
8484
cid: channel.cid,
@@ -111,7 +111,7 @@ class MessageActions_Tests: StreamChatTestCase {
111111

112112
func test_messageActions_currentUserPinned() {
113113
// Given
114-
let channel = ChatChannel.mockDMChannel()
114+
let channel = mockDMChannel
115115
let message = ChatMessage.mock(
116116
id: .unique,
117117
cid: channel.cid,
@@ -149,7 +149,7 @@ class MessageActions_Tests: StreamChatTestCase {
149149

150150
func test_messageActions_messageNotSent() {
151151
// Given
152-
let channel = ChatChannel.mockDMChannel()
152+
let channel = mockDMChannel
153153
let message = ChatMessage.mock(
154154
id: .unique,
155155
cid: channel.cid,
@@ -178,7 +178,7 @@ class MessageActions_Tests: StreamChatTestCase {
178178

179179
func test_messageActions_attachmentFailure() {
180180
// Given
181-
let channel = ChatChannel.mockDMChannel()
181+
let channel = mockDMChannel
182182
let attachments = [
183183
ChatMessageImageAttachment.mock(
184184
id: .unique,
@@ -214,7 +214,7 @@ class MessageActions_Tests: StreamChatTestCase {
214214

215215
func test_messageActions_bouncedMessage() {
216216
// Given
217-
let channel = ChatChannel.mockDMChannel()
217+
let channel = mockDMChannel
218218
let moderationDetails = MessageModerationDetails(
219219
originalText: "Some text",
220220
action: .bounce,
@@ -251,4 +251,12 @@ class MessageActions_Tests: StreamChatTestCase {
251251
XCTAssert(messageActions[2].title == "Edit Message")
252252
XCTAssert(messageActions[3].title == "Delete Message")
253253
}
254+
255+
// MARK: - Private
256+
257+
private var mockDMChannel: ChatChannel {
258+
ChatChannel.mockDMChannel(
259+
ownCapabilities: [.sendMessage, .uploadFile, .pinMessage]
260+
)
261+
}
254262
}

0 commit comments

Comments
 (0)