@hadoku/rooms-protocol 0.45.104 → 0.45.105
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-reactions.d.ts +21 -0
- package/dist/chat-reactions.d.ts.map +1 -0
- package/dist/chat-reactions.js +30 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reaction rule, shared by the server that records reactions and the
|
|
3
|
+
* client that shows its own toggle before the server answers (optimistic). One
|
|
4
|
+
* implementation, so the two cannot disagree about what a toggle does.
|
|
5
|
+
*/
|
|
6
|
+
/** Distinct emoji one message may carry (Discord's own cap is 20). */
|
|
7
|
+
export declare const CHAT_MAX_REACTIONS = 20;
|
|
8
|
+
/** Who reacted with one emoji, in the order they did. `by` holds reactor
|
|
9
|
+
* handles (a participant handle, or the connection id for a sender with
|
|
10
|
+
* none) — the same ids `author` already puts on the wire, never a name. */
|
|
11
|
+
export interface ChatReaction {
|
|
12
|
+
emoji: string;
|
|
13
|
+
by: string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `reactions` with `handle`'s `emoji` added (`on`) or removed, or null when
|
|
17
|
+
* nothing changes (already there, not there, or a new emoji past the cap).
|
|
18
|
+
* Pure; the order is first-reacted, as Discord shows it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function applyReaction(reactions: ChatReaction[] | undefined, emoji: string, handle: string, on: boolean): ChatReaction[] | null;
|
|
21
|
+
//# sourceMappingURL=chat-reactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-reactions.d.ts","sourceRoot":"","sources":["../src/chat-reactions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,sEAAsE;AACtE,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC;;4EAE4E;AAC5E,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,EAAE,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,YAAY,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,GAAG,YAAY,EAAE,GAAG,IAAI,CActI"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reaction rule, shared by the server that records reactions and the
|
|
3
|
+
* client that shows its own toggle before the server answers (optimistic). One
|
|
4
|
+
* implementation, so the two cannot disagree about what a toggle does.
|
|
5
|
+
*/
|
|
6
|
+
/** Distinct emoji one message may carry (Discord's own cap is 20). */
|
|
7
|
+
export const CHAT_MAX_REACTIONS = 20;
|
|
8
|
+
/**
|
|
9
|
+
* `reactions` with `handle`'s `emoji` added (`on`) or removed, or null when
|
|
10
|
+
* nothing changes (already there, not there, or a new emoji past the cap).
|
|
11
|
+
* Pure; the order is first-reacted, as Discord shows it.
|
|
12
|
+
*/
|
|
13
|
+
export function applyReaction(reactions, emoji, handle, on) {
|
|
14
|
+
const list = reactions ?? [];
|
|
15
|
+
const at = list.findIndex((r) => r.emoji === emoji);
|
|
16
|
+
if (on) {
|
|
17
|
+
if (at >= 0) {
|
|
18
|
+
if (list[at].by.includes(handle))
|
|
19
|
+
return null;
|
|
20
|
+
return list.map((r, i) => (i === at ? { emoji, by: [...r.by, handle] } : r));
|
|
21
|
+
}
|
|
22
|
+
if (list.length >= CHAT_MAX_REACTIONS)
|
|
23
|
+
return null;
|
|
24
|
+
return [...list, { emoji, by: [handle] }];
|
|
25
|
+
}
|
|
26
|
+
if (at < 0 || !list[at].by.includes(handle))
|
|
27
|
+
return null;
|
|
28
|
+
const by = list[at].by.filter((h) => h !== handle);
|
|
29
|
+
return by.length ? list.map((r, i) => (i === at ? { emoji, by } : r)) : list.filter((_, i) => i !== at);
|
|
30
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/rooms-protocol",
|
|
3
|
-
"version": "0.45.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.45.105",
|
|
4
|
+
"gitHead": "b286195549147e8ed759e73ad0a9f249e8e7cae8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Room, identity and seating protocol — the wire contract shared by rooms-server and rooms-client.",
|