@gakr-gakr/matrix 0.1.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/CHANGELOG.md +285 -0
- package/SPEC-SUPPORT.md +116 -0
- package/api.ts +38 -0
- package/auth-presence.ts +56 -0
- package/autobot.plugin.json +28 -0
- package/channel-plugin-api.ts +3 -0
- package/cli-metadata.ts +11 -0
- package/contract-api.ts +17 -0
- package/doctor-contract-api.ts +1 -0
- package/helper-api.ts +3 -0
- package/index.ts +55 -0
- package/package.json +101 -0
- package/plugin-entry.handlers.runtime.ts +1 -0
- package/runtime-api.ts +72 -0
- package/runtime-heavy-api.ts +1 -0
- package/runtime-setter-api.ts +3 -0
- package/secret-contract-api.ts +5 -0
- package/setup-entry.ts +17 -0
- package/setup-plugin-api.ts +3 -0
- package/src/account-selection.ts +223 -0
- package/src/actions.ts +346 -0
- package/src/approval-auth.ts +25 -0
- package/src/approval-handler.runtime.ts +595 -0
- package/src/approval-ids.ts +6 -0
- package/src/approval-native.ts +348 -0
- package/src/approval-reaction-auth.ts +45 -0
- package/src/approval-reactions.ts +313 -0
- package/src/auth-precedence.ts +61 -0
- package/src/channel-account-paths.ts +97 -0
- package/src/channel.runtime.ts +17 -0
- package/src/channel.setup.ts +48 -0
- package/src/channel.ts +667 -0
- package/src/cli-metadata.ts +19 -0
- package/src/cli.ts +2298 -0
- package/src/config-adapter.ts +41 -0
- package/src/config-schema.ts +159 -0
- package/src/config-ui-hints.ts +56 -0
- package/src/directory-live.ts +238 -0
- package/src/doctor-contract.ts +287 -0
- package/src/doctor.ts +262 -0
- package/src/env-vars.ts +92 -0
- package/src/exec-approval-resolver.ts +23 -0
- package/src/exec-approvals.ts +293 -0
- package/src/group-mentions.ts +41 -0
- package/src/legacy-crypto-inspector-availability.ts +60 -0
- package/src/legacy-crypto.ts +531 -0
- package/src/legacy-state.ts +156 -0
- package/src/matrix/account-config.ts +175 -0
- package/src/matrix/accounts.ts +194 -0
- package/src/matrix/actions/client.ts +31 -0
- package/src/matrix/actions/devices.ts +34 -0
- package/src/matrix/actions/limits.ts +6 -0
- package/src/matrix/actions/messages.ts +129 -0
- package/src/matrix/actions/pins.ts +63 -0
- package/src/matrix/actions/polls.ts +109 -0
- package/src/matrix/actions/profile.ts +37 -0
- package/src/matrix/actions/reactions.ts +59 -0
- package/src/matrix/actions/room.ts +71 -0
- package/src/matrix/actions/summary.ts +88 -0
- package/src/matrix/actions/types.ts +63 -0
- package/src/matrix/actions/verification.ts +589 -0
- package/src/matrix/actions.ts +37 -0
- package/src/matrix/active-client.ts +26 -0
- package/src/matrix/async-lock.ts +18 -0
- package/src/matrix/backup-health.ts +124 -0
- package/src/matrix/client/config-runtime-api.ts +9 -0
- package/src/matrix/client/config-secret-input.runtime.ts +1 -0
- package/src/matrix/client/config.ts +853 -0
- package/src/matrix/client/create-client.ts +105 -0
- package/src/matrix/client/env-auth.ts +95 -0
- package/src/matrix/client/file-sync-store.ts +289 -0
- package/src/matrix/client/logging.ts +140 -0
- package/src/matrix/client/migration-snapshot.runtime.ts +1 -0
- package/src/matrix/client/private-network-host.ts +1 -0
- package/src/matrix/client/runtime.ts +4 -0
- package/src/matrix/client/shared.ts +316 -0
- package/src/matrix/client/storage.ts +543 -0
- package/src/matrix/client/types.ts +50 -0
- package/src/matrix/client/url-validation.ts +76 -0
- package/src/matrix/client-bootstrap.ts +173 -0
- package/src/matrix/client.ts +23 -0
- package/src/matrix/config-paths.ts +31 -0
- package/src/matrix/config-update.ts +292 -0
- package/src/matrix/credentials-read.ts +207 -0
- package/src/matrix/credentials-write.runtime.ts +35 -0
- package/src/matrix/credentials.ts +95 -0
- package/src/matrix/deps.ts +309 -0
- package/src/matrix/device-health.ts +31 -0
- package/src/matrix/direct-management.ts +349 -0
- package/src/matrix/direct-room.ts +128 -0
- package/src/matrix/draft-stream.ts +225 -0
- package/src/matrix/encryption-guidance.ts +24 -0
- package/src/matrix/errors.ts +21 -0
- package/src/matrix/format.ts +426 -0
- package/src/matrix/legacy-crypto-inspector.ts +95 -0
- package/src/matrix/media-errors.ts +20 -0
- package/src/matrix/media-text.ts +162 -0
- package/src/matrix/monitor/access-state.ts +145 -0
- package/src/matrix/monitor/ack-config.ts +27 -0
- package/src/matrix/monitor/allowlist.ts +92 -0
- package/src/matrix/monitor/auto-join.ts +86 -0
- package/src/matrix/monitor/config.ts +569 -0
- package/src/matrix/monitor/context-summary.ts +43 -0
- package/src/matrix/monitor/direct.ts +296 -0
- package/src/matrix/monitor/events.ts +397 -0
- package/src/matrix/monitor/handler.ts +2271 -0
- package/src/matrix/monitor/inbound-dedupe.ts +267 -0
- package/src/matrix/monitor/index.ts +540 -0
- package/src/matrix/monitor/legacy-crypto-restore.ts +139 -0
- package/src/matrix/monitor/location.ts +108 -0
- package/src/matrix/monitor/media.ts +119 -0
- package/src/matrix/monitor/mentions.ts +256 -0
- package/src/matrix/monitor/reaction-events.ts +197 -0
- package/src/matrix/monitor/recent-invite.ts +30 -0
- package/src/matrix/monitor/replies.ts +136 -0
- package/src/matrix/monitor/reply-context.ts +92 -0
- package/src/matrix/monitor/room-history.ts +301 -0
- package/src/matrix/monitor/room-info.ts +126 -0
- package/src/matrix/monitor/rooms.ts +52 -0
- package/src/matrix/monitor/route.ts +179 -0
- package/src/matrix/monitor/runtime-api.ts +28 -0
- package/src/matrix/monitor/startup-verification.ts +237 -0
- package/src/matrix/monitor/startup.ts +218 -0
- package/src/matrix/monitor/status.ts +120 -0
- package/src/matrix/monitor/sync-lifecycle.ts +91 -0
- package/src/matrix/monitor/task-runner.ts +38 -0
- package/src/matrix/monitor/test-events.ts +21 -0
- package/src/matrix/monitor/thread-context.ts +108 -0
- package/src/matrix/monitor/threads.ts +85 -0
- package/src/matrix/monitor/types.ts +30 -0
- package/src/matrix/monitor/verification-events.ts +643 -0
- package/src/matrix/monitor/verification-utils.ts +46 -0
- package/src/matrix/outbound-media-runtime.ts +1 -0
- package/src/matrix/poll-summary.ts +110 -0
- package/src/matrix/poll-types.ts +429 -0
- package/src/matrix/probe.runtime.ts +4 -0
- package/src/matrix/probe.ts +97 -0
- package/src/matrix/profile.ts +184 -0
- package/src/matrix/reaction-common.ts +147 -0
- package/src/matrix/sdk/crypto-bootstrap.ts +438 -0
- package/src/matrix/sdk/crypto-facade.ts +242 -0
- package/src/matrix/sdk/crypto-node.runtime.ts +17 -0
- package/src/matrix/sdk/crypto-runtime.ts +14 -0
- package/src/matrix/sdk/decrypt-bridge.ts +410 -0
- package/src/matrix/sdk/event-helpers.ts +83 -0
- package/src/matrix/sdk/http-client.ts +87 -0
- package/src/matrix/sdk/idb-persistence-lock.ts +51 -0
- package/src/matrix/sdk/idb-persistence.ts +286 -0
- package/src/matrix/sdk/logger.ts +108 -0
- package/src/matrix/sdk/read-response-with-limit.ts +19 -0
- package/src/matrix/sdk/recovery-key-store.ts +453 -0
- package/src/matrix/sdk/timeout-abort-signal.ts +1 -0
- package/src/matrix/sdk/transport-runtime-api.ts +18 -0
- package/src/matrix/sdk/transport.ts +352 -0
- package/src/matrix/sdk/types.ts +245 -0
- package/src/matrix/sdk/verification-manager.ts +795 -0
- package/src/matrix/sdk/verification-status.ts +23 -0
- package/src/matrix/sdk.ts +2152 -0
- package/src/matrix/send/client.ts +93 -0
- package/src/matrix/send/formatting.ts +189 -0
- package/src/matrix/send/media.ts +244 -0
- package/src/matrix/send/targets.ts +104 -0
- package/src/matrix/send/types.ts +131 -0
- package/src/matrix/send.ts +660 -0
- package/src/matrix/session-store-metadata.ts +108 -0
- package/src/matrix/startup-abort.ts +44 -0
- package/src/matrix/subagent-hooks.ts +308 -0
- package/src/matrix/sync-state.ts +27 -0
- package/src/matrix/target-ids.ts +79 -0
- package/src/matrix/thread-bindings-shared.ts +206 -0
- package/src/matrix/thread-bindings.ts +580 -0
- package/src/matrix-migration.runtime.ts +9 -0
- package/src/migration-config.ts +243 -0
- package/src/migration-snapshot-backup.ts +116 -0
- package/src/migration-snapshot.ts +53 -0
- package/src/onboarding.ts +775 -0
- package/src/outbound.ts +248 -0
- package/src/plugin-entry.runtime.js +115 -0
- package/src/plugin-entry.runtime.ts +70 -0
- package/src/profile-update.ts +71 -0
- package/src/record-shared.ts +3 -0
- package/src/resolve-targets.ts +175 -0
- package/src/resolver.runtime.ts +5 -0
- package/src/resolver.ts +21 -0
- package/src/runtime-api.ts +106 -0
- package/src/runtime.ts +13 -0
- package/src/secret-contract.ts +174 -0
- package/src/session-route.ts +126 -0
- package/src/setup-bootstrap.ts +102 -0
- package/src/setup-config.ts +222 -0
- package/src/setup-contract.ts +90 -0
- package/src/setup-core.ts +146 -0
- package/src/setup-dm-policy.ts +15 -0
- package/src/setup-surface.ts +4 -0
- package/src/startup-maintenance.ts +114 -0
- package/src/storage-paths.ts +92 -0
- package/src/thread-binding-api.ts +23 -0
- package/src/tool-actions.runtime.ts +1 -0
- package/src/tool-actions.ts +498 -0
- package/src/types.ts +257 -0
- package/subagent-hooks-api.ts +31 -0
- package/test-api.ts +21 -0
- package/thread-binding-api.ts +4 -0
- package/thread-bindings-runtime.ts +4 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createChannelApprovalCapability,
|
|
3
|
+
createApproverRestrictedNativeApprovalCapability,
|
|
4
|
+
splitChannelApprovalCapability,
|
|
5
|
+
} from "autobot/plugin-sdk/approval-delivery-runtime";
|
|
6
|
+
import { createLazyChannelApprovalNativeRuntimeAdapter } from "autobot/plugin-sdk/approval-handler-adapter-runtime";
|
|
7
|
+
import type { ChannelApprovalNativeRuntimeAdapter } from "autobot/plugin-sdk/approval-handler-runtime";
|
|
8
|
+
import {
|
|
9
|
+
createChannelNativeOriginTargetResolver,
|
|
10
|
+
resolveApprovalRequestSessionConversation,
|
|
11
|
+
} from "autobot/plugin-sdk/approval-native-runtime";
|
|
12
|
+
import type {
|
|
13
|
+
ExecApprovalRequest,
|
|
14
|
+
PluginApprovalRequest,
|
|
15
|
+
} from "autobot/plugin-sdk/approval-runtime";
|
|
16
|
+
import type { ChannelApprovalCapability } from "autobot/plugin-sdk/channel-contract";
|
|
17
|
+
import {
|
|
18
|
+
normalizeLowercaseStringOrEmpty,
|
|
19
|
+
normalizeOptionalStringifiedId,
|
|
20
|
+
} from "autobot/plugin-sdk/string-coerce-runtime";
|
|
21
|
+
import { getMatrixApprovalAuthApprovers, matrixApprovalAuth } from "./approval-auth.js";
|
|
22
|
+
import { normalizeMatrixApproverId } from "./approval-ids.js";
|
|
23
|
+
import {
|
|
24
|
+
getMatrixApprovalApprovers,
|
|
25
|
+
getMatrixExecApprovalApprovers,
|
|
26
|
+
isMatrixAnyApprovalClientEnabled,
|
|
27
|
+
isMatrixApprovalClientEnabled,
|
|
28
|
+
isMatrixExecApprovalClientEnabled,
|
|
29
|
+
isMatrixExecApprovalAuthorizedSender,
|
|
30
|
+
resolveMatrixExecApprovalTarget,
|
|
31
|
+
shouldHandleMatrixApprovalRequest,
|
|
32
|
+
} from "./exec-approvals.js";
|
|
33
|
+
import { listMatrixAccountIds } from "./matrix/accounts.js";
|
|
34
|
+
import { normalizeMatrixUserId } from "./matrix/monitor/allowlist.js";
|
|
35
|
+
import { resolveMatrixTargetIdentity } from "./matrix/target-ids.js";
|
|
36
|
+
import type { CoreConfig } from "./types.js";
|
|
37
|
+
|
|
38
|
+
type ApprovalRequest = ExecApprovalRequest | PluginApprovalRequest;
|
|
39
|
+
type ApprovalKind = "exec" | "plugin";
|
|
40
|
+
type MatrixOriginTarget = { to: string; threadId?: string };
|
|
41
|
+
|
|
42
|
+
function normalizeComparableTarget(value: string): string {
|
|
43
|
+
const target = resolveMatrixTargetIdentity(value);
|
|
44
|
+
if (!target) {
|
|
45
|
+
return normalizeLowercaseStringOrEmpty(value);
|
|
46
|
+
}
|
|
47
|
+
if (target.kind === "user") {
|
|
48
|
+
return `user:${normalizeMatrixUserId(target.id)}`;
|
|
49
|
+
}
|
|
50
|
+
return `${normalizeLowercaseStringOrEmpty(target.kind)}:${target.id}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function resolveMatrixNativeTarget(raw: string): string | null {
|
|
54
|
+
const target = resolveMatrixTargetIdentity(raw);
|
|
55
|
+
if (!target) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return target.kind === "user" ? `user:${target.id}` : `room:${target.id}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function resolveTurnSourceMatrixOriginTarget(request: ApprovalRequest): MatrixOriginTarget | null {
|
|
62
|
+
const turnSourceChannel = normalizeLowercaseStringOrEmpty(request.request.turnSourceChannel);
|
|
63
|
+
const turnSourceTo = request.request.turnSourceTo?.trim() || "";
|
|
64
|
+
const target = resolveMatrixNativeTarget(turnSourceTo);
|
|
65
|
+
if (turnSourceChannel !== "matrix" || !target) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
to: target,
|
|
70
|
+
threadId: normalizeOptionalStringifiedId(request.request.turnSourceThreadId),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resolveSessionMatrixOriginTarget(sessionTarget: {
|
|
75
|
+
to: string;
|
|
76
|
+
threadId?: string | number | null;
|
|
77
|
+
}): MatrixOriginTarget | null {
|
|
78
|
+
const target = resolveMatrixNativeTarget(sessionTarget.to);
|
|
79
|
+
if (!target) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
to: target,
|
|
84
|
+
threadId: normalizeOptionalStringifiedId(sessionTarget.threadId),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function normalizeMatrixOriginTarget(target: MatrixOriginTarget): MatrixOriginTarget {
|
|
89
|
+
return {
|
|
90
|
+
...target,
|
|
91
|
+
to: normalizeComparableTarget(target.to),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function hasMatrixPluginApprovers(params: { cfg: CoreConfig; accountId?: string | null }): boolean {
|
|
96
|
+
return getMatrixApprovalAuthApprovers(params).length > 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function availabilityState(enabled: boolean) {
|
|
100
|
+
return enabled ? ({ kind: "enabled" } as const) : ({ kind: "disabled" } as const);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function hasMatrixApprovalApprovers(params: {
|
|
104
|
+
cfg: CoreConfig;
|
|
105
|
+
accountId?: string | null;
|
|
106
|
+
approvalKind: ApprovalKind;
|
|
107
|
+
}): boolean {
|
|
108
|
+
return (
|
|
109
|
+
getMatrixApprovalApprovers({
|
|
110
|
+
cfg: params.cfg,
|
|
111
|
+
accountId: params.accountId,
|
|
112
|
+
approvalKind: params.approvalKind,
|
|
113
|
+
}).length > 0
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function hasAnyMatrixApprovalApprovers(params: {
|
|
118
|
+
cfg: CoreConfig;
|
|
119
|
+
accountId?: string | null;
|
|
120
|
+
}): boolean {
|
|
121
|
+
return (
|
|
122
|
+
getMatrixExecApprovalApprovers(params).length > 0 ||
|
|
123
|
+
getMatrixApprovalAuthApprovers(params).length > 0
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function isMatrixPluginAuthorizedSender(params: {
|
|
128
|
+
cfg: CoreConfig;
|
|
129
|
+
accountId?: string | null;
|
|
130
|
+
senderId?: string | null;
|
|
131
|
+
}): boolean {
|
|
132
|
+
const normalizedSenderId = params.senderId
|
|
133
|
+
? normalizeMatrixApproverId(params.senderId)
|
|
134
|
+
: undefined;
|
|
135
|
+
if (!normalizedSenderId) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return getMatrixApprovalAuthApprovers(params).includes(normalizedSenderId);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function resolveSuppressionAccountId(params: {
|
|
142
|
+
target: { accountId?: string | null };
|
|
143
|
+
request: { request: { turnSourceAccountId?: string | null } };
|
|
144
|
+
}): string | undefined {
|
|
145
|
+
return (
|
|
146
|
+
params.target.accountId?.trim() ||
|
|
147
|
+
params.request.request.turnSourceAccountId?.trim() ||
|
|
148
|
+
undefined
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const resolveMatrixOriginTarget = createChannelNativeOriginTargetResolver({
|
|
153
|
+
channel: "matrix",
|
|
154
|
+
shouldHandleRequest: ({ cfg, accountId, request }) =>
|
|
155
|
+
shouldHandleMatrixApprovalRequest({
|
|
156
|
+
cfg,
|
|
157
|
+
accountId,
|
|
158
|
+
request,
|
|
159
|
+
}),
|
|
160
|
+
resolveTurnSourceTarget: resolveTurnSourceMatrixOriginTarget,
|
|
161
|
+
resolveSessionTarget: resolveSessionMatrixOriginTarget,
|
|
162
|
+
normalizeTargetForMatch: normalizeMatrixOriginTarget,
|
|
163
|
+
resolveFallbackTarget: (request) => {
|
|
164
|
+
const sessionConversation = resolveApprovalRequestSessionConversation({
|
|
165
|
+
request,
|
|
166
|
+
channel: "matrix",
|
|
167
|
+
});
|
|
168
|
+
if (!sessionConversation) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
const target = resolveMatrixNativeTarget(sessionConversation.id);
|
|
172
|
+
if (!target) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
to: target,
|
|
177
|
+
threadId: normalizeOptionalStringifiedId(sessionConversation.threadId),
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
function resolveMatrixApproverDmTargets(params: {
|
|
183
|
+
cfg: CoreConfig;
|
|
184
|
+
accountId?: string | null;
|
|
185
|
+
approvalKind: ApprovalKind;
|
|
186
|
+
request: ApprovalRequest;
|
|
187
|
+
}): { to: string }[] {
|
|
188
|
+
if (!shouldHandleMatrixApprovalRequest(params)) {
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
return getMatrixApprovalApprovers(params)
|
|
192
|
+
.map((approver) => {
|
|
193
|
+
const normalized = normalizeMatrixUserId(approver);
|
|
194
|
+
return normalized ? { to: `user:${normalized}` } : null;
|
|
195
|
+
})
|
|
196
|
+
.filter((target): target is { to: string } => target !== null);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const matrixNativeApprovalCapability = createApproverRestrictedNativeApprovalCapability({
|
|
200
|
+
channel: "matrix",
|
|
201
|
+
channelLabel: "Matrix",
|
|
202
|
+
describeExecApprovalSetup: ({
|
|
203
|
+
accountId,
|
|
204
|
+
}: Parameters<NonNullable<ChannelApprovalCapability["describeExecApprovalSetup"]>>[0]) => {
|
|
205
|
+
const prefix =
|
|
206
|
+
accountId && accountId !== "default"
|
|
207
|
+
? `channels.matrix.accounts.${accountId}`
|
|
208
|
+
: "channels.matrix";
|
|
209
|
+
return `Approve it from the Web UI or terminal UI for now. Matrix supports native exec approvals for this account. Configure \`${prefix}.execApprovals.approvers\` or \`${prefix}.dm.allowFrom\`; leave \`${prefix}.execApprovals.enabled\` unset/\`auto\` or set it to \`true\`.`;
|
|
210
|
+
},
|
|
211
|
+
listAccountIds: listMatrixAccountIds,
|
|
212
|
+
hasApprovers: ({ cfg, accountId }) =>
|
|
213
|
+
hasAnyMatrixApprovalApprovers({
|
|
214
|
+
cfg: cfg as CoreConfig,
|
|
215
|
+
accountId,
|
|
216
|
+
}),
|
|
217
|
+
isExecAuthorizedSender: ({ cfg, accountId, senderId }) =>
|
|
218
|
+
isMatrixExecApprovalAuthorizedSender({ cfg, accountId, senderId }),
|
|
219
|
+
isPluginAuthorizedSender: ({ cfg, accountId, senderId }) =>
|
|
220
|
+
isMatrixPluginAuthorizedSender({
|
|
221
|
+
cfg: cfg as CoreConfig,
|
|
222
|
+
accountId,
|
|
223
|
+
senderId,
|
|
224
|
+
}),
|
|
225
|
+
isNativeDeliveryEnabled: ({ cfg, accountId }) =>
|
|
226
|
+
isMatrixExecApprovalClientEnabled({ cfg, accountId }),
|
|
227
|
+
resolveNativeDeliveryMode: ({ cfg, accountId }) =>
|
|
228
|
+
resolveMatrixExecApprovalTarget({ cfg, accountId }),
|
|
229
|
+
requireMatchingTurnSourceChannel: true,
|
|
230
|
+
resolveSuppressionAccountId,
|
|
231
|
+
resolveOriginTarget: resolveMatrixOriginTarget,
|
|
232
|
+
resolveApproverDmTargets: resolveMatrixApproverDmTargets,
|
|
233
|
+
notifyOriginWhenDmOnly: true,
|
|
234
|
+
nativeRuntime: createLazyChannelApprovalNativeRuntimeAdapter({
|
|
235
|
+
eventKinds: ["exec", "plugin"],
|
|
236
|
+
isConfigured: ({ cfg, accountId }) =>
|
|
237
|
+
isMatrixAnyApprovalClientEnabled({
|
|
238
|
+
cfg,
|
|
239
|
+
accountId,
|
|
240
|
+
}),
|
|
241
|
+
shouldHandle: ({ cfg, accountId, request }) =>
|
|
242
|
+
shouldHandleMatrixApprovalRequest({
|
|
243
|
+
cfg,
|
|
244
|
+
accountId,
|
|
245
|
+
request,
|
|
246
|
+
}),
|
|
247
|
+
load: async () =>
|
|
248
|
+
(await import("./approval-handler.runtime.js"))
|
|
249
|
+
.matrixApprovalNativeRuntime as unknown as ChannelApprovalNativeRuntimeAdapter,
|
|
250
|
+
}),
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const splitMatrixApprovalCapability = splitChannelApprovalCapability(
|
|
254
|
+
matrixNativeApprovalCapability,
|
|
255
|
+
);
|
|
256
|
+
const matrixBaseNativeApprovalAdapter = splitMatrixApprovalCapability.native;
|
|
257
|
+
const matrixBaseDeliveryAdapter = splitMatrixApprovalCapability.delivery;
|
|
258
|
+
type MatrixForwardingSuppressionParams = Parameters<
|
|
259
|
+
NonNullable<NonNullable<typeof matrixBaseDeliveryAdapter>["shouldSuppressForwardingFallback"]>
|
|
260
|
+
>[0];
|
|
261
|
+
const matrixDeliveryAdapter = matrixBaseDeliveryAdapter && {
|
|
262
|
+
...matrixBaseDeliveryAdapter,
|
|
263
|
+
shouldSuppressForwardingFallback: (params: MatrixForwardingSuppressionParams) => {
|
|
264
|
+
const accountId = resolveSuppressionAccountId(params);
|
|
265
|
+
if (
|
|
266
|
+
!hasMatrixApprovalApprovers({
|
|
267
|
+
cfg: params.cfg as CoreConfig,
|
|
268
|
+
accountId,
|
|
269
|
+
approvalKind: params.approvalKind,
|
|
270
|
+
})
|
|
271
|
+
) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
return matrixBaseDeliveryAdapter.shouldSuppressForwardingFallback?.(params) ?? false;
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
const matrixNativeAdapter = matrixBaseNativeApprovalAdapter && {
|
|
278
|
+
describeDeliveryCapabilities: (
|
|
279
|
+
params: Parameters<typeof matrixBaseNativeApprovalAdapter.describeDeliveryCapabilities>[0],
|
|
280
|
+
) => {
|
|
281
|
+
const capabilities = matrixBaseNativeApprovalAdapter.describeDeliveryCapabilities(params);
|
|
282
|
+
const hasApprovers = hasMatrixApprovalApprovers({
|
|
283
|
+
cfg: params.cfg as CoreConfig,
|
|
284
|
+
accountId: params.accountId,
|
|
285
|
+
approvalKind: params.approvalKind,
|
|
286
|
+
});
|
|
287
|
+
const clientEnabled = isMatrixApprovalClientEnabled({
|
|
288
|
+
cfg: params.cfg,
|
|
289
|
+
accountId: params.accountId,
|
|
290
|
+
approvalKind: params.approvalKind,
|
|
291
|
+
});
|
|
292
|
+
return {
|
|
293
|
+
...capabilities,
|
|
294
|
+
enabled: capabilities.enabled && hasApprovers && clientEnabled,
|
|
295
|
+
};
|
|
296
|
+
},
|
|
297
|
+
resolveOriginTarget: matrixBaseNativeApprovalAdapter.resolveOriginTarget,
|
|
298
|
+
resolveApproverDmTargets: matrixBaseNativeApprovalAdapter.resolveApproverDmTargets,
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export const matrixApprovalCapability = createChannelApprovalCapability({
|
|
302
|
+
authorizeActorAction: (
|
|
303
|
+
params: Parameters<NonNullable<ChannelApprovalCapability["authorizeActorAction"]>>[0],
|
|
304
|
+
) => {
|
|
305
|
+
if (params.approvalKind !== "plugin") {
|
|
306
|
+
return matrixNativeApprovalCapability.authorizeActorAction?.(params) ?? { authorized: true };
|
|
307
|
+
}
|
|
308
|
+
if (
|
|
309
|
+
!hasMatrixPluginApprovers({
|
|
310
|
+
cfg: params.cfg as CoreConfig,
|
|
311
|
+
accountId: params.accountId,
|
|
312
|
+
})
|
|
313
|
+
) {
|
|
314
|
+
return {
|
|
315
|
+
authorized: false,
|
|
316
|
+
reason: "❌ Matrix plugin approvals are not enabled for this bot account.",
|
|
317
|
+
} as const;
|
|
318
|
+
}
|
|
319
|
+
return matrixApprovalAuth.authorizeActorAction(params);
|
|
320
|
+
},
|
|
321
|
+
getActionAvailabilityState: (
|
|
322
|
+
params: Parameters<NonNullable<ChannelApprovalCapability["getActionAvailabilityState"]>>[0],
|
|
323
|
+
) => {
|
|
324
|
+
if (params.approvalKind === "plugin") {
|
|
325
|
+
return availabilityState(
|
|
326
|
+
hasMatrixPluginApprovers({
|
|
327
|
+
cfg: params.cfg as CoreConfig,
|
|
328
|
+
accountId: params.accountId,
|
|
329
|
+
}),
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
return (
|
|
333
|
+
matrixNativeApprovalCapability.getActionAvailabilityState?.(params) ?? {
|
|
334
|
+
kind: "disabled",
|
|
335
|
+
}
|
|
336
|
+
);
|
|
337
|
+
},
|
|
338
|
+
getExecInitiatingSurfaceState: (
|
|
339
|
+
params: Parameters<NonNullable<ChannelApprovalCapability["getExecInitiatingSurfaceState"]>>[0],
|
|
340
|
+
) =>
|
|
341
|
+
matrixNativeApprovalCapability.getExecInitiatingSurfaceState?.(params) ??
|
|
342
|
+
({ kind: "disabled" } as const),
|
|
343
|
+
describeExecApprovalSetup: matrixNativeApprovalCapability.describeExecApprovalSetup,
|
|
344
|
+
delivery: matrixDeliveryAdapter,
|
|
345
|
+
nativeRuntime: matrixNativeApprovalCapability.nativeRuntime,
|
|
346
|
+
native: matrixNativeAdapter,
|
|
347
|
+
render: matrixNativeApprovalCapability.render,
|
|
348
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { resolveApprovalApprovers } from "autobot/plugin-sdk/approval-auth-runtime";
|
|
2
|
+
import { normalizeMatrixApproverId } from "./approval-ids.js";
|
|
3
|
+
import { resolveMatrixAccount } from "./matrix/accounts.js";
|
|
4
|
+
import type { CoreConfig } from "./types.js";
|
|
5
|
+
|
|
6
|
+
type MatrixApprovalReactionKind = "exec" | "plugin";
|
|
7
|
+
|
|
8
|
+
function normalizeMatrixExecApproverId(value: string | number): string | undefined {
|
|
9
|
+
const normalized = normalizeMatrixApproverId(value);
|
|
10
|
+
return normalized === "*" ? undefined : normalized;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getMatrixApprovalReactionApprovers(params: {
|
|
14
|
+
cfg: CoreConfig;
|
|
15
|
+
accountId?: string | null;
|
|
16
|
+
approvalKind: MatrixApprovalReactionKind;
|
|
17
|
+
}): string[] {
|
|
18
|
+
const account = resolveMatrixAccount(params).config;
|
|
19
|
+
if (params.approvalKind === "plugin") {
|
|
20
|
+
return resolveApprovalApprovers({
|
|
21
|
+
allowFrom: account.dm?.allowFrom,
|
|
22
|
+
normalizeApprover: normalizeMatrixApproverId,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return resolveApprovalApprovers({
|
|
26
|
+
explicit: account.execApprovals?.approvers,
|
|
27
|
+
allowFrom: account.dm?.allowFrom,
|
|
28
|
+
normalizeApprover: normalizeMatrixExecApproverId,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isMatrixApprovalReactionAuthorizedSender(params: {
|
|
33
|
+
cfg: CoreConfig;
|
|
34
|
+
accountId?: string | null;
|
|
35
|
+
senderId?: string | null;
|
|
36
|
+
approvalKind: MatrixApprovalReactionKind;
|
|
37
|
+
}): boolean {
|
|
38
|
+
const normalizedSenderId = params.senderId
|
|
39
|
+
? normalizeMatrixApproverId(params.senderId)
|
|
40
|
+
: undefined;
|
|
41
|
+
if (!normalizedSenderId) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return getMatrixApprovalReactionApprovers(params).includes(normalizedSenderId);
|
|
45
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import type { ExecApprovalReplyDecision } from "autobot/plugin-sdk/approval-runtime";
|
|
2
|
+
import { getOptionalMatrixRuntime } from "./runtime.js";
|
|
3
|
+
|
|
4
|
+
const MATRIX_APPROVAL_REACTION_META = {
|
|
5
|
+
"allow-once": {
|
|
6
|
+
emoji: "✅",
|
|
7
|
+
label: "Allow once",
|
|
8
|
+
},
|
|
9
|
+
"allow-always": {
|
|
10
|
+
emoji: "♾️",
|
|
11
|
+
label: "Allow always",
|
|
12
|
+
},
|
|
13
|
+
deny: {
|
|
14
|
+
emoji: "❌",
|
|
15
|
+
label: "Deny",
|
|
16
|
+
},
|
|
17
|
+
} satisfies Record<ExecApprovalReplyDecision, { emoji: string; label: string }>;
|
|
18
|
+
|
|
19
|
+
const MATRIX_APPROVAL_REACTION_ORDER = [
|
|
20
|
+
"allow-once",
|
|
21
|
+
"allow-always",
|
|
22
|
+
"deny",
|
|
23
|
+
] as const satisfies readonly ExecApprovalReplyDecision[];
|
|
24
|
+
|
|
25
|
+
const PERSISTENT_NAMESPACE = "matrix.approval-reactions";
|
|
26
|
+
const PERSISTENT_MAX_ENTRIES = 1000;
|
|
27
|
+
const DEFAULT_REACTION_TARGET_TTL_MS = 24 * 60 * 60 * 1000;
|
|
28
|
+
|
|
29
|
+
export type MatrixApprovalReactionBinding = {
|
|
30
|
+
decision: ExecApprovalReplyDecision;
|
|
31
|
+
emoji: string;
|
|
32
|
+
label: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type MatrixApprovalReactionResolution = {
|
|
36
|
+
approvalId: string;
|
|
37
|
+
decision: ExecApprovalReplyDecision;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type MatrixApprovalReactionTarget = {
|
|
41
|
+
approvalId: string;
|
|
42
|
+
allowedDecisions: readonly ExecApprovalReplyDecision[];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type PersistedMatrixApprovalReactionTarget = {
|
|
46
|
+
version: 1;
|
|
47
|
+
target: MatrixApprovalReactionTarget;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type MatrixApprovalReactionStore = {
|
|
51
|
+
register(
|
|
52
|
+
key: string,
|
|
53
|
+
value: PersistedMatrixApprovalReactionTarget,
|
|
54
|
+
opts?: { ttlMs?: number },
|
|
55
|
+
): Promise<void>;
|
|
56
|
+
lookup(key: string): Promise<PersistedMatrixApprovalReactionTarget | undefined>;
|
|
57
|
+
delete(key: string): Promise<boolean>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const matrixApprovalReactionTargets = new Map<string, MatrixApprovalReactionTarget>();
|
|
61
|
+
let persistentStore: MatrixApprovalReactionStore | undefined;
|
|
62
|
+
let persistentStoreDisabled = false;
|
|
63
|
+
|
|
64
|
+
function buildReactionTargetKey(roomId: string, eventId: string): string | null {
|
|
65
|
+
const normalizedRoomId = roomId.trim();
|
|
66
|
+
const normalizedEventId = eventId.trim();
|
|
67
|
+
if (!normalizedRoomId || !normalizedEventId) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return `${normalizedRoomId}:${normalizedEventId}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function reportPersistentApprovalReactionError(error: unknown): void {
|
|
74
|
+
try {
|
|
75
|
+
getOptionalMatrixRuntime()
|
|
76
|
+
?.logging.getChildLogger({ plugin: "matrix", feature: "approval-reaction-state" })
|
|
77
|
+
.warn("Matrix persistent approval reaction state failed", { error: String(error) });
|
|
78
|
+
} catch {
|
|
79
|
+
// Best effort only: persistent state must never break Matrix reactions.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function disablePersistentApprovalReactionStore(error: unknown): void {
|
|
84
|
+
persistentStoreDisabled = true;
|
|
85
|
+
persistentStore = undefined;
|
|
86
|
+
reportPersistentApprovalReactionError(error);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getPersistentApprovalReactionStore(): MatrixApprovalReactionStore | undefined {
|
|
90
|
+
if (persistentStoreDisabled) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
if (persistentStore) {
|
|
94
|
+
return persistentStore;
|
|
95
|
+
}
|
|
96
|
+
const runtime = getOptionalMatrixRuntime();
|
|
97
|
+
if (!runtime) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
persistentStore = runtime.state.openKeyedStore<PersistedMatrixApprovalReactionTarget>({
|
|
102
|
+
namespace: PERSISTENT_NAMESPACE,
|
|
103
|
+
maxEntries: PERSISTENT_MAX_ENTRIES,
|
|
104
|
+
defaultTtlMs: DEFAULT_REACTION_TARGET_TTL_MS,
|
|
105
|
+
});
|
|
106
|
+
return persistentStore;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
disablePersistentApprovalReactionStore(error);
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function readPersistedTarget(value: unknown): MatrixApprovalReactionTarget | null {
|
|
114
|
+
const persisted = value as PersistedMatrixApprovalReactionTarget | undefined;
|
|
115
|
+
if (
|
|
116
|
+
persisted?.version !== 1 ||
|
|
117
|
+
!persisted.target ||
|
|
118
|
+
typeof persisted.target.approvalId !== "string" ||
|
|
119
|
+
!Array.isArray(persisted.target.allowedDecisions)
|
|
120
|
+
) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return persisted.target;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function rememberPersistentApprovalReactionTarget(params: {
|
|
127
|
+
key: string;
|
|
128
|
+
target: MatrixApprovalReactionTarget;
|
|
129
|
+
ttlMs?: number;
|
|
130
|
+
}): void {
|
|
131
|
+
const ttlMs = params.ttlMs == null ? DEFAULT_REACTION_TARGET_TTL_MS : Math.max(1, params.ttlMs);
|
|
132
|
+
const store = getPersistentApprovalReactionStore();
|
|
133
|
+
if (!store) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
void store
|
|
137
|
+
.register(params.key, { version: 1, target: params.target }, { ttlMs })
|
|
138
|
+
.catch(disablePersistentApprovalReactionStore);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function forgetPersistentApprovalReactionTarget(key: string): void {
|
|
142
|
+
const store = getPersistentApprovalReactionStore();
|
|
143
|
+
if (!store) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
void store.delete(key).catch(disablePersistentApprovalReactionStore);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function lookupPersistentApprovalReactionTarget(
|
|
150
|
+
key: string,
|
|
151
|
+
): Promise<MatrixApprovalReactionTarget | null> {
|
|
152
|
+
const store = getPersistentApprovalReactionStore();
|
|
153
|
+
if (!store) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
return readPersistedTarget(await store.lookup(key));
|
|
158
|
+
} catch (error) {
|
|
159
|
+
disablePersistentApprovalReactionStore(error);
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function listMatrixApprovalReactionBindings(
|
|
165
|
+
allowedDecisions: readonly ExecApprovalReplyDecision[],
|
|
166
|
+
): MatrixApprovalReactionBinding[] {
|
|
167
|
+
const allowed = new Set(allowedDecisions);
|
|
168
|
+
return MATRIX_APPROVAL_REACTION_ORDER.filter((decision) => allowed.has(decision)).map(
|
|
169
|
+
(decision) => ({
|
|
170
|
+
decision,
|
|
171
|
+
emoji: MATRIX_APPROVAL_REACTION_META[decision].emoji,
|
|
172
|
+
label: MATRIX_APPROVAL_REACTION_META[decision].label,
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function buildMatrixApprovalReactionHint(
|
|
178
|
+
allowedDecisions: readonly ExecApprovalReplyDecision[],
|
|
179
|
+
): string | null {
|
|
180
|
+
const bindings = listMatrixApprovalReactionBindings(allowedDecisions);
|
|
181
|
+
if (bindings.length === 0) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return `React here: ${bindings.map((binding) => `${binding.emoji} ${binding.label}`).join(", ")}`;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function resolveMatrixApprovalReactionDecision(
|
|
188
|
+
reactionKey: string,
|
|
189
|
+
allowedDecisions: readonly ExecApprovalReplyDecision[],
|
|
190
|
+
): ExecApprovalReplyDecision | null {
|
|
191
|
+
const normalizedReaction = reactionKey.trim();
|
|
192
|
+
if (!normalizedReaction) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
const allowed = new Set(allowedDecisions);
|
|
196
|
+
for (const decision of MATRIX_APPROVAL_REACTION_ORDER) {
|
|
197
|
+
if (!allowed.has(decision)) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (MATRIX_APPROVAL_REACTION_META[decision].emoji === normalizedReaction) {
|
|
201
|
+
return decision;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function registerMatrixApprovalReactionTarget(params: {
|
|
208
|
+
roomId: string;
|
|
209
|
+
eventId: string;
|
|
210
|
+
approvalId: string;
|
|
211
|
+
allowedDecisions: readonly ExecApprovalReplyDecision[];
|
|
212
|
+
ttlMs?: number;
|
|
213
|
+
}): void {
|
|
214
|
+
const key = buildReactionTargetKey(params.roomId, params.eventId);
|
|
215
|
+
const approvalId = params.approvalId.trim();
|
|
216
|
+
const allowedDecisions = Array.from(
|
|
217
|
+
new Set(
|
|
218
|
+
params.allowedDecisions.filter(
|
|
219
|
+
(decision): decision is ExecApprovalReplyDecision =>
|
|
220
|
+
decision === "allow-once" || decision === "allow-always" || decision === "deny",
|
|
221
|
+
),
|
|
222
|
+
),
|
|
223
|
+
);
|
|
224
|
+
if (!key || !approvalId || allowedDecisions.length === 0) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const target = {
|
|
228
|
+
approvalId,
|
|
229
|
+
allowedDecisions,
|
|
230
|
+
};
|
|
231
|
+
matrixApprovalReactionTargets.set(key, target);
|
|
232
|
+
rememberPersistentApprovalReactionTarget({
|
|
233
|
+
key,
|
|
234
|
+
target,
|
|
235
|
+
ttlMs: params.ttlMs,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function unregisterMatrixApprovalReactionTarget(params: {
|
|
240
|
+
roomId: string;
|
|
241
|
+
eventId: string;
|
|
242
|
+
}): void {
|
|
243
|
+
const key = buildReactionTargetKey(params.roomId, params.eventId);
|
|
244
|
+
if (!key) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
matrixApprovalReactionTargets.delete(key);
|
|
248
|
+
forgetPersistentApprovalReactionTarget(key);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function resolveTarget(params: {
|
|
252
|
+
target: MatrixApprovalReactionTarget | null | undefined;
|
|
253
|
+
reactionKey: string;
|
|
254
|
+
}): MatrixApprovalReactionResolution | null {
|
|
255
|
+
const target = params.target;
|
|
256
|
+
if (!target) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const decision = resolveMatrixApprovalReactionDecision(
|
|
260
|
+
params.reactionKey,
|
|
261
|
+
target.allowedDecisions,
|
|
262
|
+
);
|
|
263
|
+
if (!decision) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
approvalId: target.approvalId,
|
|
268
|
+
decision,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function resolveMatrixApprovalReactionTarget(params: {
|
|
273
|
+
roomId: string;
|
|
274
|
+
eventId: string;
|
|
275
|
+
reactionKey: string;
|
|
276
|
+
}): MatrixApprovalReactionResolution | null {
|
|
277
|
+
const key = buildReactionTargetKey(params.roomId, params.eventId);
|
|
278
|
+
if (!key) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
return resolveTarget({
|
|
282
|
+
target: matrixApprovalReactionTargets.get(key),
|
|
283
|
+
reactionKey: params.reactionKey,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export async function resolveMatrixApprovalReactionTargetWithPersistence(params: {
|
|
288
|
+
roomId: string;
|
|
289
|
+
eventId: string;
|
|
290
|
+
reactionKey: string;
|
|
291
|
+
}): Promise<MatrixApprovalReactionResolution | null> {
|
|
292
|
+
const key = buildReactionTargetKey(params.roomId, params.eventId);
|
|
293
|
+
if (!key) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
const inMemory = resolveTarget({
|
|
297
|
+
target: matrixApprovalReactionTargets.get(key),
|
|
298
|
+
reactionKey: params.reactionKey,
|
|
299
|
+
});
|
|
300
|
+
if (inMemory) {
|
|
301
|
+
return inMemory;
|
|
302
|
+
}
|
|
303
|
+
return resolveTarget({
|
|
304
|
+
target: await lookupPersistentApprovalReactionTarget(key),
|
|
305
|
+
reactionKey: params.reactionKey,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export function clearMatrixApprovalReactionTargetsForTest(): void {
|
|
310
|
+
matrixApprovalReactionTargets.clear();
|
|
311
|
+
persistentStore = undefined;
|
|
312
|
+
persistentStoreDisabled = false;
|
|
313
|
+
}
|