@cometchat/chat-uikit-react-native 5.4.0 → 5.5.0
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/CometChatClipboardModule.kt +34 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +605 -6
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +20 -1
- package/ios/CometChatClipboardModule.m +5 -0
- package/ios/CometChatClipboardModule.swift +22 -0
- package/ios/RichTextEditorView.swift +648 -35
- package/ios/RichTextEditorViewManager.m +2 -0
- package/ios/RichTextEditorViewManager.swift +16 -0
- package/package.json +2 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +245 -55
- package/src/CometChatCompactMessageComposer/index.ts +2 -0
- package/src/CometChatConversations/CometChatConversations.tsx +291 -14
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
- package/src/CometChatMessageList/CometChatMessageList.tsx +568 -15
- package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +14 -1
- package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +940 -0
- package/src/CometChatPinnedMessages/index.ts +5 -0
- package/src/CometChatPinnedMessages/style.ts +216 -0
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +5 -0
- package/src/CometChatRichTextEditor/index.tsx +27 -1
- package/src/CometChatRichTextEditor/types.ts +19 -1
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +634 -0
- package/src/CometChatSavedMessages/index.ts +5 -0
- package/src/CometChatSavedMessages/style.ts +159 -0
- package/src/CometChatSearch/CometChatSearch.tsx +47 -340
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
- package/src/index.ts +60 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +16 -0
- package/src/shared/base/Types.ts +5 -0
- package/src/shared/constants/UIKitConstants.ts +13 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +34 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +37 -0
- package/src/shared/events/ListenerInitializer.ts +20 -1
- package/src/shared/events/messages.ts +18 -0
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +95 -8
- package/src/shared/formatters/index.ts +14 -0
- package/src/shared/formatters/richTextWireFormat.ts +165 -0
- package/src/shared/framework/MessageDataSource.tsx +296 -3
- package/src/shared/icons/components/thread-follow.tsx +13 -0
- package/src/shared/icons/components/thread-unfollow.tsx +13 -0
- package/src/shared/icons/components/unsave.tsx +13 -0
- package/src/shared/icons/icon-mapping.tsx +6 -0
- package/src/shared/index.ts +37 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +54 -0
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +2 -1
- package/src/shared/utils/MarkdownUtils.ts +25 -4
- package/src/shared/utils/MessageUtils.tsx +80 -5
- package/src/shared/utils/PinConversationHelper.ts +245 -0
- package/src/shared/utils/PinSaveFeatureGates.ts +178 -0
- package/src/shared/utils/PinSaveHelper.ts +549 -0
- package/src/shared/utils/SavedMessagesHelper.ts +231 -0
- package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
- package/src/shared/utils/conversationUtils.ts +8 -1
- package/src/shared/utils/elementType.tsx +38 -0
- package/src/shared/utils/stripRichText.ts +7 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +21 -0
- package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +28 -14
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
- package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +4 -0
- package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +1 -0
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +4 -0
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +4 -3
- package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
- package/src/theme/default/default.ts +6 -0
- package/src/theme/type.ts +4 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-owned gates for Pin Message, Save Message and Pin Conversation.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS IS IN THE KIT: these three are not integrator preferences, they are app settings —
|
|
5
|
+
* the server decides whether the plan has them and, for pin-conversation, whether ops has mapped
|
|
6
|
+
* the flag for that app at all. Until now the kit shipped the switches (PinSaveConfig,
|
|
7
|
+
* PinConversationConfig) but never asked the server, so every integrator had to know to do it
|
|
8
|
+
* themselves. The sample app did; nobody else would. The two failure modes both look like bugs:
|
|
9
|
+
* leave them off and the features silently never appear, or hardcode them on and the options
|
|
10
|
+
* render on an app whose flag is unmapped, where every tap toasts "this feature isn't available".
|
|
11
|
+
*
|
|
12
|
+
* The kit already owns exactly this kind of state for conversation update settings — fetched on
|
|
13
|
+
* login and re-fetched on every reconnection so a dashboard change lands without a restart. This
|
|
14
|
+
* follows that precedent rather than inventing a second pattern, and mirrors what the React UI Kit
|
|
15
|
+
* does in its own `pinSaveFeatures` module.
|
|
16
|
+
*
|
|
17
|
+
* Thread subscription is deliberately NOT here: no server flag exists for it in the SDK, so it
|
|
18
|
+
* stays a genuine integrator opt-in via ThreadSubscriptionConfig.
|
|
19
|
+
*
|
|
20
|
+
* @module PinSaveFeatureGates
|
|
21
|
+
*/
|
|
22
|
+
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
23
|
+
import { PinSaveConfig } from "./PinSaveHelper";
|
|
24
|
+
import { PinConversationConfig } from "./PinConversationHelper";
|
|
25
|
+
|
|
26
|
+
/** Resolved state of the three server flags. */
|
|
27
|
+
export interface PinSaveFeatureFlags {
|
|
28
|
+
pinMessage: boolean;
|
|
29
|
+
saveMessage: boolean;
|
|
30
|
+
pinConversation: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Everything off — the value before resolution completes, and after any failure.
|
|
35
|
+
*
|
|
36
|
+
* Off is the safe direction: a hidden option is a missing feature, a shown one the server refuses
|
|
37
|
+
* is a broken feature. Only the second generates support tickets.
|
|
38
|
+
*/
|
|
39
|
+
export const PIN_SAVE_FEATURES_DISABLED: PinSaveFeatureFlags = Object.freeze({
|
|
40
|
+
pinMessage: false,
|
|
41
|
+
saveMessage: false,
|
|
42
|
+
pinConversation: false,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
let cached: PinSaveFeatureFlags | null = null;
|
|
46
|
+
let inFlight: Promise<PinSaveFeatureFlags> | null = null;
|
|
47
|
+
/**
|
|
48
|
+
* Bumped by reset(). A resolution records the epoch it started under and only commits if that
|
|
49
|
+
* epoch is still current, so a logout→login fast enough to overlap an in-flight read cannot have
|
|
50
|
+
* the older result land last and apply the previous app's flags to the new session.
|
|
51
|
+
*/
|
|
52
|
+
let epoch = 0;
|
|
53
|
+
|
|
54
|
+
type FlagMethod =
|
|
55
|
+
| "isPinMessageEnabled"
|
|
56
|
+
| "isSaveMessageEnabled"
|
|
57
|
+
| "isPinConversationEnabled";
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Ask the SDK for one flag, treating every failure as "off".
|
|
61
|
+
*
|
|
62
|
+
* The typeof check is not defensive noise: these methods ship with the pin/save SDK, and a kit
|
|
63
|
+
* running against an older build would otherwise throw on a missing function rather than simply
|
|
64
|
+
* not offering the feature.
|
|
65
|
+
*/
|
|
66
|
+
const resolveFlag = async (name: FlagMethod): Promise<boolean> => {
|
|
67
|
+
const fn = (CometChat as unknown as Record<string, unknown>)[name];
|
|
68
|
+
if (typeof fn !== "function") return false;
|
|
69
|
+
try {
|
|
70
|
+
return !!(await (fn as () => Promise<boolean>).call(CometChat));
|
|
71
|
+
} catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** Push resolved flags into the switches the components actually read. */
|
|
77
|
+
const applyToConfigs = (flags: PinSaveFeatureFlags): void => {
|
|
78
|
+
PinSaveConfig.enablePin(flags.pinMessage);
|
|
79
|
+
PinSaveConfig.enableSave(flags.saveMessage);
|
|
80
|
+
PinConversationConfig.enable(flags.pinConversation);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Resolve all three flags and apply them, asking the SDK at most once per session.
|
|
85
|
+
*
|
|
86
|
+
* Concurrent callers share the in-flight promise — several components mounting at once resolve
|
|
87
|
+
* together rather than firing three reads each.
|
|
88
|
+
*/
|
|
89
|
+
export async function resolvePinSaveFeatures(): Promise<PinSaveFeatureFlags> {
|
|
90
|
+
if (cached) return cached;
|
|
91
|
+
if (inFlight) return inFlight;
|
|
92
|
+
|
|
93
|
+
const startedAt = epoch;
|
|
94
|
+
inFlight = Promise.all([
|
|
95
|
+
resolveFlag("isPinMessageEnabled"),
|
|
96
|
+
resolveFlag("isSaveMessageEnabled"),
|
|
97
|
+
resolveFlag("isPinConversationEnabled"),
|
|
98
|
+
])
|
|
99
|
+
.then(([pinMessage, saveMessage, pinConversation]) => {
|
|
100
|
+
const resolved: PinSaveFeatureFlags = { pinMessage, saveMessage, pinConversation };
|
|
101
|
+
if (startedAt === epoch) {
|
|
102
|
+
cached = resolved;
|
|
103
|
+
applyToConfigs(resolved);
|
|
104
|
+
}
|
|
105
|
+
return cached ?? resolved;
|
|
106
|
+
})
|
|
107
|
+
.catch(() => PIN_SAVE_FEATURES_DISABLED)
|
|
108
|
+
.finally(() => {
|
|
109
|
+
if (startedAt === epoch) inFlight = null;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return inFlight;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Re-read the flags mid-session, for a reconnection.
|
|
117
|
+
*
|
|
118
|
+
* Deliberately does NOT clear the applied values first. Clearing then re-reading would leave a
|
|
119
|
+
* window where the options vanish and come back, which looks like a glitch; the previous answer
|
|
120
|
+
* stays in force until a newer one actually arrives.
|
|
121
|
+
*/
|
|
122
|
+
/**
|
|
123
|
+
* Pull the app settings from the SERVER, replacing the SDK's cached copy.
|
|
124
|
+
*
|
|
125
|
+
* The SDK reads settings through a cache that is populated once and only re-fetched when it
|
|
126
|
+
* is empty, so everything derived from it — the three feature flags AND the pin/save caps —
|
|
127
|
+
* is frozen at whatever the app was configured with when this session logged in. The public
|
|
128
|
+
* `getAppSettings()` is the one call that goes to the network and writes that cache back.
|
|
129
|
+
*
|
|
130
|
+
* Guarded on the method existing: an older SDK build must degrade to the stale-but-working
|
|
131
|
+
* behaviour rather than throwing inside a reconnect handler.
|
|
132
|
+
*/
|
|
133
|
+
const refreshAppSettings = async (): Promise<void> => {
|
|
134
|
+
const fetchSettings = (CometChat as unknown as Record<string, unknown>).getAppSettings;
|
|
135
|
+
if (typeof fetchSettings !== "function") return;
|
|
136
|
+
try {
|
|
137
|
+
await (fetchSettings as () => Promise<unknown>).call(CometChat);
|
|
138
|
+
} catch {
|
|
139
|
+
// Offline, or the endpoint refused. The cached settings stay in place, which is exactly
|
|
140
|
+
// the behaviour this function is improving on — never worse than not having tried.
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Re-ask the server, discarding everything already known.
|
|
146
|
+
*
|
|
147
|
+
* Refreshes the app settings FIRST (ENG-38180). Without that this only re-read the SDK's
|
|
148
|
+
* cache and could never return a different answer than the last resolution — a flag or a cap
|
|
149
|
+
* changed in the dashboard reached the client only after a full logout and login.
|
|
150
|
+
*
|
|
151
|
+
* The caps ride along for free: `getPinMessageLimit()` / `getSaveMessageLimit()` read the
|
|
152
|
+
* same cache, so once it is refreshed the "you can only pin N messages" toast starts quoting
|
|
153
|
+
* the current N. That is why the limit is NOT refreshed on the error path itself — doing it
|
|
154
|
+
* here means the number is already correct by the time anything needs to print it, with no
|
|
155
|
+
* network round trip standing between the user's tap and the toast.
|
|
156
|
+
*/
|
|
157
|
+
export async function refreshPinSaveFeatures(): Promise<PinSaveFeatureFlags> {
|
|
158
|
+
await refreshAppSettings();
|
|
159
|
+
cached = null;
|
|
160
|
+
inFlight = null;
|
|
161
|
+
return resolvePinSaveFeatures();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Last resolved flags. Everything-off until the first resolution lands. */
|
|
165
|
+
export function getPinSaveFeatures(): PinSaveFeatureFlags {
|
|
166
|
+
return cached ?? PIN_SAVE_FEATURES_DISABLED;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Drop the cache and turn the switches off. Called on logout: flags are per-app, and the next
|
|
171
|
+
* login may be a different app entirely, so carrying them over would be worse than re-asking.
|
|
172
|
+
*/
|
|
173
|
+
export function resetPinSaveFeatures(): void {
|
|
174
|
+
cached = null;
|
|
175
|
+
inFlight = null;
|
|
176
|
+
epoch++;
|
|
177
|
+
applyToConfigs(PIN_SAVE_FEATURES_DISABLED);
|
|
178
|
+
}
|