@cometchat/chat-uikit-react-native 5.3.8 → 5.3.10
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/package.json +1 -1
- package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +6 -3
- package/src/CometChatConversations/CometChatConversations.tsx +9 -0
- package/src/CometChatMessageList/CometChatMessageList.tsx +84 -5
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +478 -0
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +613 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +12 -4
- package/src/CometChatSearch/CometChatSearch.tsx +16 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +76 -0
- package/src/shared/CometChatUiKit/checkAuthSettings-review.md +211 -0
- package/src/shared/constants/UIKitConstants.ts +5 -1
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +5 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +4 -0
- package/src/shared/events/CometChatUIEvents.ts +1 -0
- package/src/shared/events/ListenerInitializer.ts +3 -0
- package/src/shared/framework/DataSource.ts +10 -0
- package/src/shared/framework/DataSourceDecorator.tsx +13 -0
- package/src/shared/framework/MessageDataSource.tsx +70 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +502 -500
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +2 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +522 -520
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +522 -520
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +7 -0
- package/src/shared/utils/conversationUtils.ts +26 -0
- package/src/shared/utils/stripRichText.ts +41 -0
- package/src/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.tsx +107 -48
- package/src/shared/views/CometChatCardBubble/CometChatCardBubble.tsx +118 -0
- package/src/shared/views/CometChatCardBubble/index.ts +2 -0
- package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +63 -0
- package/src/shared/views/index.ts +2 -0
- package/src/CometChatMessageList/MANUAL_TEST_CASES.md +0 -154
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# CometChatUIKit.ts — Auth-check refactor
|
|
2
|
+
|
|
3
|
+
## What changed
|
|
4
|
+
|
|
5
|
+
The `checkAuthSettings()` helper and its call sites were refactored. The single
|
|
6
|
+
function that did three jobs (predicate + error construction + error
|
|
7
|
+
dispatch via a callback) was split into three small, single-purpose pieces:
|
|
8
|
+
|
|
9
|
+
| Member | Kind | Responsibility |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `checkAuthSettings()` | public, pure predicate | Returns `true` when the UIKit is configured well enough to make authenticated calls (`uiKitSettings != null && uiKitSettings.appId` set). No side effects. |
|
|
12
|
+
| `authError()` | private factory | Single source of truth for the "not initialized" exception. Returns the correct `CometChatException` (`code: "ERR"` when settings are null, `code: "appIdErr"` when only `appId` is missing). |
|
|
13
|
+
| `assertInitialized()` | private guard | Throws `authError()` when unconfigured. Safe in both `async` methods (the throw becomes a rejected promise) and sync methods that are caught. |
|
|
14
|
+
|
|
15
|
+
Call sites updated:
|
|
16
|
+
|
|
17
|
+
- `getLoggedInUser()` / `login()` → `CometChatUIKit.assertInitialized();`
|
|
18
|
+
- `logout()` / `createUser()` / `updateUser()` → `if (!this.checkAuthSettings()) return Promise.reject(this.authError());`
|
|
19
|
+
|
|
20
|
+
## Why it was necessary
|
|
21
|
+
|
|
22
|
+
The old `checkAuthSettings(onError)` took an error callback and returned a
|
|
23
|
+
boolean, and **every call site was using it incorrectly** — the guard either
|
|
24
|
+
did nothing or did the opposite of what was intended:
|
|
25
|
+
|
|
26
|
+
1. **No-op guards (`getLoggedInUser`, `login`)**
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
if (CometChatUIKit.checkAuthSettings(Promise.reject)) null;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`Promise.reject` was passed as the `onError` callback, but its return value
|
|
33
|
+
was discarded and the `if` body was just `null`. When settings were missing
|
|
34
|
+
the method continued anyway instead of stopping — so the guard provided **no
|
|
35
|
+
protection at all**.
|
|
36
|
+
|
|
37
|
+
2. **Inverted logic (`logout`)**
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
if (this.checkAuthSettings(Promise.reject)) {
|
|
41
|
+
return Promise.reject(/* not initialized */);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`checkAuthSettings` returned `true` when the UIKit **was** properly
|
|
46
|
+
configured. So this rejected with "UIKit not initialized" exactly when it
|
|
47
|
+
*was* initialized, and proceeded when it was not — **backwards**.
|
|
48
|
+
|
|
49
|
+
3. **Empty guards (`createUser`, `updateUser`)**
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
if (this.checkAuthSettings(Promise.reject)) {
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Empty body. The only effect was the `Promise.reject` callback firing as a
|
|
57
|
+
side effect, creating an unhandled rejection while the method continued.
|
|
58
|
+
|
|
59
|
+
The root cause was a function that mixed a **predicate** with **error
|
|
60
|
+
dispatch**, which made every call site ambiguous and easy to get wrong. After
|
|
61
|
+
the split:
|
|
62
|
+
|
|
63
|
+
- `checkAuthSettings()` reads as a plain question — `if (!checkAuthSettings())`
|
|
64
|
+
is unambiguous.
|
|
65
|
+
- Async methods `assertInitialized()` (throw → rejected promise).
|
|
66
|
+
- The exception text/codes live in one place (`authError()`), so the
|
|
67
|
+
"call `init()` first" message is consistent everywhere.
|
|
68
|
+
|
|
69
|
+
## Behavioral result
|
|
70
|
+
|
|
71
|
+
Every public entry point now **actually fails fast** with the correct
|
|
72
|
+
`CometChatException` when the UIKit has not been initialized, instead of
|
|
73
|
+
silently continuing or rejecting on the wrong condition.
|
|
74
|
+
|
|
75
|
+
The accompanying test file `__tests__/CometChatUIKit.test.ts` was updated to
|
|
76
|
+
cover these guards.
|
|
@@ -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.
|
|
@@ -159,6 +159,7 @@ export const MessageCategoryConstants = {
|
|
|
159
159
|
call: CometChat.CATEGORY_CALL,
|
|
160
160
|
interactive: CometChat.CATEGORY_INTERACTIVE,
|
|
161
161
|
agentic: CometChat.CATEGORY_AGENTIC,
|
|
162
|
+
card: CometChat.CATEGORY_CARD,
|
|
162
163
|
stream: "stream_message",
|
|
163
164
|
};
|
|
164
165
|
|
|
@@ -207,7 +208,10 @@ export const streamMessageTypes = {
|
|
|
207
208
|
tool_call_start: CometChat.AI_ASSISTANT_EVENTS.TOOL_CALL_STARTED,
|
|
208
209
|
tool_call_end: CometChat.AI_ASSISTANT_EVENTS.TOOL_CALL_ENDED,
|
|
209
210
|
tool_call_args: CometChat.AI_ASSISTANT_EVENTS.TOOL_CALL_ARGUMENT,
|
|
210
|
-
tool_call_result: CometChat.AI_ASSISTANT_EVENTS.TOOL_CALL_RESULT
|
|
211
|
+
tool_call_result: CometChat.AI_ASSISTANT_EVENTS.TOOL_CALL_RESULT,
|
|
212
|
+
card_start: CometChat.AI_ASSISTANT_EVENTS.CARD_START,
|
|
213
|
+
card: CometChat.AI_ASSISTANT_EVENTS.CARD,
|
|
214
|
+
card_end: CometChat.AI_ASSISTANT_EVENTS.CARD_END,
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
export const ReceiverTypeConstants = {
|
|
@@ -400,6 +400,11 @@ export class CometChatUIEventHandler {
|
|
|
400
400
|
param as { id: string; data: Array<SuggestionItem> }
|
|
401
401
|
);
|
|
402
402
|
break;
|
|
403
|
+
case listener._eventListener?.ccCardActionClicked?.name:
|
|
404
|
+
listener._eventListener?.ccCardActionClicked?.(
|
|
405
|
+
param as { message: any; action: any }
|
|
406
|
+
);
|
|
407
|
+
break;
|
|
403
408
|
}
|
|
404
409
|
});
|
|
405
410
|
}
|
|
@@ -234,6 +234,7 @@ type UIEvents = {
|
|
|
234
234
|
ccComposeMessage?: (item: any) => void;
|
|
235
235
|
// ccMentionClick?:(item)=>void,
|
|
236
236
|
ccSuggestionData?: (item: { id: string | number; data: Array<SuggestionItem> }) => void;
|
|
237
|
+
ccCardActionClicked?: (item: { message: any; action: any }) => void;
|
|
237
238
|
};
|
|
238
239
|
export class UIEventListener {
|
|
239
240
|
showPanel?: (item: any) => void;
|
|
@@ -243,6 +244,7 @@ export class UIEventListener {
|
|
|
243
244
|
ccComposeMessage?: (item: any) => void;
|
|
244
245
|
// ccMentionClick?:(item)=>void;
|
|
245
246
|
ccSuggestionData?: (item: { id: string | number; data: Array<SuggestionItem> }) => void;
|
|
247
|
+
ccCardActionClicked?: (item: { message: any; action: any }) => void;
|
|
246
248
|
constructor({
|
|
247
249
|
showPanel,
|
|
248
250
|
hidePanel,
|
|
@@ -251,6 +253,7 @@ export class UIEventListener {
|
|
|
251
253
|
ccComposeMessage,
|
|
252
254
|
// ccMentionClick,
|
|
253
255
|
ccSuggestionData,
|
|
256
|
+
ccCardActionClicked,
|
|
254
257
|
}: UIEvents) {
|
|
255
258
|
if (!isFalsy(hidePanel)) this.hidePanel = hidePanel;
|
|
256
259
|
if (!isFalsy(showPanel)) this.showPanel = showPanel;
|
|
@@ -259,6 +262,7 @@ export class UIEventListener {
|
|
|
259
262
|
if (!isFalsy(ccComposeMessage)) this.ccComposeMessage = ccComposeMessage;
|
|
260
263
|
// if (!isFalsy(ccMentionClick)) this.ccMentionClick = ccMentionClick;
|
|
261
264
|
if (!isFalsy(ccSuggestionData)) this.ccSuggestionData = ccSuggestionData;
|
|
265
|
+
if (!isFalsy(ccCardActionClicked)) this.ccCardActionClicked = ccCardActionClicked;
|
|
262
266
|
}
|
|
263
267
|
}
|
|
264
268
|
export class GroupUIEventListener {
|
|
@@ -97,6 +97,9 @@ export class ListenerInitializer {
|
|
|
97
97
|
},
|
|
98
98
|
onMessagesReadByAll: (messageReceipt: CometChat.MessageReceipt) => {
|
|
99
99
|
CometChatUIEventHandler.emitMessageEvent(MessageEvents.onMessagesReadByAll, messageReceipt);
|
|
100
|
+
},
|
|
101
|
+
onCardMessageReceived: (cardMessage: any) => {
|
|
102
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.onCardMessageReceived, cardMessage);
|
|
100
103
|
}
|
|
101
104
|
});
|
|
102
105
|
}
|
|
@@ -192,6 +192,16 @@ export interface DataSource {
|
|
|
192
192
|
theme: CometChatTheme,
|
|
193
193
|
additionalParams?: AdditionalParams
|
|
194
194
|
): CometChatMessageTemplate;
|
|
195
|
+
getCardBubbleTemplate(
|
|
196
|
+
theme: CometChatTheme,
|
|
197
|
+
additionalParams?: AdditionalParams
|
|
198
|
+
): CometChatMessageTemplate;
|
|
199
|
+
getCardBubbleContentView(
|
|
200
|
+
message: CometChat.BaseMessage,
|
|
201
|
+
alignment: MessageBubbleAlignmentType,
|
|
202
|
+
theme: CometChatTheme,
|
|
203
|
+
additionalParams?: AdditionalParams
|
|
204
|
+
): JSX.Element;
|
|
195
205
|
|
|
196
206
|
//attachment options
|
|
197
207
|
// getAttachmentOptions(theme: CometChatTheme, conversation: CometChat.User | CometChat.Group): Array<CometChatMessageComposerAction>
|
|
@@ -225,6 +225,19 @@ export class DataSourceDecorator implements DataSource {
|
|
|
225
225
|
return this.dataSource.getCardMessageTemplate(theme, additionalParams);
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
getCardBubbleTemplate(theme: CometChatTheme, additionalParams?: AdditionalParams): CometChatMessageTemplate {
|
|
229
|
+
return this.dataSource.getCardBubbleTemplate(theme, additionalParams);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
getCardBubbleContentView(
|
|
233
|
+
message: CometChat.BaseMessage,
|
|
234
|
+
alignment: MessageBubbleAlignmentType,
|
|
235
|
+
theme: CometChatTheme,
|
|
236
|
+
additionalParams?: AdditionalParams
|
|
237
|
+
): JSX.Element {
|
|
238
|
+
return this.dataSource.getCardBubbleContentView(message, alignment, theme, additionalParams);
|
|
239
|
+
}
|
|
240
|
+
|
|
228
241
|
getAudioMessageTemplate(theme: CometChatTheme, additionalParams?: AdditionalParams): CometChatMessageTemplate {
|
|
229
242
|
return this.dataSource.getAudioMessageTemplate(theme, additionalParams);
|
|
230
243
|
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
MessageCategoryConstants,
|
|
23
23
|
MessageOptionConstants,
|
|
24
24
|
MessageTypeConstants,
|
|
25
|
+
ReceiverTypeConstants,
|
|
25
26
|
} from "../constants/UIKitConstants";
|
|
26
27
|
import { CometChatUiKitConstants } from "../index";
|
|
27
28
|
import { CometChatMessageComposerAction } from "../helper/types";
|
|
@@ -38,6 +39,7 @@ import { CometChatTextBubble } from "../views/CometChatTextBubble";
|
|
|
38
39
|
import { CometChatVideoBubble } from "../views/CometChatVideoBubble";
|
|
39
40
|
import CometChatAIAssistantMessageBubble from '../views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble';
|
|
40
41
|
import CometChatStreamMessageBubble from '../views/CometChatStreamMessageBubble/CometChatStreamMessageBubble';
|
|
42
|
+
import { CometChatCardBubble } from "../views/CometChatCardBubble";
|
|
41
43
|
import { ChatConfigurator } from "./ChatConfigurator";
|
|
42
44
|
import { DataSource } from "./DataSource";
|
|
43
45
|
import { CommonUtils } from "../utils/CommonUtils";
|
|
@@ -130,12 +132,23 @@ export class MessageDataSource implements DataSource {
|
|
|
130
132
|
};
|
|
131
133
|
|
|
132
134
|
|
|
133
|
-
getAgentAssistantMessageTemplate(
|
|
135
|
+
getAgentAssistantMessageTemplate(
|
|
136
|
+
theme: CometChatTheme,
|
|
137
|
+
additionalParams?: AdditionalParams
|
|
138
|
+
): CometChatMessageTemplate {
|
|
134
139
|
return new CometChatMessageTemplate({
|
|
135
140
|
type: 'assistant',
|
|
136
141
|
category: 'agentic',
|
|
137
|
-
ContentView: (message: CometChat.BaseMessage) =>
|
|
142
|
+
ContentView: (message: CometChat.BaseMessage) =>
|
|
138
143
|
this.getAgentAssistantMessageBubble(message, theme),
|
|
144
|
+
ReplyView: (message: CometChat.BaseMessage, _alignment: MessageBubbleAlignmentType) => {
|
|
145
|
+
if (message.getReceiverType() !== ReceiverTypeConstants.group) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const replyView = ChatConfigurator.dataSource.getReplyView?.(message, theme, additionalParams) || null;
|
|
149
|
+
if (!replyView) return null;
|
|
150
|
+
return <View style={{ marginTop: 2, marginBottom: 6 }}>{replyView}</View>;
|
|
151
|
+
},
|
|
139
152
|
|
|
140
153
|
options: undefined,
|
|
141
154
|
|
|
@@ -1733,6 +1746,53 @@ export class MessageDataSource implements DataSource {
|
|
|
1733
1746
|
});
|
|
1734
1747
|
}
|
|
1735
1748
|
|
|
1749
|
+
// --- Developer card (category: "card") ----------------------------------
|
|
1750
|
+
getCardBubbleContentView(
|
|
1751
|
+
message: CometChat.BaseMessage,
|
|
1752
|
+
alignment: MessageBubbleAlignmentType,
|
|
1753
|
+
theme: CometChatTheme,
|
|
1754
|
+
additionalParams?: AdditionalParams
|
|
1755
|
+
): JSX.Element {
|
|
1756
|
+
return <CometChatCardBubble message={message} theme={theme} />;
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
getCardBubbleTemplate(
|
|
1760
|
+
theme: CometChatTheme,
|
|
1761
|
+
additionalParams?: AdditionalParams
|
|
1762
|
+
): CometChatMessageTemplate {
|
|
1763
|
+
return new CometChatMessageTemplate({
|
|
1764
|
+
// Sentinel type; developer card `type` is arbitrary and resolved on category alone.
|
|
1765
|
+
type: MessageTypeConstants.card,
|
|
1766
|
+
category: MessageCategoryConstants.card,
|
|
1767
|
+
ContentView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
|
|
1768
|
+
if (isDeletedMessage(message)) {
|
|
1769
|
+
return ChatConfigurator.dataSource.getDeleteMessageBubble(message, theme);
|
|
1770
|
+
}
|
|
1771
|
+
return ChatConfigurator.dataSource.getCardBubbleContentView(
|
|
1772
|
+
message,
|
|
1773
|
+
alignment,
|
|
1774
|
+
theme,
|
|
1775
|
+
additionalParams
|
|
1776
|
+
);
|
|
1777
|
+
},
|
|
1778
|
+
// Same option set as the text bubble, minus edit and copy.
|
|
1779
|
+
options: (loggedInuser, message, theme, group) =>
|
|
1780
|
+
ChatConfigurator.dataSource
|
|
1781
|
+
.getTextMessageOptions(loggedInuser, message, theme, group, additionalParams)
|
|
1782
|
+
.filter(
|
|
1783
|
+
(o: CometChatMessageOption) =>
|
|
1784
|
+
o.id !== MessageOptionConstants.editMessage &&
|
|
1785
|
+
o.id !== MessageOptionConstants.copyMessage
|
|
1786
|
+
),
|
|
1787
|
+
ReplyView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
|
|
1788
|
+
return ChatConfigurator.dataSource.getReplyView?.(message, theme, additionalParams) || null;
|
|
1789
|
+
},
|
|
1790
|
+
BottomView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
|
|
1791
|
+
return ChatConfigurator.dataSource.getBottomView(message, alignment);
|
|
1792
|
+
},
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1736
1796
|
getAllMessageTemplates(
|
|
1737
1797
|
theme: CometChatTheme,
|
|
1738
1798
|
additionalParams?: AdditionalParams
|
|
@@ -1748,6 +1808,7 @@ export class MessageDataSource implements DataSource {
|
|
|
1748
1808
|
ChatConfigurator.dataSource.getFormMessageTemplate(theme, additionalParams),
|
|
1749
1809
|
ChatConfigurator.dataSource.getSchedulerMessageTemplate(theme, additionalParams),
|
|
1750
1810
|
ChatConfigurator.dataSource.getCardMessageTemplate(theme, additionalParams),
|
|
1811
|
+
ChatConfigurator.dataSource.getCardBubbleTemplate(theme, additionalParams),
|
|
1751
1812
|
ChatConfigurator.dataSource.getAgentAssistantMessageTemplate(theme, additionalParams),
|
|
1752
1813
|
];
|
|
1753
1814
|
}
|
|
@@ -1764,6 +1825,11 @@ export class MessageDataSource implements DataSource {
|
|
|
1764
1825
|
//in case of call message return undefined
|
|
1765
1826
|
if (MessageCategory == MessageCategoryConstants.call) return null;
|
|
1766
1827
|
|
|
1828
|
+
// Developer card: resolve on category alone (developer `type` is arbitrary).
|
|
1829
|
+
if (MessageCategory == MessageCategoryConstants.card) {
|
|
1830
|
+
return ChatConfigurator.dataSource.getCardBubbleTemplate(theme, additionalParams);
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1767
1833
|
switch (messageType) {
|
|
1768
1834
|
case MessageTypeConstants.text:
|
|
1769
1835
|
template = ChatConfigurator.dataSource.getTextMessageTemplate(theme, additionalParams);
|
|
@@ -1819,7 +1885,8 @@ export class MessageDataSource implements DataSource {
|
|
|
1819
1885
|
MessageCategoryConstants.message,
|
|
1820
1886
|
MessageCategoryConstants.action,
|
|
1821
1887
|
MessageCategoryConstants.interactive,
|
|
1822
|
-
MessageCategoryConstants.agentic
|
|
1888
|
+
MessageCategoryConstants.agentic,
|
|
1889
|
+
MessageCategoryConstants.card
|
|
1823
1890
|
];
|
|
1824
1891
|
}
|
|
1825
1892
|
getAuxiliaryOptions(
|