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 {
378
378
379
379
// MARK: - private
380
380
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
-
389
381
private func edit(
390
382
message: ChatMessage ,
391
383
completion: @escaping ( ) -> Void
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ open class TwoStepMentionCommand: CommandHandler {
72
72
73
73
selectedUser = chatUser
74
74
75
- let mentionText = self . mentionText ( for : chatUser)
75
+ let mentionText = " \( mentionSymbol ) \( chatUser. mentionText ) "
76
76
let newText = ( text. wrappedValue as NSString ) . replacingCharacters (
77
77
in: typingSuggestionValue. locationRange,
78
78
with: mentionText
@@ -98,7 +98,7 @@ open class TwoStepMentionCommand: CommandHandler {
98
98
99
99
public func commandHandler( for command: ComposerCommand ) -> CommandHandler ? {
100
100
if let selectedUser = selectedUser,
101
- command. typingSuggestion. text != mentionText ( for : selectedUser) {
101
+ command. typingSuggestion. text != " \( mentionSymbol ) \( selectedUser. mentionText ) " {
102
102
self . selectedUser = nil
103
103
}
104
104
return command. id == id ? self : nil
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ public struct MentionsCommandHandler: CommandHandler {
62
62
return
63
63
}
64
64
65
- let mentionText = self . mentionText ( for : chatUser )
65
+ let mentionText = chatUser . mentionText
66
66
let newText = ( text. wrappedValue as NSString ) . replacingCharacters (
67
67
in: typingSuggestionValue. locationRange,
68
68
with: mentionText
@@ -149,15 +149,7 @@ public struct MentionsCommandHandler: CommandHandler {
149
149
sort: [ . init( key: . name, isAscending: true ) ]
150
150
)
151
151
}
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
+
161
153
private func searchAllUsers( for typingMention: String ) -> Future < SuggestionInfo , Error > {
162
154
Future { promise in
163
155
let query = queryForMentionSuggestionsSearch ( typingMention: typingMention)
Original file line number Diff line number Diff line change @@ -31,3 +31,14 @@ extension ChatChannel {
31
31
DateUtils . timeAgo
32
32
}
33
33
}
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