@cometchat/chat-uikit-react-native 5.5.0 → 5.5.1
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/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +20 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +9 -1
- package/ios/RichTextEditorView.swift +43 -0
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/RichTextEditorViewManager.swift +8 -0
- package/package.json +5 -2
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +38 -9
- package/src/CometChatConversations/CometChatConversations.tsx +8 -1
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +2 -2
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +15 -3
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +10 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +5 -2
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +478 -0
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +613 -0
- package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +313 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +7 -8
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +43 -19
- package/src/CometChatRichTextEditor/index.tsx +4 -0
- package/src/CometChatRichTextEditor/types.ts +2 -0
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +251 -14
- package/src/CometChatSearch/CometChatSearch.tsx +29 -6
- package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +76 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +2 -1
- package/src/shared/CometChatUiKit/checkAuthSettings-review.md +211 -0
- package/src/shared/constants/UIKitConstants.ts +3 -17
- package/src/shared/constants/textPatterns.ts +27 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +25 -259
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +31 -19
- package/src/shared/formatters/CometChatTextFormatter.ts +22 -0
- package/src/shared/formatters/applyRawFormatters.ts +31 -0
- package/src/shared/framework/MessageDataSource.tsx +14 -8
- package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +15 -30
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +138 -19
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +0 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +54 -1
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +11 -0
- package/src/shared/utils/MarkdownUtils.ts +34 -4
- package/src/shared/utils/PinnedMessagesHelper.ts +65 -0
- package/src/shared/utils/SavedMessagesHelper.ts +42 -6
- package/src/shared/utils/__testUtils__/messagesRequestBuilderMock.ts +37 -0
- package/src/shared/utils/cloneRequestBuilder.ts +25 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +15 -4
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +5 -0
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +4 -1
- package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +8 -1
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +5 -0
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +5 -0
- package/src/shared/views/CometChatList/Header.tsx +8 -2
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +5 -0
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +5 -0
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/src/CometChatMessageList/MANUAL_TEST_CASES.md +0 -154
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# `checkAuthSettings` — Code Review & Recommended Approach
|
|
2
|
+
|
|
3
|
+
> File: `packages/ChatUiKit/src/shared/CometChatUiKit/CometChatUIKit.ts`
|
|
4
|
+
> Trigger: "is using `!` the best approach in `if (!this.checkAuthSettings(Promise.reject))`?"
|
|
5
|
+
> Verified against source on review date — **5** call sites, line numbers below.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. TL;DR
|
|
10
|
+
|
|
11
|
+
- The `!` you asked about is the **logical NOT operator**, not a TypeScript non-null assertion. It is
|
|
12
|
+
correct and idiomatic — **keep it**. It was never the problem.
|
|
13
|
+
- The real problems sit *around* it:
|
|
14
|
+
1. `checkAuthSettings` is a **side-effecting predicate** — it returns a `boolean` *and* fires an
|
|
15
|
+
`onError` callback. (line 323)
|
|
16
|
+
2. Every caller passes `Promise.reject` as that callback, which creates a **floating, unhandled
|
|
17
|
+
rejected promise**.
|
|
18
|
+
3. `logout()` is the only caller that branches correctly — but it **double-fires** the error.
|
|
19
|
+
4. The other **four** callers (`getLoggedInUser`, `login`, `createUser`, `updateUser`) use the guard
|
|
20
|
+
as a **no-op** — validation is silently skipped.
|
|
21
|
+
5. Separately: `uiKitSettings` is typed non-optional but is `undefined` until `init()` runs — the
|
|
22
|
+
type lies, which is what lets the unsafe `.authKey` access compile.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 2. Call-site inventory (verified)
|
|
27
|
+
|
|
28
|
+
| Method | Line | Form | Effect |
|
|
29
|
+
| --- | --- | --- | --- |
|
|
30
|
+
| `getLoggedInUser` | 220 | `if (checkAuthSettings(Promise.reject)) null;` | **no-op** |
|
|
31
|
+
| `login` | 267 | `if (checkAuthSettings(Promise.reject)) null;` | **no-op** |
|
|
32
|
+
| `logout` | 293 | `if (!checkAuthSettings(Promise.reject)) { return Promise.reject(...) }` | branches, but double-fires |
|
|
33
|
+
| `createUser` | 309 | `if (checkAuthSettings(Promise.reject)) { }` | **no-op** |
|
|
34
|
+
| `updateUser` | 316 | `if (checkAuthSettings(Promise.reject)) { }` | **no-op** |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 3. The guard itself (line 323)
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// returns boolean AND calls onError as a side effect
|
|
42
|
+
static checkAuthSettings(onError: (e: CometChat.CometChatException) => void): boolean {
|
|
43
|
+
if (this.uiKitSettings == null) {
|
|
44
|
+
if (onError != null) {
|
|
45
|
+
onError(new CometChat.CometChatException({
|
|
46
|
+
code: "ERR", name: "Authentication null",
|
|
47
|
+
message: "Populate authSettings before initializing",
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (!this.uiKitSettings?.appId) {
|
|
53
|
+
if (onError != null) {
|
|
54
|
+
onError(new CometChat.CometChatException({
|
|
55
|
+
code: "appIdErr", name: "APP ID null",
|
|
56
|
+
message: "Populate appId in authSettings before initializing",
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 4. Why this is a problem
|
|
68
|
+
|
|
69
|
+
### 4.1 `Promise.reject` as a callback → unhandled rejection
|
|
70
|
+
`Promise.reject(error)` does **not** reject the calling function. It synchronously constructs a new,
|
|
71
|
+
already-rejected promise that nobody awaits or `.catch()`es. On Hermes/Node this surfaces as an
|
|
72
|
+
`UnhandledPromiseRejection` — noise at best, a crash signal at worst.
|
|
73
|
+
|
|
74
|
+
### 4.2 Dual contract (command + query)
|
|
75
|
+
`checkAuthSettings` both **answers a question** (is config valid?) and **performs an action** (fire the
|
|
76
|
+
error). Callers can't tell from the signature that calling it has side effects — which is precisely how
|
|
77
|
+
the no-op call sites slipped in. A predicate should be pure.
|
|
78
|
+
|
|
79
|
+
### 4.3 `logout()` double-fires (line 293)
|
|
80
|
+
```ts
|
|
81
|
+
if (!this.checkAuthSettings(Promise.reject)) { // (a) fires Promise.reject(error) internally
|
|
82
|
+
return Promise.reject(new CometChat.CometChatException({ code: "ERR", ... })); // (b) fires again
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
`(a)` is an unhandled rejection that also carries the *more specific* code (`appIdErr` when appId is
|
|
86
|
+
missing); `(b)` is the real return but always uses the generic `ERR`. One failure, two error objects,
|
|
87
|
+
worse error code.
|
|
88
|
+
|
|
89
|
+
### 4.4 Four call sites validate nothing
|
|
90
|
+
`if (cond) null;` and `if (cond) {}` are no-ops — the result is computed and thrown away. `getLoggedInUser`,
|
|
91
|
+
`login`, `createUser`, and `updateUser` proceed even when `uiKitSettings` is `null`, deferring to a
|
|
92
|
+
later, more cryptic crash (e.g. `this.uiKitSettings.authKey` reading a property of `undefined`).
|
|
93
|
+
|
|
94
|
+
### 4.5 The type lies (line 21)
|
|
95
|
+
```ts
|
|
96
|
+
static uiKitSettings: UIKitSettings; // declared always-present, but undefined until init()
|
|
97
|
+
```
|
|
98
|
+
Because the declared type is non-optional, TypeScript believes `this.uiKitSettings.authKey` is always
|
|
99
|
+
safe — so the unsafe access in `createUser`/`updateUser` compiles cleanly. The type should be
|
|
100
|
+
`UIKitSettings | undefined` so the compiler forces a guard.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 5. Recommended approach
|
|
105
|
+
|
|
106
|
+
Make `checkAuthSettings` a **pure predicate**, centralize the exception in a factory, and let each
|
|
107
|
+
caller decide how to report failure. Throwing assertions (no eager `Promise.reject`) avoid
|
|
108
|
+
re-introducing the unhandled-rejection footgun.
|
|
109
|
+
|
|
110
|
+
> ⚠️ **Breaking change:** dropping `onError` changes the signature of the `static` (public)
|
|
111
|
+
> `checkAuthSettings`. Grep the repo + consuming apps and migrate all callers, or keep `onError`
|
|
112
|
+
> optional and ignore it. Treat as a semver-minor/major change, not a drop-in edit.
|
|
113
|
+
|
|
114
|
+
### 5.1 Pure predicate + error factory + throwing assert
|
|
115
|
+
```ts
|
|
116
|
+
/** Pure predicate: is the UIKit configured well enough to make authenticated calls? */
|
|
117
|
+
static checkAuthSettings(): boolean {
|
|
118
|
+
return this.uiKitSettings != null && !!this.uiKitSettings.appId;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Single source of truth for the "not initialized" exception (preserves the specific code). */
|
|
122
|
+
private static authError(): CometChat.CometChatException {
|
|
123
|
+
if (this.uiKitSettings == null) {
|
|
124
|
+
return new CometChat.CometChatException({
|
|
125
|
+
code: "ERR", name: "Authentication null",
|
|
126
|
+
message: "Populate authSettings before initializing. Call CometChatUIKit.init() first.",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return new CometChat.CometChatException({
|
|
130
|
+
code: "appIdErr", name: "APP ID null",
|
|
131
|
+
message: "Populate appId in authSettings before initializing.",
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Throws the right exception when unconfigured. Works in sync (caught below) and async methods. */
|
|
136
|
+
private static assertInitialized(): void {
|
|
137
|
+
if (!this.checkAuthSettings()) throw this.authError();
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 5.2 Call sites — async methods just `throw`
|
|
142
|
+
```ts
|
|
143
|
+
static async getLoggedInUser(): Promise<CometChat.User> {
|
|
144
|
+
this.assertInitialized(); // rejection is automatic in an async fn
|
|
145
|
+
// ...existing logic
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static async login({ uid, authToken }: { uid?: string; authToken?: string }): Promise<CometChat.User> {
|
|
149
|
+
this.assertInitialized(); // keep the destructured params — body uses uid/authToken
|
|
150
|
+
// ...existing logic
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 5.3 Call sites — sync methods return a rejected promise once
|
|
155
|
+
```ts
|
|
156
|
+
static logout(): Promise<Object> {
|
|
157
|
+
if (!this.checkAuthSettings()) return Promise.reject(this.authError()); // single fire, correct code
|
|
158
|
+
return CometChat.logout().then(() => {
|
|
159
|
+
CometChatUIKit.loggedInUser = null;
|
|
160
|
+
return {};
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
static createUser(user: CometChat.User): Promise<CometChat.User> {
|
|
165
|
+
if (!this.checkAuthSettings()) return Promise.reject(this.authError());
|
|
166
|
+
// authKey is safe here because checkAuthSettings() guaranteed uiKitSettings is set
|
|
167
|
+
return CometChat.createUser(user, this.uiKitSettings.authKey as string);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static updateUser(user: CometChat.User): Promise<CometChat.User> {
|
|
171
|
+
if (!this.checkAuthSettings()) return Promise.reject(this.authError());
|
|
172
|
+
return CometChat.updateUser(user, this.uiKitSettings.authKey as string);
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
> Why not a `requireAuth()` helper that returns a `Promise.reject`? Because building the rejected
|
|
177
|
+
> promise inside the helper makes it float unhandled for a microtask if the caller `await`s anything
|
|
178
|
+
> before returning it — re-creating bug 4.1. A **throwing** assert has no such window.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 6. Before / After
|
|
183
|
+
|
|
184
|
+
| Concern | Before | After |
|
|
185
|
+
| --- | --- | --- |
|
|
186
|
+
| `checkAuthSettings` contract | boolean **+** side effect | pure boolean predicate |
|
|
187
|
+
| `checkAuthSettings` signature | `(onError)` | `()` — **breaking; migrate callers** |
|
|
188
|
+
| Unhandled rejections | yes (`Promise.reject` as callback) | none (throw / single return) |
|
|
189
|
+
| `logout` error firing | twice; generic code wins | once; specific code preserved |
|
|
190
|
+
| `getLoggedInUser` / `login` validation | no-op (`if (...) null;`) | real guard |
|
|
191
|
+
| `createUser` / `updateUser` validation | no-op (empty block) | real guard |
|
|
192
|
+
| Error message source | duplicated inline ×5 | single `authError()` factory |
|
|
193
|
+
| `uiKitSettings` type | non-optional (lies) | `UIKitSettings \| undefined` (optional improvement) |
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 7. Answer to the original question
|
|
198
|
+
|
|
199
|
+
`if (!this.checkAuthSettings())` is the clearest way to express "bail out when config is invalid" — the
|
|
200
|
+
`!` is correct and should stay. What actually deserved scrutiny was the side-effecting validator and the
|
|
201
|
+
`Promise.reject`-as-callback pattern wrapped around it. Fix those (pure predicate + factory + throwing
|
|
202
|
+
assert) and the `!` reads exactly as intended at every call site.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## 8. Follow-ups (out of scope here)
|
|
207
|
+
|
|
208
|
+
- Change `uiKitSettings` to `UIKitSettings | undefined` so the compiler enforces the guard.
|
|
209
|
+
- Add unit tests asserting each public method rejects with the right `code` when `uiKitSettings` is
|
|
210
|
+
`null` and when `appId` is missing (covers all 5 call sites).
|
|
211
|
+
- Consider a lint rule against expression-statement no-ops (`if (x) null;`) to prevent regressions.
|
|
@@ -52,23 +52,9 @@ export const PASSWORD_GROUP_COLOR = "rgb(247, 165, 0)";
|
|
|
52
52
|
export const IMAGE_PREFETCH_MAX_ATTEMPTS = 5;
|
|
53
53
|
export const IMAGE_PREFETCH_TIMEOUT = 800;
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const emailPattern =
|
|
61
|
-
wordBoundary.start + `[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}` + wordBoundary.end;
|
|
62
|
-
|
|
63
|
-
export const urlPattern =
|
|
64
|
-
`((https?://|ftp://|www\\.|pic\\.)[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]+[\\w/#](\\(\\))?` +
|
|
65
|
-
`|[a-zA-Z][a-zA-Z0-9]*[-a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\\.[a-zA-Z]{2,}(?:[:/][-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]*[\\w/#](\\(\\))?)?)` +
|
|
66
|
-
wordBoundary.end;
|
|
67
|
-
|
|
68
|
-
export const phoneNumPattern =
|
|
69
|
-
wordBoundary.start +
|
|
70
|
-
`(?:\\+?(\\d{1,3}))?([-. (]*(\\d{3})[-. )]*)?((\\d{3})[-. ]*(\\d{2,4})(?:[-.x ]*(\\d+))?)` +
|
|
71
|
-
wordBoundary.end;
|
|
55
|
+
// Moved to their own import-free module so a leaf like MarkdownUtils can use `urlPattern`
|
|
56
|
+
// without dragging the Chat SDK in through this file. Re-exported so callers are unaffected.
|
|
57
|
+
export { emailPattern, urlPattern, phoneNumPattern } from "./textPatterns";
|
|
72
58
|
|
|
73
59
|
export const MetadataConstants = {
|
|
74
60
|
file: "file",
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The link/email/phone patterns, kept in their OWN module with no imports.
|
|
3
|
+
*
|
|
4
|
+
* They live here rather than in UIKitConstants because that file imports the Chat SDK on its
|
|
5
|
+
* first line. Anything that pulls a pattern from it also pulls the SDK, which reads native
|
|
6
|
+
* modules at load — enough to break any consumer (and any test) that does not have the whole
|
|
7
|
+
* SDK available. MarkdownUtils needs `urlPattern` and is exactly that kind of leaf.
|
|
8
|
+
*
|
|
9
|
+
* UIKitConstants re-exports these, so existing imports keep working.
|
|
10
|
+
*/
|
|
11
|
+
export const wordBoundary = {
|
|
12
|
+
start: `(?:^|:|;|'|"|,|{|}|\\.|\\s|\\!|\\?|\\(|\\)|\\[|\\]|\\*)`,
|
|
13
|
+
end: `(?=$|:|;|'|"|,|{|}|\\.|\\s|\\!|\\?|\\(|\\)|\\[|\\]|\\*)`,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const emailPattern =
|
|
17
|
+
wordBoundary.start + `[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}` + wordBoundary.end;
|
|
18
|
+
|
|
19
|
+
export const urlPattern =
|
|
20
|
+
`((https?://|ftp://|www\\.|pic\\.)[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]+[\\w/#](\\(\\))?` +
|
|
21
|
+
`|[a-zA-Z][a-zA-Z0-9]*[-a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\\.[a-zA-Z]{2,}(?:[:/][-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]*[\\w/#](\\(\\))?)?)` +
|
|
22
|
+
wordBoundary.end;
|
|
23
|
+
|
|
24
|
+
export const phoneNumPattern =
|
|
25
|
+
wordBoundary.start +
|
|
26
|
+
`(?:\\+?(\\d{1,3}))?([-. (]*(\\d{3})[-. )]*)?((\\d{3})[-. ]*(\\d{2,4})(?:[-.x ]*(\\d+))?)` +
|
|
27
|
+
wordBoundary.end;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { SuggestionItem } from "../../views";
|
|
2
1
|
import {
|
|
3
2
|
CallListener,
|
|
4
3
|
CallUIEventListener,
|
|
@@ -26,60 +25,28 @@ export class CometChatUIEventHandler {
|
|
|
26
25
|
|
|
27
26
|
constructor() {}
|
|
28
27
|
|
|
29
|
-
static
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
private static dispatch(
|
|
29
|
+
handlers: ReadonlyArray<{ _eventListener?: object }> | undefined,
|
|
30
|
+
name: string,
|
|
31
|
+
param: object
|
|
32
|
+
) {
|
|
33
|
+
// Never dispatch to an inherited built-in ("constructor", "toString", "__proto__", …).
|
|
34
|
+
if (name in Object.prototype) return;
|
|
35
|
+
|
|
36
|
+
handlers?.forEach(({ _eventListener }) => {
|
|
37
|
+
const listener = _eventListener as Record<string, unknown> | undefined;
|
|
38
|
+
const handler = listener?.[name];
|
|
39
|
+
// .call keeps the receiver, so a method handler's `this` is its own listener object.
|
|
40
|
+
if (typeof handler === "function") (handler as (p: object) => void).call(listener, param);
|
|
39
41
|
});
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
static emitPanelEvent(name: string, param: object) {
|
|
45
|
+
CometChatUIEventHandler.dispatch(CometChatUIEventHandler.panelHandlers, name, param);
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
static emitCallEvent(name: string, param: object) {
|
|
43
|
-
CometChatUIEventHandler.callHandlers
|
|
44
|
-
switch (name) {
|
|
45
|
-
case listener._eventListener?.ccIncomingCallReceived?.name:
|
|
46
|
-
listener._eventListener?.ccIncomingCallReceived?.(param);
|
|
47
|
-
break;
|
|
48
|
-
case listener._eventListener?.ccOutgoingCallAccepted?.name:
|
|
49
|
-
listener._eventListener?.ccOutgoingCallAccepted?.(param);
|
|
50
|
-
break;
|
|
51
|
-
case listener._eventListener?.ccOutgoingCallRejected?.name:
|
|
52
|
-
listener._eventListener?.ccOutgoingCallRejected?.(param);
|
|
53
|
-
break;
|
|
54
|
-
case listener._eventListener?.ccIncomingCallCancelled?.name:
|
|
55
|
-
listener._eventListener?.ccIncomingCallCancelled?.(param);
|
|
56
|
-
break;
|
|
57
|
-
case listener._eventListener?.ccOutgoingCall?.name:
|
|
58
|
-
listener._eventListener?.ccOutgoingCall?.(param);
|
|
59
|
-
break;
|
|
60
|
-
case listener._eventListener?.ccCallAccepted?.name:
|
|
61
|
-
listener._eventListener?.ccCallAccepted?.(param);
|
|
62
|
-
break;
|
|
63
|
-
case listener._eventListener?.ccCallRejected?.name:
|
|
64
|
-
listener._eventListener?.ccCallRejected?.(param);
|
|
65
|
-
break;
|
|
66
|
-
case listener._eventListener?.ccCallEnded?.name:
|
|
67
|
-
listener._eventListener?.ccCallEnded?.(param);
|
|
68
|
-
break;
|
|
69
|
-
case listener._eventListener?.ccOutgoingCallCancelled?.name:
|
|
70
|
-
listener._eventListener?.ccOutgoingCallCancelled?.(param);
|
|
71
|
-
break;
|
|
72
|
-
case listener._eventListener?.ccCallInitiated?.name:
|
|
73
|
-
listener._eventListener?.ccCallInitiated?.(param);
|
|
74
|
-
break;
|
|
75
|
-
case listener._eventListener?.ccShowOngoingCall?.name:
|
|
76
|
-
listener._eventListener?.ccShowOngoingCall?.(param);
|
|
77
|
-
break;
|
|
78
|
-
case listener._eventListener?.ccCallFailed?.name:
|
|
79
|
-
listener._eventListener?.ccCallFailed?.(param);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
49
|
+
CometChatUIEventHandler.dispatch(CometChatUIEventHandler.callHandlers, name, param);
|
|
83
50
|
}
|
|
84
51
|
|
|
85
52
|
static addCallListener(name: string, callHandler: CallUIEventListener) {
|
|
@@ -111,125 +78,7 @@ export class CometChatUIEventHandler {
|
|
|
111
78
|
}
|
|
112
79
|
|
|
113
80
|
static emitMessageEvent(name: string, param: object) {
|
|
114
|
-
CometChatUIEventHandler.messageHandlers
|
|
115
|
-
switch (name) {
|
|
116
|
-
case listener._eventListener?.ccThreadSubscriptionChanged?.name:
|
|
117
|
-
listener._eventListener?.ccThreadSubscriptionChanged?.(param);
|
|
118
|
-
break;
|
|
119
|
-
case listener._eventListener?.ccMessageDeleted?.name:
|
|
120
|
-
listener._eventListener?.ccMessageDeleted?.(param);
|
|
121
|
-
break;
|
|
122
|
-
case listener._eventListener?.ccMessageEdited?.name:
|
|
123
|
-
listener._eventListener?.ccMessageEdited?.(param);
|
|
124
|
-
break;
|
|
125
|
-
case listener._eventListener?.ccMessageRead?.name:
|
|
126
|
-
listener._eventListener?.ccMessageRead?.(param);
|
|
127
|
-
break;
|
|
128
|
-
case listener._eventListener?.ccMessageSent?.name:
|
|
129
|
-
listener._eventListener?.ccMessageSent?.(param);
|
|
130
|
-
break;
|
|
131
|
-
case listener._eventListener?.ccMessageDelivered?.name:
|
|
132
|
-
listener._eventListener?.ccMessageSent?.(param);
|
|
133
|
-
break;
|
|
134
|
-
case listener._eventListener?.ccActiveChatChanged?.name:
|
|
135
|
-
listener._eventListener?.ccActiveChatChanged?.(param);
|
|
136
|
-
break;
|
|
137
|
-
case listener._eventListener?.onTextMessageReceived?.name:
|
|
138
|
-
listener._eventListener?.onTextMessageReceived?.(param);
|
|
139
|
-
break;
|
|
140
|
-
case listener._eventListener?.onMediaMessageReceived?.name:
|
|
141
|
-
listener._eventListener?.onMediaMessageReceived?.(param);
|
|
142
|
-
break;
|
|
143
|
-
case listener._eventListener?.onCustomMessageReceived?.name:
|
|
144
|
-
listener._eventListener?.onCustomMessageReceived?.(param);
|
|
145
|
-
break;
|
|
146
|
-
case listener._eventListener?.onTypingStarted?.name:
|
|
147
|
-
listener._eventListener?.onTypingStarted?.(param);
|
|
148
|
-
break;
|
|
149
|
-
case listener._eventListener?.onTypingEnded?.name:
|
|
150
|
-
listener._eventListener?.onTypingEnded?.(param);
|
|
151
|
-
break;
|
|
152
|
-
case listener._eventListener?.onMessagesDelivered?.name:
|
|
153
|
-
listener._eventListener?.onMessagesDelivered?.(param);
|
|
154
|
-
break;
|
|
155
|
-
case listener._eventListener?.onMessagesRead?.name:
|
|
156
|
-
listener._eventListener?.onMessagesRead?.(param);
|
|
157
|
-
break;
|
|
158
|
-
case listener._eventListener?.onMessageEdited?.name:
|
|
159
|
-
listener._eventListener?.onMessageEdited?.(param);
|
|
160
|
-
break;
|
|
161
|
-
case listener._eventListener?.onMessageDeleted?.name:
|
|
162
|
-
listener._eventListener?.onMessageDeleted?.(param);
|
|
163
|
-
break;
|
|
164
|
-
case listener._eventListener?.onTransientMessageReceived?.name:
|
|
165
|
-
listener._eventListener?.onTransientMessageReceived?.(param);
|
|
166
|
-
break;
|
|
167
|
-
case listener._eventListener?.onFormMessageReceived?.name:
|
|
168
|
-
listener._eventListener?.onFormMessageReceived?.(param);
|
|
169
|
-
break;
|
|
170
|
-
case listener._eventListener?.onCardMessageReceived?.name:
|
|
171
|
-
listener._eventListener?.onCardMessageReceived?.(param);
|
|
172
|
-
break;
|
|
173
|
-
case listener._eventListener?.onSchedulerMessageReceived?.name:
|
|
174
|
-
listener._eventListener?.onSchedulerMessageReceived?.(param);
|
|
175
|
-
break;
|
|
176
|
-
case listener._eventListener?.onCustomInteractiveMessageReceived?.name:
|
|
177
|
-
listener._eventListener?.onCustomInteractiveMessageReceived?.(param);
|
|
178
|
-
break;
|
|
179
|
-
case listener._eventListener?.onInteractionGoalCompleted?.name:
|
|
180
|
-
listener._eventListener?.onInteractionGoalCompleted?.(param);
|
|
181
|
-
break;
|
|
182
|
-
case listener._eventListener?.onMessageReactionRemoved?.name:
|
|
183
|
-
listener._eventListener?.onMessageReactionRemoved?.(param);
|
|
184
|
-
break;
|
|
185
|
-
case listener._eventListener?.onMessageReactionAdded?.name:
|
|
186
|
-
listener._eventListener?.onMessageReactionAdded?.(param);
|
|
187
|
-
break;
|
|
188
|
-
case listener._eventListener?.onMessagesDeliveredToAll?.name:
|
|
189
|
-
listener._eventListener?.onMessagesDeliveredToAll?.(param);
|
|
190
|
-
break;
|
|
191
|
-
case listener._eventListener?.onMessagesReadByAll?.name:
|
|
192
|
-
listener._eventListener?.onMessagesReadByAll?.(param);
|
|
193
|
-
break;
|
|
194
|
-
case listener._eventListener?.onAIAssistantMessageReceived?.name:
|
|
195
|
-
listener._eventListener?.onAIAssistantMessageReceived?.(param);
|
|
196
|
-
break;
|
|
197
|
-
case listener._eventListener?.onMessageModerated?.name:
|
|
198
|
-
listener._eventListener?.onMessageModerated?.(param);
|
|
199
|
-
break;
|
|
200
|
-
// Pin & Save realtime. Without these four the SDK parses the socket frame,
|
|
201
|
-
// ListenerInitializer emits it, and the emit lands in a switch that matches
|
|
202
|
-
// nothing — so a pin made by another participant never reaches the message
|
|
203
|
-
// list and only appears on the next fetch.
|
|
204
|
-
case listener._eventListener?.onMessagePinned?.name:
|
|
205
|
-
listener._eventListener?.onMessagePinned?.(param);
|
|
206
|
-
break;
|
|
207
|
-
case listener._eventListener?.onMessageUnpinned?.name:
|
|
208
|
-
listener._eventListener?.onMessageUnpinned?.(param);
|
|
209
|
-
break;
|
|
210
|
-
case listener._eventListener?.onMessageSaved?.name:
|
|
211
|
-
listener._eventListener?.onMessageSaved?.(param);
|
|
212
|
-
break;
|
|
213
|
-
case listener._eventListener?.onMessageUnsaved?.name:
|
|
214
|
-
listener._eventListener?.onMessageUnsaved?.(param);
|
|
215
|
-
break;
|
|
216
|
-
// The cc* half: emitted by the device that PERFORMED the action, so a panel
|
|
217
|
-
// open next to the message list updates without waiting for a socket echo
|
|
218
|
-
// (and in a 1-1, where no echo is coming at all).
|
|
219
|
-
case listener._eventListener?.ccMessagePinned?.name:
|
|
220
|
-
listener._eventListener?.ccMessagePinned?.(param);
|
|
221
|
-
break;
|
|
222
|
-
case listener._eventListener?.ccMessageUnpinned?.name:
|
|
223
|
-
listener._eventListener?.ccMessageUnpinned?.(param);
|
|
224
|
-
break;
|
|
225
|
-
case listener._eventListener?.ccMessageSaved?.name:
|
|
226
|
-
listener._eventListener?.ccMessageSaved?.(param);
|
|
227
|
-
break;
|
|
228
|
-
case listener._eventListener?.ccMessageUnsaved?.name:
|
|
229
|
-
listener._eventListener?.ccMessageUnsaved?.(param);
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
});
|
|
81
|
+
CometChatUIEventHandler.dispatch(CometChatUIEventHandler.messageHandlers, name, param);
|
|
233
82
|
}
|
|
234
83
|
|
|
235
84
|
static addMessageListener(name: string, messageHandler: MessageUIEventListener) {
|
|
@@ -261,17 +110,7 @@ export class CometChatUIEventHandler {
|
|
|
261
110
|
}
|
|
262
111
|
|
|
263
112
|
static emitConversationEvent(name: string, param: object) {
|
|
264
|
-
CometChatUIEventHandler.conversationHandlers
|
|
265
|
-
switch (name) {
|
|
266
|
-
case listener._eventListener?.ccConversationDeleted?.name:
|
|
267
|
-
listener._eventListener?.ccConversationDeleted?.(param);
|
|
268
|
-
break;
|
|
269
|
-
//added for markAsUnread
|
|
270
|
-
case listener._eventListener?.ccUpdateConversation?.name:
|
|
271
|
-
listener._eventListener?.ccUpdateConversation?.(param);
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
});
|
|
113
|
+
CometChatUIEventHandler.dispatch(CometChatUIEventHandler.conversationHandlers, name, param);
|
|
275
114
|
}
|
|
276
115
|
|
|
277
116
|
static addConversationListener(name: string, conversationHandler: ConversationUIEventListener) {
|
|
@@ -303,40 +142,7 @@ export class CometChatUIEventHandler {
|
|
|
303
142
|
}
|
|
304
143
|
|
|
305
144
|
static emitGroupEvent(name: string, param: object) {
|
|
306
|
-
CometChatUIEventHandler.groupHandlers
|
|
307
|
-
switch (name) {
|
|
308
|
-
case listener._eventListener?.ccGroupCreated?.name:
|
|
309
|
-
listener._eventListener?.ccGroupCreated?.(param);
|
|
310
|
-
break;
|
|
311
|
-
case listener._eventListener?.ccGroupDeleted?.name:
|
|
312
|
-
listener._eventListener?.ccGroupDeleted?.(param);
|
|
313
|
-
break;
|
|
314
|
-
case listener._eventListener?.ccGroupLeft?.name:
|
|
315
|
-
listener._eventListener?.ccGroupLeft?.(param);
|
|
316
|
-
break;
|
|
317
|
-
case listener._eventListener?.ccGroupMemberBanned?.name:
|
|
318
|
-
listener._eventListener?.ccGroupMemberBanned?.(param);
|
|
319
|
-
break;
|
|
320
|
-
case listener._eventListener?.ccGroupMemberJoined?.name:
|
|
321
|
-
listener._eventListener?.ccGroupMemberJoined?.(param);
|
|
322
|
-
break;
|
|
323
|
-
case listener._eventListener?.ccGroupMemberKicked?.name:
|
|
324
|
-
listener._eventListener?.ccGroupMemberKicked?.(param);
|
|
325
|
-
break;
|
|
326
|
-
case listener._eventListener?.ccGroupMemberScopeChanged?.name:
|
|
327
|
-
listener._eventListener?.ccGroupMemberScopeChanged?.(param);
|
|
328
|
-
break;
|
|
329
|
-
case listener._eventListener?.ccGroupMemberUnBanned?.name:
|
|
330
|
-
listener._eventListener?.ccGroupMemberUnBanned?.(param);
|
|
331
|
-
break;
|
|
332
|
-
case listener._eventListener?.ccOwnershipChanged?.name:
|
|
333
|
-
listener._eventListener?.ccOwnershipChanged?.(param);
|
|
334
|
-
break;
|
|
335
|
-
case listener._eventListener?.ccGroupMemberAdded?.name:
|
|
336
|
-
listener._eventListener?.ccGroupMemberAdded?.(param);
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
});
|
|
145
|
+
CometChatUIEventHandler.dispatch(CometChatUIEventHandler.groupHandlers, name, param);
|
|
340
146
|
}
|
|
341
147
|
|
|
342
148
|
static addGroupListener(name: string, groupHandler: GroupUIEventListener) {
|
|
@@ -368,16 +174,7 @@ export class CometChatUIEventHandler {
|
|
|
368
174
|
}
|
|
369
175
|
|
|
370
176
|
static emitUserEvent(name: string, param: object) {
|
|
371
|
-
CometChatUIEventHandler.userHandlers
|
|
372
|
-
switch (name) {
|
|
373
|
-
case listener._eventListener?.ccUserBlocked?.name:
|
|
374
|
-
listener._eventListener?.ccUserBlocked?.(param);
|
|
375
|
-
break;
|
|
376
|
-
case listener._eventListener?.ccUserUnBlocked?.name:
|
|
377
|
-
listener._eventListener?.ccUserUnBlocked?.(param);
|
|
378
|
-
break;
|
|
379
|
-
}
|
|
380
|
-
});
|
|
177
|
+
CometChatUIEventHandler.dispatch(CometChatUIEventHandler.userHandlers, name, param);
|
|
381
178
|
}
|
|
382
179
|
|
|
383
180
|
static addUserListener(name: string, userHandler: UserUIEventListener) {
|
|
@@ -409,38 +206,7 @@ export class CometChatUIEventHandler {
|
|
|
409
206
|
}
|
|
410
207
|
|
|
411
208
|
static emitUIEvent(name: string, param: object) {
|
|
412
|
-
CometChatUIEventHandler.uiHandlers
|
|
413
|
-
switch (name) {
|
|
414
|
-
case listener._eventListener?.hidePanel?.name:
|
|
415
|
-
listener._eventListener?.hidePanel?.(param);
|
|
416
|
-
break;
|
|
417
|
-
case listener._eventListener?.showPanel?.name:
|
|
418
|
-
listener._eventListener?.showPanel?.(param);
|
|
419
|
-
break;
|
|
420
|
-
case listener._eventListener?.openChat?.name:
|
|
421
|
-
listener._eventListener?.openChat?.(param);
|
|
422
|
-
break;
|
|
423
|
-
case listener._eventListener?.ccToggleBottomSheet?.name:
|
|
424
|
-
listener._eventListener?.ccToggleBottomSheet?.(param);
|
|
425
|
-
break;
|
|
426
|
-
case listener._eventListener?.ccComposeMessage?.name:
|
|
427
|
-
listener._eventListener?.ccComposeMessage?.(param);
|
|
428
|
-
break;
|
|
429
|
-
// case listener._eventListener?.ccMentionClick?.name:
|
|
430
|
-
// listener._eventListener?.ccMentionClick(param);
|
|
431
|
-
// break;
|
|
432
|
-
case listener._eventListener?.ccSuggestionData?.name:
|
|
433
|
-
listener._eventListener?.ccSuggestionData?.(
|
|
434
|
-
param as { id: string; data: Array<SuggestionItem> }
|
|
435
|
-
);
|
|
436
|
-
break;
|
|
437
|
-
case listener._eventListener?.ccCardActionClicked?.name:
|
|
438
|
-
listener._eventListener?.ccCardActionClicked?.(
|
|
439
|
-
param as { message: any; action: any }
|
|
440
|
-
);
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
});
|
|
209
|
+
CometChatUIEventHandler.dispatch(CometChatUIEventHandler.uiHandlers, name, param);
|
|
444
210
|
}
|
|
445
211
|
|
|
446
212
|
static addUIListener(name: string, uiHandlers: UIEventListener) {
|
|
@@ -461,13 +227,13 @@ export class CometChatUIEventHandler {
|
|
|
461
227
|
|
|
462
228
|
static removeUIListener(name: string) {
|
|
463
229
|
try {
|
|
464
|
-
CometChatUIEventHandler.
|
|
230
|
+
CometChatUIEventHandler.uiHandlers = CometChatUIEventHandler.uiHandlers?.filter(
|
|
465
231
|
(listener) => {
|
|
466
232
|
return listener._name !== name;
|
|
467
233
|
}
|
|
468
234
|
);
|
|
469
235
|
} catch (err) {
|
|
470
|
-
console.log("
|
|
236
|
+
console.log("removeUIListener", err);
|
|
471
237
|
}
|
|
472
238
|
}
|
|
473
239
|
}
|