@thrillee/aegischat 0.1.10 → 0.1.12
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/dist/index.d.mts +34 -34
- package/dist/index.d.ts +34 -34
- package/dist/index.js +9 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useAutoRead.ts +1 -15
- package/src/hooks/useChannels.ts +3 -3
- package/src/hooks/useChat.ts +2 -13
- package/src/services/api.ts +25 -26
package/dist/index.d.mts
CHANGED
|
@@ -300,14 +300,14 @@ declare const chatApi: {
|
|
|
300
300
|
/**
|
|
301
301
|
* Connect to chat session
|
|
302
302
|
*/
|
|
303
|
-
connect(params: ChatConnectParams, signal?: AbortSignal): Promise<
|
|
303
|
+
connect(params: ChatConnectParams, signal?: AbortSignal): Promise<ChatSession>;
|
|
304
304
|
/**
|
|
305
305
|
* Refresh access token
|
|
306
306
|
*/
|
|
307
|
-
refreshToken(refreshToken: string, signal?: AbortSignal): Promise<
|
|
307
|
+
refreshToken(refreshToken: string, signal?: AbortSignal): Promise<{
|
|
308
308
|
access_token: string;
|
|
309
309
|
expires_in: number;
|
|
310
|
-
}
|
|
310
|
+
}>;
|
|
311
311
|
};
|
|
312
312
|
declare const channelsApi: {
|
|
313
313
|
/**
|
|
@@ -316,17 +316,17 @@ declare const channelsApi: {
|
|
|
316
316
|
list(options?: {
|
|
317
317
|
type?: string;
|
|
318
318
|
limit?: number;
|
|
319
|
-
}, signal?: AbortSignal): Promise<
|
|
319
|
+
}, signal?: AbortSignal): Promise<{
|
|
320
320
|
channels: ChannelListItem[];
|
|
321
|
-
}
|
|
321
|
+
}>;
|
|
322
322
|
/**
|
|
323
323
|
* Get channel by ID
|
|
324
324
|
*/
|
|
325
|
-
get(channelId: string, signal?: AbortSignal): Promise<
|
|
325
|
+
get(channelId: string, signal?: AbortSignal): Promise<Channel>;
|
|
326
326
|
/**
|
|
327
327
|
* Get or create DM channel
|
|
328
328
|
*/
|
|
329
|
-
getOrCreateDM(userId: string, signal?: AbortSignal): Promise<
|
|
329
|
+
getOrCreateDM(userId: string, signal?: AbortSignal): Promise<Channel>;
|
|
330
330
|
/**
|
|
331
331
|
* Create channel
|
|
332
332
|
*/
|
|
@@ -335,19 +335,19 @@ declare const channelsApi: {
|
|
|
335
335
|
type?: string;
|
|
336
336
|
description?: string;
|
|
337
337
|
metadata?: Record<string, unknown>;
|
|
338
|
-
}, signal?: AbortSignal): Promise<
|
|
338
|
+
}, signal?: AbortSignal): Promise<Channel>;
|
|
339
339
|
/**
|
|
340
340
|
* Mark channel as read
|
|
341
341
|
*/
|
|
342
|
-
markAsRead(channelId: string, signal?: AbortSignal): Promise<
|
|
342
|
+
markAsRead(channelId: string, signal?: AbortSignal): Promise<{
|
|
343
343
|
unread_count: number;
|
|
344
|
-
}
|
|
344
|
+
}>;
|
|
345
345
|
/**
|
|
346
346
|
* Get channel members
|
|
347
347
|
*/
|
|
348
|
-
getMembers(channelId: string, signal?: AbortSignal): Promise<
|
|
348
|
+
getMembers(channelId: string, signal?: AbortSignal): Promise<{
|
|
349
349
|
members: UserSummary[];
|
|
350
|
-
}
|
|
350
|
+
}>;
|
|
351
351
|
/**
|
|
352
352
|
* Update channel
|
|
353
353
|
*/
|
|
@@ -355,7 +355,7 @@ declare const channelsApi: {
|
|
|
355
355
|
name?: string;
|
|
356
356
|
description?: string;
|
|
357
357
|
metadata?: Record<string, unknown>;
|
|
358
|
-
}, signal?: AbortSignal): Promise<
|
|
358
|
+
}, signal?: AbortSignal): Promise<Channel>;
|
|
359
359
|
};
|
|
360
360
|
declare const messagesApi: {
|
|
361
361
|
/**
|
|
@@ -364,7 +364,7 @@ declare const messagesApi: {
|
|
|
364
364
|
list(channelId: string, options?: {
|
|
365
365
|
limit?: number;
|
|
366
366
|
before?: string;
|
|
367
|
-
}, signal?: AbortSignal): Promise<
|
|
367
|
+
}, signal?: AbortSignal): Promise<MessagesResponse>;
|
|
368
368
|
/**
|
|
369
369
|
* Send a message
|
|
370
370
|
*/
|
|
@@ -374,46 +374,46 @@ declare const messagesApi: {
|
|
|
374
374
|
parent_id?: string;
|
|
375
375
|
metadata?: Record<string, unknown>;
|
|
376
376
|
file_ids?: string[];
|
|
377
|
-
}, signal?: AbortSignal): Promise<
|
|
377
|
+
}, signal?: AbortSignal): Promise<Message>;
|
|
378
378
|
/**
|
|
379
379
|
* Update a message
|
|
380
380
|
*/
|
|
381
381
|
update(channelId: string, messageId: string, data: {
|
|
382
382
|
content?: string;
|
|
383
383
|
metadata?: Record<string, unknown>;
|
|
384
|
-
}, signal?: AbortSignal): Promise<
|
|
384
|
+
}, signal?: AbortSignal): Promise<Message>;
|
|
385
385
|
/**
|
|
386
386
|
* Delete a message
|
|
387
387
|
*/
|
|
388
|
-
delete(channelId: string, messageId: string, signal?: AbortSignal): Promise<
|
|
388
|
+
delete(channelId: string, messageId: string, signal?: AbortSignal): Promise<{
|
|
389
389
|
success: boolean;
|
|
390
|
-
}
|
|
390
|
+
}>;
|
|
391
391
|
/**
|
|
392
392
|
* Mark messages as delivered
|
|
393
393
|
*/
|
|
394
|
-
markDelivered(channelId: string, signal?: AbortSignal): Promise<
|
|
394
|
+
markDelivered(channelId: string, signal?: AbortSignal): Promise<{
|
|
395
395
|
success: boolean;
|
|
396
|
-
}
|
|
396
|
+
}>;
|
|
397
397
|
/**
|
|
398
398
|
* Mark messages as read
|
|
399
399
|
*/
|
|
400
|
-
markRead(channelId: string, signal?: AbortSignal): Promise<
|
|
400
|
+
markRead(channelId: string, signal?: AbortSignal): Promise<{
|
|
401
401
|
success: boolean;
|
|
402
|
-
}
|
|
402
|
+
}>;
|
|
403
403
|
};
|
|
404
404
|
declare const reactionsApi: {
|
|
405
405
|
/**
|
|
406
406
|
* Add reaction to a message
|
|
407
407
|
*/
|
|
408
|
-
add(channelId: string, messageId: string, emoji: string, signal?: AbortSignal): Promise<
|
|
408
|
+
add(channelId: string, messageId: string, emoji: string, signal?: AbortSignal): Promise<{
|
|
409
409
|
reactions: ReactionSummary[];
|
|
410
|
-
}
|
|
410
|
+
}>;
|
|
411
411
|
/**
|
|
412
412
|
* Remove reaction from a message
|
|
413
413
|
*/
|
|
414
|
-
remove(channelId: string, messageId: string, emoji: string, signal?: AbortSignal): Promise<
|
|
414
|
+
remove(channelId: string, messageId: string, emoji: string, signal?: AbortSignal): Promise<{
|
|
415
415
|
reactions: ReactionSummary[];
|
|
416
|
-
}
|
|
416
|
+
}>;
|
|
417
417
|
};
|
|
418
418
|
declare const filesApi: {
|
|
419
419
|
/**
|
|
@@ -423,32 +423,32 @@ declare const filesApi: {
|
|
|
423
423
|
file_name: string;
|
|
424
424
|
file_type: string;
|
|
425
425
|
file_size: number;
|
|
426
|
-
}, signal?: AbortSignal): Promise<
|
|
426
|
+
}, signal?: AbortSignal): Promise<UploadUrlResponse>;
|
|
427
427
|
/**
|
|
428
428
|
* Confirm file upload
|
|
429
429
|
*/
|
|
430
|
-
confirm(fileId: string, signal?: AbortSignal): Promise<
|
|
430
|
+
confirm(fileId: string, signal?: AbortSignal): Promise<{
|
|
431
431
|
file: FileAttachment;
|
|
432
|
-
}
|
|
432
|
+
}>;
|
|
433
433
|
/**
|
|
434
434
|
* Get download URL
|
|
435
435
|
*/
|
|
436
|
-
getDownloadUrl(fileId: string, signal?: AbortSignal): Promise<
|
|
436
|
+
getDownloadUrl(fileId: string, signal?: AbortSignal): Promise<{
|
|
437
437
|
url: string;
|
|
438
438
|
expires_at: string;
|
|
439
|
-
}
|
|
439
|
+
}>;
|
|
440
440
|
};
|
|
441
441
|
declare const usersApi: {
|
|
442
442
|
/**
|
|
443
443
|
* Search users
|
|
444
444
|
*/
|
|
445
|
-
search(query: string, signal?: AbortSignal): Promise<
|
|
445
|
+
search(query: string, signal?: AbortSignal): Promise<{
|
|
446
446
|
users: UserSummary[];
|
|
447
|
-
}
|
|
447
|
+
}>;
|
|
448
448
|
/**
|
|
449
449
|
* Get user by ID
|
|
450
450
|
*/
|
|
451
|
-
get(userId: string, signal?: AbortSignal): Promise<
|
|
451
|
+
get(userId: string, signal?: AbortSignal): Promise<UserSummary>;
|
|
452
452
|
};
|
|
453
453
|
|
|
454
454
|
export { type AegisConfig, type ApiError, type ApiResponse, type Channel, type ChannelListItem, type ChannelType, type ChannelsResponse, type ChatConnectParams, type ChatSession, type FileAttachment, type Message, type MessageMetadata, type MessageStatus, type MessageSummary, type MessageType, type MessagesResponse, type PaginatedResponse, type PaginationMeta, type PaginationParams, type ReactionEvent, type ReactionSummary, type TypingEvent, type TypingUser, type UploadProgress, type UseAutoReadOptions, type UseAutoReadReturn, type UseChannelsOptions, type UseChannelsReturn, type UseChatOptions, type UseChatReturn, type UseFileUploadOptions, type UseMentionsOptions, type UseMessagesOptions, type UseMessagesReturn, type UseReactionsOptions, type UseTypingIndicatorOptions, type UserStatus, type UserSummary, type WebSocketMessage, type WebSocketStatus, channelsApi, chatApi, configureApiClient, filesApi, messagesApi, reactionsApi, useAutoRead, useChannels, useChat, useFileUpload, useMentions, useMessages, useReactions, useTypingIndicator, usersApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -300,14 +300,14 @@ declare const chatApi: {
|
|
|
300
300
|
/**
|
|
301
301
|
* Connect to chat session
|
|
302
302
|
*/
|
|
303
|
-
connect(params: ChatConnectParams, signal?: AbortSignal): Promise<
|
|
303
|
+
connect(params: ChatConnectParams, signal?: AbortSignal): Promise<ChatSession>;
|
|
304
304
|
/**
|
|
305
305
|
* Refresh access token
|
|
306
306
|
*/
|
|
307
|
-
refreshToken(refreshToken: string, signal?: AbortSignal): Promise<
|
|
307
|
+
refreshToken(refreshToken: string, signal?: AbortSignal): Promise<{
|
|
308
308
|
access_token: string;
|
|
309
309
|
expires_in: number;
|
|
310
|
-
}
|
|
310
|
+
}>;
|
|
311
311
|
};
|
|
312
312
|
declare const channelsApi: {
|
|
313
313
|
/**
|
|
@@ -316,17 +316,17 @@ declare const channelsApi: {
|
|
|
316
316
|
list(options?: {
|
|
317
317
|
type?: string;
|
|
318
318
|
limit?: number;
|
|
319
|
-
}, signal?: AbortSignal): Promise<
|
|
319
|
+
}, signal?: AbortSignal): Promise<{
|
|
320
320
|
channels: ChannelListItem[];
|
|
321
|
-
}
|
|
321
|
+
}>;
|
|
322
322
|
/**
|
|
323
323
|
* Get channel by ID
|
|
324
324
|
*/
|
|
325
|
-
get(channelId: string, signal?: AbortSignal): Promise<
|
|
325
|
+
get(channelId: string, signal?: AbortSignal): Promise<Channel>;
|
|
326
326
|
/**
|
|
327
327
|
* Get or create DM channel
|
|
328
328
|
*/
|
|
329
|
-
getOrCreateDM(userId: string, signal?: AbortSignal): Promise<
|
|
329
|
+
getOrCreateDM(userId: string, signal?: AbortSignal): Promise<Channel>;
|
|
330
330
|
/**
|
|
331
331
|
* Create channel
|
|
332
332
|
*/
|
|
@@ -335,19 +335,19 @@ declare const channelsApi: {
|
|
|
335
335
|
type?: string;
|
|
336
336
|
description?: string;
|
|
337
337
|
metadata?: Record<string, unknown>;
|
|
338
|
-
}, signal?: AbortSignal): Promise<
|
|
338
|
+
}, signal?: AbortSignal): Promise<Channel>;
|
|
339
339
|
/**
|
|
340
340
|
* Mark channel as read
|
|
341
341
|
*/
|
|
342
|
-
markAsRead(channelId: string, signal?: AbortSignal): Promise<
|
|
342
|
+
markAsRead(channelId: string, signal?: AbortSignal): Promise<{
|
|
343
343
|
unread_count: number;
|
|
344
|
-
}
|
|
344
|
+
}>;
|
|
345
345
|
/**
|
|
346
346
|
* Get channel members
|
|
347
347
|
*/
|
|
348
|
-
getMembers(channelId: string, signal?: AbortSignal): Promise<
|
|
348
|
+
getMembers(channelId: string, signal?: AbortSignal): Promise<{
|
|
349
349
|
members: UserSummary[];
|
|
350
|
-
}
|
|
350
|
+
}>;
|
|
351
351
|
/**
|
|
352
352
|
* Update channel
|
|
353
353
|
*/
|
|
@@ -355,7 +355,7 @@ declare const channelsApi: {
|
|
|
355
355
|
name?: string;
|
|
356
356
|
description?: string;
|
|
357
357
|
metadata?: Record<string, unknown>;
|
|
358
|
-
}, signal?: AbortSignal): Promise<
|
|
358
|
+
}, signal?: AbortSignal): Promise<Channel>;
|
|
359
359
|
};
|
|
360
360
|
declare const messagesApi: {
|
|
361
361
|
/**
|
|
@@ -364,7 +364,7 @@ declare const messagesApi: {
|
|
|
364
364
|
list(channelId: string, options?: {
|
|
365
365
|
limit?: number;
|
|
366
366
|
before?: string;
|
|
367
|
-
}, signal?: AbortSignal): Promise<
|
|
367
|
+
}, signal?: AbortSignal): Promise<MessagesResponse>;
|
|
368
368
|
/**
|
|
369
369
|
* Send a message
|
|
370
370
|
*/
|
|
@@ -374,46 +374,46 @@ declare const messagesApi: {
|
|
|
374
374
|
parent_id?: string;
|
|
375
375
|
metadata?: Record<string, unknown>;
|
|
376
376
|
file_ids?: string[];
|
|
377
|
-
}, signal?: AbortSignal): Promise<
|
|
377
|
+
}, signal?: AbortSignal): Promise<Message>;
|
|
378
378
|
/**
|
|
379
379
|
* Update a message
|
|
380
380
|
*/
|
|
381
381
|
update(channelId: string, messageId: string, data: {
|
|
382
382
|
content?: string;
|
|
383
383
|
metadata?: Record<string, unknown>;
|
|
384
|
-
}, signal?: AbortSignal): Promise<
|
|
384
|
+
}, signal?: AbortSignal): Promise<Message>;
|
|
385
385
|
/**
|
|
386
386
|
* Delete a message
|
|
387
387
|
*/
|
|
388
|
-
delete(channelId: string, messageId: string, signal?: AbortSignal): Promise<
|
|
388
|
+
delete(channelId: string, messageId: string, signal?: AbortSignal): Promise<{
|
|
389
389
|
success: boolean;
|
|
390
|
-
}
|
|
390
|
+
}>;
|
|
391
391
|
/**
|
|
392
392
|
* Mark messages as delivered
|
|
393
393
|
*/
|
|
394
|
-
markDelivered(channelId: string, signal?: AbortSignal): Promise<
|
|
394
|
+
markDelivered(channelId: string, signal?: AbortSignal): Promise<{
|
|
395
395
|
success: boolean;
|
|
396
|
-
}
|
|
396
|
+
}>;
|
|
397
397
|
/**
|
|
398
398
|
* Mark messages as read
|
|
399
399
|
*/
|
|
400
|
-
markRead(channelId: string, signal?: AbortSignal): Promise<
|
|
400
|
+
markRead(channelId: string, signal?: AbortSignal): Promise<{
|
|
401
401
|
success: boolean;
|
|
402
|
-
}
|
|
402
|
+
}>;
|
|
403
403
|
};
|
|
404
404
|
declare const reactionsApi: {
|
|
405
405
|
/**
|
|
406
406
|
* Add reaction to a message
|
|
407
407
|
*/
|
|
408
|
-
add(channelId: string, messageId: string, emoji: string, signal?: AbortSignal): Promise<
|
|
408
|
+
add(channelId: string, messageId: string, emoji: string, signal?: AbortSignal): Promise<{
|
|
409
409
|
reactions: ReactionSummary[];
|
|
410
|
-
}
|
|
410
|
+
}>;
|
|
411
411
|
/**
|
|
412
412
|
* Remove reaction from a message
|
|
413
413
|
*/
|
|
414
|
-
remove(channelId: string, messageId: string, emoji: string, signal?: AbortSignal): Promise<
|
|
414
|
+
remove(channelId: string, messageId: string, emoji: string, signal?: AbortSignal): Promise<{
|
|
415
415
|
reactions: ReactionSummary[];
|
|
416
|
-
}
|
|
416
|
+
}>;
|
|
417
417
|
};
|
|
418
418
|
declare const filesApi: {
|
|
419
419
|
/**
|
|
@@ -423,32 +423,32 @@ declare const filesApi: {
|
|
|
423
423
|
file_name: string;
|
|
424
424
|
file_type: string;
|
|
425
425
|
file_size: number;
|
|
426
|
-
}, signal?: AbortSignal): Promise<
|
|
426
|
+
}, signal?: AbortSignal): Promise<UploadUrlResponse>;
|
|
427
427
|
/**
|
|
428
428
|
* Confirm file upload
|
|
429
429
|
*/
|
|
430
|
-
confirm(fileId: string, signal?: AbortSignal): Promise<
|
|
430
|
+
confirm(fileId: string, signal?: AbortSignal): Promise<{
|
|
431
431
|
file: FileAttachment;
|
|
432
|
-
}
|
|
432
|
+
}>;
|
|
433
433
|
/**
|
|
434
434
|
* Get download URL
|
|
435
435
|
*/
|
|
436
|
-
getDownloadUrl(fileId: string, signal?: AbortSignal): Promise<
|
|
436
|
+
getDownloadUrl(fileId: string, signal?: AbortSignal): Promise<{
|
|
437
437
|
url: string;
|
|
438
438
|
expires_at: string;
|
|
439
|
-
}
|
|
439
|
+
}>;
|
|
440
440
|
};
|
|
441
441
|
declare const usersApi: {
|
|
442
442
|
/**
|
|
443
443
|
* Search users
|
|
444
444
|
*/
|
|
445
|
-
search(query: string, signal?: AbortSignal): Promise<
|
|
445
|
+
search(query: string, signal?: AbortSignal): Promise<{
|
|
446
446
|
users: UserSummary[];
|
|
447
|
-
}
|
|
447
|
+
}>;
|
|
448
448
|
/**
|
|
449
449
|
* Get user by ID
|
|
450
450
|
*/
|
|
451
|
-
get(userId: string, signal?: AbortSignal): Promise<
|
|
451
|
+
get(userId: string, signal?: AbortSignal): Promise<UserSummary>;
|
|
452
452
|
};
|
|
453
453
|
|
|
454
454
|
export { type AegisConfig, type ApiError, type ApiResponse, type Channel, type ChannelListItem, type ChannelType, type ChannelsResponse, type ChatConnectParams, type ChatSession, type FileAttachment, type Message, type MessageMetadata, type MessageStatus, type MessageSummary, type MessageType, type MessagesResponse, type PaginatedResponse, type PaginationMeta, type PaginationParams, type ReactionEvent, type ReactionSummary, type TypingEvent, type TypingUser, type UploadProgress, type UseAutoReadOptions, type UseAutoReadReturn, type UseChannelsOptions, type UseChannelsReturn, type UseChatOptions, type UseChatReturn, type UseFileUploadOptions, type UseMentionsOptions, type UseMessagesOptions, type UseMessagesReturn, type UseReactionsOptions, type UseTypingIndicatorOptions, type UserStatus, type UserSummary, type WebSocketMessage, type WebSocketStatus, channelsApi, chatApi, configureApiClient, filesApi, messagesApi, reactionsApi, useAutoRead, useChannels, useChat, useFileUpload, useMentions, useMessages, useReactions, useTypingIndicator, usersApi };
|
package/dist/index.js
CHANGED
|
@@ -123,7 +123,7 @@ var channelsApi = {
|
|
|
123
123
|
* Create channel
|
|
124
124
|
*/
|
|
125
125
|
async create(data, signal) {
|
|
126
|
-
return fetchWithAuth("/
|
|
126
|
+
return fetchWithAuth("/channels", {
|
|
127
127
|
method: "POST",
|
|
128
128
|
body: JSON.stringify(data),
|
|
129
129
|
signal
|
|
@@ -133,7 +133,7 @@ var channelsApi = {
|
|
|
133
133
|
* Mark channel as read
|
|
134
134
|
*/
|
|
135
135
|
async markAsRead(channelId, signal) {
|
|
136
|
-
return fetchWithAuth(`/
|
|
136
|
+
return fetchWithAuth(`/channels/${channelId}/read`, {
|
|
137
137
|
method: "POST",
|
|
138
138
|
signal
|
|
139
139
|
});
|
|
@@ -148,7 +148,7 @@ var channelsApi = {
|
|
|
148
148
|
* Update channel
|
|
149
149
|
*/
|
|
150
150
|
async update(channelId, data, signal) {
|
|
151
|
-
return fetchWithAuth(`/
|
|
151
|
+
return fetchWithAuth(`/channels/${channelId}`, {
|
|
152
152
|
method: "PATCH",
|
|
153
153
|
body: JSON.stringify(data),
|
|
154
154
|
signal
|
|
@@ -336,9 +336,6 @@ function useChat(options = {}) {
|
|
|
336
336
|
(0, import_react.useEffect)(() => {
|
|
337
337
|
activeChannelIdRef.current = activeChannelId;
|
|
338
338
|
}, [activeChannelId]);
|
|
339
|
-
(0, import_react.useEffect)(() => {
|
|
340
|
-
activeChannelIdRef.current = activeChannelId;
|
|
341
|
-
}, [activeChannelId]);
|
|
342
339
|
const getActiveChannelId = (0, import_react.useCallback)(() => {
|
|
343
340
|
if (typeof window === "undefined") return null;
|
|
344
341
|
return sessionStorage.getItem(SESSION_STORAGE_KEY);
|
|
@@ -613,8 +610,8 @@ function useChat(options = {}) {
|
|
|
613
610
|
if (!currentSession) return;
|
|
614
611
|
setIsLoadingChannels(true);
|
|
615
612
|
try {
|
|
616
|
-
const response = await
|
|
617
|
-
setChannels(response.
|
|
613
|
+
const response = await fetchFromComms("/channels");
|
|
614
|
+
setChannels(response.channels || []);
|
|
618
615
|
} catch (error) {
|
|
619
616
|
console.error("[AegisChat] Failed to fetch channels:", error);
|
|
620
617
|
} finally {
|
|
@@ -654,12 +651,6 @@ function useChat(options = {}) {
|
|
|
654
651
|
if (response.oldest_id) {
|
|
655
652
|
oldestMessageId.current = response.oldest_id;
|
|
656
653
|
}
|
|
657
|
-
await markAsRead(channelId);
|
|
658
|
-
setChannels(
|
|
659
|
-
(prev) => prev.map(
|
|
660
|
-
(ch) => ch.id === channelId ? { ...ch, unread_count: 0 } : ch
|
|
661
|
-
)
|
|
662
|
-
);
|
|
663
654
|
} catch (error) {
|
|
664
655
|
console.error("[AegisChat] Failed to load messages:", error);
|
|
665
656
|
setMessages([]);
|
|
@@ -1105,7 +1096,6 @@ function useChat(options = {}) {
|
|
|
1105
1096
|
|
|
1106
1097
|
// src/hooks/useAutoRead.ts
|
|
1107
1098
|
var import_react2 = require("react");
|
|
1108
|
-
var SESSION_STORAGE_KEY2 = "@aegischat/activeChannel";
|
|
1109
1099
|
function useAutoRead(options = {}) {
|
|
1110
1100
|
const [isFocused, setIsFocused] = (0, import_react2.useState)(false);
|
|
1111
1101
|
(0, import_react2.useEffect)(() => {
|
|
@@ -1119,18 +1109,6 @@ function useAutoRead(options = {}) {
|
|
|
1119
1109
|
window.removeEventListener("blur", handleBlur);
|
|
1120
1110
|
};
|
|
1121
1111
|
}, []);
|
|
1122
|
-
(0, import_react2.useEffect)(() => {
|
|
1123
|
-
const handleVisibilityChange = () => {
|
|
1124
|
-
if (!document.hidden) {
|
|
1125
|
-
const activeChannelId = sessionStorage.getItem(SESSION_STORAGE_KEY2);
|
|
1126
|
-
if (activeChannelId) {
|
|
1127
|
-
markAsRead(activeChannelId);
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
};
|
|
1131
|
-
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
1132
|
-
return () => document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
1133
|
-
}, []);
|
|
1134
1112
|
const markAsRead = (0, import_react2.useCallback)(async (channelId) => {
|
|
1135
1113
|
if (!isFocused) return;
|
|
1136
1114
|
try {
|
|
@@ -1144,7 +1122,7 @@ function useAutoRead(options = {}) {
|
|
|
1144
1122
|
if (!isFocused) return;
|
|
1145
1123
|
try {
|
|
1146
1124
|
const response = await channelsApi.list({});
|
|
1147
|
-
const channels = response.
|
|
1125
|
+
const channels = response.channels || [];
|
|
1148
1126
|
await Promise.all(
|
|
1149
1127
|
channels.filter((ch) => ch.unread_count > 0).map((ch) => channelsApi.markAsRead(ch.id))
|
|
1150
1128
|
);
|
|
@@ -1169,7 +1147,7 @@ function useChannels(options = {}) {
|
|
|
1169
1147
|
try {
|
|
1170
1148
|
const response = await channelsApi.list({ type, limit }, signal);
|
|
1171
1149
|
if (signal?.aborted) return;
|
|
1172
|
-
setChannels(response.
|
|
1150
|
+
setChannels(response.channels);
|
|
1173
1151
|
} catch (err) {
|
|
1174
1152
|
if (err instanceof Error && err.name === "AbortError") return;
|
|
1175
1153
|
const error2 = err instanceof Error ? err : new Error("Failed to fetch channels");
|
|
@@ -1192,8 +1170,8 @@ function useChannels(options = {}) {
|
|
|
1192
1170
|
const controller = new AbortController();
|
|
1193
1171
|
abortControllerRef.current = controller;
|
|
1194
1172
|
fetchChannels(controller.signal);
|
|
1195
|
-
onChannelCreated?.(response
|
|
1196
|
-
return response
|
|
1173
|
+
onChannelCreated?.(response);
|
|
1174
|
+
return response;
|
|
1197
1175
|
} catch (err) {
|
|
1198
1176
|
const error2 = err instanceof Error ? err : new Error("Failed to create DM");
|
|
1199
1177
|
onError?.(error2);
|