@cometchat/chat-uikit-react-native 5.5.2 → 5.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/build.gradle +17 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +265 -4
- package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +209 -119
- package/ios/RichTextEditorView.swift +321 -24
- package/ios/SoundPlayer.m +152 -6
- package/package.json +4 -1
- package/react-native-cometchat-ui-kit.podspec +1 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +43 -24
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +27 -19
- package/src/CometChatMessageList/CometChatMessageList.tsx +60 -25
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +48 -47
package/ios/SoundPlayer.m
CHANGED
|
@@ -2,12 +2,129 @@
|
|
|
2
2
|
#import <React/RCTBridgeModule.h>
|
|
3
3
|
#import "SoundPlayer.h"
|
|
4
4
|
#import "AVFoundation/AVFoundation.h"
|
|
5
|
+
#import <WebKit/WebKit.h>
|
|
6
|
+
#import <React/RCTUtils.h>
|
|
7
|
+
|
|
8
|
+
// AVAudioPlayer can't decode WebM/Opus — which is what browser MediaRecorder produces (the web UI Kit
|
|
9
|
+
// sends voice notes as WebM, sometimes under a .wav name). WebKit can, so those clips fall back to a
|
|
10
|
+
// hidden WKWebView <audio>. Everything AVAudioPlayer can open keeps the native path.
|
|
11
|
+
@interface CCWebAudioHandler : NSObject <WKScriptMessageHandler>
|
|
12
|
+
@property (nonatomic, copy) void (^onMessage)(NSDictionary *msg);
|
|
13
|
+
@end
|
|
14
|
+
@implementation CCWebAudioHandler
|
|
15
|
+
- (void)userContentController:(WKUserContentController *)ucc didReceiveScriptMessage:(WKScriptMessage *)message {
|
|
16
|
+
if ([message.body isKindOfClass:[NSDictionary class]] && self.onMessage) self.onMessage(message.body);
|
|
17
|
+
}
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
// Duration: a MediaRecorder WebM has no duration header (audio.duration === Infinity) until you seek
|
|
21
|
+
// past the end, so dur() forces that seek once, then rewinds.
|
|
22
|
+
static NSString *const kWebAudioJS =
|
|
23
|
+
@"var a=new Audio();function post(m){window.webkit.messageHandlers.cc.postMessage(m)}"
|
|
24
|
+
"a.onended=function(){post({t:'end'})};"
|
|
25
|
+
"a.ontimeupdate=function(){if(!a._p)post({t:'pos',v:a.currentTime})};"
|
|
26
|
+
"a.onerror=function(){post({t:'err'})};"
|
|
27
|
+
"function dur(cb){if(isFinite(a.duration)&&a.duration>0)return cb(a.duration);a._p=true;"
|
|
28
|
+
"a.addEventListener('timeupdate',function h(){if(isFinite(a.duration)){a.removeEventListener('timeupdate',h);a._p=false;a.currentTime=0;cb(a.duration)}});a.currentTime=1e7}"
|
|
29
|
+
"function start(u,play){a.onloadedmetadata=function(){dur(function(d){post({t:'dur',v:d});"
|
|
30
|
+
"if(play)a.play().then(function(){post({t:'played'})}).catch(function(){post({t:'err'})})})};a.src=u;a.load()}";
|
|
5
31
|
|
|
6
32
|
|
|
7
33
|
@implementation CometChatSoundPlayer {
|
|
8
34
|
AVAudioPlayer *audioPlayer;
|
|
9
35
|
bool hasListeners;
|
|
10
36
|
NSString *currentUrl;
|
|
37
|
+
// WebM fallback player (see CCWebAudioHandler). Created and torn down with dispatch_sync on the
|
|
38
|
+
// main queue, so the method queue never sees a half-started player (a pause right after play
|
|
39
|
+
// used to find webPlayer == nil and fall through to audioPlayer).
|
|
40
|
+
WKWebView *webPlayer;
|
|
41
|
+
BOOL webPlaying;
|
|
42
|
+
double webPosition;
|
|
43
|
+
NSMutableSet<WKWebView *> *probes;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Hidden web view that loads `url` and reports {t:dur|played|pos|end|err} to `onMessage`.
|
|
47
|
+
- (WKWebView *)webAudioFor:(NSString *)url play:(BOOL)play onMessage:(void (^)(NSDictionary *))onMessage {
|
|
48
|
+
CCWebAudioHandler *handler = [CCWebAudioHandler new];
|
|
49
|
+
handler.onMessage = onMessage;
|
|
50
|
+
WKWebViewConfiguration *config = [WKWebViewConfiguration new];
|
|
51
|
+
config.allowsInlineMediaPlayback = YES;
|
|
52
|
+
config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
|
|
53
|
+
[config.userContentController addScriptMessageHandler:handler name:@"cc"];
|
|
54
|
+
NSData *json = [NSJSONSerialization dataWithJSONObject:@[url] options:0 error:nil];
|
|
55
|
+
NSString *arg = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding]; // ["<escaped url>"]
|
|
56
|
+
NSString *js = [NSString stringWithFormat:@"%@;start(%@[0],%@);", kWebAudioJS, arg, play ? @"true" : @"false"];
|
|
57
|
+
[config.userContentController addUserScript:[[WKUserScript alloc] initWithSource:js injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]];
|
|
58
|
+
WKWebView *web = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 1, 1) configuration:config];
|
|
59
|
+
web.alpha = 0.01; // in a window so WebKit doesn't throttle it, but invisible
|
|
60
|
+
[RCTKeyWindow() addSubview:web];
|
|
61
|
+
[web loadHTMLString:@"<html><body></body></html>" baseURL:[NSURL URLWithString:@"https://localhost/"]];
|
|
62
|
+
return web;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
- (void)stopWebPlayer {
|
|
66
|
+
RCTUnsafeExecuteOnMainQueueSync(^{
|
|
67
|
+
[self->webPlayer evaluateJavaScript:@"a.pause()" completionHandler:nil];
|
|
68
|
+
[self->webPlayer.configuration.userContentController removeScriptMessageHandlerForName:@"cc"];
|
|
69
|
+
[self->webPlayer removeFromSuperview];
|
|
70
|
+
self->webPlayer = nil;
|
|
71
|
+
self->webPlaying = NO;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// One-shot duration probe for a clip AVAudioPlayer couldn't open.
|
|
76
|
+
- (void)probeWebDuration:(NSString *)url resolve:(RCTResponseSenderBlock)resolve {
|
|
77
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
78
|
+
if (!self->probes) self->probes = [NSMutableSet new];
|
|
79
|
+
__block WKWebView *probe = nil;
|
|
80
|
+
__block BOOL done = NO;
|
|
81
|
+
void (^finish)(int) = ^(int duration) { // main queue only; resolves once, tears the probe down
|
|
82
|
+
if (done) return;
|
|
83
|
+
done = YES;
|
|
84
|
+
resolve(@[[NSString stringWithFormat:@"{\"duration\":%d}", duration]]);
|
|
85
|
+
[probe.configuration.userContentController removeScriptMessageHandlerForName:@"cc"];
|
|
86
|
+
[probe removeFromSuperview];
|
|
87
|
+
[self->probes removeObject:probe];
|
|
88
|
+
};
|
|
89
|
+
probe = [self webAudioFor:url play:NO onMessage:^(NSDictionary *msg) {
|
|
90
|
+
if ([msg[@"t"] isEqual:@"dur"]) finish([msg[@"v"] intValue]);
|
|
91
|
+
else if ([msg[@"t"] isEqual:@"err"]) finish(0);
|
|
92
|
+
}];
|
|
93
|
+
[self->probes addObject:probe];
|
|
94
|
+
// A stalled load sends neither dur nor err: give up after 10 s instead of leaking the web view.
|
|
95
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ finish(0); });
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
- (void)playWeb:(NSString *)url resolve:(RCTResponseSenderBlock)resolve {
|
|
100
|
+
RCTUnsafeExecuteOnMainQueueSync(^{
|
|
101
|
+
__block BOOL resolved = NO;
|
|
102
|
+
__block int duration = 0;
|
|
103
|
+
self->webPosition = 0;
|
|
104
|
+
self->webPlayer = [self webAudioFor:url play:YES onMessage:^(NSDictionary *msg) {
|
|
105
|
+
NSString *t = msg[@"t"];
|
|
106
|
+
if ([t isEqual:@"dur"]) {
|
|
107
|
+
duration = [msg[@"v"] intValue];
|
|
108
|
+
} else if ([t isEqual:@"played"]) {
|
|
109
|
+
self->webPlaying = YES;
|
|
110
|
+
if (!resolved) { resolved = YES; resolve(@[[NSString stringWithFormat:@"{\"success\":1, \"duration\":%d}", duration]]); }
|
|
111
|
+
} else if ([t isEqual:@"pos"]) {
|
|
112
|
+
self->webPosition = [msg[@"v"] doubleValue];
|
|
113
|
+
} else if ([t isEqual:@"end"]) {
|
|
114
|
+
self->webPlaying = NO;
|
|
115
|
+
if (self->hasListeners) [self sendEventWithName:@"soundPlayStatus" body:@{@"url": url}];
|
|
116
|
+
} else if ([t isEqual:@"err"]) {
|
|
117
|
+
if (!resolved) {
|
|
118
|
+
resolved = YES;
|
|
119
|
+
resolve(@[@"{\"success\":0, \"error\":\"Unsupported audio format\"}"]);
|
|
120
|
+
} else {
|
|
121
|
+
// Failed mid-clip (e.g. network drop): end it like a finished clip so the bubble resets.
|
|
122
|
+
self->webPlaying = NO;
|
|
123
|
+
if (self->hasListeners) [self sendEventWithName:@"soundPlayStatus" body:@{@"url": url}];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}];
|
|
127
|
+
});
|
|
11
128
|
}
|
|
12
129
|
|
|
13
130
|
- (void)startObserving {
|
|
@@ -46,6 +163,10 @@ RCT_EXPORT_METHOD(prepareMediaPlayer:(NSString *) url
|
|
|
46
163
|
}
|
|
47
164
|
currentUrl = url;
|
|
48
165
|
audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:nil];
|
|
166
|
+
if (!audioPlayer && data) {
|
|
167
|
+
[self probeWebDuration:url resolve:resolve];
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
49
170
|
[audioPlayer setDelegate: self];
|
|
50
171
|
int duration = [audioPlayer duration];
|
|
51
172
|
NSString *response = [NSString stringWithFormat:@"{\"duration\":%d}", duration];
|
|
@@ -85,12 +206,15 @@ RCT_EXPORT_METHOD(play:(NSString *) url
|
|
|
85
206
|
[audioPlayer stop];
|
|
86
207
|
[self sendEventWithName:@"soundPlayStatus" body:@{@"url": currentUrl}];
|
|
87
208
|
}
|
|
209
|
+
if (webPlayer) {
|
|
210
|
+
if (webPlaying && currentUrl) [self sendEventWithName:@"soundPlayStatus" body:@{@"url": currentUrl}];
|
|
211
|
+
[self stopWebPlayer];
|
|
212
|
+
}
|
|
88
213
|
currentUrl = url;
|
|
89
214
|
NSError *playerError = nil;
|
|
90
215
|
audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:&playerError];
|
|
91
216
|
if (!audioPlayer) {
|
|
92
|
-
|
|
93
|
-
resolve(@[response]);
|
|
217
|
+
[self playWeb:url resolve:resolve];
|
|
94
218
|
return;
|
|
95
219
|
}
|
|
96
220
|
[audioPlayer setDelegate: self];
|
|
@@ -106,7 +230,12 @@ RCT_EXPORT_METHOD(play:(NSString *) url
|
|
|
106
230
|
// NOT seek. Matches Android's playAt(seconds) → seekTo().
|
|
107
231
|
RCT_EXPORT_METHOD(playAt:(NSInteger) atTime resolver:(RCTResponseSenderBlock)resolve) {
|
|
108
232
|
bool res = NO;
|
|
109
|
-
if (
|
|
233
|
+
if (webPlayer) {
|
|
234
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
235
|
+
[self->webPlayer evaluateJavaScript:[NSString stringWithFormat:@"a.currentTime=%ld", (long)atTime] completionHandler:nil];
|
|
236
|
+
});
|
|
237
|
+
res = YES;
|
|
238
|
+
} else if (audioPlayer != nil) {
|
|
110
239
|
audioPlayer.currentTime = (NSTimeInterval)atTime;
|
|
111
240
|
res = YES;
|
|
112
241
|
}
|
|
@@ -115,11 +244,18 @@ RCT_EXPORT_METHOD(playAt:(NSInteger) atTime resolver:(RCTResponseSenderBlock)res
|
|
|
115
244
|
}
|
|
116
245
|
|
|
117
246
|
RCT_EXPORT_METHOD(resume) {
|
|
247
|
+
if (webPlayer) {
|
|
248
|
+
webPlaying = YES;
|
|
249
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [self->webPlayer evaluateJavaScript:@"a.play()" completionHandler:nil]; });
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
118
252
|
[audioPlayer play];
|
|
119
253
|
}
|
|
120
254
|
|
|
121
255
|
RCT_EXPORT_METHOD(getPosition:(RCTResponseSenderBlock) resolve) {
|
|
122
|
-
if (
|
|
256
|
+
if (webPlayer && webPlaying) {
|
|
257
|
+
resolve(@[[NSString stringWithFormat:@"{\"position\":%f}", webPosition]]);
|
|
258
|
+
} else if ([audioPlayer isPlaying]) {
|
|
123
259
|
NSString *response = [NSString stringWithFormat:@"{\"position\":%f}", [audioPlayer currentTime]];
|
|
124
260
|
resolve(@[response]);
|
|
125
261
|
} else {
|
|
@@ -128,7 +264,11 @@ RCT_EXPORT_METHOD(getPosition:(RCTResponseSenderBlock) resolve) {
|
|
|
128
264
|
}
|
|
129
265
|
|
|
130
266
|
RCT_EXPORT_METHOD(pause: (RCTResponseSenderBlock) resolve) {
|
|
131
|
-
if (
|
|
267
|
+
if (webPlayer && webPlaying) {
|
|
268
|
+
webPlaying = NO;
|
|
269
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [self->webPlayer evaluateJavaScript:@"a.pause()" completionHandler:nil]; });
|
|
270
|
+
resolve(@[@"{\"success\": true}"]);
|
|
271
|
+
} else if ([audioPlayer isPlaying]) {
|
|
132
272
|
[audioPlayer pause];
|
|
133
273
|
resolve(@[@"{\"success\": true}"]);
|
|
134
274
|
} else {
|
|
@@ -137,6 +277,10 @@ RCT_EXPORT_METHOD(pause: (RCTResponseSenderBlock) resolve) {
|
|
|
137
277
|
}
|
|
138
278
|
|
|
139
279
|
RCT_EXPORT_METHOD(releaseMediaPlayer) {
|
|
280
|
+
// Stopping a clip that is playing must say so, or its bubble stays on "playing".
|
|
281
|
+
BOOL wasPlaying = (webPlayer && webPlaying) || [audioPlayer isPlaying];
|
|
282
|
+
if (wasPlaying && currentUrl && hasListeners) [self sendEventWithName:@"soundPlayStatus" body:@{@"url": currentUrl}];
|
|
283
|
+
if (webPlayer) [self stopWebPlayer];
|
|
140
284
|
if (audioPlayer) {
|
|
141
285
|
[audioPlayer stop];
|
|
142
286
|
audioPlayer = nil;
|
|
@@ -145,7 +289,9 @@ RCT_EXPORT_METHOD(releaseMediaPlayer) {
|
|
|
145
289
|
}
|
|
146
290
|
|
|
147
291
|
RCT_EXPORT_METHOD(getCurrentTime: (RCTResponseSenderBlock)resolve) {
|
|
148
|
-
if (
|
|
292
|
+
if (webPlayer && webPlaying) {
|
|
293
|
+
resolve(@[[NSString stringWithFormat:@"{\"time\": %f}", webPosition]]);
|
|
294
|
+
} else if ([audioPlayer isPlaying]) {
|
|
149
295
|
NSString *response = [NSString stringWithFormat:@"{\"time\": %f}",[audioPlayer currentTime]];
|
|
150
296
|
resolve(@[response]);
|
|
151
297
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cometchat/chat-uikit-react-native",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.4",
|
|
4
4
|
"description": "Ready-to-use Chat UI Components for React Native",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"module": "src/index",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"react-native-cometchat-ui-kit.podspec",
|
|
17
17
|
"!lib/typescript/example",
|
|
18
18
|
"!android/build",
|
|
19
|
+
"!android/src/test",
|
|
19
20
|
"!ios/build",
|
|
20
21
|
"!**/__tests__",
|
|
21
22
|
"!**/__fixtures__",
|
|
@@ -23,6 +24,8 @@
|
|
|
23
24
|
],
|
|
24
25
|
"scripts": {
|
|
25
26
|
"test": "jest",
|
|
27
|
+
"test:native:android": "cd ../../examples/masterapp/android && ./gradlew :cometchat_chat-uikit-react-native:testDebugUnitTest",
|
|
28
|
+
"test:native:ios": "cd ios-tests && UDID=$(xcrun simctl list devices available | grep -m1 iPhone | grep -oE '[0-9A-F-]{36}'); if [ -z \"$UDID\" ]; then echo \"No iPhone simulator is available. Install one via Xcode > Settings > Components.\" >&2; exit 1; fi; xcodebuild test -scheme RichTextEditorKit-Package -destination \"platform=iOS Simulator,id=$UDID\"",
|
|
26
29
|
"typescript": "tsc --noEmit",
|
|
27
30
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
28
31
|
"release": "release-it",
|
|
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
|
|
|
16
16
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
17
17
|
|
|
18
18
|
s.static_framework = true # Set static_framework for the main spec if needed
|
|
19
|
-
s.frameworks = ["PhotosUI"]
|
|
19
|
+
s.frameworks = ["PhotosUI", "WebKit"]
|
|
20
20
|
|
|
21
21
|
s.subspec "Video" do |ss|
|
|
22
22
|
ss.source_files = "ios/Video/*.{h,m}"
|
|
@@ -640,13 +640,15 @@ export interface CometChatCompactMessageComposerInterface {
|
|
|
640
640
|
onChangeText?: (text: string) => void;
|
|
641
641
|
|
|
642
642
|
/**
|
|
643
|
-
* Flag to turn off sound for outgoing messages.
|
|
643
|
+
* Flag to turn off sound for outgoing messages. The composer owns the send sound;
|
|
644
|
+
* CometChatMessageList only plays incoming-message sounds.
|
|
644
645
|
* @type {boolean}
|
|
646
|
+
* @defaultValue false
|
|
645
647
|
*/
|
|
646
648
|
disableSoundForOutgoingMessages?: boolean;
|
|
647
649
|
|
|
648
650
|
/**
|
|
649
|
-
*
|
|
651
|
+
* Alias for disableSoundForOutgoingMessages, which takes precedence when both are set.
|
|
650
652
|
* @type {boolean}
|
|
651
653
|
*/
|
|
652
654
|
disableSoundForMessages?: boolean;
|
|
@@ -658,7 +660,7 @@ export interface CometChatCompactMessageComposerInterface {
|
|
|
658
660
|
customSoundForOutgoingMessage?: any;
|
|
659
661
|
|
|
660
662
|
/**
|
|
661
|
-
*
|
|
663
|
+
* Alias for customSoundForOutgoingMessage, which takes precedence when both are set.
|
|
662
664
|
* @type {*}
|
|
663
665
|
*/
|
|
664
666
|
customSoundForMessage?: any;
|
|
@@ -1188,7 +1190,9 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
1188
1190
|
parentMessageId,
|
|
1189
1191
|
disableTypingEvents: propDisableTypingEvents,
|
|
1190
1192
|
disableMentions: propDisableMentions,
|
|
1191
|
-
|
|
1193
|
+
disableSoundForOutgoingMessages,
|
|
1194
|
+
disableSoundForMessages,
|
|
1195
|
+
customSoundForOutgoingMessage,
|
|
1192
1196
|
customSoundForMessage,
|
|
1193
1197
|
textFormatters,
|
|
1194
1198
|
onError,
|
|
@@ -1244,6 +1248,12 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
1244
1248
|
enableMultipleAttachments = true,
|
|
1245
1249
|
} = props;
|
|
1246
1250
|
|
|
1251
|
+
// The documented names (…ForOutgoingMessage[s]) were declared but never read, so only the
|
|
1252
|
+
// aliases had any effect. Honour both, documented name first. Sound is on by default:
|
|
1253
|
+
// the composer owns the send sound now that the message list plays incoming sounds only.
|
|
1254
|
+
const disableOutgoingSound = disableSoundForOutgoingMessages ?? disableSoundForMessages ?? false;
|
|
1255
|
+
const outgoingSound = customSoundForOutgoingMessage ?? customSoundForMessage;
|
|
1256
|
+
|
|
1247
1257
|
// Auto-expand is always enabled (internal behavior)
|
|
1248
1258
|
const autoExpand = true;
|
|
1249
1259
|
|
|
@@ -2218,10 +2228,28 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2218
2228
|
}
|
|
2219
2229
|
}, []);
|
|
2220
2230
|
|
|
2231
|
+
// An agent chat that opens on its last conversation (CometChatMessageList's
|
|
2232
|
+
// loadLastAgentConversation) announces that conversation through ccActiveChatChanged.
|
|
2233
|
+
// Continue THAT conversation: without it the next question went out with no parent, the
|
|
2234
|
+
// server started a new conversation the list doesn't track, and every later question was
|
|
2235
|
+
// stamped with the new root and filtered out of the list until a reload (ENG-41058).
|
|
2236
|
+
// Read through a ref so the once-registered listener sees current props.
|
|
2237
|
+
const adoptAgentConversationRef = React.useRef<(item: any) => void>(() => {});
|
|
2238
|
+
adoptAgentConversationRef.current = (item: any) => {
|
|
2239
|
+
if (!isAgenticUser() || parentMessageId || parentMessageIdRef.current) return;
|
|
2240
|
+
if (item?.parentMessageId) return; // a thread view's list, not the main agent chat
|
|
2241
|
+
const msg = item?.message;
|
|
2242
|
+
if (!msg || item?.user?.getUid?.() !== user?.getUid?.()) return;
|
|
2243
|
+
const loadedParentId = Number(msg.getParentMessageId?.());
|
|
2244
|
+
const rootId = loadedParentId > 0 ? loadedParentId : Number(msg.getId?.());
|
|
2245
|
+
if (rootId > 0) parentMessageIdRef.current = rootId;
|
|
2246
|
+
};
|
|
2247
|
+
|
|
2221
2248
|
// Add edit message event listener
|
|
2222
2249
|
useEffect(() => {
|
|
2223
2250
|
CometChatUIEventHandler.addMessageListener(editMessageListenerID, {
|
|
2224
2251
|
ccMessageEdited: (item: { message: any; status: string }) => previewMessage(item),
|
|
2252
|
+
ccActiveChatChanged: (item: any) => adoptAgentConversationRef.current(item),
|
|
2225
2253
|
});
|
|
2226
2254
|
|
|
2227
2255
|
return () => {
|
|
@@ -2550,14 +2578,11 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2550
2578
|
setShowActionSheet(false);
|
|
2551
2579
|
clearInputBox();
|
|
2552
2580
|
|
|
2553
|
-
if (!
|
|
2554
|
-
CometChatSoundManager.play(
|
|
2555
|
-
CometChatSoundManager.SoundOutput.outgoingMessage,
|
|
2556
|
-
customSoundForMessage
|
|
2557
|
-
);
|
|
2581
|
+
if (!disableOutgoingSound) {
|
|
2582
|
+
CometChatSoundManager.play('outgoingMessage', outgoingSound);
|
|
2558
2583
|
}
|
|
2559
2584
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2560
|
-
}, [uploadQueue, parentMessageId,
|
|
2585
|
+
}, [uploadQueue, parentMessageId, disableOutgoingSound, outgoingSound]);
|
|
2561
2586
|
|
|
2562
2587
|
/**
|
|
2563
2588
|
* Send media message (image, video, audio, file)
|
|
@@ -2672,7 +2697,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2672
2697
|
});
|
|
2673
2698
|
|
|
2674
2699
|
// Play sound if enabled
|
|
2675
|
-
if (!
|
|
2700
|
+
if (!disableOutgoingSound) {
|
|
2676
2701
|
playAudio();
|
|
2677
2702
|
}
|
|
2678
2703
|
|
|
@@ -2695,19 +2720,13 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2695
2720
|
};
|
|
2696
2721
|
|
|
2697
2722
|
/**
|
|
2698
|
-
* Play outgoing message sound
|
|
2723
|
+
* Play outgoing message sound.
|
|
2724
|
+
* play() switches on the sound's NAME. Passing SoundOutput.outgoingMessage (the asset
|
|
2725
|
+
* itself) matched no case, so the composer never made a sound (GitHub #117). A missing
|
|
2726
|
+
* custom sound falls back to the built-in one.
|
|
2699
2727
|
*/
|
|
2700
2728
|
const playAudio = () => {
|
|
2701
|
-
|
|
2702
|
-
CometChatSoundManager.play(
|
|
2703
|
-
CometChatSoundManager.SoundOutput.outgoingMessage,
|
|
2704
|
-
customSoundForMessage
|
|
2705
|
-
);
|
|
2706
|
-
} else {
|
|
2707
|
-
CometChatSoundManager.play(
|
|
2708
|
-
CometChatSoundManager.SoundOutput.outgoingMessage
|
|
2709
|
-
);
|
|
2710
|
-
}
|
|
2729
|
+
CometChatSoundManager.play('outgoingMessage', outgoingSound);
|
|
2711
2730
|
};
|
|
2712
2731
|
|
|
2713
2732
|
/**
|
|
@@ -4428,7 +4447,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4428
4447
|
});
|
|
4429
4448
|
|
|
4430
4449
|
// Play sound if enabled
|
|
4431
|
-
if (!
|
|
4450
|
+
if (!disableOutgoingSound) {
|
|
4432
4451
|
playAudio();
|
|
4433
4452
|
}
|
|
4434
4453
|
|
|
@@ -4562,7 +4581,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4562
4581
|
}
|
|
4563
4582
|
|
|
4564
4583
|
// Play sound if enabled
|
|
4565
|
-
if (!
|
|
4584
|
+
if (!disableOutgoingSound) {
|
|
4566
4585
|
playAudio();
|
|
4567
4586
|
}
|
|
4568
4587
|
|
|
@@ -197,9 +197,11 @@ export interface CometChatMessageComposerInterface {
|
|
|
197
197
|
group?: CometChat.Group;
|
|
198
198
|
|
|
199
199
|
/**
|
|
200
|
-
* Flag to turn off sound for outgoing messages.
|
|
200
|
+
* Flag to turn off sound for outgoing messages. The composer owns the send sound;
|
|
201
|
+
* CometChatMessageList only plays incoming-message sounds.
|
|
201
202
|
*
|
|
202
203
|
* @type {boolean}
|
|
204
|
+
* @defaultValue false
|
|
203
205
|
*/
|
|
204
206
|
disableSoundForOutgoingMessages?: boolean;
|
|
205
207
|
|
|
@@ -497,7 +499,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
497
499
|
id,
|
|
498
500
|
user,
|
|
499
501
|
group,
|
|
500
|
-
disableSoundForOutgoingMessages =
|
|
502
|
+
disableSoundForOutgoingMessages = false,
|
|
501
503
|
customSoundForOutgoingMessage,
|
|
502
504
|
disableTypingEvents: propDisableTypingEvents,
|
|
503
505
|
initialComposertext,
|
|
@@ -1117,15 +1119,11 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1117
1119
|
void launchPicker(fileType);
|
|
1118
1120
|
};
|
|
1119
1121
|
|
|
1122
|
+
// play() switches on the sound's NAME. Passing SoundOutput.outgoingMessage (the asset
|
|
1123
|
+
// itself) matched no case, so the composer never made a sound and its sound props did
|
|
1124
|
+
// nothing (GitHub #117). A missing custom sound falls back to the built-in one.
|
|
1120
1125
|
const playAudio = () => {
|
|
1121
|
-
|
|
1122
|
-
CometChatSoundManager.play(
|
|
1123
|
-
CometChatSoundManager.SoundOutput.outgoingMessage,
|
|
1124
|
-
customSoundForOutgoingMessage
|
|
1125
|
-
);
|
|
1126
|
-
} else {
|
|
1127
|
-
CometChatSoundManager.play(CometChatSoundManager.SoundOutput.outgoingMessage);
|
|
1128
|
-
}
|
|
1126
|
+
CometChatSoundManager.play('outgoingMessage', customSoundForOutgoingMessage);
|
|
1129
1127
|
};
|
|
1130
1128
|
|
|
1131
1129
|
const sendMultiAttachmentMediaMessage = useCallback(() => {
|
|
@@ -1237,14 +1235,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1237
1235
|
setReplyMessage(null);
|
|
1238
1236
|
|
|
1239
1237
|
if (!disableSoundForOutgoingMessages) {
|
|
1240
|
-
|
|
1241
|
-
CometChatSoundManager.play(
|
|
1242
|
-
CometChatSoundManager.SoundOutput.outgoingMessage,
|
|
1243
|
-
customSoundForOutgoingMessage
|
|
1244
|
-
);
|
|
1245
|
-
} else {
|
|
1246
|
-
CometChatSoundManager.play(CometChatSoundManager.SoundOutput.outgoingMessage);
|
|
1247
|
-
}
|
|
1238
|
+
CometChatSoundManager.play('outgoingMessage', customSoundForOutgoingMessage);
|
|
1248
1239
|
}
|
|
1249
1240
|
}, [
|
|
1250
1241
|
uploadQueue,
|
|
@@ -1465,7 +1456,6 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1465
1456
|
|
|
1466
1457
|
inputValueRef.current = "";
|
|
1467
1458
|
clearInputBox();
|
|
1468
|
-
messageInputRef.current.textContent = "";
|
|
1469
1459
|
|
|
1470
1460
|
setMessagePreview(null);
|
|
1471
1461
|
|
|
@@ -2108,6 +2098,23 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2108
2098
|
replyMessage,
|
|
2109
2099
|
]);
|
|
2110
2100
|
|
|
2101
|
+
// An agent chat that opens on its last conversation (CometChatMessageList's
|
|
2102
|
+
// loadLastAgentConversation) announces that conversation through ccActiveChatChanged.
|
|
2103
|
+
// Continue THAT conversation: without it the next question went out with no parent, the
|
|
2104
|
+
// server started a new conversation the list doesn't track, and every later question was
|
|
2105
|
+
// stamped with the new root and filtered out of the list until a reload (ENG-41058).
|
|
2106
|
+
// Read through a ref so the once-registered listener sees current props.
|
|
2107
|
+
const adoptAgentConversationRef = useRef<(item: any) => void>(() => {});
|
|
2108
|
+
adoptAgentConversationRef.current = (item: any) => {
|
|
2109
|
+
if (!isAgenticUser() || parentMessageId || parentMessageIdRef.current) return;
|
|
2110
|
+
if (item?.parentMessageId) return; // a thread view's list, not the main agent chat
|
|
2111
|
+
const msg = item?.message;
|
|
2112
|
+
if (!msg || item?.user?.getUid?.() !== user?.getUid?.()) return;
|
|
2113
|
+
const loadedParentId = Number(msg.getParentMessageId?.());
|
|
2114
|
+
const rootId = loadedParentId > 0 ? loadedParentId : Number(msg.getId?.());
|
|
2115
|
+
if (rootId > 0) parentMessageIdRef.current = String(rootId);
|
|
2116
|
+
};
|
|
2117
|
+
|
|
2111
2118
|
useEffect(() => {
|
|
2112
2119
|
CometChatUIEventHandler.addMessageListener(editMessageListenerID, {
|
|
2113
2120
|
ccMessageEdited: (item: any) => {
|
|
@@ -2118,6 +2125,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2118
2125
|
previewMessage(item);
|
|
2119
2126
|
}
|
|
2120
2127
|
},
|
|
2128
|
+
ccActiveChatChanged: (item: any) => adoptAgentConversationRef.current(item),
|
|
2121
2129
|
});
|
|
2122
2130
|
CometChatMessageEvents.addListener(
|
|
2123
2131
|
CometChatMessageEvents.ccReplyToMessage,
|
|
@@ -270,11 +270,12 @@ export interface CometChatMessageListProps {
|
|
|
270
270
|
*/
|
|
271
271
|
receiptsVisibility?: boolean;
|
|
272
272
|
/**
|
|
273
|
-
* Flag to disable sound for incoming messages.
|
|
273
|
+
* Flag to disable sound for incoming messages. The send sound belongs to the composer
|
|
274
|
+
* (its disableSoundForOutgoingMessages / customSoundForOutgoingMessage props).
|
|
274
275
|
*/
|
|
275
276
|
disableSoundForMessages?: boolean;
|
|
276
277
|
/**
|
|
277
|
-
* Custom sound URL for messages.
|
|
278
|
+
* Custom sound URL for incoming messages.
|
|
278
279
|
*/
|
|
279
280
|
customSoundForMessages?: string;
|
|
280
281
|
/**
|
|
@@ -1514,10 +1515,15 @@ export const CometChatMessageList = memo(
|
|
|
1514
1515
|
return;
|
|
1515
1516
|
}
|
|
1516
1517
|
|
|
1517
|
-
// Create request builder for next messages (messages after the target)
|
|
1518
|
+
// Create request builder for next messages (messages after the target).
|
|
1519
|
+
// Same types/categories filter as the main list: without it the server also returns
|
|
1520
|
+
// the hidden edit/delete records (category "action", type "message"), which no
|
|
1521
|
+
// template renders, so each one became an empty padded row after the jump.
|
|
1518
1522
|
let nextMessagesRequest = new CometChat.MessagesRequestBuilder()
|
|
1519
1523
|
.setLimit(15)
|
|
1520
|
-
.setMessageId(targetMessageId)
|
|
1524
|
+
.setMessageId(targetMessageId)
|
|
1525
|
+
.setTypes(ChatConfigurator.dataSource.getAllMessageTypes())
|
|
1526
|
+
.setCategories(ChatConfigurator.dataSource.getAllMessageCategories());
|
|
1521
1527
|
|
|
1522
1528
|
if (user) {
|
|
1523
1529
|
nextMessagesRequest = nextMessagesRequest.setUID(user.getUid());
|
|
@@ -1618,9 +1624,13 @@ export const CometChatMessageList = memo(
|
|
|
1618
1624
|
const lastReadMsgId = conversation.getLastReadMessageId();
|
|
1619
1625
|
|
|
1620
1626
|
if (lastReadMsgId) {
|
|
1627
|
+
// Filtered like the main list, so the "New messages" marker lands on the
|
|
1628
|
+
// first unread message that is actually shown, not on a hidden edit/delete record.
|
|
1621
1629
|
let request = new CometChat.MessagesRequestBuilder()
|
|
1622
1630
|
.setLimit(1)
|
|
1623
|
-
.setMessageId(Number(lastReadMsgId))
|
|
1631
|
+
.setMessageId(Number(lastReadMsgId))
|
|
1632
|
+
.setTypes(ChatConfigurator.dataSource.getAllMessageTypes())
|
|
1633
|
+
.setCategories(ChatConfigurator.dataSource.getAllMessageCategories());
|
|
1624
1634
|
|
|
1625
1635
|
if (user) request = request.setUID(user.getUid());
|
|
1626
1636
|
if (group) request = request.setGUID(group.getGuid());
|
|
@@ -1994,26 +2004,23 @@ export const CometChatMessageList = memo(
|
|
|
1994
2004
|
return _plainString;
|
|
1995
2005
|
};
|
|
1996
2006
|
|
|
2007
|
+
// Read through a ref: playNotificationSound reaches the SDK/UI listeners, which are
|
|
2008
|
+
// registered once, so with [] deps it kept the sound props from the FIRST render and a
|
|
2009
|
+
// later change to them never took effect.
|
|
2010
|
+
const soundPropsRef = useRef({ disableSoundForMessages, customSoundForMessages });
|
|
2011
|
+
soundPropsRef.current = { disableSoundForMessages, customSoundForMessages };
|
|
2012
|
+
|
|
2013
|
+
// Incoming messages only, as documented. The composer owns the send sound: playing
|
|
2014
|
+
// 'outgoingMessage' here as well made the composer's sound props ineffective, made this
|
|
2015
|
+
// list's "incoming" switch mute sends too, and would double the chime now that the
|
|
2016
|
+
// composer's own sound works (GitHub #117).
|
|
1997
2017
|
const playNotificationSound = useCallback((message: any) => {
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
if (message?.category
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
? "outgoingMessage"
|
|
2005
|
-
: "incomingMessage",
|
|
2006
|
-
customSoundForMessages
|
|
2007
|
-
);
|
|
2008
|
-
} else {
|
|
2009
|
-
CometChatSoundManager.play(
|
|
2010
|
-
// "incomingMessage"
|
|
2011
|
-
loggedInUser.current?.getUid() == message["sender"]["uid"]
|
|
2012
|
-
? "outgoingMessage"
|
|
2013
|
-
: "incomingMessage"
|
|
2014
|
-
);
|
|
2015
|
-
}
|
|
2016
|
-
}
|
|
2018
|
+
const soundProps = soundPropsRef.current;
|
|
2019
|
+
if (soundProps.disableSoundForMessages) return;
|
|
2020
|
+
if (message?.category !== MessageCategoryConstants.message) return;
|
|
2021
|
+
if (loggedInUser.current?.getUid() === message?.sender?.uid) return;
|
|
2022
|
+
|
|
2023
|
+
CometChatSoundManager.play("incomingMessage", soundProps.customSoundForMessages);
|
|
2017
2024
|
}, []);
|
|
2018
2025
|
|
|
2019
2026
|
const markMessageAsRead = (message: any) => {
|
|
@@ -2988,6 +2995,17 @@ export const CometChatMessageList = memo(
|
|
|
2988
2995
|
setMessagesList(uniqueMsgs);
|
|
2989
2996
|
onLoad && onLoad([...uniqueMsgs].reverse());
|
|
2990
2997
|
setListState("loaded");
|
|
2998
|
+
// Announce the conversation now shown, as getPreviousMessages does for the
|
|
2999
|
+
// first page of any chat. This path fetched on its own and never did, so the
|
|
3000
|
+
// composer never learned it: its next question started a new conversation the
|
|
3001
|
+
// list doesn't track, and later questions were filtered out (ENG-41058).
|
|
3002
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccActiveChatChanged, {
|
|
3003
|
+
message: lastMsg,
|
|
3004
|
+
user: user,
|
|
3005
|
+
group: group,
|
|
3006
|
+
theme: mergedTheme,
|
|
3007
|
+
parentMessageId: parentMessageId,
|
|
3008
|
+
});
|
|
2991
3009
|
} else {
|
|
2992
3010
|
setListState("loaded");
|
|
2993
3011
|
onEmpty && onEmpty();
|
|
@@ -3360,6 +3378,19 @@ export const CometChatMessageList = memo(
|
|
|
3360
3378
|
message.getCategory() === MessageCategoryConstants.message
|
|
3361
3379
|
) {
|
|
3362
3380
|
agenticParentMessageIdRef.current = String(message.getId());
|
|
3381
|
+
} else if (
|
|
3382
|
+
isAgenticUser &&
|
|
3383
|
+
!parentMessageId &&
|
|
3384
|
+
agenticParentMessageIdRef.current !== undefined &&
|
|
3385
|
+
!(Number(message.getParentMessageId?.()) > 0) &&
|
|
3386
|
+
message.getType() === MessageTypeConstants.text &&
|
|
3387
|
+
message.getCategory() === MessageCategoryConstants.message
|
|
3388
|
+
) {
|
|
3389
|
+
// A question sent with no parent starts a NEW agent conversation on the server
|
|
3390
|
+
// (for example one sent before this list announced the conversation it loaded).
|
|
3391
|
+
// Follow it, or its reply and every later question in it are filtered out of
|
|
3392
|
+
// the list until a reload (ENG-41058).
|
|
3393
|
+
agenticParentMessageIdRef.current = String(message.getId());
|
|
3363
3394
|
}
|
|
3364
3395
|
if (isAgenticUser && agenticParentMessageIdRef.current !== undefined) {
|
|
3365
3396
|
const streamMessage = createStreamMessage(message);
|
|
@@ -5422,9 +5453,13 @@ export const CometChatMessageList = memo(
|
|
|
5422
5453
|
loadingMessagesRef.current = true;
|
|
5423
5454
|
|
|
5424
5455
|
try {
|
|
5456
|
+
// Filtered like the main list (see getMessagesAroundId): scrolling down after a jump
|
|
5457
|
+
// must not pull in hidden edit/delete records as empty rows either.
|
|
5425
5458
|
let nextMessagesRequest = new CometChat.MessagesRequestBuilder()
|
|
5426
5459
|
.setLimit(30)
|
|
5427
|
-
.setMessageId(newestMessageId)
|
|
5460
|
+
.setMessageId(newestMessageId)
|
|
5461
|
+
.setTypes(ChatConfigurator.dataSource.getAllMessageTypes())
|
|
5462
|
+
.setCategories(ChatConfigurator.dataSource.getAllMessageCategories());
|
|
5428
5463
|
|
|
5429
5464
|
if (user) {
|
|
5430
5465
|
nextMessagesRequest = nextMessagesRequest.setUID(user.getUid());
|