Skip to content

Commit de372c6

Browse files
Implemented channel config for typing indicators
1 parent 09b741c commit de372c6

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

Sources/StreamChatSwiftUI/ChatChannel/ChannelHeader/ChatChannelHeaderViewModifier.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public struct DefaultChatChannelHeader: ToolbarContent {
3333
VStack(spacing: 2) {
3434
Text(channelNamer(channel, currentUserId) ?? "")
3535
.font(fonts.bodyBold)
36-
if !channel.currentlyTypingUsersFiltered(currentUserId: currentUserId).isEmpty
37-
&& utils.typingIndicatorPlacement == .navigationBar {
36+
if shouldShowTypingIndicator {
3837
HStack {
3938
TypingIndicatorView()
4039
SubtitleText(text: channel.typingIndicatorString(currentUserId: currentUserId))
@@ -57,6 +56,12 @@ public struct DefaultChatChannelHeader: ToolbarContent {
5756
}
5857
}
5958

59+
private var shouldShowTypingIndicator: Bool {
60+
!channel.currentlyTypingUsersFiltered(currentUserId: currentUserId).isEmpty
61+
&& utils.typingIndicatorPlacement == .navigationBar
62+
&& channel.config.typingEventsEnabled
63+
}
64+
6065
private var onlineIndicatorShown: Bool {
6166
!channel.lastActiveMembers.filter { member in
6267
member.id != chatClient.currentUserId && member.isOnline

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
146146
DateIndicatorView(date: date)
147147
}
148148

149-
if !channel.currentlyTypingUsersFiltered(currentUserId: chatClient.currentUserId).isEmpty
150-
&& utils.typingIndicatorPlacement == .bottomOverlay {
149+
if shouldShowTypingIndicator {
151150
TypingIndicatorBottomView(
152151
typingIndicatorString: channel.typingIndicatorString(currentUserId: chatClient.currentUserId)
153152
)
@@ -169,6 +168,12 @@ struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
169168
.modifier(HideKeyboardOnTapGesture(shouldAdd: keyboardShown))
170169
}
171170

171+
private var shouldShowTypingIndicator: Bool {
172+
!channel.currentlyTypingUsersFiltered(currentUserId: chatClient.currentUserId).isEmpty
173+
&& utils.typingIndicatorPlacement == .bottomOverlay
174+
&& channel.config.typingEventsEnabled
175+
}
176+
172177
private func showsAllData(for message: ChatMessage) -> Bool {
173178
let dateString = dateFormatter.string(from: message.createdAt)
174179
let prefix = message.author.id

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListItem.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ public struct ChatChannelListItem: View {
4848
}
4949
} else {
5050
HStack(spacing: 4) {
51-
if !channel.currentlyTypingUsersFiltered(
52-
currentUserId: chatClient.currentUserId
53-
).isEmpty {
51+
if shouldShowTypingIndicator {
5452
TypingIndicatorView()
5553
}
5654
SubtitleText(text: subtitleText)
@@ -93,12 +91,16 @@ public struct ChatChannelListItem: View {
9391
.id("\(channel.id)-base")
9492
}
9593

94+
private var shouldShowTypingIndicator: Bool {
95+
!channel.currentlyTypingUsersFiltered(
96+
currentUserId: chatClient.currentUserId
97+
).isEmpty && channel.config.typingEventsEnabled
98+
}
99+
96100
private var subtitleText: String {
97101
if channel.isMuted {
98102
return L10n.Channel.Item.muted
99-
} else if !channel.currentlyTypingUsersFiltered(
100-
currentUserId: chatClient.currentUserId
101-
).isEmpty {
103+
} else if shouldShowTypingIndicator {
102104
return channel.typingIndicatorString(currentUserId: chatClient.currentUserId)
103105
} else if let latestMessage = channel.latestMessages.first {
104106
return "\(latestMessage.author.name ?? latestMessage.author.id): \(latestMessage.textContent ?? latestMessage.text)"

0 commit comments

Comments
 (0)