@hadoku/rooms-protocol 0.45.104 → 0.45.106

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.
@@ -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
@@ -15,4 +15,5 @@ export * from './match-channel.js';
15
15
  export * from './avatars.js';
16
16
  export * from './session.js';
17
17
  export * from './feed.js';
18
+ export * from './chat-reactions.js';
18
19
  //# sourceMappingURL=index.d.ts.map
@@ -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
@@ -15,3 +15,4 @@ export * from './match-channel.js';
15
15
  export * from './avatars.js';
16
16
  export * from './session.js';
17
17
  export * from './feed.js';
18
+ export * from './chat-reactions.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/rooms-protocol",
3
- "version": "0.45.104",
4
- "gitHead": "43ca2d92541758f8319cc7180e0df935dd3e8525",
3
+ "version": "0.45.106",
4
+ "gitHead": "a03ad7ed8c879811e1818bad820593c37398dd2e",
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.",