@cometchat/chat-uikit-react-native 5.5.3 → 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.
@@ -832,6 +832,11 @@ class RichTextView: UITextView {
832
832
  return true
833
833
  }
834
834
  }
835
+ // Allow the spelling correction so tapping a floating spell-check suggestion replaces the
836
+ // misspelled word. Only this selector, not all of super (keeps Look Up/Share/system B/I/U hidden).
837
+ if action == NSSelectorFromString("replace:") {
838
+ return super.canPerformAction(action, withSender: sender)
839
+ }
835
840
  return false
836
841
  }
837
842
 
@@ -1188,6 +1193,9 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
1188
1193
  /// emoji, a paste, an IME commit — and without this the anchor below treats every one of those
1189
1194
  /// as "the user moved the caret" and disarms the pending colour mid-sentence (ENG-38257).
1190
1195
  private var lastKnownTextLength: Int = 0
1196
+ /// The text as of the last keyboard edit, so colourEditThatBypassedInheritance can find what
1197
+ /// the next edit changed.
1198
+ private var lastEditSnapshot: NSAttributedString?
1191
1199
 
1192
1200
  /// Caret-armed consumer inline colour (no selection). A UIColor cannot live in a
1193
1201
  /// `Set<String>` cleanly, so the value lives here while `ExternalColorPendingKey` goes into
@@ -1510,6 +1518,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
1510
1518
  // A captured inheritance would otherwise be painted onto the first character of the
1511
1519
  // next message, which is the same leak by a different route.
1512
1520
  clearPendingInherit()
1521
+ lastEditSnapshot = nil
1513
1522
  // Reset typingAttributes to plain so next typed text has no ghost formatting
1514
1523
  let paragraphStyle = NSMutableParagraphStyle()
1515
1524
  paragraphStyle.lineHeightMultiple = RichTextEditorView.defaultLineHeightMultiple
@@ -1575,6 +1584,78 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
1575
1584
  clearPendingInherit()
1576
1585
  }
1577
1586
 
1587
+ /// Colours a keyboard edit that bypassed the inheritance capture in shouldChangeTextIn.
1588
+ ///
1589
+ /// iOS makes the double-space full stop by swapping the space for ". " without that capture
1590
+ /// taking effect, so the full stop and the space after it came out in the default colour and
1591
+ /// broke the coloured run — at the end of the text and mid-text alike (ENG-40922). This diffs
1592
+ /// the text against the last edit and gives the changed run the colour the shouldChangeTextIn
1593
+ /// rules would have: an armed colour first, else the run it replaced, else the character before.
1594
+ ///
1595
+ /// Only keyboard-sized edits (a few characters) are considered, so a programmatic change that
1596
+ /// slipped between two snapshots — a send, setText from JS — is never mistaken for one.
1597
+ private func colourEditThatBypassedInheritance() {
1598
+ guard let now = textView.attributedText else { return }
1599
+ let before = lastEditSnapshot
1600
+ lastEditSnapshot = NSAttributedString(attributedString: now)
1601
+ // No snapshot yet means nothing was typed since the composer was last empty, so the old
1602
+ // text is empty — the first keystroke still gets diffed rather than skipped.
1603
+ let old = before ?? NSAttributedString()
1604
+ guard !pendingExternalForegroundCleared,
1605
+ !pendingStyles.contains("code"), !pendingStyles.contains("codeBlock") else { return }
1606
+
1607
+ let oldS = old.string as NSString, newS = now.string as NSString
1608
+ let minLen = min(oldS.length, newS.length)
1609
+ var prefix = 0
1610
+ while prefix < minLen && oldS.character(at: prefix) == newS.character(at: prefix) { prefix += 1 }
1611
+ var suffix = 0
1612
+ while suffix < minLen - prefix &&
1613
+ oldS.character(at: oldS.length - 1 - suffix) == newS.character(at: newS.length - 1 - suffix) { suffix += 1 }
1614
+ let oldRun = NSRange(location: prefix, length: oldS.length - prefix - suffix)
1615
+ var newRun = NSRange(location: prefix, length: newS.length - prefix - suffix)
1616
+ guard newRun.length > 0, newRun.length <= 3, oldRun.length <= 3 else { return }
1617
+
1618
+ func isColoured(_ r: NSRange) -> Bool {
1619
+ var found = false
1620
+ now.enumerateAttribute(ExternalForegroundKey, in: r) { v, _, stop in
1621
+ if v != nil { found = true; stop.pointee = true }
1622
+ }
1623
+ return found
1624
+ }
1625
+ // An insertion next to identical characters is ambiguous: a space typed beside an existing
1626
+ // space diffs as if the existing one were new, and colouring that one recolours text the
1627
+ // user did not touch. A keyboard insertion always ends at the caret, so among the equally
1628
+ // valid positions (sliding left through equal characters) take the one ending there.
1629
+ // Pure insertions only — a replacement has a definite position.
1630
+ if oldRun.length == 0 {
1631
+ var leftmost = newRun.location
1632
+ while leftmost > 0,
1633
+ newS.character(at: leftmost - 1) == newS.character(at: leftmost - 1 + newRun.length) {
1634
+ leftmost -= 1
1635
+ }
1636
+ let atCaret = textView.selectedRange.location - newRun.length
1637
+ if textView.selectedRange.length == 0, atCaret >= leftmost, atCaret <= newRun.location {
1638
+ newRun.location = atCaret
1639
+ }
1640
+ }
1641
+ // Leave it alone if the run already carries a colour — the normal rules ran.
1642
+ guard !isColoured(newRun) else { return }
1643
+
1644
+ let source: [NSAttributedString.Key: Any]? =
1645
+ oldRun.length > 0 ? old.attributes(at: oldRun.location, effectiveRange: nil)
1646
+ : (newRun.location > 0 ? now.attributes(at: newRun.location - 1, effectiveRange: nil) : nil)
1647
+ let armed = pendingStyles.contains(ExternalColorPendingKey) ? pendingExternalForeground : nil
1648
+ guard source?[MentionMarkerKey] == nil, source?[LinkURLAttributeKey] == nil,
1649
+ let colour = armed ?? source?[ExternalForegroundKey] as? UIColor else { return }
1650
+
1651
+ let wasInternal = isInternalChange
1652
+ isInternalChange = true
1653
+ textView.textStorage.addAttribute(ExternalForegroundKey, value: colour, range: newRun)
1654
+ textView.textStorage.addAttribute(.foregroundColor, value: colour, range: newRun)
1655
+ isInternalChange = wasInternal
1656
+ lastEditSnapshot = NSAttributedString(attributedString: textView.attributedText)
1657
+ }
1658
+
1578
1659
  func textViewDidChangeSelection(_ textView: UITextView) {
1579
1660
  let range = textView.selectedRange
1580
1661
  if range.length > 0 {
@@ -1609,7 +1690,12 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
1609
1690
  // emoji, a paste, or an IME commit. Comparing against a hardcoded +1 classified all of
1610
1691
  // those as a deliberate caret move and disarmed the colour, so text typed from the first
1611
1692
  // autocorrection onwards sent as plain (ENG-38257).
1612
- let isTypingAdvance = insertedCount > 0 && range.location == pendingStylesInsertPos + insertedCount
1693
+ //
1694
+ // Deleting at the anchor is editing too: a backspace moves the caret back by exactly the
1695
+ // characters removed. Counting only forward moves read it as a caret jump and dropped the
1696
+ // colour — accept a suggestion, backspace its trailing space, double-space for a full
1697
+ // stop, and everything after it sent plain (ENG-40922).
1698
+ let isTypingAdvance = insertedCount != 0 && range.location == pendingStylesInsertPos + insertedCount
1613
1699
  if range.location != pendingStylesInsertPos && !isTypingAdvance {
1614
1700
  // Preserve "codeBlock" across cursor movements — it's a persistent
1615
1701
  // block-level style that should survive until explicitly toggled off
@@ -2625,6 +2711,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
2625
2711
  // Before anything reads or snapshots the text: give the characters the keyboard just
2626
2712
  // inserted the formatting they inherited (see applyPendingInheritedColour).
2627
2713
  applyPendingInheritedColour()
2714
+ colourEditThatBypassedInheritance()
2628
2715
 
2629
2716
  // Clear pending styles after text was typed (typingAttributes already applied them).
2630
2717
  // Preserve inline styles (bold, italic, underline, strikethrough) — they persist
@@ -6022,7 +6109,15 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
6022
6109
 
6023
6110
  isInternalChange = true
6024
6111
  let savedTypingAttrs = textView.typingAttributes
6112
+ // Assigning attributedText moves the caret to the end. JS pushes mention ranges after
6113
+ // every content change, so editing mid-text — a double-space full stop, for one — sent
6114
+ // the caret to the end of the message (ENG-40922). The string is unchanged here, only
6115
+ // its attributes, so the old caret is still valid.
6116
+ let savedSelection = textView.selectedRange
6025
6117
  textView.attributedText = mutableAttr
6118
+ if NSMaxRange(savedSelection) <= mutableAttr.length {
6119
+ textView.selectedRange = savedSelection
6120
+ }
6026
6121
  textView.typingAttributes = savedTypingAttrs
6027
6122
  // If a deferred restore is pending (from autoContinueListOnEnter),
6028
6123
  // use those attrs instead — they carry the user's active formatting.
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
- NSString *response = [NSString stringWithFormat:@"{\"success\":0, \"error\":\"%@\"}", [playerError localizedDescription]];
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 (audioPlayer != nil) {
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 ([audioPlayer isPlaying]) {
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 ([audioPlayer isPlaying]) {
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 ([audioPlayer isPlaying]) {
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",
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,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
- * Flag to turn off sound for messages (alias for disableSoundForOutgoingMessages).
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
- * Custom audio sound for messages (alias for customSoundForOutgoingMessage).
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
- disableSoundForMessages = true,
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 (!disableSoundForMessages) {
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, disableSoundForMessages, customSoundForMessage]);
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 (!disableSoundForMessages) {
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
- if (customSoundForMessage) {
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 (!disableSoundForMessages) {
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 (!disableSoundForMessages) {
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 = true,
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
- if (customSoundForOutgoingMessage) {
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
- if (customSoundForOutgoingMessage) {
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,