File tree Expand file tree Collapse file tree 4 files changed +15
-20
lines changed
Sources/StreamChatSwiftUI/ChatChannel Expand file tree Collapse file tree 4 files changed +15
-20
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments