@antzsoft/chat-core 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -38
- package/dist/chat.store-DLNRJ5ZT.js +7 -0
- package/dist/{chunk-P7VAN6NA.js → chunk-6NMA64BX.js} +71 -11
- package/dist/chunk-6NMA64BX.js.map +1 -0
- package/dist/{chunk-GUO5QQGK.js → chunk-EOL5B7GS.js} +4 -2
- package/dist/chunk-EOL5B7GS.js.map +1 -0
- package/dist/index.cjs +207 -101
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +137 -94
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +68 -8
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/dist/{storage-2unXhGDN.d.cts → storage-Bp6fk9aM.d.cts} +79 -4
- package/dist/{storage-2unXhGDN.d.ts → storage-Bp6fk9aM.d.ts} +79 -4
- package/docs/integration-guide.html +504 -31
- package/package.json +1 -1
- package/dist/chat.store-JC6QYDDL.js +0 -7
- package/dist/chunk-GUO5QQGK.js.map +0 -1
- package/dist/chunk-P7VAN6NA.js.map +0 -1
- /package/dist/{chat.store-JC6QYDDL.js.map → chat.store-DLNRJ5ZT.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as Attachment,
|
|
1
|
+
import { Y as ResolvedCompressionConfig, o as LoginCredentials, c as AuthResponse, W as RegisterData, d as AuthTokens, a7 as User, a as AppConfig, a0 as SendMessagePayload, l as CursorPaginatedResponse, M as Message, P as PaginatedResponse, x as MessageReceiptsResponse, i as ConversationListParams, h as Conversation, H as Participant, k as ConversationUnreadCount, a3 as UnreadSummary, a8 as UserPreferences, Z as ResolvedConfig, I as PersistStorage, R as PresignedUrlRequest, S as PresignedUrlResponse, F as FileResponse, C as CompletedPart, n as FileType, A as AntzChatConfig, a6 as UploadableFile, B as BatchUploadResult } from './storage-Bp6fk9aM.cjs';
|
|
2
|
+
export { b as Attachment, e as CompressedFile, f as CompressionAlgorithm, g as CompressionConfig, j as ConversationType, m as FileSizeLimits, L as LastReaction, p as MessageAckEvent, q as MessageContent, r as MessageDeletedEvent, s as MessageDeletedForMeEvent, t as MessageDeliveredEvent, u as MessageMetadata, v as MessageReaction, w as MessageReceiptEntry, y as MessageReplyReference, z as MessageUpdatedEvent, D as MessagesDeliveredEvent, E as MultipartPartUrl, G as MultipartUploadInfo, N as NewMessageEvent, O as OptimisticAttachment, J as PlatformCompressFn, K as PlatformUploadFn, Q as PlatformUploadPartFn, T as QuietHours, U as ReactionUpdatedEvent, V as ReadReceiptEvent, X as ReplyAttachmentSnapshot, _ as ResolvedFileSizeLimits, $ as SendMessageAttachment, a1 as SystemMessageMetadata, a2 as TypingIndicatorEvent, a4 as UploadConfig, a5 as UploadProgress, a9 as UserStatusEvent, aa as resolveConfig, ab as storageApi, ac as uploadBatch } from './storage-Bp6fk9aM.cjs';
|
|
3
3
|
import { AxiosInstance } from 'axios';
|
|
4
4
|
import { Socket } from 'socket.io-client';
|
|
5
5
|
import * as zustand_middleware from 'zustand/middleware';
|
|
@@ -72,6 +72,7 @@ declare const messagesApi: {
|
|
|
72
72
|
pin(messageId: string): Promise<Message>;
|
|
73
73
|
unpin(messageId: string): Promise<Message>;
|
|
74
74
|
getPinned(conversationId: string): Promise<Message[]>;
|
|
75
|
+
getReceipts(messageId: string): Promise<MessageReceiptsResponse>;
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
declare function normalizeConversation(conv: any): Conversation;
|
|
@@ -397,6 +398,8 @@ interface ChatState {
|
|
|
397
398
|
isSidebarOpen: boolean;
|
|
398
399
|
isGroupInfoOpen: boolean;
|
|
399
400
|
isStarredPanelOpen: boolean;
|
|
401
|
+
/** messageId currently shown in the Message Info panel, null = closed */
|
|
402
|
+
messageInfoId: string | null;
|
|
400
403
|
setActiveConversation: (id: string | null) => void;
|
|
401
404
|
setPendingTarget: (target: {
|
|
402
405
|
conversationId: string;
|
|
@@ -417,9 +420,23 @@ interface ChatState {
|
|
|
417
420
|
setGroupInfoOpen: (open: boolean) => void;
|
|
418
421
|
toggleStarredPanel: () => void;
|
|
419
422
|
setStarredPanelOpen: (open: boolean) => void;
|
|
423
|
+
setMessageInfoId: (id: string | null) => void;
|
|
420
424
|
}
|
|
421
425
|
declare const useChatStore: zustand.UseBoundStore<zustand.StoreApi<ChatState>>;
|
|
422
426
|
|
|
427
|
+
/**
|
|
428
|
+
* Resolves viewer-aware display text for system messages.
|
|
429
|
+
*
|
|
430
|
+
* The server stores a neutral third-person text in content.text (used for push
|
|
431
|
+
* notifications and exports) and structured actor/target fields in metadata.
|
|
432
|
+
* This function uses those fields plus the current viewer's userId to produce
|
|
433
|
+
* the correct first-person variant ("You removed Ajay", "Anil removed you", etc.).
|
|
434
|
+
*
|
|
435
|
+
* Backward compatible: if the server does not send actorUserId (old server), the
|
|
436
|
+
* raw content.text is returned unchanged so old behaviour is preserved.
|
|
437
|
+
*/
|
|
438
|
+
declare function resolveSystemMessageText(message: Message, currentUserId: string): string;
|
|
439
|
+
|
|
423
440
|
interface ClientSocketHandle {
|
|
424
441
|
emit: typeof socketEmit;
|
|
425
442
|
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
@@ -476,6 +493,7 @@ declare class AntzChatClient {
|
|
|
476
493
|
pin(messageId: string): Promise<Message>;
|
|
477
494
|
unpin(messageId: string): Promise<Message>;
|
|
478
495
|
getPinned(conversationId: string): Promise<Message[]>;
|
|
496
|
+
getReceipts(messageId: string): Promise<MessageReceiptsResponse>;
|
|
479
497
|
};
|
|
480
498
|
readonly conversations: {
|
|
481
499
|
list(params?: ConversationListParams): Promise<PaginatedResponse<Conversation>>;
|
|
@@ -515,6 +533,7 @@ declare class AntzChatClient {
|
|
|
515
533
|
expiresAt: string;
|
|
516
534
|
}>;
|
|
517
535
|
deleteFile(fileId: string): Promise<void>;
|
|
536
|
+
completeMultipartUpload(fileId: string, uploadId: string, parts: CompletedPart[]): Promise<FileResponse>;
|
|
518
537
|
getConversationFiles(conversationId: string, params?: {
|
|
519
538
|
page?: number;
|
|
520
539
|
limit?: number;
|
|
@@ -547,4 +566,4 @@ declare class AntzChatClient {
|
|
|
547
566
|
uploadIcon(conversationId: string, file: UploadableFile): Promise<Conversation>;
|
|
548
567
|
}
|
|
549
568
|
|
|
550
|
-
export { AntzChatClient, AntzChatConfig, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, Conversation, ConversationListParams, ConversationUnreadCount, type CreateDirectData, type CreateGroupData, CursorPaginatedResponse, FileResponse, FileType, type LastReadEntry, type ListMessagesParams, LoginCredentials, Message, type MobileDeviceToken, PaginatedResponse, Participant, PersistStorage, PresignedUrlRequest, PresignedUrlResponse, RegisterData, type RegisterDeviceTokenPayload, ResolvedCompressionConfig, ResolvedConfig, type SearchParams, type SendData, SendMessagePayload, type SocketStatus, type StatusListener, type TokenStore, UnreadSummary, type UpdateConversationData, type UpdateProfilePayload, UploadableFile, User, UserPreferences, type WebPushDeviceToken, appConfigApi, authApi, connectSocket, conversationsApi, createAuthStore, devicesApi, disconnectSocket, getApiClient, getAuthStore, getCompressionStrategy, getSocket, getSocketStatus, initApiClient, initAuthStore, messagesApi, normalizeConversation, onSocketStatus, reconnectSocket, refreshSocketAuth, resetAuthStore, setApiClientInstance, setTransitSession, socketEmit, tryGetSocket, useChatStore, usersApi };
|
|
569
|
+
export { AntzChatClient, AntzChatConfig, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, CompletedPart, Conversation, ConversationListParams, ConversationUnreadCount, type CreateDirectData, type CreateGroupData, CursorPaginatedResponse, FileResponse, FileType, type LastReadEntry, type ListMessagesParams, LoginCredentials, Message, MessageReceiptsResponse, type MobileDeviceToken, PaginatedResponse, Participant, PersistStorage, PresignedUrlRequest, PresignedUrlResponse, RegisterData, type RegisterDeviceTokenPayload, ResolvedCompressionConfig, ResolvedConfig, type SearchParams, type SendData, SendMessagePayload, type SocketStatus, type StatusListener, type TokenStore, UnreadSummary, type UpdateConversationData, type UpdateProfilePayload, UploadableFile, User, UserPreferences, type WebPushDeviceToken, appConfigApi, authApi, connectSocket, conversationsApi, createAuthStore, devicesApi, disconnectSocket, getApiClient, getAuthStore, getCompressionStrategy, getSocket, getSocketStatus, initApiClient, initAuthStore, messagesApi, normalizeConversation, onSocketStatus, reconnectSocket, refreshSocketAuth, resetAuthStore, resolveSystemMessageText, setApiClientInstance, setTransitSession, socketEmit, tryGetSocket, useChatStore, usersApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as Attachment,
|
|
1
|
+
import { Y as ResolvedCompressionConfig, o as LoginCredentials, c as AuthResponse, W as RegisterData, d as AuthTokens, a7 as User, a as AppConfig, a0 as SendMessagePayload, l as CursorPaginatedResponse, M as Message, P as PaginatedResponse, x as MessageReceiptsResponse, i as ConversationListParams, h as Conversation, H as Participant, k as ConversationUnreadCount, a3 as UnreadSummary, a8 as UserPreferences, Z as ResolvedConfig, I as PersistStorage, R as PresignedUrlRequest, S as PresignedUrlResponse, F as FileResponse, C as CompletedPart, n as FileType, A as AntzChatConfig, a6 as UploadableFile, B as BatchUploadResult } from './storage-Bp6fk9aM.js';
|
|
2
|
+
export { b as Attachment, e as CompressedFile, f as CompressionAlgorithm, g as CompressionConfig, j as ConversationType, m as FileSizeLimits, L as LastReaction, p as MessageAckEvent, q as MessageContent, r as MessageDeletedEvent, s as MessageDeletedForMeEvent, t as MessageDeliveredEvent, u as MessageMetadata, v as MessageReaction, w as MessageReceiptEntry, y as MessageReplyReference, z as MessageUpdatedEvent, D as MessagesDeliveredEvent, E as MultipartPartUrl, G as MultipartUploadInfo, N as NewMessageEvent, O as OptimisticAttachment, J as PlatformCompressFn, K as PlatformUploadFn, Q as PlatformUploadPartFn, T as QuietHours, U as ReactionUpdatedEvent, V as ReadReceiptEvent, X as ReplyAttachmentSnapshot, _ as ResolvedFileSizeLimits, $ as SendMessageAttachment, a1 as SystemMessageMetadata, a2 as TypingIndicatorEvent, a4 as UploadConfig, a5 as UploadProgress, a9 as UserStatusEvent, aa as resolveConfig, ab as storageApi, ac as uploadBatch } from './storage-Bp6fk9aM.js';
|
|
3
3
|
import { AxiosInstance } from 'axios';
|
|
4
4
|
import { Socket } from 'socket.io-client';
|
|
5
5
|
import * as zustand_middleware from 'zustand/middleware';
|
|
@@ -72,6 +72,7 @@ declare const messagesApi: {
|
|
|
72
72
|
pin(messageId: string): Promise<Message>;
|
|
73
73
|
unpin(messageId: string): Promise<Message>;
|
|
74
74
|
getPinned(conversationId: string): Promise<Message[]>;
|
|
75
|
+
getReceipts(messageId: string): Promise<MessageReceiptsResponse>;
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
declare function normalizeConversation(conv: any): Conversation;
|
|
@@ -397,6 +398,8 @@ interface ChatState {
|
|
|
397
398
|
isSidebarOpen: boolean;
|
|
398
399
|
isGroupInfoOpen: boolean;
|
|
399
400
|
isStarredPanelOpen: boolean;
|
|
401
|
+
/** messageId currently shown in the Message Info panel, null = closed */
|
|
402
|
+
messageInfoId: string | null;
|
|
400
403
|
setActiveConversation: (id: string | null) => void;
|
|
401
404
|
setPendingTarget: (target: {
|
|
402
405
|
conversationId: string;
|
|
@@ -417,9 +420,23 @@ interface ChatState {
|
|
|
417
420
|
setGroupInfoOpen: (open: boolean) => void;
|
|
418
421
|
toggleStarredPanel: () => void;
|
|
419
422
|
setStarredPanelOpen: (open: boolean) => void;
|
|
423
|
+
setMessageInfoId: (id: string | null) => void;
|
|
420
424
|
}
|
|
421
425
|
declare const useChatStore: zustand.UseBoundStore<zustand.StoreApi<ChatState>>;
|
|
422
426
|
|
|
427
|
+
/**
|
|
428
|
+
* Resolves viewer-aware display text for system messages.
|
|
429
|
+
*
|
|
430
|
+
* The server stores a neutral third-person text in content.text (used for push
|
|
431
|
+
* notifications and exports) and structured actor/target fields in metadata.
|
|
432
|
+
* This function uses those fields plus the current viewer's userId to produce
|
|
433
|
+
* the correct first-person variant ("You removed Ajay", "Anil removed you", etc.).
|
|
434
|
+
*
|
|
435
|
+
* Backward compatible: if the server does not send actorUserId (old server), the
|
|
436
|
+
* raw content.text is returned unchanged so old behaviour is preserved.
|
|
437
|
+
*/
|
|
438
|
+
declare function resolveSystemMessageText(message: Message, currentUserId: string): string;
|
|
439
|
+
|
|
423
440
|
interface ClientSocketHandle {
|
|
424
441
|
emit: typeof socketEmit;
|
|
425
442
|
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
@@ -476,6 +493,7 @@ declare class AntzChatClient {
|
|
|
476
493
|
pin(messageId: string): Promise<Message>;
|
|
477
494
|
unpin(messageId: string): Promise<Message>;
|
|
478
495
|
getPinned(conversationId: string): Promise<Message[]>;
|
|
496
|
+
getReceipts(messageId: string): Promise<MessageReceiptsResponse>;
|
|
479
497
|
};
|
|
480
498
|
readonly conversations: {
|
|
481
499
|
list(params?: ConversationListParams): Promise<PaginatedResponse<Conversation>>;
|
|
@@ -515,6 +533,7 @@ declare class AntzChatClient {
|
|
|
515
533
|
expiresAt: string;
|
|
516
534
|
}>;
|
|
517
535
|
deleteFile(fileId: string): Promise<void>;
|
|
536
|
+
completeMultipartUpload(fileId: string, uploadId: string, parts: CompletedPart[]): Promise<FileResponse>;
|
|
518
537
|
getConversationFiles(conversationId: string, params?: {
|
|
519
538
|
page?: number;
|
|
520
539
|
limit?: number;
|
|
@@ -547,4 +566,4 @@ declare class AntzChatClient {
|
|
|
547
566
|
uploadIcon(conversationId: string, file: UploadableFile): Promise<Conversation>;
|
|
548
567
|
}
|
|
549
568
|
|
|
550
|
-
export { AntzChatClient, AntzChatConfig, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, Conversation, ConversationListParams, ConversationUnreadCount, type CreateDirectData, type CreateGroupData, CursorPaginatedResponse, FileResponse, FileType, type LastReadEntry, type ListMessagesParams, LoginCredentials, Message, type MobileDeviceToken, PaginatedResponse, Participant, PersistStorage, PresignedUrlRequest, PresignedUrlResponse, RegisterData, type RegisterDeviceTokenPayload, ResolvedCompressionConfig, ResolvedConfig, type SearchParams, type SendData, SendMessagePayload, type SocketStatus, type StatusListener, type TokenStore, UnreadSummary, type UpdateConversationData, type UpdateProfilePayload, UploadableFile, User, UserPreferences, type WebPushDeviceToken, appConfigApi, authApi, connectSocket, conversationsApi, createAuthStore, devicesApi, disconnectSocket, getApiClient, getAuthStore, getCompressionStrategy, getSocket, getSocketStatus, initApiClient, initAuthStore, messagesApi, normalizeConversation, onSocketStatus, reconnectSocket, refreshSocketAuth, resetAuthStore, setApiClientInstance, setTransitSession, socketEmit, tryGetSocket, useChatStore, usersApi };
|
|
569
|
+
export { AntzChatClient, AntzChatConfig, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, CompletedPart, Conversation, ConversationListParams, ConversationUnreadCount, type CreateDirectData, type CreateGroupData, CursorPaginatedResponse, FileResponse, FileType, type LastReadEntry, type ListMessagesParams, LoginCredentials, Message, MessageReceiptsResponse, type MobileDeviceToken, PaginatedResponse, Participant, PersistStorage, PresignedUrlRequest, PresignedUrlResponse, RegisterData, type RegisterDeviceTokenPayload, ResolvedCompressionConfig, ResolvedConfig, type SearchParams, type SendData, SendMessagePayload, type SocketStatus, type StatusListener, type TokenStore, UnreadSummary, type UpdateConversationData, type UpdateProfilePayload, UploadableFile, User, UserPreferences, type WebPushDeviceToken, appConfigApi, authApi, connectSocket, conversationsApi, createAuthStore, devicesApi, disconnectSocket, getApiClient, getAuthStore, getCompressionStrategy, getSocket, getSocketStatus, initApiClient, initAuthStore, messagesApi, normalizeConversation, onSocketStatus, reconnectSocket, refreshSocketAuth, resetAuthStore, resolveSystemMessageText, setApiClientInstance, setTransitSession, socketEmit, tryGetSocket, useChatStore, usersApi };
|
package/dist/index.js
CHANGED
|
@@ -13,10 +13,10 @@ import {
|
|
|
13
13
|
setTransitSession,
|
|
14
14
|
storageApi,
|
|
15
15
|
uploadBatch
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-6NMA64BX.js";
|
|
17
17
|
import {
|
|
18
18
|
useChatStore
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-EOL5B7GS.js";
|
|
20
20
|
|
|
21
21
|
// src/config/types.ts
|
|
22
22
|
function resolveConfig(config) {
|
|
@@ -63,6 +63,7 @@ function resolveConfig(config) {
|
|
|
63
63
|
onProgress: config.upload?.onProgress
|
|
64
64
|
},
|
|
65
65
|
platformUploadFn: config.platformUploadFn,
|
|
66
|
+
platformUploadPartFn: config.platformUploadPartFn,
|
|
66
67
|
platformCompressFn: config.platformCompressFn,
|
|
67
68
|
compression: {
|
|
68
69
|
enabled: config.compression?.enabled ?? config.platformCompressFn != null,
|
|
@@ -128,6 +129,123 @@ var appConfigApi = {
|
|
|
128
129
|
}
|
|
129
130
|
};
|
|
130
131
|
|
|
132
|
+
// src/stores/auth.store.ts
|
|
133
|
+
import { create } from "zustand";
|
|
134
|
+
import { persist } from "zustand/middleware";
|
|
135
|
+
function createAuthStore(storage) {
|
|
136
|
+
if (!storage) throw new Error("[AntzChat] createAuthStore requires a valid PersistStorage \u2014 received undefined. Make sure the SDK config is fully resolved before initializing the store.");
|
|
137
|
+
const ref = { store: null };
|
|
138
|
+
const store = create()(
|
|
139
|
+
persist(
|
|
140
|
+
(set) => ({
|
|
141
|
+
user: null,
|
|
142
|
+
tokens: null,
|
|
143
|
+
isAuthenticated: false,
|
|
144
|
+
isLoading: false,
|
|
145
|
+
isHydrated: false,
|
|
146
|
+
setAuth: (user, tokens) => set({ user, tokens, isAuthenticated: true, isLoading: false }),
|
|
147
|
+
setTokens: (tokens) => set({ tokens }),
|
|
148
|
+
setUser: (user) => set({ user }),
|
|
149
|
+
logout: () => set({ user: null, tokens: null, isAuthenticated: false, isLoading: false }),
|
|
150
|
+
setLoading: (isLoading) => set({ isLoading }),
|
|
151
|
+
setHydrated: (isHydrated) => set({ isHydrated })
|
|
152
|
+
}),
|
|
153
|
+
{
|
|
154
|
+
name: "antz-chat-auth",
|
|
155
|
+
storage: {
|
|
156
|
+
getItem: (name) => {
|
|
157
|
+
const result = storage.getItem(name);
|
|
158
|
+
if (result instanceof Promise) {
|
|
159
|
+
return result.then((str) => str ? JSON.parse(str) : null);
|
|
160
|
+
}
|
|
161
|
+
return result ? JSON.parse(result) : null;
|
|
162
|
+
},
|
|
163
|
+
setItem: (name, value) => {
|
|
164
|
+
storage.setItem(name, JSON.stringify(value));
|
|
165
|
+
},
|
|
166
|
+
removeItem: (name) => storage.removeItem(name)
|
|
167
|
+
},
|
|
168
|
+
partialize: (state) => ({
|
|
169
|
+
user: state.user,
|
|
170
|
+
tokens: state.tokens,
|
|
171
|
+
isAuthenticated: state.isAuthenticated
|
|
172
|
+
}),
|
|
173
|
+
onRehydrateStorage: () => (state, error) => {
|
|
174
|
+
if (error) {
|
|
175
|
+
console.warn("[AntzChat] Auth store rehydration failed:", error);
|
|
176
|
+
}
|
|
177
|
+
ref.store?.setState({ isHydrated: true });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
);
|
|
182
|
+
ref.store = store;
|
|
183
|
+
if (!store.getState().isHydrated) {
|
|
184
|
+
const hydrationTimeout = setTimeout(() => {
|
|
185
|
+
if (!store.getState().isHydrated) {
|
|
186
|
+
store.setState({ isHydrated: true });
|
|
187
|
+
}
|
|
188
|
+
}, 3e3);
|
|
189
|
+
const unsub = store.subscribe((s) => {
|
|
190
|
+
if (s.isHydrated) {
|
|
191
|
+
clearTimeout(hydrationTimeout);
|
|
192
|
+
unsub();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const tokenStore = {
|
|
197
|
+
getAccessToken: () => store.getState().tokens?.accessToken,
|
|
198
|
+
getRefreshToken: () => store.getState().tokens?.refreshToken,
|
|
199
|
+
setTokens: (tokens) => store.getState().setTokens(tokens),
|
|
200
|
+
clearTokens: () => store.getState().logout()
|
|
201
|
+
};
|
|
202
|
+
return { useAuthStore: store, authTokenStore: tokenStore };
|
|
203
|
+
}
|
|
204
|
+
var _authStore = null;
|
|
205
|
+
function initAuthStore(storage) {
|
|
206
|
+
if (!_authStore) {
|
|
207
|
+
_authStore = createAuthStore(storage);
|
|
208
|
+
}
|
|
209
|
+
return _authStore;
|
|
210
|
+
}
|
|
211
|
+
function getAuthStore() {
|
|
212
|
+
if (!_authStore) throw new Error("[AntzChat] Auth store not initialized. Call initAuthStore first.");
|
|
213
|
+
return _authStore;
|
|
214
|
+
}
|
|
215
|
+
function resetAuthStore() {
|
|
216
|
+
_authStore = null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/utils/resolveSystemMessageText.ts
|
|
220
|
+
function resolveSystemMessageText(message, currentUserId) {
|
|
221
|
+
const m = message.metadata;
|
|
222
|
+
if (!m?.systemOperationType || !m.actorUserId) {
|
|
223
|
+
return message.content.text ?? "";
|
|
224
|
+
}
|
|
225
|
+
const iActor = m.actorUserId === currentUserId;
|
|
226
|
+
const iTarget = m.targetUserId === currentUserId;
|
|
227
|
+
const actor = iActor ? "You" : m.actorUserName ?? "Someone";
|
|
228
|
+
const target = iTarget ? "you" : m.targetUserName ?? "a member";
|
|
229
|
+
switch (m.systemOperationType) {
|
|
230
|
+
case "group_created":
|
|
231
|
+
return iActor ? "You created the group" : `${actor} created the group`;
|
|
232
|
+
case "user_added":
|
|
233
|
+
return iActor ? `You added ${target}` : `${actor} added ${target}`;
|
|
234
|
+
case "user_removed":
|
|
235
|
+
return iActor ? `You removed ${target}` : `${actor} removed ${target}`;
|
|
236
|
+
case "user_left":
|
|
237
|
+
return iActor ? "You left the group" : `${actor} left the group`;
|
|
238
|
+
case "admin_promoted":
|
|
239
|
+
return iActor ? `You made ${target} an admin` : `${actor} made ${target} an admin`;
|
|
240
|
+
case "admin_demoted":
|
|
241
|
+
return iActor ? `You removed ${target} as admin` : `${actor} removed ${target} as admin`;
|
|
242
|
+
case "group_updated":
|
|
243
|
+
return iActor ? "You updated the group" : `${actor} updated the group`;
|
|
244
|
+
default:
|
|
245
|
+
return message.content.text ?? "";
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
131
249
|
// src/api/messages.ts
|
|
132
250
|
var messagesApi = {
|
|
133
251
|
async list(conversationId, params = {}) {
|
|
@@ -140,7 +258,14 @@ var messagesApi = {
|
|
|
140
258
|
`/conversations/${conversationId}/messages`,
|
|
141
259
|
{ params: serverParams }
|
|
142
260
|
);
|
|
143
|
-
|
|
261
|
+
const currentUserId = getAuthStore().useAuthStore.getState().user?.id;
|
|
262
|
+
if (!currentUserId) return data;
|
|
263
|
+
return {
|
|
264
|
+
...data,
|
|
265
|
+
data: data.data.map(
|
|
266
|
+
(m) => m.content.type === "system" ? { ...m, content: { ...m.content, text: resolveSystemMessageText(m, currentUserId) } } : m
|
|
267
|
+
)
|
|
268
|
+
};
|
|
144
269
|
},
|
|
145
270
|
async get(messageId) {
|
|
146
271
|
const { data } = await getApiClient().get(`/messages/${messageId}`);
|
|
@@ -207,6 +332,10 @@ var messagesApi = {
|
|
|
207
332
|
async getPinned(conversationId) {
|
|
208
333
|
const { data } = await getApiClient().get(`/conversations/${conversationId}/pinned-messages`);
|
|
209
334
|
return data;
|
|
335
|
+
},
|
|
336
|
+
async getReceipts(messageId) {
|
|
337
|
+
const { data } = await getApiClient().get(`/messages/${messageId}/receipts`);
|
|
338
|
+
return data;
|
|
210
339
|
}
|
|
211
340
|
};
|
|
212
341
|
|
|
@@ -238,7 +367,7 @@ function normalizeLastMessage(lastMsg) {
|
|
|
238
367
|
id: lastMsg.messageId ?? "",
|
|
239
368
|
tenantId: "",
|
|
240
369
|
conversationId: "",
|
|
241
|
-
senderId: "",
|
|
370
|
+
senderId: lastMsg.senderId ?? "",
|
|
242
371
|
content: {
|
|
243
372
|
type: lastMsg.hasAttachments ? "attachment" : "text",
|
|
244
373
|
text: lastMsg.contentPreview
|
|
@@ -724,13 +853,13 @@ async function _doConnect(config, getToken) {
|
|
|
724
853
|
});
|
|
725
854
|
}
|
|
726
855
|
secureOn(_socket, "read_receipt", (event) => {
|
|
727
|
-
import("./chat.store-
|
|
856
|
+
import("./chat.store-DLNRJ5ZT.js").then(({ useChatStore: useChatStore2 }) => {
|
|
728
857
|
const e = event;
|
|
729
858
|
useChatStore2.getState().setLastRead(e.conversationId, e.messageId, e.readAt);
|
|
730
859
|
});
|
|
731
860
|
});
|
|
732
861
|
secureOn(_socket, "user_online", (event) => {
|
|
733
|
-
import("./chat.store-
|
|
862
|
+
import("./chat.store-DLNRJ5ZT.js").then(({ useChatStore: useChatStore2 }) => {
|
|
734
863
|
const store = useChatStore2.getState();
|
|
735
864
|
const e = event;
|
|
736
865
|
store.setUserOnline(e.userId);
|
|
@@ -738,7 +867,7 @@ async function _doConnect(config, getToken) {
|
|
|
738
867
|
});
|
|
739
868
|
});
|
|
740
869
|
secureOn(_socket, "user_offline", (event) => {
|
|
741
|
-
import("./chat.store-
|
|
870
|
+
import("./chat.store-DLNRJ5ZT.js").then(({ useChatStore: useChatStore2 }) => {
|
|
742
871
|
const e = event;
|
|
743
872
|
const store = useChatStore2.getState();
|
|
744
873
|
store.setUserOffline(e.userId);
|
|
@@ -940,93 +1069,6 @@ var socketEmit = {
|
|
|
940
1069
|
}
|
|
941
1070
|
};
|
|
942
1071
|
|
|
943
|
-
// src/stores/auth.store.ts
|
|
944
|
-
import { create } from "zustand";
|
|
945
|
-
import { persist } from "zustand/middleware";
|
|
946
|
-
function createAuthStore(storage) {
|
|
947
|
-
if (!storage) throw new Error("[AntzChat] createAuthStore requires a valid PersistStorage \u2014 received undefined. Make sure the SDK config is fully resolved before initializing the store.");
|
|
948
|
-
const ref = { store: null };
|
|
949
|
-
const store = create()(
|
|
950
|
-
persist(
|
|
951
|
-
(set) => ({
|
|
952
|
-
user: null,
|
|
953
|
-
tokens: null,
|
|
954
|
-
isAuthenticated: false,
|
|
955
|
-
isLoading: false,
|
|
956
|
-
isHydrated: false,
|
|
957
|
-
setAuth: (user, tokens) => set({ user, tokens, isAuthenticated: true, isLoading: false }),
|
|
958
|
-
setTokens: (tokens) => set({ tokens }),
|
|
959
|
-
setUser: (user) => set({ user }),
|
|
960
|
-
logout: () => set({ user: null, tokens: null, isAuthenticated: false, isLoading: false }),
|
|
961
|
-
setLoading: (isLoading) => set({ isLoading }),
|
|
962
|
-
setHydrated: (isHydrated) => set({ isHydrated })
|
|
963
|
-
}),
|
|
964
|
-
{
|
|
965
|
-
name: "antz-chat-auth",
|
|
966
|
-
storage: {
|
|
967
|
-
getItem: (name) => {
|
|
968
|
-
const result = storage.getItem(name);
|
|
969
|
-
if (result instanceof Promise) {
|
|
970
|
-
return result.then((str) => str ? JSON.parse(str) : null);
|
|
971
|
-
}
|
|
972
|
-
return result ? JSON.parse(result) : null;
|
|
973
|
-
},
|
|
974
|
-
setItem: (name, value) => {
|
|
975
|
-
storage.setItem(name, JSON.stringify(value));
|
|
976
|
-
},
|
|
977
|
-
removeItem: (name) => storage.removeItem(name)
|
|
978
|
-
},
|
|
979
|
-
partialize: (state) => ({
|
|
980
|
-
user: state.user,
|
|
981
|
-
tokens: state.tokens,
|
|
982
|
-
isAuthenticated: state.isAuthenticated
|
|
983
|
-
}),
|
|
984
|
-
onRehydrateStorage: () => (state, error) => {
|
|
985
|
-
if (error) {
|
|
986
|
-
console.warn("[AntzChat] Auth store rehydration failed:", error);
|
|
987
|
-
}
|
|
988
|
-
ref.store?.setState({ isHydrated: true });
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
)
|
|
992
|
-
);
|
|
993
|
-
ref.store = store;
|
|
994
|
-
if (!store.getState().isHydrated) {
|
|
995
|
-
const hydrationTimeout = setTimeout(() => {
|
|
996
|
-
if (!store.getState().isHydrated) {
|
|
997
|
-
store.setState({ isHydrated: true });
|
|
998
|
-
}
|
|
999
|
-
}, 3e3);
|
|
1000
|
-
const unsub = store.subscribe((s) => {
|
|
1001
|
-
if (s.isHydrated) {
|
|
1002
|
-
clearTimeout(hydrationTimeout);
|
|
1003
|
-
unsub();
|
|
1004
|
-
}
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
const tokenStore = {
|
|
1008
|
-
getAccessToken: () => store.getState().tokens?.accessToken,
|
|
1009
|
-
getRefreshToken: () => store.getState().tokens?.refreshToken,
|
|
1010
|
-
setTokens: (tokens) => store.getState().setTokens(tokens),
|
|
1011
|
-
clearTokens: () => store.getState().logout()
|
|
1012
|
-
};
|
|
1013
|
-
return { useAuthStore: store, authTokenStore: tokenStore };
|
|
1014
|
-
}
|
|
1015
|
-
var _authStore = null;
|
|
1016
|
-
function initAuthStore(storage) {
|
|
1017
|
-
if (!_authStore) {
|
|
1018
|
-
_authStore = createAuthStore(storage);
|
|
1019
|
-
}
|
|
1020
|
-
return _authStore;
|
|
1021
|
-
}
|
|
1022
|
-
function getAuthStore() {
|
|
1023
|
-
if (!_authStore) throw new Error("[AntzChat] Auth store not initialized. Call initAuthStore first.");
|
|
1024
|
-
return _authStore;
|
|
1025
|
-
}
|
|
1026
|
-
function resetAuthStore() {
|
|
1027
|
-
_authStore = null;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
1072
|
// src/client-facade.ts
|
|
1031
1073
|
var AntzChatClient = class {
|
|
1032
1074
|
constructor(rawConfig) {
|
|
@@ -1099,6 +1141,7 @@ export {
|
|
|
1099
1141
|
refreshSocketAuth,
|
|
1100
1142
|
resetAuthStore,
|
|
1101
1143
|
resolveConfig,
|
|
1144
|
+
resolveSystemMessageText,
|
|
1102
1145
|
setApiClientInstance,
|
|
1103
1146
|
setTransitSession,
|
|
1104
1147
|
socketEmit,
|