Skip to content

Filter deactivated users in channel info view #758

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Feb 17, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix visibility of tabbar when reactions are shown [#750](https://github.com/GetStream/stream-chat-swiftui/pull/750)
### 🔄 Changed
- Only show "Pin/Unpin message" Action if user has permission [#749](https://github.com/GetStream/stream-chat-swiftui/pull/749)
- Filter deactivated users in channel info view [#758](https://github.com/GetStream/stream-chat-swiftui/pull/758)

# [4.72.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.72.0)
_February 04, 2025_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
}) {
return [otherParticipant]
}

let participants = self.participants.filter { $0.isDeactivated == false }

if participants.count <= 6 {
return participants
Expand Down Expand Up @@ -98,7 +100,8 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
public var notDisplayedParticipantsCount: Int {
let total = channel.memberCount
let displayed = displayedParticipants.count
return total - displayed
let deactivated = participants.filter { $0.isDeactivated }.count
return total - displayed - deactivated
}

public var mutedText: String {
Expand All @@ -124,7 +127,8 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
ParticipantInfo(
chatUser: member,
displayName: member.name ?? member.id,
onlineInfoText: onlineInfo(for: member)
onlineInfoText: onlineInfo(for: member),
isDeactivated: member.isDeactivated
)
}
}
Expand Down Expand Up @@ -198,7 +202,8 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
ParticipantInfo(
chatUser: member,
displayName: member.name ?? member.id,
onlineInfoText: onlineInfo(for: member)
onlineInfoText: onlineInfo(for: member),
isDeactivated: member.isDeactivated
)
}
}
Expand Down Expand Up @@ -247,7 +252,8 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
ParticipantInfo(
chatUser: member,
displayName: member.name ?? member.id,
onlineInfoText: self.onlineInfo(for: member)
onlineInfoText: self.onlineInfo(for: member),
isDeactivated: member.isDeactivated
)
}
if newMembers.count > self.participants.count {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,17 @@ public struct ParticipantInfo: Identifiable {
public let chatUser: ChatUser
public let displayName: String
public let onlineInfoText: String
public let isDeactivated: Bool

public init(chatUser: ChatUser, displayName: String, onlineInfoText: String) {
public init(
chatUser: ChatUser,
displayName: String,
onlineInfoText: String,
isDeactivated: Bool = false
) {
self.chatUser = chatUser
self.displayName = displayName
self.onlineInfoText = onlineInfoText
self.isDeactivated = isDeactivated
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ struct ChannelInfoMockUtils {
static func setupMockMembers(
count: Int,
currentUserId: String,
onlineUserIndexes: [Int] = []
onlineUserIndexes: [Int] = [],
deactivatedUserIndexes: [Int] = []
) -> [ChatChannelMember] {
var activeMembers = [ChatChannelMember]()
for i in 0..<count {
Expand All @@ -25,7 +26,8 @@ struct ChannelInfoMockUtils {
let member: ChatChannelMember = .mock(
id: id,
name: "Test \(i)",
isOnline: isOnline
isOnline: isOnline,
userDeactivatedAt: deactivatedUserIndexes.contains(i) ? Date() : nil
)
activeMembers.append(member)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ class ChatChannelInfoView_Tests: StreamChatTestCase {
// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_chatChannelInfoView_smallGroupDeactivatedSnapshot() {
// Given
let members = ChannelInfoMockUtils.setupMockMembers(
count: 3,
currentUserId: chatClient.currentUserId!,
onlineUserIndexes: [0, 1],
deactivatedUserIndexes: [2]
)
let group = ChatChannel.mock(
cid: .unique,
name: "Test Group",
ownCapabilities: [.leaveChannel, .updateChannel],
lastActiveMembers: members,
memberCount: members.count
)

// When
let view = ChatChannelInfoView(channel: group)
.applyDefaultSize()

// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_chatChannelInfoView_groupExpandedSnapshot() {
// Given
Expand All @@ -140,6 +164,56 @@ class ChatChannelInfoView_Tests: StreamChatTestCase {
// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_chatChannelInfoView_groupCollapsedDeactivatedSnapshot() {
// Given
let members = ChannelInfoMockUtils.setupMockMembers(
count: 8,
currentUserId: chatClient.currentUserId!,
onlineUserIndexes: [0, 1],
deactivatedUserIndexes: [2, 3]
)
let group = ChatChannel.mock(
cid: .unique,
name: "Test Group",
ownCapabilities: [.deleteChannel, .updateChannel],
lastActiveMembers: members,
memberCount: members.count
)
let viewModel = ChatChannelInfoViewModel(channel: group)

// When
let view = ChatChannelInfoView(viewModel: viewModel)
.applyDefaultSize()

// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_chatChannelInfoView_groupCollapsedLargeDeactivatedSnapshot() {
// Given
let members = ChannelInfoMockUtils.setupMockMembers(
count: 8,
currentUserId: chatClient.currentUserId!,
onlineUserIndexes: [0, 1],
deactivatedUserIndexes: [5]
)
let group = ChatChannel.mock(
cid: .unique,
name: "Test Group",
ownCapabilities: [.deleteChannel, .updateChannel],
lastActiveMembers: members,
memberCount: members.count
)
let viewModel = ChatChannelInfoViewModel(channel: group)

// When
let view = ChatChannelInfoView(viewModel: viewModel)
.applyDefaultSize()

// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_chatChannelInfoView_navBarSnapshot() {
// Given
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MessageActionsViewModel_Tests: StreamChatTestCase {
text: "test",
author: .mock(id: .unique)
),
channel: .mockDMChannel(),
channel: .mockDMChannel(ownCapabilities: [.sendMessage, .uploadFile, .pinMessage]),
chatClient: chatClient,
onFinish: { _ in },
onError: { _ in }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MessageActions_Tests: StreamChatTestCase {

func test_messageActions_currentUserDefault() {
// Given
let channel = ChatChannel.mockDMChannel()
let channel = mockDMChannel
let message = ChatMessage.mock(
id: .unique,
cid: channel.cid,
Expand Down Expand Up @@ -42,7 +42,7 @@ class MessageActions_Tests: StreamChatTestCase {

func test_messageActions_otherUserDefault() {
// Given
let channel = ChatChannel.mockDMChannel()
let channel = mockDMChannel
let message = ChatMessage.mock(
id: .unique,
cid: channel.cid,
Expand Down Expand Up @@ -78,7 +78,7 @@ class MessageActions_Tests: StreamChatTestCase {
chatClient: chatClient,
utils: .init(messageListConfig: .init(userBlockingEnabled: true))
)
let channel = ChatChannel.mockDMChannel()
let channel = mockDMChannel
let message = ChatMessage.mock(
id: .unique,
cid: channel.cid,
Expand Down Expand Up @@ -111,7 +111,7 @@ class MessageActions_Tests: StreamChatTestCase {

func test_messageActions_currentUserPinned() {
// Given
let channel = ChatChannel.mockDMChannel()
let channel = mockDMChannel
let message = ChatMessage.mock(
id: .unique,
cid: channel.cid,
Expand Down Expand Up @@ -149,7 +149,7 @@ class MessageActions_Tests: StreamChatTestCase {

func test_messageActions_messageNotSent() {
// Given
let channel = ChatChannel.mockDMChannel()
let channel = mockDMChannel
let message = ChatMessage.mock(
id: .unique,
cid: channel.cid,
Expand Down Expand Up @@ -178,7 +178,7 @@ class MessageActions_Tests: StreamChatTestCase {

func test_messageActions_attachmentFailure() {
// Given
let channel = ChatChannel.mockDMChannel()
let channel = mockDMChannel
let attachments = [
ChatMessageImageAttachment.mock(
id: .unique,
Expand Down Expand Up @@ -214,7 +214,7 @@ class MessageActions_Tests: StreamChatTestCase {

func test_messageActions_bouncedMessage() {
// Given
let channel = ChatChannel.mockDMChannel()
let channel = mockDMChannel
let moderationDetails = MessageModerationDetails(
originalText: "Some text",
action: .bounce,
Expand Down Expand Up @@ -251,4 +251,12 @@ class MessageActions_Tests: StreamChatTestCase {
XCTAssert(messageActions[2].title == "Edit Message")
XCTAssert(messageActions[3].title == "Delete Message")
}

// MARK: - Private

private var mockDMChannel: ChatChannel {
ChatChannel.mockDMChannel(
ownCapabilities: [.sendMessage, .uploadFile, .pinMessage]
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ReactionsOverlayView_Tests: StreamChatTestCase {
let view = VerticallyCenteredView {
ReactionsOverlayView(
factory: DefaultViewFactory.shared,
channel: .mockDMChannel(),
channel: .mockDMChannel(ownCapabilities: [.sendMessage, .uploadFile, .pinMessage]),
currentSnapshot: self.overlayImage,
messageDisplayInfo: messageDisplayInfo,
onBackgroundTap: {},
Expand Down
Loading