@wtfalch/chat 0.10.0 → 0.11.0
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 +4 -0
- package/dist/chat/client.js +28 -4
- package/dist/chat/react/MessageRow.d.ts +4 -1
- package/dist/chat/react/MessageRow.js +6 -4
- package/dist/chat/types.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,10 @@ Team chat, on Matrix. Mirrors [`@wtfalch/email`](https://github.com/wtfalch/emai
|
|
|
4
4
|
shape: a client the agora gives a way to get a token, a React section built on
|
|
5
5
|
it.
|
|
6
6
|
|
|
7
|
+
## Breaking in 0.11.0
|
|
8
|
+
|
|
9
|
+
- `ChatTimelineEvent` has two new required fields: `viaAssistant` (`string | null`) and `undecryptable` (`boolean`). Code that builds a `ChatTimelineEvent` by hand must set them, for example `viaAssistant: null` and `undecryptable: false`.
|
|
10
|
+
|
|
7
11
|
## Breaking in 0.10.0
|
|
8
12
|
|
|
9
13
|
- `stop()` returns `Promise<void>` instead of `void`. It settles once every store the client built is destroyed, and it never rejects. A hand-written `ChatClient` with `stop: () => {}` no longer compiles; return a resolved promise.
|
package/dist/chat/client.js
CHANGED
|
@@ -862,6 +862,14 @@ export function createChatClient(options) {
|
|
|
862
862
|
for (const listener of timelineListeners.get(roomId) ?? [])
|
|
863
863
|
listener();
|
|
864
864
|
}
|
|
865
|
+
/** An event finished decrypting, or failed to: the row appears (or
|
|
866
|
+
* changes) without waiting for a sync. Removed with the client's other
|
|
867
|
+
* listeners by `removeAllListeners`. */
|
|
868
|
+
function onEventDecrypted(event) {
|
|
869
|
+
const roomId = event.getRoomId();
|
|
870
|
+
if (roomId)
|
|
871
|
+
notifyTimeline(roomId);
|
|
872
|
+
}
|
|
865
873
|
/** `RoomEvent.Timeline` (a page landing, a new event arriving) and
|
|
866
874
|
* `RoomEvent.LocalEchoUpdated` (an optimistic send's status changing) are
|
|
867
875
|
* both re-emitted onto the client itself for every room (`sync.ts`'s
|
|
@@ -1016,19 +1024,30 @@ export function createChatClient(options) {
|
|
|
1016
1024
|
* room's own state -- which is out of this ticket's scope (chat plan
|
|
1017
1025
|
* section 9). */
|
|
1018
1026
|
function toTimelineEvent(event, room, inThread) {
|
|
1019
|
-
|
|
1027
|
+
const encrypted = event.getWireType() === EventType.RoomMessageEncrypted;
|
|
1028
|
+
// Still decrypting: shown once `MatrixEventEvent.Decrypted` fires.
|
|
1029
|
+
if (encrypted && event.isBeingDecrypted())
|
|
1030
|
+
return undefined;
|
|
1031
|
+
const undecryptable = encrypted &&
|
|
1032
|
+
(event.isDecryptionFailure() || event.getType() === EventType.RoomMessageEncrypted);
|
|
1033
|
+
if (!undecryptable && event.getType() !== EventType.RoomMessage)
|
|
1020
1034
|
return undefined;
|
|
1021
1035
|
if (event.isRelation(RelationType.Replace))
|
|
1022
1036
|
return undefined;
|
|
1037
|
+
if (event.isRelation(RelationType.Annotation))
|
|
1038
|
+
return undefined;
|
|
1023
1039
|
const id = event.getId();
|
|
1024
1040
|
const senderId = event.getSender();
|
|
1025
1041
|
if (!id || !senderId)
|
|
1026
1042
|
return undefined;
|
|
1027
1043
|
const content = event.getContent();
|
|
1028
|
-
const body = typeof content.body === 'string' ? content.body : '';
|
|
1029
|
-
const formattedBody =
|
|
1044
|
+
const body = !undecryptable && typeof content.body === 'string' ? content.body : '';
|
|
1045
|
+
const formattedBody = !undecryptable &&
|
|
1046
|
+
content.format === 'org.matrix.custom.html' &&
|
|
1047
|
+
typeof content.formatted_body === 'string'
|
|
1030
1048
|
? content.formatted_body
|
|
1031
1049
|
: null;
|
|
1050
|
+
const via = content['com.wtfalch.via'];
|
|
1032
1051
|
return {
|
|
1033
1052
|
id,
|
|
1034
1053
|
senderId,
|
|
@@ -1042,9 +1061,11 @@ export function createChatClient(options) {
|
|
|
1042
1061
|
mentionsMe: mentionsMe(event),
|
|
1043
1062
|
edited: event.replacingEventId() !== undefined,
|
|
1044
1063
|
deleted: event.isRedacted(),
|
|
1045
|
-
attachment: event.isRedacted() ? null : toAttachment(event),
|
|
1064
|
+
attachment: event.isRedacted() || undecryptable ? null : toAttachment(event),
|
|
1046
1065
|
upload: null,
|
|
1047
1066
|
mine: senderId === client?.getUserId(),
|
|
1067
|
+
viaAssistant: typeof via === 'string' && via !== '' ? via : null,
|
|
1068
|
+
undecryptable,
|
|
1048
1069
|
};
|
|
1049
1070
|
}
|
|
1050
1071
|
/** `event.status` is `null`/`undefined` once the real event has replaced
|
|
@@ -1527,6 +1548,8 @@ export function createChatClient(options) {
|
|
|
1527
1548
|
},
|
|
1528
1549
|
upload: { loaded: upload.loaded, total: upload.file.size },
|
|
1529
1550
|
mine: true,
|
|
1551
|
+
viaAssistant: null,
|
|
1552
|
+
undecryptable: false,
|
|
1530
1553
|
};
|
|
1531
1554
|
}
|
|
1532
1555
|
function uploadRows(room, threadId) {
|
|
@@ -2296,6 +2319,7 @@ export function createChatClient(options) {
|
|
|
2296
2319
|
created.on(ClientEvent.Sync, onSync);
|
|
2297
2320
|
created.on(RoomEvent.Timeline, onRoomTimelineChanged);
|
|
2298
2321
|
created.on(RoomEvent.LocalEchoUpdated, onRoomTimelineChanged);
|
|
2322
|
+
created.on(MatrixEventEvent.Decrypted, onEventDecrypted);
|
|
2299
2323
|
created.on(RoomEvent.Receipt, onRoomReceipt);
|
|
2300
2324
|
created.on(RoomEvent.AccountData, watchForDraft);
|
|
2301
2325
|
created.on(UserEvent.Presence, onUserPresence);
|
|
@@ -11,6 +11,9 @@ export type MessageRowProps = {
|
|
|
11
11
|
/** The message the reader was sent here to find, marked so they can see
|
|
12
12
|
* which one it is. */
|
|
13
13
|
highlighted?: boolean;
|
|
14
|
+
/** Given, a locked message (one this client holds no key for) offers
|
|
15
|
+
* "Verify to read", and this is called on press. */
|
|
16
|
+
onVerify?: () => void;
|
|
14
17
|
};
|
|
15
18
|
/** One `m.room.message` event: sender, time, body, and -- pending or failed
|
|
16
19
|
* -- its own optimistic-send state. `formatted_body` is a stranger's HTML,
|
|
@@ -18,4 +21,4 @@ export type MessageRowProps = {
|
|
|
18
21
|
* ticket #15's safety requirement); plain `body` needs no such pass and is
|
|
19
22
|
* drawn as text, with `chat.css`'s `white-space: pre-wrap` carrying its
|
|
20
23
|
* own line breaks. */
|
|
21
|
-
export declare function MessageRow({ event, client, roomId, onOpenThread, highlighted }: MessageRowProps): import("react").JSX.Element;
|
|
24
|
+
export declare function MessageRow({ event, client, roomId, onOpenThread, highlighted, onVerify, }: MessageRowProps): import("react").JSX.Element;
|
|
@@ -14,7 +14,7 @@ const QUICK_REACTIONS = ['👍', '🎉', '👀', '❤️', '😄', '🤔'];
|
|
|
14
14
|
* ticket #15's safety requirement); plain `body` needs no such pass and is
|
|
15
15
|
* drawn as text, with `chat.css`'s `white-space: pre-wrap` carrying its
|
|
16
16
|
* own line breaks. */
|
|
17
|
-
export function MessageRow({ event, client, roomId, onOpenThread, highlighted }) {
|
|
17
|
+
export function MessageRow({ event, client, roomId, onOpenThread, highlighted, onVerify, }) {
|
|
18
18
|
const time = new Date(event.ts).toLocaleTimeString(undefined, {
|
|
19
19
|
hour: 'numeric',
|
|
20
20
|
minute: '2-digit',
|
|
@@ -32,7 +32,7 @@ export function MessageRow({ event, client, roomId, onOpenThread, highlighted })
|
|
|
32
32
|
/** Only your own, and only once it is really sent: Matrix ignores an
|
|
33
33
|
* `m.replace` from anybody else, and an event still in flight has no id
|
|
34
34
|
* on the server to replace or redact yet. */
|
|
35
|
-
const own = event.mine && event.status === 'sent' && !event.deleted;
|
|
35
|
+
const own = event.mine && event.status === 'sent' && !event.deleted && !event.undecryptable;
|
|
36
36
|
function react(key) {
|
|
37
37
|
setPicking(false);
|
|
38
38
|
client.toggleReaction(roomId, event.id, key).catch(() => {
|
|
@@ -41,7 +41,7 @@ export function MessageRow({ event, client, roomId, onOpenThread, highlighted })
|
|
|
41
41
|
// would be this component's own guess about a count it does not own.
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
return (_jsxs("div", { className: `chat-message${event.status !== 'sent' ? ` is-${event.status}` : ''}${highlighted ? ' is-here' : ''}${event.mentionsMe ? ' is-mentioned' : ''}`, "data-event-id": event.id, "data-status": event.status, children: [_jsxs("div", { className: "chat-message-meta", children: [_jsx("span", { className: "chat-message-sender", children: event.senderName }), _jsx("time", { className: "chat-message-time", dateTime: new Date(event.ts).toISOString(), children: time }), event.edited && !event.deleted && _jsx("span", { className: "chat-message-edited", children: "edited" })] }), event.deleted ? (
|
|
44
|
+
return (_jsxs("div", { className: `chat-message${event.status !== 'sent' ? ` is-${event.status}` : ''}${highlighted ? ' is-here' : ''}${event.mentionsMe ? ' is-mentioned' : ''}`, "data-event-id": event.id, "data-status": event.status, children: [_jsxs("div", { className: "chat-message-meta", children: [_jsx("span", { className: "chat-message-sender", children: event.senderName }), _jsx("time", { className: "chat-message-time", dateTime: new Date(event.ts).toISOString(), children: time }), event.edited && !event.deleted && _jsx("span", { className: "chat-message-edited", children: "edited" })] }), event.undecryptable ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "chat-message-body is-undecryptable", children: "Locked message" }), onVerify && (_jsx(Button, { kind: "ghost", size: "sm", onPress: onVerify, children: "Verify to read" }))] })) : event.deleted ? (
|
|
45
45
|
// The row stays where it was. Dropping it would move every message
|
|
46
46
|
// under it while somebody is reading, and a thread hanging off this
|
|
47
47
|
// one still has to have something to hang from.
|
|
@@ -56,7 +56,8 @@ export function MessageRow({ event, client, roomId, onOpenThread, highlighted })
|
|
|
56
56
|
dangerouslySetInnerHTML: { __html: html } })) : event.attachment ? (
|
|
57
57
|
// A file names itself in its own row, so the body would say the
|
|
58
58
|
// same thing twice.
|
|
59
|
-
_jsx(AttachmentView, { attachment: event.attachment, client: client, roomId: roomId, upload: event.upload })) : (_jsx("div", { className: "chat-message-body", children: event.body })),
|
|
59
|
+
_jsx(AttachmentView, { attachment: event.attachment, client: client, roomId: roomId, upload: event.upload })) : (_jsx("div", { className: "chat-message-body", children: event.body })), !event.undecryptable &&
|
|
60
|
+
(event.reactions.length > 0 || (event.status === 'sent' && !event.deleted)) && (_jsxs("div", { className: "chat-reactions", children: [event.reactions.map((reaction) => (_jsx(ReactionPill, { reaction: reaction, onPress: react }, reaction.key))), event.status === 'sent' && !event.deleted && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "chat-react", onClick: () => setPicking((open) => !open), "aria-expanded": picking, children: "React" }), picking && (_jsx("span", { className: "chat-react-choices", children: QUICK_REACTIONS.map((key) => (_jsx("button", { type: "button", className: "chat-react-choice", onClick: () => react(key), "aria-label": `React with ${key}`, children: key }, key))) }))] })), own && !editing && !confirmingDelete && (_jsxs(_Fragment, { children: [!event.attachment && (_jsx("button", { type: "button", className: "chat-react", onClick: () => setEditing(true), children: "Edit" })), _jsx("button", { type: "button", className: "chat-react", onClick: () => setConfirmingDelete(true), children: "Delete" })] })), own && confirmingDelete && (
|
|
60
61
|
// Asked in the row rather than in a dialog: a redaction cannot
|
|
61
62
|
// be taken back, and a browser dialog would take the whole
|
|
62
63
|
// conversation away to ask one question.
|
|
@@ -66,6 +67,7 @@ export function MessageRow({ event, client, roomId, onOpenThread, highlighted })
|
|
|
66
67
|
// As above: the message stays, and sync says what is there.
|
|
67
68
|
});
|
|
68
69
|
}, children: "Delete" }), _jsx("button", { type: "button", className: "chat-react", onClick: () => setConfirmingDelete(false), children: "Keep" })] }))] })), onOpenThread &&
|
|
70
|
+
!event.undecryptable &&
|
|
69
71
|
(event.thread ? (
|
|
70
72
|
// Always drawn: a thread hanging off a message is something the
|
|
71
73
|
// reader needs to know is there, not an action they have to go
|
package/dist/chat/types.d.ts
CHANGED
|
@@ -268,6 +268,13 @@ export type ChatTimelineEvent = {
|
|
|
268
268
|
* anybody but the original sender, and moderating other people's
|
|
269
269
|
* messages is the manage app's (ticket #19's "not in this ticket"). */
|
|
270
270
|
readonly mine: boolean;
|
|
271
|
+
/** The assistant's name when an assistant sent this message for a person
|
|
272
|
+
* (`com.wtfalch.via` in the event's content), `null` otherwise. */
|
|
273
|
+
readonly viaAssistant: string | null;
|
|
274
|
+
/** `true` for an encrypted event this client holds no key for. `body` is
|
|
275
|
+
* `''` and `formattedBody` and `attachment` are `null`. `false`
|
|
276
|
+
* otherwise. */
|
|
277
|
+
readonly undecryptable: boolean;
|
|
271
278
|
};
|
|
272
279
|
/** The rest of what a send can carry, beyond the text itself. */
|
|
273
280
|
export type ChatSendOptions = {
|