feeddo-react-native 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +401 -2
- package/android/build.gradle +39 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/dev/feeddo/reactnative/FeeddoReactNativeModule.java +380 -0
- package/android/src/main/java/dev/feeddo/reactnative/FeeddoReactNativePackage.java +25 -0
- package/dist/Feeddo.d.ts +131 -0
- package/dist/Feeddo.d.ts.map +1 -0
- package/dist/Feeddo.js +176 -0
- package/dist/Feeddo.js.map +1 -0
- package/dist/FeeddoClient.d.ts +151 -0
- package/dist/FeeddoClient.d.ts.map +1 -0
- package/dist/FeeddoClient.js +690 -0
- package/dist/FeeddoClient.js.map +1 -0
- package/dist/FeeddoProvider.d.ts +23 -0
- package/dist/FeeddoProvider.d.ts.map +1 -0
- package/dist/FeeddoProvider.js +76 -0
- package/dist/FeeddoProvider.js.map +1 -0
- package/dist/config/FeeddoConfig.d.ts +10 -0
- package/dist/config/FeeddoConfig.d.ts.map +1 -0
- package/dist/config/FeeddoConfig.js +10 -0
- package/dist/config/FeeddoConfig.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/models/Conversation.d.ts +27 -0
- package/dist/models/Conversation.d.ts.map +1 -0
- package/dist/models/Conversation.js +24 -0
- package/dist/models/Conversation.js.map +1 -0
- package/dist/models/EndUser.d.ts +49 -0
- package/dist/models/EndUser.d.ts.map +1 -0
- package/dist/models/EndUser.js +2 -0
- package/dist/models/EndUser.js.map +1 -0
- package/dist/models/FeeddoNotification.d.ts +15 -0
- package/dist/models/FeeddoNotification.d.ts.map +1 -0
- package/dist/models/FeeddoNotification.js +15 -0
- package/dist/models/FeeddoNotification.js.map +1 -0
- package/dist/models/HomeData.d.ts +16 -0
- package/dist/models/HomeData.d.ts.map +1 -0
- package/dist/models/HomeData.js +19 -0
- package/dist/models/HomeData.js.map +1 -0
- package/dist/models/Message.d.ts +12 -0
- package/dist/models/Message.d.ts.map +1 -0
- package/dist/models/Message.js +25 -0
- package/dist/models/Message.js.map +1 -0
- package/dist/models/PushProvider.d.ts +14 -0
- package/dist/models/PushProvider.d.ts.map +1 -0
- package/dist/models/PushProvider.js +9 -0
- package/dist/models/PushProvider.js.map +1 -0
- package/dist/models/Task.d.ts +17 -0
- package/dist/models/Task.d.ts.map +1 -0
- package/dist/models/Task.js +22 -0
- package/dist/models/Task.js.map +1 -0
- package/dist/models/TaskComment.d.ts +11 -0
- package/dist/models/TaskComment.d.ts.map +1 -0
- package/dist/models/TaskComment.js +27 -0
- package/dist/models/TaskComment.js.map +1 -0
- package/dist/models/Ticket.d.ts +13 -0
- package/dist/models/Ticket.d.ts.map +1 -0
- package/dist/models/Ticket.js +14 -0
- package/dist/models/Ticket.js.map +1 -0
- package/dist/native/FeeddoNative.d.ts +58 -0
- package/dist/native/FeeddoNative.d.ts.map +1 -0
- package/dist/native/FeeddoNative.js +22 -0
- package/dist/native/FeeddoNative.js.map +1 -0
- package/dist/push/FeeddoPushNotificationApns.d.ts +73 -0
- package/dist/push/FeeddoPushNotificationApns.d.ts.map +1 -0
- package/dist/push/FeeddoPushNotificationApns.js +301 -0
- package/dist/push/FeeddoPushNotificationApns.js.map +1 -0
- package/dist/services/ApiService.d.ts +64 -0
- package/dist/services/ApiService.d.ts.map +1 -0
- package/dist/services/ApiService.js +406 -0
- package/dist/services/ApiService.js.map +1 -0
- package/dist/services/ConversationService.d.ts +45 -0
- package/dist/services/ConversationService.d.ts.map +1 -0
- package/dist/services/ConversationService.js +259 -0
- package/dist/services/ConversationService.js.map +1 -0
- package/dist/services/WebSocketService.d.ts +26 -0
- package/dist/services/WebSocketService.d.ts.map +1 -0
- package/dist/services/WebSocketService.js +157 -0
- package/dist/services/WebSocketService.js.map +1 -0
- package/dist/theme/FeeddoTheme.d.ts +31 -0
- package/dist/theme/FeeddoTheme.d.ts.map +1 -0
- package/dist/theme/FeeddoTheme.js +60 -0
- package/dist/theme/FeeddoTheme.js.map +1 -0
- package/dist/ui/FeeddoFeedbackCard.d.ts +15 -0
- package/dist/ui/FeeddoFeedbackCard.d.ts.map +1 -0
- package/dist/ui/FeeddoFeedbackCard.js +188 -0
- package/dist/ui/FeeddoFeedbackCard.js.map +1 -0
- package/dist/ui/FeeddoModal.d.ts +20 -0
- package/dist/ui/FeeddoModal.d.ts.map +1 -0
- package/dist/ui/FeeddoModal.js +180 -0
- package/dist/ui/FeeddoModal.js.map +1 -0
- package/dist/ui/components/AttachmentPreview.d.ts +10 -0
- package/dist/ui/components/AttachmentPreview.d.ts.map +1 -0
- package/dist/ui/components/AttachmentPreview.js +143 -0
- package/dist/ui/components/AttachmentPreview.js.map +1 -0
- package/dist/ui/components/ChatInputArea.d.ts +16 -0
- package/dist/ui/components/ChatInputArea.d.ts.map +1 -0
- package/dist/ui/components/ChatInputArea.js +85 -0
- package/dist/ui/components/ChatInputArea.js.map +1 -0
- package/dist/ui/components/FeeddoIcon.d.ts +10 -0
- package/dist/ui/components/FeeddoIcon.d.ts.map +1 -0
- package/dist/ui/components/FeeddoIcon.js +690 -0
- package/dist/ui/components/FeeddoIcon.js.map +1 -0
- package/dist/ui/components/FeeddoNotificationBadge.d.ts +14 -0
- package/dist/ui/components/FeeddoNotificationBadge.d.ts.map +1 -0
- package/dist/ui/components/FeeddoNotificationBadge.js +171 -0
- package/dist/ui/components/FeeddoNotificationBadge.js.map +1 -0
- package/dist/ui/components/MessageBubble.d.ts +13 -0
- package/dist/ui/components/MessageBubble.d.ts.map +1 -0
- package/dist/ui/components/MessageBubble.js +163 -0
- package/dist/ui/components/MessageBubble.js.map +1 -0
- package/dist/ui/components/NotificationsSheet.d.ts +10 -0
- package/dist/ui/components/NotificationsSheet.d.ts.map +1 -0
- package/dist/ui/components/NotificationsSheet.js +252 -0
- package/dist/ui/components/NotificationsSheet.js.map +1 -0
- package/dist/ui/components/RatingWidget.d.ts +11 -0
- package/dist/ui/components/RatingWidget.d.ts.map +1 -0
- package/dist/ui/components/RatingWidget.js +34 -0
- package/dist/ui/components/RatingWidget.js.map +1 -0
- package/dist/ui/components/TaskCard.d.ts +12 -0
- package/dist/ui/components/TaskCard.d.ts.map +1 -0
- package/dist/ui/components/TaskCard.js +210 -0
- package/dist/ui/components/TaskCard.js.map +1 -0
- package/dist/ui/components/TaskDetailsSheet.d.ts +15 -0
- package/dist/ui/components/TaskDetailsSheet.d.ts.map +1 -0
- package/dist/ui/components/TaskDetailsSheet.js +577 -0
- package/dist/ui/components/TaskDetailsSheet.js.map +1 -0
- package/dist/ui/components/TicketCard.d.ts +11 -0
- package/dist/ui/components/TicketCard.d.ts.map +1 -0
- package/dist/ui/components/TicketCard.js +100 -0
- package/dist/ui/components/TicketCard.js.map +1 -0
- package/dist/ui/components/TicketDetailsSheet.d.ts +14 -0
- package/dist/ui/components/TicketDetailsSheet.d.ts.map +1 -0
- package/dist/ui/components/TicketDetailsSheet.js +254 -0
- package/dist/ui/components/TicketDetailsSheet.js.map +1 -0
- package/dist/ui/components/TypingIndicator.d.ts +10 -0
- package/dist/ui/components/TypingIndicator.d.ts.map +1 -0
- package/dist/ui/components/TypingIndicator.js +77 -0
- package/dist/ui/components/TypingIndicator.js.map +1 -0
- package/dist/ui/screens/FeeddoChatScreen.d.ts +13 -0
- package/dist/ui/screens/FeeddoChatScreen.d.ts.map +1 -0
- package/dist/ui/screens/FeeddoChatScreen.js +681 -0
- package/dist/ui/screens/FeeddoChatScreen.js.map +1 -0
- package/dist/ui/screens/FeeddoHomeScreen.d.ts +15 -0
- package/dist/ui/screens/FeeddoHomeScreen.d.ts.map +1 -0
- package/dist/ui/screens/FeeddoHomeScreen.js +653 -0
- package/dist/ui/screens/FeeddoHomeScreen.js.map +1 -0
- package/dist/ui/screens/FeeddoMessagesScreen.d.ts +12 -0
- package/dist/ui/screens/FeeddoMessagesScreen.d.ts.map +1 -0
- package/dist/ui/screens/FeeddoMessagesScreen.js +326 -0
- package/dist/ui/screens/FeeddoMessagesScreen.js.map +1 -0
- package/dist/ui/screens/FeeddoTasksScreen.d.ts +13 -0
- package/dist/ui/screens/FeeddoTasksScreen.d.ts.map +1 -0
- package/dist/ui/screens/FeeddoTasksScreen.js +517 -0
- package/dist/ui/screens/FeeddoTasksScreen.js.map +1 -0
- package/dist/ui/screens/FeeddoTicketsScreen.d.ts +10 -0
- package/dist/ui/screens/FeeddoTicketsScreen.d.ts.map +1 -0
- package/dist/ui/screens/FeeddoTicketsScreen.js +112 -0
- package/dist/ui/screens/FeeddoTicketsScreen.js.map +1 -0
- package/dist/utils/DeviceInfoHelper.d.ts +29 -0
- package/dist/utils/DeviceInfoHelper.d.ts.map +1 -0
- package/dist/utils/DeviceInfoHelper.js +190 -0
- package/dist/utils/DeviceInfoHelper.js.map +1 -0
- package/dist/utils/MediaHelper.d.ts +20 -0
- package/dist/utils/MediaHelper.d.ts.map +1 -0
- package/dist/utils/MediaHelper.js +92 -0
- package/dist/utils/MediaHelper.js.map +1 -0
- package/dist/utils/NotificationSupport.d.ts +22 -0
- package/dist/utils/NotificationSupport.d.ts.map +1 -0
- package/dist/utils/NotificationSupport.js +211 -0
- package/dist/utils/NotificationSupport.js.map +1 -0
- package/dist/utils/StorageHelper.d.ts +65 -0
- package/dist/utils/StorageHelper.d.ts.map +1 -0
- package/dist/utils/StorageHelper.js +273 -0
- package/dist/utils/StorageHelper.js.map +1 -0
- package/feeddo-react-native.podspec +26 -0
- package/ios/FeeddoReactNativeModule.h +8 -0
- package/ios/FeeddoReactNativeModule.m +831 -0
- package/package.json +56 -4
- package/src/Feeddo.ts +247 -0
- package/src/FeeddoClient.ts +895 -0
- package/src/FeeddoProvider.tsx +139 -0
- package/src/config/FeeddoConfig.ts +9 -0
- package/src/index.ts +67 -0
- package/src/models/Conversation.ts +50 -0
- package/src/models/EndUser.ts +65 -0
- package/src/models/FeeddoNotification.ts +29 -0
- package/src/models/HomeData.ts +33 -0
- package/src/models/Message.ts +36 -0
- package/src/models/PushProvider.ts +15 -0
- package/src/models/Task.ts +40 -0
- package/src/models/TaskComment.ts +36 -0
- package/src/models/Ticket.ts +25 -0
- package/src/native/FeeddoNative.ts +80 -0
- package/src/push/FeeddoPushNotificationApns.ts +362 -0
- package/src/services/ApiService.ts +456 -0
- package/src/services/ConversationService.ts +305 -0
- package/src/services/WebSocketService.ts +185 -0
- package/src/theme/FeeddoTheme.ts +85 -0
- package/src/ui/FeeddoFeedbackCard.tsx +245 -0
- package/src/ui/FeeddoModal.tsx +309 -0
- package/src/ui/components/AttachmentPreview.tsx +192 -0
- package/src/ui/components/ChatInputArea.tsx +154 -0
- package/src/ui/components/FeeddoIcon.tsx +903 -0
- package/src/ui/components/FeeddoNotificationBadge.tsx +234 -0
- package/src/ui/components/MessageBubble.tsx +223 -0
- package/src/ui/components/NotificationsSheet.tsx +324 -0
- package/src/ui/components/RatingWidget.tsx +64 -0
- package/src/ui/components/TaskCard.tsx +259 -0
- package/src/ui/components/TaskDetailsSheet.tsx +747 -0
- package/src/ui/components/TicketCard.tsx +128 -0
- package/src/ui/components/TicketDetailsSheet.tsx +324 -0
- package/src/ui/components/TypingIndicator.tsx +104 -0
- package/src/ui/screens/FeeddoChatScreen.tsx +877 -0
- package/src/ui/screens/FeeddoHomeScreen.tsx +824 -0
- package/src/ui/screens/FeeddoMessagesScreen.tsx +414 -0
- package/src/ui/screens/FeeddoTasksScreen.tsx +671 -0
- package/src/ui/screens/FeeddoTicketsScreen.tsx +164 -0
- package/src/utils/DeviceInfoHelper.ts +209 -0
- package/src/utils/MediaHelper.ts +105 -0
- package/src/utils/NotificationSupport.ts +233 -0
- package/src/utils/StorageHelper.ts +305 -0
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { ApiService } from './services/ApiService';
|
|
3
|
+
import { WebSocketService } from './services/WebSocketService';
|
|
4
|
+
import { ConversationService } from './services/ConversationService';
|
|
5
|
+
import { FeeddoConfig } from './config/FeeddoConfig';
|
|
6
|
+
import { FeeddoTheme } from './theme/FeeddoTheme';
|
|
7
|
+
import { parseConversation } from './models/Conversation';
|
|
8
|
+
import { StorageHelper } from './utils/StorageHelper';
|
|
9
|
+
import { DeviceInfoHelper } from './utils/DeviceInfoHelper';
|
|
10
|
+
import { getFeeddoNativeModule } from './native/FeeddoNative';
|
|
11
|
+
import { NotificationDeduplicator, buildNotificationDedupKey, intValue, isConversationNotification, isTaskNotification, normalizeNotificationPayload, stringValue, } from './utils/NotificationSupport';
|
|
12
|
+
export class FeeddoInternal {
|
|
13
|
+
constructor(apiKey) {
|
|
14
|
+
this._cachedUserId = null;
|
|
15
|
+
this._chatBotName = 'Feeddo';
|
|
16
|
+
this._recentConversation = null;
|
|
17
|
+
this._isInAppNotificationOn = true;
|
|
18
|
+
this._notificationTheme = FeeddoTheme.dark();
|
|
19
|
+
this._notificationDuration = 10000;
|
|
20
|
+
this.initLock = null;
|
|
21
|
+
this.notificationListeners = new Set();
|
|
22
|
+
this.notificationDeduplicator = new NotificationDeduplicator();
|
|
23
|
+
this.apiService = new ApiService(FeeddoConfig.apiUrl, apiKey);
|
|
24
|
+
this.webSocketService = new WebSocketService(this.apiService.apiUrl, this.apiService.apiKey);
|
|
25
|
+
this.conversationService = new ConversationService(this.apiService, this.webSocketService);
|
|
26
|
+
this.unsubscribeWsNotifications = this.webSocketService.subscribe(this.handleWebSocketNotification.bind(this));
|
|
27
|
+
this.unsubscribeConvUnread = this.conversationService.onUnreadCountChange((count) => {
|
|
28
|
+
FeeddoInternal.notifyUnreadListeners(count);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
static get instance() {
|
|
32
|
+
if (!this._instance) {
|
|
33
|
+
throw new Error('Feeddo not initialized. Call Feeddo.init() first.');
|
|
34
|
+
}
|
|
35
|
+
return this._instance;
|
|
36
|
+
}
|
|
37
|
+
static get isInitialized() {
|
|
38
|
+
return Boolean(this._instance && this._instance.apiService.apiKey);
|
|
39
|
+
}
|
|
40
|
+
static notifyUnreadListeners(count) {
|
|
41
|
+
this.unreadListeners.forEach((l) => {
|
|
42
|
+
try {
|
|
43
|
+
l(count);
|
|
44
|
+
}
|
|
45
|
+
catch (_) { }
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
static addUnreadCountListener(listener) {
|
|
49
|
+
this.unreadListeners.add(listener);
|
|
50
|
+
if (this._instance) {
|
|
51
|
+
try {
|
|
52
|
+
listener(this._instance.conversationService.unreadMessageCount);
|
|
53
|
+
}
|
|
54
|
+
catch (_) { }
|
|
55
|
+
}
|
|
56
|
+
return () => {
|
|
57
|
+
this.unreadListeners.delete(listener);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
get userId() {
|
|
61
|
+
return this._cachedUserId;
|
|
62
|
+
}
|
|
63
|
+
get chatBotName() {
|
|
64
|
+
return this._chatBotName;
|
|
65
|
+
}
|
|
66
|
+
get recentConversation() {
|
|
67
|
+
return this._recentConversation;
|
|
68
|
+
}
|
|
69
|
+
get isInAppNotificationOn() {
|
|
70
|
+
return this._isInAppNotificationOn;
|
|
71
|
+
}
|
|
72
|
+
get notificationTheme() {
|
|
73
|
+
return this._notificationTheme;
|
|
74
|
+
}
|
|
75
|
+
get notificationDuration() {
|
|
76
|
+
return this._notificationDuration;
|
|
77
|
+
}
|
|
78
|
+
subscribeNotifications(listener) {
|
|
79
|
+
this.notificationListeners.add(listener);
|
|
80
|
+
return () => {
|
|
81
|
+
this.notificationListeners.delete(listener);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
static onModalStateChange(listener) {
|
|
85
|
+
this.modalStateListeners.add(listener);
|
|
86
|
+
listener(this.currentModalState);
|
|
87
|
+
return () => {
|
|
88
|
+
this.modalStateListeners.delete(listener);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
onModalStateChange(listener) {
|
|
92
|
+
return FeeddoInternal.onModalStateChange(listener);
|
|
93
|
+
}
|
|
94
|
+
static onInAppNotification(listener) {
|
|
95
|
+
this.inAppNotificationListeners.add(listener);
|
|
96
|
+
if (this.pendingBanners.length > 0) {
|
|
97
|
+
const queued = [...this.pendingBanners];
|
|
98
|
+
this.pendingBanners = [];
|
|
99
|
+
for (const banner of queued) {
|
|
100
|
+
try {
|
|
101
|
+
listener(banner);
|
|
102
|
+
}
|
|
103
|
+
catch (_) { }
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return () => {
|
|
107
|
+
this.inAppNotificationListeners.delete(listener);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
onInAppNotification(listener) {
|
|
111
|
+
return FeeddoInternal.onInAppNotification(listener);
|
|
112
|
+
}
|
|
113
|
+
static onClearNotifications(listener) {
|
|
114
|
+
this.clearNotificationsListeners.add(listener);
|
|
115
|
+
return () => {
|
|
116
|
+
this.clearNotificationsListeners.delete(listener);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
static setModalState(state) {
|
|
120
|
+
const nextNavId = state.visible === true
|
|
121
|
+
? ++this.modalNavigationCounter
|
|
122
|
+
: this.currentModalState.navigationId;
|
|
123
|
+
this.currentModalState = {
|
|
124
|
+
...this.currentModalState,
|
|
125
|
+
...state,
|
|
126
|
+
navigationId: nextNavId,
|
|
127
|
+
};
|
|
128
|
+
this.modalStateListeners.forEach((l) => {
|
|
129
|
+
try {
|
|
130
|
+
l(this.currentModalState);
|
|
131
|
+
}
|
|
132
|
+
catch (_) { }
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
setModalState(state) {
|
|
136
|
+
FeeddoInternal.setModalState(state);
|
|
137
|
+
}
|
|
138
|
+
static showInAppNotificationBanner(state) {
|
|
139
|
+
if (this.inAppNotificationListeners.size === 0) {
|
|
140
|
+
this.pendingBanners.push(state);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
this.inAppNotificationListeners.forEach((l) => {
|
|
144
|
+
try {
|
|
145
|
+
l(state);
|
|
146
|
+
}
|
|
147
|
+
catch (_) { }
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
showInAppNotificationBanner(state) {
|
|
151
|
+
FeeddoInternal.showInAppNotificationBanner(state);
|
|
152
|
+
}
|
|
153
|
+
static clearAllNotifications() {
|
|
154
|
+
this.pendingBanners = [];
|
|
155
|
+
this.clearNotificationsListeners.forEach((l) => {
|
|
156
|
+
try {
|
|
157
|
+
l();
|
|
158
|
+
}
|
|
159
|
+
catch (_) { }
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
static async init(options) {
|
|
163
|
+
if (options.storageAdapter) {
|
|
164
|
+
StorageHelper.setStorageAdapter(options.storageAdapter);
|
|
165
|
+
}
|
|
166
|
+
await StorageHelper.recordFirstAppOpenAt();
|
|
167
|
+
await DeviceInfoHelper.loadDeviceInfo().catch(() => { });
|
|
168
|
+
if (!this._instance || this._instance.apiService.apiKey !== options.apiKey) {
|
|
169
|
+
if (this._instance) {
|
|
170
|
+
this._instance.cleanupResources();
|
|
171
|
+
}
|
|
172
|
+
this._instance = new FeeddoInternal(options.apiKey);
|
|
173
|
+
}
|
|
174
|
+
const inst = this._instance;
|
|
175
|
+
inst._isInAppNotificationOn = options.isInAppNotificationOn ?? true;
|
|
176
|
+
inst._notificationTheme = options.theme ?? FeeddoTheme.dark();
|
|
177
|
+
if (options.notificationDuration !== undefined) {
|
|
178
|
+
inst._notificationDuration = options.notificationDuration;
|
|
179
|
+
}
|
|
180
|
+
// Check if user identity or attributes changed
|
|
181
|
+
const existingExtId = await StorageHelper.getExternalUserId();
|
|
182
|
+
const existingName = await StorageHelper.getUserName();
|
|
183
|
+
const existingEmail = await StorageHelper.getEmail();
|
|
184
|
+
const existingPush = await StorageHelper.getPendingPushToken();
|
|
185
|
+
const hasChanges = (options.externalUserId !== undefined && options.externalUserId !== existingExtId) ||
|
|
186
|
+
(options.userName !== undefined && options.userName !== existingName) ||
|
|
187
|
+
(options.email !== undefined && options.email !== existingEmail) ||
|
|
188
|
+
(options.pushToken !== undefined && options.pushToken !== existingPush);
|
|
189
|
+
if (hasChanges) {
|
|
190
|
+
await StorageHelper.setSyncedWithBackend(false);
|
|
191
|
+
}
|
|
192
|
+
// Save locally
|
|
193
|
+
await StorageHelper.saveUserData({
|
|
194
|
+
externalUserId: options.externalUserId,
|
|
195
|
+
userName: options.userName,
|
|
196
|
+
email: options.email,
|
|
197
|
+
userSegment: options.userSegment,
|
|
198
|
+
subscriptionStatus: options.subscriptionStatus,
|
|
199
|
+
customAttributes: options.customAttributes,
|
|
200
|
+
});
|
|
201
|
+
if (options.pushToken) {
|
|
202
|
+
await StorageHelper.savePendingPushToken(options.pushToken, options.pushProvider);
|
|
203
|
+
if (Platform.OS === 'android') {
|
|
204
|
+
getFeeddoNativeModule()
|
|
205
|
+
?.createNotificationChannel('feeddo_notifications_channel', 'Feeddo Notifications', 'Feeddo notifications for support messages and community updates')
|
|
206
|
+
.catch(() => { });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const localUserId = await StorageHelper.getOrCreateLocalUserId();
|
|
210
|
+
inst._cachedUserId = localUserId;
|
|
211
|
+
inst.webSocketService.setUserId(localUserId);
|
|
212
|
+
// Setup real-time notification listener for WebSocket chat messages
|
|
213
|
+
if (inst._isInAppNotificationOn) {
|
|
214
|
+
inst.setupNotificationListener();
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
inst.conversationService.onNewMessage = undefined;
|
|
218
|
+
}
|
|
219
|
+
const pendingTap = this.pendingNotificationTap;
|
|
220
|
+
this.pendingNotificationTap = null;
|
|
221
|
+
// Check for unread notifications if active conversation exists (3s timeout matching Flutter)
|
|
222
|
+
let recentConv;
|
|
223
|
+
const hasActiveConv = await StorageHelper.hasActiveConversation();
|
|
224
|
+
if (hasActiveConv && inst._isInAppNotificationOn) {
|
|
225
|
+
try {
|
|
226
|
+
const unreadData = await inst.apiService.getUnreadData(localUserId, 3000);
|
|
227
|
+
if (unreadData) {
|
|
228
|
+
await StorageHelper.setHasActiveConversation(unreadData.hasActiveConversation);
|
|
229
|
+
if (unreadData.recentConversation) {
|
|
230
|
+
recentConv = unreadData.recentConversation;
|
|
231
|
+
inst._recentConversation = recentConv;
|
|
232
|
+
inst.conversationService.updateConversation(recentConv);
|
|
233
|
+
if (recentConv.unreadMessages > 0 && !pendingTap) {
|
|
234
|
+
inst.showInAppNotificationBanner({
|
|
235
|
+
visible: true,
|
|
236
|
+
title: recentConv.displayName || inst.chatBotName,
|
|
237
|
+
body: recentConv.lastMessagePreview || '',
|
|
238
|
+
timestamp: recentConv.lastMessageAt,
|
|
239
|
+
theme: inst._notificationTheme,
|
|
240
|
+
duration: inst._notificationDuration,
|
|
241
|
+
onTap: () => {
|
|
242
|
+
inst.setModalState({
|
|
243
|
+
visible: true,
|
|
244
|
+
initialScreen: 'chat',
|
|
245
|
+
initialConversation: recentConv,
|
|
246
|
+
theme: inst._notificationTheme,
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (unreadData.unreadMessageCount > inst.conversationService.unreadMessageCount) {
|
|
253
|
+
inst.conversationService.setTotalUnreadCount(unreadData.unreadMessageCount);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch (_) { }
|
|
258
|
+
}
|
|
259
|
+
if (pendingTap) {
|
|
260
|
+
await inst.handleNotificationTap(pendingTap.data, pendingTap.theme).catch(() => { });
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
userId: localUserId,
|
|
264
|
+
recentConversation: recentConv,
|
|
265
|
+
hasUnreadMessages: Boolean(recentConv && recentConv.unreadMessages > 0),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
async ensureUserInitialized() {
|
|
269
|
+
if (this.initLock) {
|
|
270
|
+
return await this.initLock;
|
|
271
|
+
}
|
|
272
|
+
this.initLock = this.performUserSync();
|
|
273
|
+
try {
|
|
274
|
+
const id = await this.initLock;
|
|
275
|
+
return id;
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
this.initLock = null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async performUserSync() {
|
|
282
|
+
const isSynced = await StorageHelper.isSyncedWithBackend();
|
|
283
|
+
if (!this._cachedUserId) {
|
|
284
|
+
this._cachedUserId = await StorageHelper.getUserId();
|
|
285
|
+
}
|
|
286
|
+
if (isSynced && this._cachedUserId && this._cachedUserId.length > 0) {
|
|
287
|
+
this.webSocketService.setUserId(this._cachedUserId);
|
|
288
|
+
return this._cachedUserId;
|
|
289
|
+
}
|
|
290
|
+
const id = await this.upsertUser();
|
|
291
|
+
this.webSocketService.setUserId(id);
|
|
292
|
+
return id;
|
|
293
|
+
}
|
|
294
|
+
async upsertUser(params) {
|
|
295
|
+
if (!this._cachedUserId) {
|
|
296
|
+
this._cachedUserId = await StorageHelper.getUserId();
|
|
297
|
+
}
|
|
298
|
+
const externalUserId = params?.externalUserId ?? (await StorageHelper.getExternalUserId()) ?? undefined;
|
|
299
|
+
const userName = params?.userName ?? (await StorageHelper.getUserName()) ?? undefined;
|
|
300
|
+
const email = params?.email ?? (await StorageHelper.getEmail()) ?? undefined;
|
|
301
|
+
const userSegment = params?.userSegment ?? (await StorageHelper.getUserSegment()) ?? undefined;
|
|
302
|
+
const subscriptionStatus = params?.subscriptionStatus ?? (await StorageHelper.getSubscriptionStatus()) ?? undefined;
|
|
303
|
+
const customAttributes = params?.customAttributes ?? (await StorageHelper.getCustomAttributes()) ?? undefined;
|
|
304
|
+
let pushToken = params?.pushToken;
|
|
305
|
+
let pushProvider = params?.pushProvider;
|
|
306
|
+
if (!pushToken) {
|
|
307
|
+
pushToken = (await StorageHelper.getPendingPushToken()) ?? undefined;
|
|
308
|
+
const prov = await StorageHelper.getPendingPushProvider();
|
|
309
|
+
if (prov)
|
|
310
|
+
pushProvider = prov;
|
|
311
|
+
}
|
|
312
|
+
const firstSeenAt = (await StorageHelper.getFirstAppOpenAt()) ?? undefined;
|
|
313
|
+
const deviceInfo = await DeviceInfoHelper.loadDeviceInfo();
|
|
314
|
+
const endUser = {
|
|
315
|
+
userId: this._cachedUserId ?? undefined,
|
|
316
|
+
externalUserId,
|
|
317
|
+
userName,
|
|
318
|
+
email,
|
|
319
|
+
platform: deviceInfo.platform,
|
|
320
|
+
deviceModel: deviceInfo.deviceModel,
|
|
321
|
+
osVersion: deviceInfo.osVersion,
|
|
322
|
+
appVersion: deviceInfo.appVersion,
|
|
323
|
+
userSegment,
|
|
324
|
+
subscriptionStatus,
|
|
325
|
+
customAttributes,
|
|
326
|
+
pushToken,
|
|
327
|
+
pushProvider,
|
|
328
|
+
firstSeenAt,
|
|
329
|
+
};
|
|
330
|
+
const res = await this.apiService.upsertEndUser(endUser);
|
|
331
|
+
this._cachedUserId = res.userId;
|
|
332
|
+
if (res.recentConversation) {
|
|
333
|
+
try {
|
|
334
|
+
this._recentConversation = parseConversation(res.recentConversation);
|
|
335
|
+
this.conversationService.updateConversation(this._recentConversation);
|
|
336
|
+
if (this._recentConversation.status !== 'resolved') {
|
|
337
|
+
await StorageHelper.setHasActiveConversation(true);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
catch (_) { }
|
|
341
|
+
}
|
|
342
|
+
await StorageHelper.saveUserId(res.userId);
|
|
343
|
+
await StorageHelper.saveUserData({
|
|
344
|
+
externalUserId: externalUserId ?? res.externalUserId,
|
|
345
|
+
userName,
|
|
346
|
+
email,
|
|
347
|
+
userSegment,
|
|
348
|
+
subscriptionStatus,
|
|
349
|
+
customAttributes,
|
|
350
|
+
});
|
|
351
|
+
await StorageHelper.setSyncedWithBackend(true);
|
|
352
|
+
return res.userId;
|
|
353
|
+
}
|
|
354
|
+
async updateUser(data) {
|
|
355
|
+
await StorageHelper.saveUserData(data);
|
|
356
|
+
if (data.pushToken) {
|
|
357
|
+
await StorageHelper.savePendingPushToken(data.pushToken, data.pushProvider);
|
|
358
|
+
}
|
|
359
|
+
const isSynced = await StorageHelper.isSyncedWithBackend();
|
|
360
|
+
if (isSynced) {
|
|
361
|
+
return await this.upsertUser(data);
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
if (!this._cachedUserId) {
|
|
365
|
+
this._cachedUserId = await StorageHelper.getOrCreateLocalUserId();
|
|
366
|
+
}
|
|
367
|
+
return this._cachedUserId;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
async registerPushToken(pushToken, pushProvider) {
|
|
371
|
+
await StorageHelper.savePendingPushToken(pushToken, pushProvider);
|
|
372
|
+
if (Platform.OS === 'android') {
|
|
373
|
+
getFeeddoNativeModule()
|
|
374
|
+
?.createNotificationChannel('feeddo_notifications_channel', 'Feeddo Notifications', 'Feeddo notifications for support messages and community updates')
|
|
375
|
+
.catch(() => { });
|
|
376
|
+
}
|
|
377
|
+
const isSynced = await StorageHelper.isSyncedWithBackend();
|
|
378
|
+
if (isSynced) {
|
|
379
|
+
try {
|
|
380
|
+
await this.upsertUser({ pushToken, pushProvider });
|
|
381
|
+
}
|
|
382
|
+
catch (e) {
|
|
383
|
+
console.warn('Feeddo: Failed to register push token:', e);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
setupNotificationListener() {
|
|
388
|
+
this.conversationService.onNewMessage = (conversation) => {
|
|
389
|
+
if (this.conversationService.activeConversationId === conversation.id) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (!this._isInAppNotificationOn || conversation.unreadMessages === 0) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
const dedupKey = buildNotificationDedupKey({
|
|
396
|
+
type: 'chat_message',
|
|
397
|
+
conversationId: conversation.id,
|
|
398
|
+
body: conversation.lastMessagePreview,
|
|
399
|
+
}, conversation.lastMessagePreview);
|
|
400
|
+
if (dedupKey && !this.notificationDeduplicator.markIfNew(dedupKey)) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
this.showInAppNotificationBanner({
|
|
404
|
+
visible: true,
|
|
405
|
+
title: conversation.displayName || this.chatBotName,
|
|
406
|
+
body: conversation.lastMessagePreview || '',
|
|
407
|
+
timestamp: conversation.lastMessageAt,
|
|
408
|
+
data: { type: 'chat_message', conversationId: conversation.id },
|
|
409
|
+
theme: this._notificationTheme,
|
|
410
|
+
duration: this._notificationDuration,
|
|
411
|
+
onTap: () => {
|
|
412
|
+
this.setModalState({
|
|
413
|
+
visible: true,
|
|
414
|
+
initialScreen: 'chat',
|
|
415
|
+
initialConversation: conversation,
|
|
416
|
+
theme: this._notificationTheme,
|
|
417
|
+
});
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
handleWebSocketNotification(data) {
|
|
423
|
+
if (data.type !== 'notification')
|
|
424
|
+
return;
|
|
425
|
+
this.notificationListeners.forEach((l) => {
|
|
426
|
+
try {
|
|
427
|
+
l(data);
|
|
428
|
+
}
|
|
429
|
+
catch (_) { }
|
|
430
|
+
});
|
|
431
|
+
if (!this._isInAppNotificationOn)
|
|
432
|
+
return;
|
|
433
|
+
const title = stringValue(data.title) || this.chatBotName;
|
|
434
|
+
const body = stringValue(data.body) || '';
|
|
435
|
+
const payloadData = data.data && typeof data.data === 'object' ? data.data : undefined;
|
|
436
|
+
this.showInAppNotification({
|
|
437
|
+
title,
|
|
438
|
+
message: body,
|
|
439
|
+
data: payloadData,
|
|
440
|
+
theme: this._notificationTheme,
|
|
441
|
+
duration: this._notificationDuration,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
showInAppNotification(options) {
|
|
445
|
+
const normalized = options.data ? normalizeNotificationPayload(options.data) : undefined;
|
|
446
|
+
const convId = normalized ? stringValue(normalized.conversationId) : undefined;
|
|
447
|
+
const type = normalized ? stringValue(normalized.type) : undefined;
|
|
448
|
+
if (convId && (!type || type === 'chat_message' || type === 'new_message')) {
|
|
449
|
+
const activeId = this.conversationService.activeConversationId;
|
|
450
|
+
if (activeId && activeId === convId) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (normalized) {
|
|
455
|
+
const dedupKey = buildNotificationDedupKey(normalized, options.message);
|
|
456
|
+
if (dedupKey && !this.notificationDeduplicator.markIfNew(dedupKey)) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
this.showInAppNotificationBanner({
|
|
461
|
+
visible: true,
|
|
462
|
+
title: options.title,
|
|
463
|
+
body: options.message,
|
|
464
|
+
timestamp: Date.now(),
|
|
465
|
+
data: normalized ?? options.data,
|
|
466
|
+
theme: options.theme ?? this._notificationTheme,
|
|
467
|
+
duration: options.duration ?? this._notificationDuration,
|
|
468
|
+
onTap: () => {
|
|
469
|
+
if (normalized ?? options.data) {
|
|
470
|
+
this.handleNotificationTap(normalized ?? options.data, options.theme);
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
handleForegroundNotification(rawData, options) {
|
|
476
|
+
try {
|
|
477
|
+
const normalized = normalizeNotificationPayload(rawData);
|
|
478
|
+
const convId = stringValue(normalized.conversationId);
|
|
479
|
+
const type = stringValue(normalized.type);
|
|
480
|
+
const activeId = this.conversationService.activeConversationId;
|
|
481
|
+
const isViewingActiveChat = Boolean(convId &&
|
|
482
|
+
activeId === convId &&
|
|
483
|
+
(!type || type === 'chat_message' || type === 'new_message'));
|
|
484
|
+
const notifTitle = stringValue(options?.title) ?? stringValue(normalized.title) ?? this.chatBotName;
|
|
485
|
+
const notifBody = stringValue(options?.message) ?? stringValue(normalized.body) ?? '';
|
|
486
|
+
const dedupKey = buildNotificationDedupKey(normalized, notifBody);
|
|
487
|
+
const isDuplicate = dedupKey ? !this.notificationDeduplicator.markIfNew(dedupKey) : false;
|
|
488
|
+
if (!isDuplicate && !isViewingActiveChat) {
|
|
489
|
+
if (convId && (!type || type === 'chat_message' || type === 'new_message')) {
|
|
490
|
+
this.conversationService.incrementUnreadCount(convId);
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
const badge = intValue(normalized.badge);
|
|
494
|
+
if (badge !== undefined) {
|
|
495
|
+
this.conversationService.setTotalUnreadCount(badge);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (isViewingActiveChat || isDuplicate || !this._isInAppNotificationOn) {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
this.showInAppNotificationBanner({
|
|
503
|
+
visible: true,
|
|
504
|
+
title: notifTitle,
|
|
505
|
+
body: notifBody,
|
|
506
|
+
timestamp: Date.now(),
|
|
507
|
+
data: normalized,
|
|
508
|
+
theme: options?.theme ?? this._notificationTheme,
|
|
509
|
+
duration: this._notificationDuration,
|
|
510
|
+
onTap: () => {
|
|
511
|
+
this.handleNotificationTap(normalized, options?.theme);
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
catch (e) {
|
|
516
|
+
console.warn('Feeddo: Error handling foreground notification:', e);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
static queueOrHandleNotificationTap(data, theme) {
|
|
520
|
+
if (!this.isInitialized) {
|
|
521
|
+
this.pendingNotificationTap = { data, theme };
|
|
522
|
+
return Promise.resolve();
|
|
523
|
+
}
|
|
524
|
+
return this.instance.handleNotificationTap(data, theme);
|
|
525
|
+
}
|
|
526
|
+
async handleNotificationTap(rawData, theme) {
|
|
527
|
+
const normalized = normalizeNotificationPayload(rawData);
|
|
528
|
+
try {
|
|
529
|
+
await this.ensureUserInitialized();
|
|
530
|
+
}
|
|
531
|
+
catch (e) {
|
|
532
|
+
console.warn('Feeddo: Failed to sync user before notification tap:', e);
|
|
533
|
+
}
|
|
534
|
+
const type = stringValue(normalized.type);
|
|
535
|
+
const effectiveTheme = theme ?? this._notificationTheme;
|
|
536
|
+
if (isTaskNotification(type, normalized)) {
|
|
537
|
+
const taskId = stringValue(normalized.taskId);
|
|
538
|
+
if (taskId) {
|
|
539
|
+
this.setModalState({
|
|
540
|
+
visible: true,
|
|
541
|
+
initialScreen: 'tasks',
|
|
542
|
+
initialTaskId: taskId,
|
|
543
|
+
theme: effectiveTheme,
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
this.setModalState({
|
|
548
|
+
visible: true,
|
|
549
|
+
initialScreen: 'tasks',
|
|
550
|
+
initialTaskId: undefined,
|
|
551
|
+
theme: effectiveTheme,
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
else if (isConversationNotification(type, normalized)) {
|
|
556
|
+
const conversationId = stringValue(normalized.conversationId);
|
|
557
|
+
if (conversationId) {
|
|
558
|
+
if (this.conversationService.activeConversationId === conversationId) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
try {
|
|
562
|
+
const conv = await this.apiService.getConversation(conversationId);
|
|
563
|
+
this.setModalState({
|
|
564
|
+
visible: true,
|
|
565
|
+
initialScreen: 'chat',
|
|
566
|
+
initialConversation: conv,
|
|
567
|
+
initialTaskId: undefined,
|
|
568
|
+
theme: effectiveTheme,
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
catch (e) {
|
|
572
|
+
console.warn('Feeddo: Failed to load conversation:', e);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
this.setModalState({
|
|
577
|
+
visible: true,
|
|
578
|
+
initialScreen: 'home',
|
|
579
|
+
initialTaskId: undefined,
|
|
580
|
+
theme: effectiveTheme,
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
async getHomeData() {
|
|
586
|
+
await this.ensureUserInitialized();
|
|
587
|
+
if (!this.userId) {
|
|
588
|
+
throw new Error('User not identified');
|
|
589
|
+
}
|
|
590
|
+
const homeData = await this.apiService.getHomeData(this.userId);
|
|
591
|
+
if (homeData.chatbotName) {
|
|
592
|
+
this._chatBotName = homeData.chatbotName;
|
|
593
|
+
}
|
|
594
|
+
if (homeData.recentConversation && homeData.recentConversation.status !== 'resolved') {
|
|
595
|
+
await StorageHelper.setHasActiveConversation(true);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
await StorageHelper.setHasActiveConversation(false);
|
|
599
|
+
}
|
|
600
|
+
return homeData;
|
|
601
|
+
}
|
|
602
|
+
static async getConversations(userId) {
|
|
603
|
+
const inst = FeeddoInternal.instance;
|
|
604
|
+
await inst.ensureUserInitialized();
|
|
605
|
+
const targetUserId = userId ?? inst.userId;
|
|
606
|
+
if (!targetUserId)
|
|
607
|
+
throw new Error('User not identified');
|
|
608
|
+
await inst.conversationService.loadConversations(targetUserId);
|
|
609
|
+
return inst.conversationService.conversations;
|
|
610
|
+
}
|
|
611
|
+
static async createConversation(options) {
|
|
612
|
+
const inst = FeeddoInternal.instance;
|
|
613
|
+
await inst.ensureUserInitialized();
|
|
614
|
+
if (!inst.userId)
|
|
615
|
+
throw new Error('User not identified');
|
|
616
|
+
const conv = await inst.conversationService.createConversation(inst.userId, options?.agentName ?? 'support_agent');
|
|
617
|
+
await StorageHelper.setHasActiveConversation(true);
|
|
618
|
+
return conv;
|
|
619
|
+
}
|
|
620
|
+
async getTickets() {
|
|
621
|
+
await this.ensureUserInitialized();
|
|
622
|
+
if (!this.userId)
|
|
623
|
+
throw new Error('User not identified');
|
|
624
|
+
return await this.apiService.getTickets(this.userId);
|
|
625
|
+
}
|
|
626
|
+
async getTicket(ticketId) {
|
|
627
|
+
await this.ensureUserInitialized();
|
|
628
|
+
return await this.apiService.getTicket(ticketId, this.userId ?? undefined);
|
|
629
|
+
}
|
|
630
|
+
async addTaskComment(taskId, content, options) {
|
|
631
|
+
await this.ensureUserInitialized();
|
|
632
|
+
return await this.apiService.addTaskComment(taskId, content, {
|
|
633
|
+
userId: this.userId ?? undefined,
|
|
634
|
+
attachments: options?.attachments,
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
async voteTask(taskId, voteType) {
|
|
638
|
+
await this.ensureUserInitialized();
|
|
639
|
+
return await this.apiService.voteTask(taskId, voteType, {
|
|
640
|
+
userId: this.userId ?? undefined,
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
async connectWebSocket(conversationId) {
|
|
644
|
+
const id = await this.ensureUserInitialized();
|
|
645
|
+
this.webSocketService.setUserId(id);
|
|
646
|
+
await this.webSocketService.connect(id, conversationId);
|
|
647
|
+
}
|
|
648
|
+
disconnectWebSocket() {
|
|
649
|
+
this.webSocketService.disconnect();
|
|
650
|
+
}
|
|
651
|
+
cleanupResources() {
|
|
652
|
+
this.conversationService.onNewMessage = undefined;
|
|
653
|
+
this.unsubscribeWsNotifications?.();
|
|
654
|
+
this.unsubscribeConvUnread?.();
|
|
655
|
+
this.notificationListeners.clear();
|
|
656
|
+
this.notificationDeduplicator.clear();
|
|
657
|
+
this.disconnectWebSocket();
|
|
658
|
+
this.webSocketService.dispose();
|
|
659
|
+
this.conversationService.dispose();
|
|
660
|
+
}
|
|
661
|
+
static dispose() {
|
|
662
|
+
if (this._instance) {
|
|
663
|
+
this._instance.cleanupResources();
|
|
664
|
+
this._instance = null;
|
|
665
|
+
}
|
|
666
|
+
this.pendingNotificationTap = null;
|
|
667
|
+
this.clearAllNotifications();
|
|
668
|
+
this.setModalState({
|
|
669
|
+
visible: false,
|
|
670
|
+
initialScreen: 'home',
|
|
671
|
+
initialConversation: null,
|
|
672
|
+
initialChatMessage: undefined,
|
|
673
|
+
initialTaskId: undefined,
|
|
674
|
+
});
|
|
675
|
+
this.notifyUnreadListeners(0);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
FeeddoInternal._instance = null;
|
|
679
|
+
FeeddoInternal.unreadListeners = new Set();
|
|
680
|
+
FeeddoInternal.modalStateListeners = new Set();
|
|
681
|
+
FeeddoInternal.inAppNotificationListeners = new Set();
|
|
682
|
+
FeeddoInternal.clearNotificationsListeners = new Set();
|
|
683
|
+
FeeddoInternal.pendingBanners = [];
|
|
684
|
+
FeeddoInternal.pendingNotificationTap = null;
|
|
685
|
+
FeeddoInternal.currentModalState = {
|
|
686
|
+
visible: false,
|
|
687
|
+
initialScreen: 'home',
|
|
688
|
+
};
|
|
689
|
+
FeeddoInternal.modalNavigationCounter = 0;
|
|
690
|
+
//# sourceMappingURL=FeeddoClient.js.map
|