Skip to content

Commit 59092eb

Browse files
Implemented channel list read indicators
1 parent d93211d commit 59092eb

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ struct MessageContainerView<Factory: ViewFactory>: View {
143143
} else if message.isSentByCurrentUser {
144144
HStack(spacing: 4) {
145145
MessageReadIndicatorView(
146-
readUsers: readUsers,
147-
isGroup: isInGroup
146+
readUsers: channel.readUsers(
147+
currentUserId: chatClient.currentUserId
148+
),
149+
showReadCount: isInGroup
148150
)
149151
MessageDateView(message: message)
150152
}
@@ -162,14 +164,6 @@ struct MessageContainerView<Factory: ViewFactory>: View {
162164
.padding(.top, reactionsShown ? 24 : 0)
163165
}
164166

165-
private var readUsers: [ChatUser] {
166-
let readUsers = channel.reads.filter {
167-
$0.lastReadAt > message.createdAt &&
168-
$0.user.id != chatClient.currentUserId
169-
}.map(\.user)
170-
return readUsers
171-
}
172-
173167
private var contentWidth: CGFloat {
174168
let padding: CGFloat = 8
175169
let minimumWidth: CGFloat = 240

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListHelperViews.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ struct MessageReadIndicatorView: View {
4646
@Injected(\.colors) private var colors
4747

4848
var readUsers: [ChatUser]
49-
var isGroup: Bool
49+
var showReadCount: Bool
5050

5151
var body: some View {
5252
HStack(spacing: 2) {
53-
if isGroup && !readUsers.isEmpty {
53+
if showReadCount && !readUsers.isEmpty {
5454
Text("\(readUsers.count)")
5555
.font(fonts.footnoteBold)
5656
.foregroundColor(colors.tintColor)
@@ -59,7 +59,7 @@ struct MessageReadIndicatorView: View {
5959
uiImage: !readUsers.isEmpty ? images.readByAll : images.messageSent
6060
)
6161
.customizable()
62-
.foregroundColor(!readUsers.isEmpty ? colors.tintColor : nil)
62+
.foregroundColor(!readUsers.isEmpty ? colors.tintColor : Color(colors.textLowEmphasis))
6363
.frame(height: 16)
6464
}
6565
}

Sources/StreamChatSwiftUI/ChatChannel/Utils/ChatChannelExtensions.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ extension ChatChannel {
4444
}
4545
}
4646

47+
func readUsers(currentUserId: UserId?) -> [ChatUser] {
48+
guard let message = latestMessages.first else {
49+
return []
50+
}
51+
let readUsers = reads.filter {
52+
$0.lastReadAt > message.createdAt &&
53+
$0.user.id != currentUserId
54+
}.map(\.user)
55+
return readUsers
56+
}
57+
4758
private var lastSeenDateFormatter: (Date) -> String? {
4859
DateUtils.timeAgo
4960
}

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelList.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ extension ChatChannel: Identifiable {
9393
}
9494

9595
public var id: String {
96-
"\(cid.id)-\(lastMessageAt ?? createdAt)-\(lastActiveMembersCount)-\(mutedString)-\(unreadCount.messages)-\(typingUsersString)"
96+
"\(cid.id)-\(lastMessageAt ?? createdAt)-\(lastActiveMembersCount)-\(mutedString)-\(unreadCount.messages)-\(typingUsersString)-\(readUsers(currentUserId: nil).count)"
9797
}
9898

9999
private var lastActiveMembersCount: Int {

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListItem.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ public struct ChatChannelListItem: View {
7070
)
7171
}
7272

73-
SubtitleText(text: timestampText)
73+
HStack(spacing: 4) {
74+
if let message = channel.latestMessages.first, message.isSentByCurrentUser {
75+
MessageReadIndicatorView(
76+
readUsers: channel.readUsers(
77+
currentUserId: chatClient.currentUserId
78+
),
79+
showReadCount: false
80+
)
81+
}
82+
SubtitleText(text: timestampText)
83+
}
7484
}
7585
}
7686
.padding(.all, 8)

0 commit comments

Comments
 (0)