Skip to content

Commit e0d1798

Browse files
moved mentionText in extension
1 parent 9d7fc6a commit e0d1798

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,6 @@ public class MessageComposerViewModel: ObservableObject {
378378

379379
// MARK: - private
380380

381-
private func mentionText(for user: ChatUser) -> String {
382-
if let name = user.name, !name.isEmpty {
383-
return name
384-
} else {
385-
return user.id
386-
}
387-
}
388-
389381
private func edit(
390382
message: ChatMessage,
391383
completion: @escaping () -> Void

Sources/StreamChatSwiftUI/ChatChannel/Composer/Suggestions/InstantCommands/TwoStepMentionCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ open class TwoStepMentionCommand: CommandHandler {
7272

7373
selectedUser = chatUser
7474

75-
let mentionText = self.mentionText(for: chatUser)
75+
let mentionText = "\(mentionSymbol)\(chatUser.mentionText)"
7676
let newText = (text.wrappedValue as NSString).replacingCharacters(
7777
in: typingSuggestionValue.locationRange,
7878
with: mentionText
@@ -98,7 +98,7 @@ open class TwoStepMentionCommand: CommandHandler {
9898

9999
public func commandHandler(for command: ComposerCommand) -> CommandHandler? {
100100
if let selectedUser = selectedUser,
101-
command.typingSuggestion.text != mentionText(for: selectedUser) {
101+
command.typingSuggestion.text != "\(mentionSymbol)\(selectedUser.mentionText)" {
102102
self.selectedUser = nil
103103
}
104104
return command.id == id ? self : nil

Sources/StreamChatSwiftUI/ChatChannel/Composer/Suggestions/Mentions/MentionsCommandHandler.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public struct MentionsCommandHandler: CommandHandler {
6262
return
6363
}
6464

65-
let mentionText = self.mentionText(for: chatUser)
65+
let mentionText = chatUser.mentionText
6666
let newText = (text.wrappedValue as NSString).replacingCharacters(
6767
in: typingSuggestionValue.locationRange,
6868
with: mentionText
@@ -149,15 +149,7 @@ public struct MentionsCommandHandler: CommandHandler {
149149
sort: [.init(key: .name, isAscending: true)]
150150
)
151151
}
152-
153-
private func mentionText(for user: ChatUser) -> String {
154-
if let name = user.name, !name.isEmpty {
155-
return name
156-
} else {
157-
return user.id
158-
}
159-
}
160-
152+
161153
private func searchAllUsers(for typingMention: String) -> Future<SuggestionInfo, Error> {
162154
Future { promise in
163155
let query = queryForMentionSuggestionsSearch(typingMention: typingMention)

Sources/StreamChatSwiftUI/ChatChannel/Utils/ChatChannelExtensions.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@ extension ChatChannel {
3131
DateUtils.timeAgo
3232
}
3333
}
34+
35+
extension ChatUser {
36+
37+
var mentionText: String {
38+
if let name = self.name, !name.isEmpty {
39+
return name
40+
} else {
41+
return id
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)