@xmtp/browser-sdk 0.0.17 → 0.0.19
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 +2 -3
- package/dist/index.d.ts +186 -31
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/package.json +2 -2
- package/src/AsyncStream.ts +80 -0
- package/src/ClientWorkerClass.ts +28 -0
- package/src/Conversation.ts +55 -15
- package/src/Conversations.ts +107 -3
- package/src/WorkerClient.ts +2 -2
- package/src/WorkerConversation.ts +38 -16
- package/src/WorkerConversations.ts +89 -11
- package/src/types/clientEvents.ts +95 -10
- package/src/types/clientStreamEvents.ts +30 -0
- package/src/types/utils.ts +26 -0
- package/src/utils/conversions.ts +63 -18
- package/src/workers/client.ts +252 -20
package/src/Conversations.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { ConversationType, type ConsentState } from "@xmtp/wasm-bindings";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
import { AsyncStream, type StreamCallback } from "@/AsyncStream";
|
|
1
4
|
import type { Client } from "@/Client";
|
|
2
5
|
import { Conversation } from "@/Conversation";
|
|
3
6
|
import { DecodedMessage } from "@/DecodedMessage";
|
|
4
7
|
import type {
|
|
8
|
+
SafeConversation,
|
|
9
|
+
SafeCreateDmOptions,
|
|
5
10
|
SafeCreateGroupOptions,
|
|
6
11
|
SafeListConversationsOptions,
|
|
12
|
+
SafeMessage,
|
|
7
13
|
} from "@/utils/conversions";
|
|
8
14
|
|
|
9
15
|
export class Conversations {
|
|
@@ -17,8 +23,10 @@ export class Conversations {
|
|
|
17
23
|
return this.#client.sendMessage("syncConversations", undefined);
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
async syncAll() {
|
|
21
|
-
return this.#client.sendMessage("syncAllConversations",
|
|
26
|
+
async syncAll(consentStates?: ConsentState[]) {
|
|
27
|
+
return this.#client.sendMessage("syncAllConversations", {
|
|
28
|
+
consentStates,
|
|
29
|
+
});
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
async getConversationById(id: string) {
|
|
@@ -88,9 +96,31 @@ export class Conversations {
|
|
|
88
96
|
return new Conversation(this.#client, conversation.id, conversation);
|
|
89
97
|
}
|
|
90
98
|
|
|
91
|
-
async
|
|
99
|
+
async newGroupByInboxIds(
|
|
100
|
+
inboxIds: string[],
|
|
101
|
+
options?: SafeCreateGroupOptions,
|
|
102
|
+
) {
|
|
103
|
+
const conversation = await this.#client.sendMessage("newGroupByInboxIds", {
|
|
104
|
+
inboxIds,
|
|
105
|
+
options,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return new Conversation(this.#client, conversation.id, conversation);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async newDm(accountAddress: string, options?: SafeCreateDmOptions) {
|
|
92
112
|
const conversation = await this.#client.sendMessage("newDm", {
|
|
93
113
|
accountAddress,
|
|
114
|
+
options,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return new Conversation(this.#client, conversation.id, conversation);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async newDmByInboxId(inboxId: string, options?: SafeCreateDmOptions) {
|
|
121
|
+
const conversation = await this.#client.sendMessage("newDmByInboxId", {
|
|
122
|
+
inboxId,
|
|
123
|
+
options,
|
|
94
124
|
});
|
|
95
125
|
|
|
96
126
|
return new Conversation(this.#client, conversation.id, conversation);
|
|
@@ -99,4 +129,78 @@ export class Conversations {
|
|
|
99
129
|
async getHmacKeys() {
|
|
100
130
|
return this.#client.sendMessage("getHmacKeys", undefined);
|
|
101
131
|
}
|
|
132
|
+
|
|
133
|
+
async stream(
|
|
134
|
+
callback?: StreamCallback<Conversation>,
|
|
135
|
+
conversationType?: ConversationType,
|
|
136
|
+
) {
|
|
137
|
+
const streamId = v4();
|
|
138
|
+
const asyncStream = new AsyncStream<Conversation>();
|
|
139
|
+
const endStream = this.#client.handleStreamMessage<SafeConversation>(
|
|
140
|
+
streamId,
|
|
141
|
+
(error, value) => {
|
|
142
|
+
const conversation = value
|
|
143
|
+
? new Conversation(this.#client, value.id, value)
|
|
144
|
+
: undefined;
|
|
145
|
+
void asyncStream.callback(error, conversation);
|
|
146
|
+
void callback?.(error, conversation);
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
await this.#client.sendMessage("streamAllGroups", {
|
|
150
|
+
streamId,
|
|
151
|
+
conversationType,
|
|
152
|
+
});
|
|
153
|
+
asyncStream.onReturn = () => {
|
|
154
|
+
void this.#client.sendMessage("endStream", {
|
|
155
|
+
streamId,
|
|
156
|
+
});
|
|
157
|
+
endStream();
|
|
158
|
+
};
|
|
159
|
+
return asyncStream;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async streamGroups(callback?: StreamCallback<Conversation>) {
|
|
163
|
+
return this.stream(callback, ConversationType.Group);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async streamDms(callback?: StreamCallback<Conversation>) {
|
|
167
|
+
return this.stream(callback, ConversationType.Dm);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async streamAllMessages(
|
|
171
|
+
callback?: StreamCallback<DecodedMessage>,
|
|
172
|
+
conversationType?: ConversationType,
|
|
173
|
+
) {
|
|
174
|
+
const streamId = v4();
|
|
175
|
+
const asyncStream = new AsyncStream<DecodedMessage>();
|
|
176
|
+
const endStream = this.#client.handleStreamMessage<SafeMessage>(
|
|
177
|
+
streamId,
|
|
178
|
+
(error, value) => {
|
|
179
|
+
const decodedMessage = value
|
|
180
|
+
? new DecodedMessage(this.#client, value)
|
|
181
|
+
: undefined;
|
|
182
|
+
void asyncStream.callback(error, decodedMessage);
|
|
183
|
+
void callback?.(error, decodedMessage);
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
await this.#client.sendMessage("streamAllMessages", {
|
|
187
|
+
streamId,
|
|
188
|
+
conversationType,
|
|
189
|
+
});
|
|
190
|
+
asyncStream.onReturn = () => {
|
|
191
|
+
void this.#client.sendMessage("endStream", {
|
|
192
|
+
streamId,
|
|
193
|
+
});
|
|
194
|
+
endStream();
|
|
195
|
+
};
|
|
196
|
+
return asyncStream;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async streamAllGroupMessages(callback?: StreamCallback<DecodedMessage>) {
|
|
200
|
+
return this.streamAllMessages(callback, ConversationType.Group);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async streamAllDmMessages(callback?: StreamCallback<DecodedMessage>) {
|
|
204
|
+
return this.streamAllMessages(callback, ConversationType.Dm);
|
|
205
|
+
}
|
|
102
206
|
}
|
package/src/WorkerClient.ts
CHANGED
|
@@ -51,9 +51,9 @@ export class WorkerClient {
|
|
|
51
51
|
return this.#client.isRegistered;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
createInboxSignatureText() {
|
|
55
55
|
try {
|
|
56
|
-
return
|
|
56
|
+
return this.#client.createInboxSignatureText();
|
|
57
57
|
} catch {
|
|
58
58
|
return undefined;
|
|
59
59
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import {
|
|
2
|
+
MessageDisappearingSettings,
|
|
3
|
+
type ConsentState,
|
|
4
|
+
type Conversation,
|
|
5
|
+
type EncodedContent,
|
|
6
|
+
type GroupMember,
|
|
7
|
+
type Message,
|
|
8
|
+
type MetadataField,
|
|
9
|
+
type PermissionPolicy,
|
|
10
|
+
type PermissionUpdateType,
|
|
9
11
|
} from "@xmtp/wasm-bindings";
|
|
12
|
+
import { type StreamCallback } from "@/AsyncStream";
|
|
10
13
|
import {
|
|
11
14
|
fromSafeListMessagesOptions,
|
|
12
15
|
toSafeGroupMember,
|
|
@@ -53,14 +56,6 @@ export class WorkerConversation {
|
|
|
53
56
|
return this.#group.updateGroupDescription(description);
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
get pinnedFrameUrl() {
|
|
57
|
-
return this.#group.groupPinnedFrameUrl();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async updatePinnedFrameUrl(pinnedFrameUrl: string) {
|
|
61
|
-
return this.#group.updateGroupPinnedFrameUrl(pinnedFrameUrl);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
59
|
get isActive() {
|
|
65
60
|
return this.#group.isActive();
|
|
66
61
|
}
|
|
@@ -187,4 +182,31 @@ export class WorkerConversation {
|
|
|
187
182
|
dmPeerInboxId() {
|
|
188
183
|
return this.#group.dmPeerInboxId();
|
|
189
184
|
}
|
|
185
|
+
|
|
186
|
+
messageDisappearingSettings() {
|
|
187
|
+
return this.#group.messageDisappearingSettings();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async updateMessageDisappearingSettings(fromNs: bigint, inNs: bigint) {
|
|
191
|
+
const settings = new MessageDisappearingSettings(fromNs, inNs);
|
|
192
|
+
return this.#group.updateMessageDisappearingSettings(settings);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async removeMessageDisappearingSettings() {
|
|
196
|
+
return this.#group.removeMessageDisappearingSettings();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
isMessageDisappearingEnabled() {
|
|
200
|
+
return this.#group.isMessageDisappearingEnabled();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
stream(callback?: StreamCallback<Message>) {
|
|
204
|
+
const on_message = (message: Message) => {
|
|
205
|
+
void callback?.(null, message);
|
|
206
|
+
};
|
|
207
|
+
const on_error = (error: Error | null) => {
|
|
208
|
+
void callback?.(error, undefined);
|
|
209
|
+
};
|
|
210
|
+
return this.#group.stream({ on_message, on_error });
|
|
211
|
+
}
|
|
190
212
|
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import type { Conversation, Conversations } from "@xmtp/wasm-bindings";
|
|
2
1
|
import {
|
|
2
|
+
ConversationType,
|
|
3
|
+
type ConsentState,
|
|
4
|
+
type Conversation,
|
|
5
|
+
type ConversationListItem,
|
|
6
|
+
type Conversations,
|
|
7
|
+
type Message,
|
|
8
|
+
} from "@xmtp/wasm-bindings";
|
|
9
|
+
import type { StreamCallback } from "@/AsyncStream";
|
|
10
|
+
import {
|
|
11
|
+
fromSafeCreateDmOptions,
|
|
3
12
|
fromSafeCreateGroupOptions,
|
|
4
13
|
fromSafeListConversationsOptions,
|
|
5
14
|
type HmacKeys,
|
|
15
|
+
type SafeCreateDmOptions,
|
|
6
16
|
type SafeCreateGroupOptions,
|
|
7
17
|
type SafeListConversationsOptions,
|
|
8
18
|
} from "@/utils/conversions";
|
|
@@ -23,8 +33,8 @@ export class WorkerConversations {
|
|
|
23
33
|
return this.#conversations.sync();
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
async syncAll() {
|
|
27
|
-
return this.#conversations.syncAllConversations();
|
|
36
|
+
async syncAll(consentStates?: ConsentState[]) {
|
|
37
|
+
return this.#conversations.syncAllConversations(consentStates);
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
getConversationById(id: string) {
|
|
@@ -58,8 +68,10 @@ export class WorkerConversations {
|
|
|
58
68
|
list(options?: SafeListConversationsOptions) {
|
|
59
69
|
const groups = this.#conversations.list(
|
|
60
70
|
options ? fromSafeListConversationsOptions(options) : undefined,
|
|
61
|
-
) as
|
|
62
|
-
return groups.map(
|
|
71
|
+
) as ConversationListItem[];
|
|
72
|
+
return groups.map(
|
|
73
|
+
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
74
|
+
);
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
listGroups(
|
|
@@ -67,15 +79,19 @@ export class WorkerConversations {
|
|
|
67
79
|
) {
|
|
68
80
|
const groups = this.#conversations.listGroups(
|
|
69
81
|
options ? fromSafeListConversationsOptions(options) : undefined,
|
|
70
|
-
) as
|
|
71
|
-
return groups.map(
|
|
82
|
+
) as ConversationListItem[];
|
|
83
|
+
return groups.map(
|
|
84
|
+
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
85
|
+
);
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">) {
|
|
75
89
|
const groups = this.#conversations.listDms(
|
|
76
90
|
options ? fromSafeListConversationsOptions(options) : undefined,
|
|
77
|
-
) as
|
|
78
|
-
return groups.map(
|
|
91
|
+
) as ConversationListItem[];
|
|
92
|
+
return groups.map(
|
|
93
|
+
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
94
|
+
);
|
|
79
95
|
}
|
|
80
96
|
|
|
81
97
|
async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {
|
|
@@ -86,12 +102,74 @@ export class WorkerConversations {
|
|
|
86
102
|
return new WorkerConversation(this.#client, group);
|
|
87
103
|
}
|
|
88
104
|
|
|
89
|
-
async
|
|
90
|
-
|
|
105
|
+
async newGroupByInboxIds(
|
|
106
|
+
inboxIds: string[],
|
|
107
|
+
options?: SafeCreateGroupOptions,
|
|
108
|
+
) {
|
|
109
|
+
const group = await this.#conversations.createGroupByInboxIds(
|
|
110
|
+
inboxIds,
|
|
111
|
+
options ? fromSafeCreateGroupOptions(options) : undefined,
|
|
112
|
+
);
|
|
113
|
+
return new WorkerConversation(this.#client, group);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async newDm(accountAddress: string, options?: SafeCreateDmOptions) {
|
|
117
|
+
const group = await this.#conversations.createDm(
|
|
118
|
+
accountAddress,
|
|
119
|
+
options ? fromSafeCreateDmOptions(options) : undefined,
|
|
120
|
+
);
|
|
121
|
+
return new WorkerConversation(this.#client, group);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async newDmByInboxId(inboxId: string, options?: SafeCreateDmOptions) {
|
|
125
|
+
const group = await this.#conversations.createDmByInboxId(
|
|
126
|
+
inboxId,
|
|
127
|
+
options ? fromSafeCreateDmOptions(options) : undefined,
|
|
128
|
+
);
|
|
91
129
|
return new WorkerConversation(this.#client, group);
|
|
92
130
|
}
|
|
93
131
|
|
|
94
132
|
getHmacKeys() {
|
|
95
133
|
return this.#conversations.getHmacKeys() as HmacKeys;
|
|
96
134
|
}
|
|
135
|
+
|
|
136
|
+
stream(
|
|
137
|
+
callback?: StreamCallback<Conversation>,
|
|
138
|
+
conversationType?: ConversationType,
|
|
139
|
+
) {
|
|
140
|
+
const on_conversation = (conversation: Conversation) => {
|
|
141
|
+
void callback?.(null, conversation);
|
|
142
|
+
};
|
|
143
|
+
const on_error = (error: Error | null) => {
|
|
144
|
+
void callback?.(error, undefined);
|
|
145
|
+
};
|
|
146
|
+
return this.#conversations.stream(
|
|
147
|
+
{ on_conversation, on_error },
|
|
148
|
+
conversationType,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
streamGroups(callback?: StreamCallback<Conversation>) {
|
|
153
|
+
return this.#conversations.stream(callback, ConversationType.Group);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
streamDms(callback?: StreamCallback<Conversation>) {
|
|
157
|
+
return this.#conversations.stream(callback, ConversationType.Dm);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
streamAllMessages(
|
|
161
|
+
callback?: StreamCallback<Message>,
|
|
162
|
+
conversationType?: ConversationType,
|
|
163
|
+
) {
|
|
164
|
+
const on_message = (message: Message) => {
|
|
165
|
+
void callback?.(null, message);
|
|
166
|
+
};
|
|
167
|
+
const on_error = (error: Error | null) => {
|
|
168
|
+
void callback?.(error, undefined);
|
|
169
|
+
};
|
|
170
|
+
return this.#conversations.streamAllMessages(
|
|
171
|
+
{ on_message, on_error },
|
|
172
|
+
conversationType,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
97
175
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ConsentEntityType,
|
|
3
3
|
ConsentState,
|
|
4
|
+
ConversationType,
|
|
4
5
|
MetadataField,
|
|
5
6
|
PermissionPolicy,
|
|
6
7
|
PermissionUpdateType,
|
|
@@ -19,6 +20,7 @@ import type {
|
|
|
19
20
|
import type {
|
|
20
21
|
SafeConsent,
|
|
21
22
|
SafeConversation,
|
|
23
|
+
SafeCreateDmOptions,
|
|
22
24
|
SafeCreateGroupOptions,
|
|
23
25
|
SafeEncodedContent,
|
|
24
26
|
SafeGroupMember,
|
|
@@ -27,9 +29,21 @@ import type {
|
|
|
27
29
|
SafeListConversationsOptions,
|
|
28
30
|
SafeListMessagesOptions,
|
|
29
31
|
SafeMessage,
|
|
32
|
+
SafeMessageDisappearingSettings,
|
|
30
33
|
} from "@/utils/conversions";
|
|
31
34
|
|
|
32
35
|
export type ClientEvents =
|
|
36
|
+
/**
|
|
37
|
+
* Stream actions
|
|
38
|
+
*/
|
|
39
|
+
| {
|
|
40
|
+
action: "endStream";
|
|
41
|
+
id: string;
|
|
42
|
+
result: undefined;
|
|
43
|
+
data: {
|
|
44
|
+
streamId: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
33
47
|
/**
|
|
34
48
|
* Client actions
|
|
35
49
|
*/
|
|
@@ -257,12 +271,31 @@ export type ClientEvents =
|
|
|
257
271
|
options?: SafeCreateGroupOptions;
|
|
258
272
|
};
|
|
259
273
|
}
|
|
274
|
+
| {
|
|
275
|
+
action: "newGroupByInboxIds";
|
|
276
|
+
id: string;
|
|
277
|
+
result: SafeConversation;
|
|
278
|
+
data: {
|
|
279
|
+
inboxIds: string[];
|
|
280
|
+
options?: SafeCreateGroupOptions;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
260
283
|
| {
|
|
261
284
|
action: "newDm";
|
|
262
285
|
id: string;
|
|
263
286
|
result: SafeConversation;
|
|
264
287
|
data: {
|
|
265
288
|
accountAddress: string;
|
|
289
|
+
options?: SafeCreateDmOptions;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
| {
|
|
293
|
+
action: "newDmByInboxId";
|
|
294
|
+
id: string;
|
|
295
|
+
result: SafeConversation;
|
|
296
|
+
data: {
|
|
297
|
+
inboxId: string;
|
|
298
|
+
options?: SafeCreateDmOptions;
|
|
266
299
|
};
|
|
267
300
|
}
|
|
268
301
|
| {
|
|
@@ -275,7 +308,9 @@ export type ClientEvents =
|
|
|
275
308
|
action: "syncAllConversations";
|
|
276
309
|
id: string;
|
|
277
310
|
result: undefined;
|
|
278
|
-
data:
|
|
311
|
+
data: {
|
|
312
|
+
consentStates?: ConsentState[];
|
|
313
|
+
};
|
|
279
314
|
}
|
|
280
315
|
| {
|
|
281
316
|
action: "getHmacKeys";
|
|
@@ -283,6 +318,24 @@ export type ClientEvents =
|
|
|
283
318
|
result: SafeHmacKeys;
|
|
284
319
|
data: undefined;
|
|
285
320
|
}
|
|
321
|
+
| {
|
|
322
|
+
action: "streamAllGroups";
|
|
323
|
+
id: string;
|
|
324
|
+
result: undefined;
|
|
325
|
+
data: {
|
|
326
|
+
streamId: string;
|
|
327
|
+
conversationType?: ConversationType;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
| {
|
|
331
|
+
action: "streamAllMessages";
|
|
332
|
+
id: string;
|
|
333
|
+
result: undefined;
|
|
334
|
+
data: {
|
|
335
|
+
streamId: string;
|
|
336
|
+
conversationType?: ConversationType;
|
|
337
|
+
};
|
|
338
|
+
}
|
|
286
339
|
/**
|
|
287
340
|
* Group actions
|
|
288
341
|
*/
|
|
@@ -470,15 +523,6 @@ export type ClientEvents =
|
|
|
470
523
|
imageUrl: string;
|
|
471
524
|
};
|
|
472
525
|
}
|
|
473
|
-
| {
|
|
474
|
-
action: "updateGroupPinnedFrameUrl";
|
|
475
|
-
id: string;
|
|
476
|
-
result: undefined;
|
|
477
|
-
data: {
|
|
478
|
-
id: string;
|
|
479
|
-
pinnedFrameUrl: string;
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
526
|
| {
|
|
483
527
|
action: "getGroupConsentState";
|
|
484
528
|
id: string;
|
|
@@ -522,6 +566,47 @@ export type ClientEvents =
|
|
|
522
566
|
data: {
|
|
523
567
|
id: string;
|
|
524
568
|
};
|
|
569
|
+
}
|
|
570
|
+
| {
|
|
571
|
+
action: "getGroupMessageDisappearingSettings";
|
|
572
|
+
id: string;
|
|
573
|
+
result: SafeMessageDisappearingSettings | undefined;
|
|
574
|
+
data: {
|
|
575
|
+
id: string;
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
| {
|
|
579
|
+
action: "updateGroupMessageDisappearingSettings";
|
|
580
|
+
id: string;
|
|
581
|
+
result: undefined;
|
|
582
|
+
data: SafeMessageDisappearingSettings & {
|
|
583
|
+
id: string;
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
| {
|
|
587
|
+
action: "removeGroupMessageDisappearingSettings";
|
|
588
|
+
id: string;
|
|
589
|
+
result: undefined;
|
|
590
|
+
data: {
|
|
591
|
+
id: string;
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
| {
|
|
595
|
+
action: "isGroupMessageDisappearingEnabled";
|
|
596
|
+
id: string;
|
|
597
|
+
result: boolean;
|
|
598
|
+
data: {
|
|
599
|
+
id: string;
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
| {
|
|
603
|
+
action: "streamGroupMessages";
|
|
604
|
+
id: string;
|
|
605
|
+
result: undefined;
|
|
606
|
+
data: {
|
|
607
|
+
groupId: string;
|
|
608
|
+
streamId: string;
|
|
609
|
+
};
|
|
525
610
|
};
|
|
526
611
|
|
|
527
612
|
export type ClientEventsActions = ClientEvents["action"];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
StreamEventsClientPostMessageData,
|
|
3
|
+
StreamEventsErrorData,
|
|
4
|
+
StreamEventsResult,
|
|
5
|
+
} from "@/types";
|
|
6
|
+
import type { SafeConversation, SafeMessage } from "@/utils/conversions";
|
|
7
|
+
|
|
8
|
+
export type ClientStreamEvents =
|
|
9
|
+
| {
|
|
10
|
+
type: "message";
|
|
11
|
+
streamId: string;
|
|
12
|
+
result: SafeMessage | undefined;
|
|
13
|
+
}
|
|
14
|
+
| {
|
|
15
|
+
type: "group";
|
|
16
|
+
streamId: string;
|
|
17
|
+
result: SafeConversation | undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ClientStreamEventsTypes = ClientStreamEvents["type"];
|
|
21
|
+
|
|
22
|
+
export type ClientStreamEventsResult<A extends ClientStreamEventsTypes> =
|
|
23
|
+
StreamEventsResult<ClientStreamEvents, A>;
|
|
24
|
+
|
|
25
|
+
export type ClientStreamEventsWorkerPostMessageData<
|
|
26
|
+
A extends ClientStreamEventsTypes,
|
|
27
|
+
> = StreamEventsClientPostMessageData<ClientStreamEvents, A>;
|
|
28
|
+
|
|
29
|
+
export type ClientStreamEventsErrorData =
|
|
30
|
+
StreamEventsErrorData<ClientStreamEvents>;
|
package/src/types/utils.ts
CHANGED
|
@@ -44,3 +44,29 @@ export type EventsErrorData<Events extends GenericEvent> = {
|
|
|
44
44
|
action: Events["action"];
|
|
45
45
|
error: string;
|
|
46
46
|
};
|
|
47
|
+
|
|
48
|
+
export type GenericStreamEvent = {
|
|
49
|
+
type: string;
|
|
50
|
+
streamId: string;
|
|
51
|
+
result: unknown;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type StreamEventsClientMessageData<Events extends GenericStreamEvent> = {
|
|
55
|
+
[Type in Events["type"]]: Omit<Extract<Events, { type: Type }>, "result">;
|
|
56
|
+
}[Events["type"]];
|
|
57
|
+
|
|
58
|
+
export type StreamEventsResult<
|
|
59
|
+
Events extends GenericStreamEvent,
|
|
60
|
+
Type extends Events["type"],
|
|
61
|
+
> = Extract<Events, { type: Type }>["result"];
|
|
62
|
+
|
|
63
|
+
export type StreamEventsClientPostMessageData<
|
|
64
|
+
Events extends GenericStreamEvent,
|
|
65
|
+
Type extends Events["type"],
|
|
66
|
+
> = Extract<Events, { type: Type }>;
|
|
67
|
+
|
|
68
|
+
export type StreamEventsErrorData<Events extends GenericStreamEvent> = {
|
|
69
|
+
streamId: string;
|
|
70
|
+
type: Events["type"];
|
|
71
|
+
error: string;
|
|
72
|
+
};
|