@go-avro/avro-js 1.6.6-rc17 → 1.6.6-rc19
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/chat.d.ts +25 -0
- package/dist/chat.js +47 -0
- package/dist/client/QueryClient.d.ts +32 -1
- package/dist/client/QueryClient.js +12 -2
- package/dist/client/cache.d.ts +4 -0
- package/dist/client/cache.js +19 -0
- package/dist/client/core/uploads.js +17 -4
- package/dist/client/hooks/chats.js +26 -0
- package/dist/client/hooks/messages.js +54 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/types/api/MemberState.d.ts +3 -0
- package/dist/types/client.d.ts +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Chat } from './types/api/Chat.js';
|
|
2
|
+
import { Reaction } from './types/api/Reaction.js';
|
|
3
|
+
/** The quick-pick reactions, as Unicode code points: 👍 ❤️ 😂 😮 😢 🙏. */
|
|
4
|
+
export declare const REACTION_CODE_POINTS: readonly [128077, 10084, 128514, 128558, 128546, 128591];
|
|
5
|
+
/**
|
|
6
|
+
* Render a reaction's code point. Older symbols (❤, ☺) default to text
|
|
7
|
+
* presentation, so they get the emoji variation selector.
|
|
8
|
+
*/
|
|
9
|
+
export declare function reactionGlyph(codePoint: number): string;
|
|
10
|
+
export interface ReactionGroup {
|
|
11
|
+
reaction: number;
|
|
12
|
+
count: number;
|
|
13
|
+
/** Ids of the users who reacted, in reaction order. */
|
|
14
|
+
userIds: string[];
|
|
15
|
+
mine: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Group a message's reactions by emoji, in first-reacted order. */
|
|
18
|
+
export declare function groupReactions(reactions: Reaction[], selfId?: string): ReactionGroup[];
|
|
19
|
+
/** When a message was sent, preferring the server's clock. */
|
|
20
|
+
export declare function messageTime(message: {
|
|
21
|
+
time_created: number | null;
|
|
22
|
+
time_sent: number;
|
|
23
|
+
}): number;
|
|
24
|
+
/** Whether `chat` has a message from someone else the caller hasn't read. */
|
|
25
|
+
export declare function isChatUnread(chat: Chat, selfId?: string): boolean;
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** The quick-pick reactions, as Unicode code points: 👍 ❤️ 😂 😮 😢 🙏. */
|
|
2
|
+
export const REACTION_CODE_POINTS = [0x1f44d, 0x2764, 0x1f602, 0x1f62e, 0x1f622, 0x1f64f];
|
|
3
|
+
/**
|
|
4
|
+
* Render a reaction's code point. Older symbols (❤, ☺) default to text
|
|
5
|
+
* presentation, so they get the emoji variation selector.
|
|
6
|
+
*/
|
|
7
|
+
export function reactionGlyph(codePoint) {
|
|
8
|
+
try {
|
|
9
|
+
const glyph = String.fromCodePoint(codePoint);
|
|
10
|
+
return codePoint < 0x1f000 ? `${glyph}️` : glyph;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Group a message's reactions by emoji, in first-reacted order. */
|
|
17
|
+
export function groupReactions(reactions, selfId) {
|
|
18
|
+
const groups = new Map();
|
|
19
|
+
for (const r of reactions ?? []) {
|
|
20
|
+
let group = groups.get(r.reaction);
|
|
21
|
+
if (!group) {
|
|
22
|
+
group = { reaction: r.reaction, count: 0, userIds: [], mine: false };
|
|
23
|
+
groups.set(r.reaction, group);
|
|
24
|
+
}
|
|
25
|
+
if (group.userIds.includes(r.sender_id))
|
|
26
|
+
continue;
|
|
27
|
+
group.userIds.push(r.sender_id);
|
|
28
|
+
group.count += 1;
|
|
29
|
+
if (r.sender_id === selfId)
|
|
30
|
+
group.mine = true;
|
|
31
|
+
}
|
|
32
|
+
return [...groups.values()];
|
|
33
|
+
}
|
|
34
|
+
/** When a message was sent, preferring the server's clock. */
|
|
35
|
+
export function messageTime(message) {
|
|
36
|
+
return message.time_created ?? (message.time_sent > 0 ? message.time_sent : 0);
|
|
37
|
+
}
|
|
38
|
+
/** Whether `chat` has a message from someone else the caller hasn't read. */
|
|
39
|
+
export function isChatUnread(chat, selfId) {
|
|
40
|
+
const last = chat.last_message;
|
|
41
|
+
if (!last || !selfId || last.sender_id === selfId)
|
|
42
|
+
return false;
|
|
43
|
+
const me = chat.user_state.find((m) => m.id === selfId);
|
|
44
|
+
if (!me)
|
|
45
|
+
return false;
|
|
46
|
+
return me.last_message_read_at == null || me.last_message_read_at < messageTime(last);
|
|
47
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Socket } from 'socket.io-client';
|
|
2
2
|
import { InfiniteData, QueryClient, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import { AuthManager } from '../auth/AuthManager.js';
|
|
4
|
-
import { _Event, ActiveSessionSummary, AddressFeatureCollection, ApiInfo, Avro, StorageAnalytics, ClientErrorReport, ErrorLogEntry, PerformanceMetrics, AuditLogEntry, AuditQueryParams, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Chat, CheckIn, Company, CompanySummary, DelayEventCreatePayload, EventUpdatePayload, LineItemType, FinancialInsightData, RevenueInsightData, Job, JobUpdate, EventInsightData, AppleLinkProof, AppleLoginResult, MicrosoftLoginResult, LoginResponse, Message, Permission, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, UserMergeSummary, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, CatalogIndustry, CatalogItem, Device, DeviceInfo, LocationServicesStatus, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus, CreateNotificationPayload, NotificationCreated, SendEmailPayload } from '../types/api.js';
|
|
4
|
+
import { _Event, ActiveSessionSummary, AddressFeatureCollection, ApiInfo, Avro, StorageAnalytics, ClientErrorReport, ErrorLogEntry, PerformanceMetrics, AuditLogEntry, AuditQueryParams, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Chat, CheckIn, Company, CompanySummary, DelayEventCreatePayload, EventUpdatePayload, LineItemType, FinancialInsightData, RevenueInsightData, Job, JobUpdate, EventInsightData, AppleLinkProof, AppleLoginResult, MicrosoftLoginResult, LoginResponse, Message, MemberState, Permission, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, UserMergeSummary, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, CatalogIndustry, CatalogItem, Device, DeviceInfo, LocationServicesStatus, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus, CreateNotificationPayload, NotificationCreated, SendEmailPayload } from '../types/api.js';
|
|
5
5
|
import { AuthState, Tokens } from '../types/auth.js';
|
|
6
6
|
import { CancelToken, ClientId, RetryStrategy, EventPhotoLinks, EventPhotoLinksVars, PdfSource, SendBillEmailVars, SendEmailMessageVars, SendNotificationVars, ImageTarget, UploadImage, UploadImagesOptions, UploadImagesResult, UploadImagesVars } from '../types/client.js';
|
|
7
7
|
import { StandardError } from '../types/error.js';
|
|
@@ -13,6 +13,7 @@ import type { EmailSucceededPayload, EmailFailedPayload, EmailType } from '../ty
|
|
|
13
13
|
import type { BulkDeleteBillsResponse, BulkEmailBillsResponse } from './hooks/bills.js';
|
|
14
14
|
import type { BillWritePayload, BreakWritePayload, CatalogItemCreatePayload, CatalogItemUpdatePayload, CompanyCreatePayload, CompanyUpdatePayload, EventCreatePayload, IntuitSyncStatus, MemberAddPayload, MemberUpdatePayload, PayoutStatusFilter, ProposalReviewPayload, ProposalWritePayload, SessionCreatePayload, SessionUpdatePayload, SkillCreatePayload, SkillUpdatePayload, TeamWritePayload, UserCreatePayload, UserUpdatePayload } from './requests.js';
|
|
15
15
|
import { type QueryPersistOptions } from './persist.js';
|
|
16
|
+
import { type NsSnapshot } from './cache.js';
|
|
16
17
|
export interface TrackEmailOptions {
|
|
17
18
|
emailType?: EmailType;
|
|
18
19
|
requestId?: string;
|
|
@@ -54,6 +55,7 @@ declare module './QueryClient.js' {
|
|
|
54
55
|
*/
|
|
55
56
|
sendNotification(body: CreateNotificationPayload, options?: {
|
|
56
57
|
companyId?: string;
|
|
58
|
+
idempotencyKey?: string;
|
|
57
59
|
}): Promise<NotificationCreated>;
|
|
58
60
|
/**
|
|
59
61
|
* Send an email from a mailbox (show photos by embedding
|
|
@@ -63,6 +65,7 @@ declare module './QueryClient.js' {
|
|
|
63
65
|
sendEmailMessage(emailId: string, body: SendEmailPayload, options?: {
|
|
64
66
|
requestId?: string;
|
|
65
67
|
proposalId?: string;
|
|
68
|
+
idempotencyKey?: string;
|
|
66
69
|
}): Promise<void>;
|
|
67
70
|
/** `uploadImages` as a mutation; refreshes the event or job when done. */
|
|
68
71
|
useUploadImages(): ReturnType<typeof useMutation<UploadImagesResult, StandardError, UploadImagesVars>>;
|
|
@@ -72,6 +75,8 @@ declare module './QueryClient.js' {
|
|
|
72
75
|
useSendBillEmail(): ReturnType<typeof useMutation<{
|
|
73
76
|
msg: string;
|
|
74
77
|
}, StandardError, SendBillEmailVars>>;
|
|
78
|
+
/** `useEventPhotoLinks` outside React (e.g. an offline outbox). */
|
|
79
|
+
getEventPhotoLinks(vars: EventPhotoLinksVars): Promise<EventPhotoLinks>;
|
|
75
80
|
/**
|
|
76
81
|
* Fetch permanent, signed links to an event's photos to embed in an
|
|
77
82
|
* email (`<img>` per position plus a "View photos" page).
|
|
@@ -357,6 +362,30 @@ declare module './QueryClient.js' {
|
|
|
357
362
|
time_sent?: number;
|
|
358
363
|
id?: string;
|
|
359
364
|
}>>;
|
|
365
|
+
useUpdateChat(): ReturnType<typeof useMutation<{
|
|
366
|
+
msg?: string;
|
|
367
|
+
}, StandardError, {
|
|
368
|
+
chatId: string;
|
|
369
|
+
name?: string;
|
|
370
|
+
status?: MemberState['state'];
|
|
371
|
+
users?: string[];
|
|
372
|
+
}>>;
|
|
373
|
+
useLeaveChat(): ReturnType<typeof useMutation<{
|
|
374
|
+
msg?: string;
|
|
375
|
+
}, StandardError, {
|
|
376
|
+
chatId: string;
|
|
377
|
+
}>>;
|
|
378
|
+
useReactToMessage(chatId: string): ReturnType<typeof useMutation<unknown, StandardError, {
|
|
379
|
+
message: Message;
|
|
380
|
+
reaction: number;
|
|
381
|
+
userId: string;
|
|
382
|
+
remove?: boolean;
|
|
383
|
+
}, {
|
|
384
|
+
snapshot: NsSnapshot;
|
|
385
|
+
}>>;
|
|
386
|
+
useMarkChatRead(chatId: string): ReturnType<typeof useMutation<unknown, StandardError, {
|
|
387
|
+
messageId: string;
|
|
388
|
+
}>>;
|
|
360
389
|
useCreateProposal(): ReturnType<typeof useMutation<{
|
|
361
390
|
msg: string;
|
|
362
391
|
id: string;
|
|
@@ -1076,6 +1105,8 @@ export declare class AvroQueryClient {
|
|
|
1076
1105
|
offset?: number;
|
|
1077
1106
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
1078
1107
|
fetchMessages(chatId: string, body?: {
|
|
1108
|
+
/** Marks this message (and the chat) as read by the caller. */
|
|
1109
|
+
last_message_read?: string;
|
|
1079
1110
|
amt?: number;
|
|
1080
1111
|
known_ids?: string[];
|
|
1081
1112
|
unknown_ids?: string[];
|
|
@@ -9,6 +9,7 @@ import { StandardError } from '../types/error.js';
|
|
|
9
9
|
import { withoutEmpty } from './wire.js';
|
|
10
10
|
import { ChangeApplier, fallbackInvalidate, patchMember, patchMemberLocation, patchTeamLocation, retryDenied, } from './realtime.js';
|
|
11
11
|
import { QueryPersister } from './persist.js';
|
|
12
|
+
import { replaceRow } from './cache.js';
|
|
12
13
|
/** Keep the original status (401/403/404/0…) when surfacing a list-fetch failure. */
|
|
13
14
|
function fetchError(err, context) {
|
|
14
15
|
if (err instanceof StandardError)
|
|
@@ -426,9 +427,18 @@ export class AvroQueryClient {
|
|
|
426
427
|
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
427
428
|
});
|
|
428
429
|
}
|
|
429
|
-
|
|
430
|
+
// Chat events reach every accepted member through their own room,
|
|
431
|
+
// so chat lists stay live without joining each chat's room.
|
|
432
|
+
on('new_message', (data) => {
|
|
430
433
|
queryClient.invalidateQueries({ queryKey: ['chats'] });
|
|
431
|
-
queryClient.invalidateQueries({
|
|
434
|
+
queryClient.invalidateQueries({
|
|
435
|
+
queryKey: data?.chat_id ? ['messages', 'infinite', data.chat_id] : ['messages'],
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
// Carries the whole message (e.g. after a reaction change).
|
|
439
|
+
on('message_updated', (data) => {
|
|
440
|
+
if (data?.id)
|
|
441
|
+
replaceRow(queryClient, 'messages', data);
|
|
432
442
|
});
|
|
433
443
|
on('connect', () => {
|
|
434
444
|
this.joinCompanyRoom();
|
package/dist/client/cache.d.ts
CHANGED
|
@@ -22,3 +22,7 @@ export declare function seedDetails<T extends {
|
|
|
22
22
|
}>(qc: QueryClient | null, ns: string, items: T[]): T[];
|
|
23
23
|
/** Remove an optimistic row (by its temporary id) from every list in `ns`. */
|
|
24
24
|
export declare function removeOptimisticRow(qc: QueryClient, ns: string, tempId: string): void;
|
|
25
|
+
/** Replace a row (matched by id) in every list in `ns` that holds it. */
|
|
26
|
+
export declare function replaceRow<T extends {
|
|
27
|
+
id?: string;
|
|
28
|
+
}>(qc: QueryClient, ns: string, row: T): void;
|
package/dist/client/cache.js
CHANGED
|
@@ -49,3 +49,22 @@ export function removeOptimisticRow(qc, ns, tempId) {
|
|
|
49
49
|
return old;
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
+
/** Replace a row (matched by id) in every list in `ns` that holds it. */
|
|
53
|
+
export function replaceRow(qc, ns, row) {
|
|
54
|
+
if (!row?.id)
|
|
55
|
+
return;
|
|
56
|
+
const swap = (x) => (x?.id === row.id ? row : x);
|
|
57
|
+
qc.setQueriesData({ predicate: (q) => q.queryKey[0] === ns && isListKey(q.queryKey) }, (old) => {
|
|
58
|
+
if (!old)
|
|
59
|
+
return old;
|
|
60
|
+
if (Array.isArray(old))
|
|
61
|
+
return old.map(swap);
|
|
62
|
+
if (Array.isArray(old.pages)) {
|
|
63
|
+
return {
|
|
64
|
+
...old,
|
|
65
|
+
pages: old.pages.map((p) => (Array.isArray(p) ? p.map(swap) : p)),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return old;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -172,12 +172,18 @@ AvroQueryClient.prototype.uploadImages = function (target, images, options) {
|
|
|
172
172
|
const base = 'eventId' in target ? `/event/${target.eventId}/image` : `/task/${target.taskId}/image`;
|
|
173
173
|
return this._uploadImages(base, images, options);
|
|
174
174
|
};
|
|
175
|
+
/**
|
|
176
|
+
* The server sends only once per key however often the request repeats.
|
|
177
|
+
* Not retried here: a caller keeps the key and resends later (an outbox).
|
|
178
|
+
*/
|
|
179
|
+
const idempotency = (key) => (key ? { headers: { 'Idempotency-Key': key } } : {});
|
|
175
180
|
AvroQueryClient.prototype.sendNotification = function (body, options = {}) {
|
|
176
181
|
const form = new FormData();
|
|
177
182
|
form.append('data', JSON.stringify(body));
|
|
178
183
|
return this.post({
|
|
179
184
|
path: `/company/${options.companyId ?? this.companyId}/notification`,
|
|
180
185
|
data: form,
|
|
186
|
+
...idempotency(options.idempotencyKey),
|
|
181
187
|
});
|
|
182
188
|
};
|
|
183
189
|
AvroQueryClient.prototype.sendEmailMessage = function (emailId, body, options = {}) {
|
|
@@ -187,7 +193,11 @@ AvroQueryClient.prototype.sendEmailMessage = function (emailId, body, options =
|
|
|
187
193
|
form.append('request_id', options.requestId);
|
|
188
194
|
if (options.proposalId)
|
|
189
195
|
form.append('proposal_id', options.proposalId);
|
|
190
|
-
return this.post({
|
|
196
|
+
return this.post({
|
|
197
|
+
path: `/email/${emailId}`,
|
|
198
|
+
data: form,
|
|
199
|
+
...idempotency(options.idempotencyKey),
|
|
200
|
+
});
|
|
191
201
|
};
|
|
192
202
|
AvroQueryClient.prototype.useUploadImages = function () {
|
|
193
203
|
return useMutation({
|
|
@@ -198,16 +208,19 @@ AvroQueryClient.prototype.useUploadImages = function () {
|
|
|
198
208
|
};
|
|
199
209
|
AvroQueryClient.prototype.useSendNotification = function () {
|
|
200
210
|
return useMutation({
|
|
201
|
-
mutationFn: ({ body, companyId }) => this.sendNotification(body, { companyId }),
|
|
211
|
+
mutationFn: ({ body, companyId, idempotencyKey }) => this.sendNotification(body, { companyId, idempotencyKey }),
|
|
202
212
|
});
|
|
203
213
|
};
|
|
204
214
|
AvroQueryClient.prototype.useSendEmailMessage = function () {
|
|
205
215
|
return useMutation({
|
|
206
|
-
mutationFn: ({ emailId, body, requestId, proposalId }) => this.sendEmailMessage(emailId, body, { requestId, proposalId }),
|
|
216
|
+
mutationFn: ({ emailId, body, requestId, proposalId, idempotencyKey, }) => this.sendEmailMessage(emailId, body, { requestId, proposalId, idempotencyKey }),
|
|
207
217
|
});
|
|
208
218
|
};
|
|
219
|
+
AvroQueryClient.prototype.getEventPhotoLinks = function ({ eventId, count }) {
|
|
220
|
+
return this.get({ path: `/event/${eventId}/photo-links?count=${count}` });
|
|
221
|
+
};
|
|
209
222
|
AvroQueryClient.prototype.useEventPhotoLinks = function () {
|
|
210
223
|
return useMutation({
|
|
211
|
-
mutationFn: (
|
|
224
|
+
mutationFn: (vars) => this.getEventPhotoLinks(vars),
|
|
212
225
|
});
|
|
213
226
|
};
|
|
@@ -60,3 +60,29 @@ AvroQueryClient.prototype.useCreateChat = function () {
|
|
|
60
60
|
},
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
|
+
AvroQueryClient.prototype.useUpdateChat = function () {
|
|
64
|
+
const queryClient = this.getQueryClient();
|
|
65
|
+
return useMutation({
|
|
66
|
+
mutationFn: ({ chatId, ...data }) => this.put({
|
|
67
|
+
path: `/chat/${chatId}`,
|
|
68
|
+
data: JSON.stringify(data),
|
|
69
|
+
headers: { 'Content-Type': 'application/json' },
|
|
70
|
+
}),
|
|
71
|
+
onSettled: (_data, _err, { chatId }) => {
|
|
72
|
+
queryClient.invalidateQueries({ queryKey: ['chats'] });
|
|
73
|
+
queryClient.invalidateQueries({ queryKey: ['messages', 'infinite', chatId] });
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
AvroQueryClient.prototype.useLeaveChat = function () {
|
|
78
|
+
const queryClient = this.getQueryClient();
|
|
79
|
+
return useMutation({
|
|
80
|
+
// The last member to leave deletes the chat.
|
|
81
|
+
mutationFn: ({ chatId }) => this.delete({ path: `/chat/${chatId}` }),
|
|
82
|
+
// Leave the thread's queries to age out: removing them while the
|
|
83
|
+
// thread is still mounted refetches a chat the caller has left.
|
|
84
|
+
onSettled: () => {
|
|
85
|
+
queryClient.invalidateQueries({ queryKey: ['chats'] });
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useInfiniteQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../QueryClient.js';
|
|
3
|
-
import { seedDetails } from '../cache.js';
|
|
3
|
+
import { replaceRow, restoreNs, seedDetails, snapshotNs } from '../cache.js';
|
|
4
4
|
import { keys } from '../realtime.js';
|
|
5
5
|
AvroQueryClient.prototype.useGetMessages = function (chatId, body) {
|
|
6
6
|
const queryClient = this.getQueryClient();
|
|
@@ -53,3 +53,56 @@ AvroQueryClient.prototype.useCreateMessage = function (chatId) {
|
|
|
53
53
|
},
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
|
+
AvroQueryClient.prototype.useReactToMessage = function (chatId) {
|
|
57
|
+
const queryClient = this.getQueryClient();
|
|
58
|
+
return useMutation({
|
|
59
|
+
// `reaction` is a Unicode code point. Adding twice, or removing one
|
|
60
|
+
// that isn't there, is a no-op server-side.
|
|
61
|
+
mutationFn: ({ message, reaction, remove }) => remove
|
|
62
|
+
? this.delete({ path: `/message/${message.id}/react/${reaction}` })
|
|
63
|
+
: this.post({
|
|
64
|
+
path: `/message/${message.id}/react`,
|
|
65
|
+
data: JSON.stringify({ reaction }),
|
|
66
|
+
headers: { 'Content-Type': 'application/json' },
|
|
67
|
+
}),
|
|
68
|
+
onMutate: async ({ message, reaction, userId, remove }) => {
|
|
69
|
+
await queryClient.cancelQueries({ queryKey: ['messages', 'infinite', chatId] });
|
|
70
|
+
const snapshot = snapshotNs(queryClient, 'messages');
|
|
71
|
+
const mine = (r) => r.sender_id === userId && r.reaction === reaction;
|
|
72
|
+
const reactions = remove
|
|
73
|
+
? message.reactions.filter((r) => !mine(r))
|
|
74
|
+
: message.reactions.some(mine)
|
|
75
|
+
? message.reactions
|
|
76
|
+
: [
|
|
77
|
+
...message.reactions,
|
|
78
|
+
{
|
|
79
|
+
id: `optimistic-${reaction}`,
|
|
80
|
+
message_id: message.id,
|
|
81
|
+
sender_id: userId,
|
|
82
|
+
reaction,
|
|
83
|
+
time_created: Math.floor(Date.now() / 1000),
|
|
84
|
+
time_updated: null,
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
replaceRow(queryClient, 'messages', { ...message, reactions });
|
|
88
|
+
return { snapshot };
|
|
89
|
+
},
|
|
90
|
+
onError: (_err, _vars, context) => restoreNs(queryClient, context?.snapshot),
|
|
91
|
+
onSettled: () => {
|
|
92
|
+
// A live socket gets `message_updated` with the real rows.
|
|
93
|
+
if (!this.socket?.connected) {
|
|
94
|
+
queryClient.invalidateQueries({ queryKey: ['messages', 'infinite', chatId] });
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
AvroQueryClient.prototype.useMarkChatRead = function (chatId) {
|
|
100
|
+
const queryClient = this.getQueryClient();
|
|
101
|
+
return useMutation({
|
|
102
|
+
// Reading a message page with `last_message_read` records the read.
|
|
103
|
+
mutationFn: ({ messageId }) => this.fetchMessages(chatId, { amt: 1, last_message_read: messageId }),
|
|
104
|
+
onSuccess: () => {
|
|
105
|
+
queryClient.invalidateQueries({ queryKey: ['chats'] });
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ import './client/hooks/timecards.js';
|
|
|
43
43
|
import './client/hooks/waivers.js';
|
|
44
44
|
import './client/hooks/email.js';
|
|
45
45
|
export { defaultPassOnFeeMethod } from './billing/fees.js';
|
|
46
|
+
export { REACTION_CODE_POINTS, reactionGlyph, groupReactions, messageTime, isChatUnread, } from './chat.js';
|
|
47
|
+
export type { ReactionGroup } from './chat.js';
|
|
46
48
|
export { reverseGeocode } from './geocode.js';
|
|
47
49
|
export { fetchCensusFeatures } from './census.js';
|
|
48
50
|
export { getDegradedServices } from './serviceStatus.js';
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,7 @@ import './client/hooks/timecards.js';
|
|
|
39
39
|
import './client/hooks/waivers.js';
|
|
40
40
|
import './client/hooks/email.js';
|
|
41
41
|
export { defaultPassOnFeeMethod } from './billing/fees.js';
|
|
42
|
+
export { REACTION_CODE_POINTS, reactionGlyph, groupReactions, messageTime, isChatUnread, } from './chat.js';
|
|
42
43
|
export { reverseGeocode } from './geocode.js';
|
|
43
44
|
export { fetchCensusFeatures } from './census.js';
|
|
44
45
|
export { getDegradedServices } from './serviceStatus.js';
|
|
@@ -2,6 +2,9 @@ import { Friendship } from './Friendship.js';
|
|
|
2
2
|
export interface MemberState {
|
|
3
3
|
/** The participant's user id. */
|
|
4
4
|
id: string;
|
|
5
|
+
/** Shown to fellow members even when the member list hides them. */
|
|
6
|
+
first_name?: string;
|
|
7
|
+
last_name?: string;
|
|
5
8
|
state: 'pending' | 'rejected' | 'typing' | 'present' | 'absent';
|
|
6
9
|
friendship: Friendship | null;
|
|
7
10
|
last_message_read_at: number | null;
|
package/dist/types/client.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ export interface SendNotificationVars {
|
|
|
72
72
|
body: CreateNotificationPayload;
|
|
73
73
|
/** Defaults to the current company. */
|
|
74
74
|
companyId?: string;
|
|
75
|
+
/** Resending with the same key never sends twice (see `useSendEmailMessage`). */
|
|
76
|
+
idempotencyKey?: string;
|
|
75
77
|
}
|
|
76
78
|
/** Variables of `useSendEmailMessage`. */
|
|
77
79
|
export interface SendEmailMessageVars {
|
|
@@ -81,6 +83,12 @@ export interface SendEmailMessageVars {
|
|
|
81
83
|
requestId?: string;
|
|
82
84
|
/** Attach this proposal's PDF (rendered server-side). */
|
|
83
85
|
proposalId?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Any unique string (e.g. a UUID) kept with the message: resending with
|
|
88
|
+
* the same key replays the first send's result instead of emailing
|
|
89
|
+
* again, so a send can be retried after a lost response.
|
|
90
|
+
*/
|
|
91
|
+
idempotencyKey?: string;
|
|
84
92
|
}
|
|
85
93
|
/** Variables of `useSendBillEmail`. */
|
|
86
94
|
export interface SendBillEmailVars {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AVRO_JS_VERSION = "1.6.6-
|
|
1
|
+
export declare const AVRO_JS_VERSION = "1.6.6-rc19";
|
package/dist/version.js
CHANGED