@openpeepshq/core 0.19.0 → 0.27.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/dist/events/index.d.ts +2 -0
- package/dist/events/index.js +1 -0
- package/dist/federation/activities.d.ts +25 -0
- package/dist/federation/activities.js +31 -1
- package/dist/federation/discovery.d.ts +70 -0
- package/dist/federation/discovery.js +155 -0
- package/dist/federation/index.d.ts +2 -1
- package/dist/federation/index.js +2 -1
- package/dist/jams/index.d.ts +1 -0
- package/dist/jams/index.js +1 -0
- package/dist/jams/spotlight.d.ts +12 -0
- package/dist/jams/spotlight.js +52 -0
- package/dist/profiles/blocks.d.ts +11 -0
- package/dist/profiles/blocks.js +11 -0
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/mutations.js +1 -0
- package/package.json +6 -6
package/dist/events/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type CoreEvents = {
|
|
|
5
5
|
postCreated: (post: PostWithMeta) => void;
|
|
6
6
|
jamRecordingCompleted: (recording: JamRecordingWithMeta) => void;
|
|
7
7
|
followCreated: (follower: Profile, followed: Profile) => void;
|
|
8
|
+
/** Follow edge removed (unfollow). Federation reacts by sending Undo(Follow) for outbound follows only. */
|
|
9
|
+
followDeleted: (follower: Profile, followed: Profile) => void;
|
|
8
10
|
notificationCreated: (notification: Notification) => void;
|
|
9
11
|
reactionCreated: (profile: Profile, post: PostWithMeta, data: ReactionData) => void;
|
|
10
12
|
entryCreated: (profile: Profile, post: PostWithMeta, data: EntryData) => void;
|
package/dist/events/index.js
CHANGED
|
@@ -15,3 +15,28 @@ export declare const findApActivityByUri: (uri: string) => Promise<{
|
|
|
15
15
|
direction: string;
|
|
16
16
|
createdAt: string;
|
|
17
17
|
}>;
|
|
18
|
+
/**
|
|
19
|
+
* The outbound Follow activity we currently have live for this (actor,
|
|
20
|
+
* object) pair, if any. `objectUri` is stored as the *target* actor URI for
|
|
21
|
+
* Follow rows (the followee), so this is the idempotency key for outbound
|
|
22
|
+
* follows and the "we followed them" marker for outbound Undos.
|
|
23
|
+
*
|
|
24
|
+
* The row's lifecycle mirrors the follow edge: it is written when we send a
|
|
25
|
+
* Follow and deleted when the edge goes away (`federateUnfollow` after the
|
|
26
|
+
* Undo), so a re-follow after an unfollow must re-send instead of being
|
|
27
|
+
* swallowed by a stale row (#241 review #1).
|
|
28
|
+
*/
|
|
29
|
+
export declare const findOutboundFollow: (actorUri: string, objectUri: string) => Promise<{
|
|
30
|
+
uri: string;
|
|
31
|
+
type: string;
|
|
32
|
+
actorUri: string;
|
|
33
|
+
objectUri: string | null;
|
|
34
|
+
direction: string;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Drop the recorded outbound Follow for this (actor, object) pair — the
|
|
39
|
+
* ledger half of a live unfollow, so the pair can be re-followed and re-sent
|
|
40
|
+
* (#241 review #1). Idempotent: deleting nothing is fine.
|
|
41
|
+
*/
|
|
42
|
+
export declare const deleteOutboundFollow: (actorUri: string, objectUri: string) => Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { eq } from 'drizzle-orm';
|
|
1
|
+
import { and, eq } from 'drizzle-orm';
|
|
2
2
|
import { pgDb } from '../db/pg/client.js';
|
|
3
3
|
import { apActivities } from '../db/pg/schema/documents.js';
|
|
4
4
|
export const recordApActivity = async (activity) => {
|
|
@@ -23,3 +23,33 @@ export const findApActivityByUri = async (uri) => {
|
|
|
23
23
|
.limit(1);
|
|
24
24
|
return row;
|
|
25
25
|
};
|
|
26
|
+
const outboundFollowWhere = (actorUri, objectUri) => and(eq(apActivities.type, 'Follow'), eq(apActivities.actorUri, actorUri), eq(apActivities.objectUri, objectUri), eq(apActivities.direction, 'out'));
|
|
27
|
+
/**
|
|
28
|
+
* The outbound Follow activity we currently have live for this (actor,
|
|
29
|
+
* object) pair, if any. `objectUri` is stored as the *target* actor URI for
|
|
30
|
+
* Follow rows (the followee), so this is the idempotency key for outbound
|
|
31
|
+
* follows and the "we followed them" marker for outbound Undos.
|
|
32
|
+
*
|
|
33
|
+
* The row's lifecycle mirrors the follow edge: it is written when we send a
|
|
34
|
+
* Follow and deleted when the edge goes away (`federateUnfollow` after the
|
|
35
|
+
* Undo), so a re-follow after an unfollow must re-send instead of being
|
|
36
|
+
* swallowed by a stale row (#241 review #1).
|
|
37
|
+
*/
|
|
38
|
+
export const findOutboundFollow = async (actorUri, objectUri) => {
|
|
39
|
+
const db = pgDb();
|
|
40
|
+
const [row] = await db
|
|
41
|
+
.select()
|
|
42
|
+
.from(apActivities)
|
|
43
|
+
.where(outboundFollowWhere(actorUri, objectUri))
|
|
44
|
+
.limit(1);
|
|
45
|
+
return row;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Drop the recorded outbound Follow for this (actor, object) pair — the
|
|
49
|
+
* ledger half of a live unfollow, so the pair can be re-followed and re-sent
|
|
50
|
+
* (#241 review #1). Idempotent: deleting nothing is fine.
|
|
51
|
+
*/
|
|
52
|
+
export const deleteOutboundFollow = async (actorUri, objectUri) => {
|
|
53
|
+
const db = pgDb();
|
|
54
|
+
await db.delete(apActivities).where(outboundFollowWhere(actorUri, objectUri));
|
|
55
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote-actor discovery for outbound follows (#241).
|
|
3
|
+
*
|
|
4
|
+
* Resolves a `user@domain` / `@user@domain` handle (via WebFinger) or an
|
|
5
|
+
* `https` actor URL into a `federated` profile row, so a local user can
|
|
6
|
+
* initiate a follow of an account that has never interacted with the
|
|
7
|
+
* instance. Pure `fetch`, no new dependency.
|
|
8
|
+
*/
|
|
9
|
+
import type { ProfileWithMeta } from '@openpeepshq/common/types';
|
|
10
|
+
import { type RemoteActorInput } from './actors';
|
|
11
|
+
/**
|
|
12
|
+
* Extract the first non-empty string from a value that may be a plain string
|
|
13
|
+
* or an ActivityStreams LanguageMap (`{ "en": "hi" }`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const asText: (value: unknown) => string | undefined;
|
|
16
|
+
/** Coerce to an `http(s)` URL, or `undefined` if it isn't one. */
|
|
17
|
+
export declare const asHttpUrl: (value: string | null | undefined) => URL | undefined;
|
|
18
|
+
type ParsedQuery = {
|
|
19
|
+
kind: 'handle';
|
|
20
|
+
user: string;
|
|
21
|
+
domain: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'url';
|
|
24
|
+
url: string;
|
|
25
|
+
} | null;
|
|
26
|
+
/**
|
|
27
|
+
* Split a discovery query. Accepts `user@domain`, `@user@domain`, or an
|
|
28
|
+
* `http(s)` actor URL. Returns `null` when nothing sensible can be parsed.
|
|
29
|
+
*/
|
|
30
|
+
export declare const parseRemoteAccountQuery: (query: string) => ParsedQuery;
|
|
31
|
+
type ActorDoc = {
|
|
32
|
+
id?: string;
|
|
33
|
+
preferredUsername?: unknown;
|
|
34
|
+
name?: unknown;
|
|
35
|
+
summary?: unknown;
|
|
36
|
+
inbox?: unknown;
|
|
37
|
+
endpoints?: {
|
|
38
|
+
sharedInbox?: unknown;
|
|
39
|
+
};
|
|
40
|
+
publicKey?: {
|
|
41
|
+
id?: unknown;
|
|
42
|
+
owner?: unknown;
|
|
43
|
+
publicKeyPem?: unknown;
|
|
44
|
+
};
|
|
45
|
+
icon?: {
|
|
46
|
+
url?: unknown;
|
|
47
|
+
} | {
|
|
48
|
+
url?: unknown;
|
|
49
|
+
}[];
|
|
50
|
+
image?: {
|
|
51
|
+
url?: unknown;
|
|
52
|
+
} | {
|
|
53
|
+
url?: unknown;
|
|
54
|
+
}[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Map a raw ActivityStreams actor document onto the `RemoteActorInput` shape
|
|
58
|
+
* consumed by {@link upsertRemoteActor}. Pure — no I/O.
|
|
59
|
+
*/
|
|
60
|
+
export declare const actorDocToRemoteInput: (doc: ActorDoc) => RemoteActorInput | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Resolve `query` to a `federated` profile, upserting the remote actor if it
|
|
63
|
+
* isn't already known. Returns `undefined` when the host is not on the
|
|
64
|
+
* allowlist, WebFinger finds no `self` link, the actor can't be resolved, or
|
|
65
|
+
* the actor has no inbox (unfederatable) — the caller maps this to a 404.
|
|
66
|
+
* Network/timeout/redirect failures propagate so the caller can surface them
|
|
67
|
+
* as a 5xx.
|
|
68
|
+
*/
|
|
69
|
+
export declare const resolveRemoteAccount: (query: string) => Promise<ProfileWithMeta | undefined>;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { config } from '../config/index.js';
|
|
2
|
+
import { federatedHandleFrom, upsertRemoteActor, } from './actors.js';
|
|
3
|
+
import { peerHostAllowed } from './peers.js';
|
|
4
|
+
/**
|
|
5
|
+
* Extract the first non-empty string from a value that may be a plain string
|
|
6
|
+
* or an ActivityStreams LanguageMap (`{ "en": "hi" }`).
|
|
7
|
+
*/
|
|
8
|
+
export const asText = (value) => {
|
|
9
|
+
if (value == null)
|
|
10
|
+
return undefined;
|
|
11
|
+
if (typeof value === 'string')
|
|
12
|
+
return value.length > 0 ? value : undefined;
|
|
13
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
14
|
+
for (const entry of Object.values(value)) {
|
|
15
|
+
if (typeof entry === 'string' && entry.length > 0)
|
|
16
|
+
return entry;
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const text = String(value);
|
|
21
|
+
return text.length > 0 ? text : undefined;
|
|
22
|
+
};
|
|
23
|
+
/** Coerce to an `http(s)` URL, or `undefined` if it isn't one. */
|
|
24
|
+
export const asHttpUrl = (value) => {
|
|
25
|
+
if (!value)
|
|
26
|
+
return undefined;
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(value);
|
|
29
|
+
return url.protocol === 'http:' || url.protocol === 'https:'
|
|
30
|
+
? url
|
|
31
|
+
: undefined;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Split a discovery query. Accepts `user@domain`, `@user@domain`, or an
|
|
39
|
+
* `http(s)` actor URL. Returns `null` when nothing sensible can be parsed.
|
|
40
|
+
*/
|
|
41
|
+
export const parseRemoteAccountQuery = (query) => {
|
|
42
|
+
const trimmed = query.trim();
|
|
43
|
+
if (!trimmed)
|
|
44
|
+
return null;
|
|
45
|
+
const httpUrl = asHttpUrl(trimmed);
|
|
46
|
+
if (httpUrl)
|
|
47
|
+
return { kind: 'url', url: httpUrl.href };
|
|
48
|
+
const bare = trimmed.replace(/^@/, '');
|
|
49
|
+
const at = bare.lastIndexOf('@');
|
|
50
|
+
if (at <= 0 || at === bare.length - 1)
|
|
51
|
+
return null;
|
|
52
|
+
const user = bare.slice(0, at).trim();
|
|
53
|
+
const domain = bare
|
|
54
|
+
.slice(at + 1)
|
|
55
|
+
.trim()
|
|
56
|
+
.toLowerCase()
|
|
57
|
+
.replace(/\.$/, '');
|
|
58
|
+
if (!user || !domain)
|
|
59
|
+
return null;
|
|
60
|
+
return { kind: 'handle', user, domain };
|
|
61
|
+
};
|
|
62
|
+
const firstImageUrl = (icon) => {
|
|
63
|
+
if (!icon)
|
|
64
|
+
return undefined;
|
|
65
|
+
const list = Array.isArray(icon) ? icon : [icon];
|
|
66
|
+
for (const entry of list) {
|
|
67
|
+
const url = asHttpUrl(asText(entry?.url));
|
|
68
|
+
if (url)
|
|
69
|
+
return url.href;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Map a raw ActivityStreams actor document onto the `RemoteActorInput` shape
|
|
75
|
+
* consumed by {@link upsertRemoteActor}. Pure — no I/O.
|
|
76
|
+
*/
|
|
77
|
+
export const actorDocToRemoteInput = (doc) => {
|
|
78
|
+
const uri = asHttpUrl(asText(doc.id));
|
|
79
|
+
if (!uri)
|
|
80
|
+
return undefined;
|
|
81
|
+
return {
|
|
82
|
+
uri: uri.href,
|
|
83
|
+
handle: federatedHandleFrom(asText(doc.preferredUsername), uri.href),
|
|
84
|
+
domain: uri.hostname.toLowerCase().replace(/\.$/, ''),
|
|
85
|
+
inboxUrl: asText(doc.inbox) ?? null,
|
|
86
|
+
sharedInboxUrl: asText(doc.endpoints?.sharedInbox) ?? null,
|
|
87
|
+
publicKeyPem: asText(doc.publicKey?.publicKeyPem) ?? null,
|
|
88
|
+
displayName: asText(doc.name),
|
|
89
|
+
bio: asText(doc.summary),
|
|
90
|
+
avatar: firstImageUrl(doc.icon ?? doc.image) ?? null,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const requestTimeout = async () => (await config()).activityPub.federation.requestTimeout;
|
|
94
|
+
/**
|
|
95
|
+
* Resolve `query` to a `federated` profile, upserting the remote actor if it
|
|
96
|
+
* isn't already known. Returns `undefined` when the host is not on the
|
|
97
|
+
* allowlist, WebFinger finds no `self` link, the actor can't be resolved, or
|
|
98
|
+
* the actor has no inbox (unfederatable) — the caller maps this to a 404.
|
|
99
|
+
* Network/timeout/redirect failures propagate so the caller can surface them
|
|
100
|
+
* as a 5xx.
|
|
101
|
+
*/
|
|
102
|
+
export const resolveRemoteAccount = async (query) => {
|
|
103
|
+
const parsed = parseRemoteAccountQuery(query);
|
|
104
|
+
if (!parsed)
|
|
105
|
+
return undefined;
|
|
106
|
+
let actorUrl;
|
|
107
|
+
if (parsed.kind === 'handle') {
|
|
108
|
+
const { user, domain } = parsed;
|
|
109
|
+
// Gate on a URL, not the bare domain: `peerHostAllowed` resolves the
|
|
110
|
+
// host via `hostnameOf` (`new URL`), which throws on a scheme-less
|
|
111
|
+
// string and would deny every allowlisted host (review #1).
|
|
112
|
+
if (!(await peerHostAllowed(new URL(`https://${domain}/`))))
|
|
113
|
+
return undefined;
|
|
114
|
+
const timeoutMs = await requestTimeout();
|
|
115
|
+
const webfingerUrl = `https://${domain}/.well-known/webfinger?resource=acct:${user}@${domain}`;
|
|
116
|
+
const webfinger = await fetch(webfingerUrl, {
|
|
117
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
118
|
+
// No redirect-following: a 302 away from the allowlisted host (e.g. to
|
|
119
|
+
// an internal address) must not bypass `peerHostAllowed` mid-flight
|
|
120
|
+
// (#241 review #5). Redirects throw and surface as a 5xx.
|
|
121
|
+
redirect: 'error',
|
|
122
|
+
});
|
|
123
|
+
if (!webfinger.ok)
|
|
124
|
+
return undefined;
|
|
125
|
+
const body = (await webfinger.json());
|
|
126
|
+
const selfLink = body.links?.find((link) => link.rel === 'self' && link.type === 'application/activity+json');
|
|
127
|
+
actorUrl = asHttpUrl(selfLink?.href);
|
|
128
|
+
if (!actorUrl)
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
actorUrl = new URL(parsed.url);
|
|
133
|
+
}
|
|
134
|
+
// Pass the URL itself, not `hostnameOf(actorUrl)`: `peerHostAllowed`
|
|
135
|
+
// re-runs `hostnameOf` internally, and a bare hostname string would be
|
|
136
|
+
// rejected again (review #1).
|
|
137
|
+
if (!(await peerHostAllowed(actorUrl)))
|
|
138
|
+
return undefined;
|
|
139
|
+
const timeoutMs = await requestTimeout();
|
|
140
|
+
const actorRes = await fetch(actorUrl.href, {
|
|
141
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
142
|
+
headers: { Accept: 'application/activity+json, application/ld+json' },
|
|
143
|
+
redirect: 'error',
|
|
144
|
+
});
|
|
145
|
+
if (!actorRes.ok)
|
|
146
|
+
return undefined;
|
|
147
|
+
const doc = (await actorRes.json());
|
|
148
|
+
const input = actorDocToRemoteInput(doc);
|
|
149
|
+
// An actor without an inbox can't receive the outbound Follow, so following
|
|
150
|
+
// it would federate nothing. Treat it as unresolvable (404) rather than
|
|
151
|
+
// upserting a profile row that can never be federated to (#241 review #6).
|
|
152
|
+
if (!input || !input.inboxUrl)
|
|
153
|
+
return undefined;
|
|
154
|
+
return upsertRemoteActor(input);
|
|
155
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { findApActivityByUri, recordApActivity } from './activities';
|
|
1
|
+
export { deleteOutboundFollow, findApActivityByUri, findOutboundFollow, recordApActivity, } from './activities';
|
|
2
2
|
export type { ApActivity, ApActivityDirection } from './activities';
|
|
3
3
|
export { federatedHandleFrom, findLocalActorIdByHandle, loadLocalActor, loadLocalActorKeys, upsertRemoteActor, } from './actors';
|
|
4
4
|
export type { LocalActor, LocalActorKeys, RemoteActorInput } from './actors';
|
|
@@ -9,3 +9,4 @@ export { loadPublicNote } from './notes';
|
|
|
9
9
|
export type { PublicNote } from './notes';
|
|
10
10
|
export { federationIsActive, hostnameOf, peerHostAllowed } from './peers';
|
|
11
11
|
export { findProfileByHandleAndDomain, findProfileByUri } from './profiles';
|
|
12
|
+
export { actorDocToRemoteInput, asHttpUrl, asText, parseRemoteAccountQuery, resolveRemoteAccount, } from './discovery';
|
package/dist/federation/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { findApActivityByUri, recordApActivity } from './activities.js';
|
|
1
|
+
export { deleteOutboundFollow, findApActivityByUri, findOutboundFollow, recordApActivity, } from './activities.js';
|
|
2
2
|
export { federatedHandleFrom, findLocalActorIdByHandle, loadLocalActor, loadLocalActorKeys, upsertRemoteActor, } from './actors.js';
|
|
3
3
|
export { ACCEPT_PATH, ACTOR_INBOX_PATH, ACTOR_PATH, CREATE_PATH, FOLLOWERS_PATH, NOTE_PATH, SHARED_INBOX_PATH, acceptActivityUri, actorUri, backfillLocalFederationIdentities, createActivityUri, federationOrigin, generateActorKeyPair, localActorScalars, localObjectScalars, objectUri, } from './identity.js';
|
|
4
4
|
export { ingestIncomingFollow, ingestIncomingUnfollow, listFederatedFollowerRecipients, withoutBlockedRecipients, } from './ingest.js';
|
|
5
5
|
export { loadPublicNote } from './notes.js';
|
|
6
6
|
export { federationIsActive, hostnameOf, peerHostAllowed } from './peers.js';
|
|
7
7
|
export { findProfileByHandleAndDomain, findProfileByUri } from './profiles.js';
|
|
8
|
+
export { actorDocToRemoteInput, asHttpUrl, asText, parseRemoteAccountQuery, resolveRemoteAccount, } from './discovery.js';
|
package/dist/jams/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { createJamToken, createJamEgressToken } from './token';
|
|
|
3
3
|
export { diagnoseLivekit, isLivekitConnected } from './health';
|
|
4
4
|
export { startRecording, stopRecording, startRtmpStream, stopRtmpStream, stopEgress, listParticipantIds, reclaimOrphanJamRoom, finishRecording, getJamRecordingUrl, getJamObserverPath, JAM_ROOM_EMPTY_TIMEOUT_SEC, JAM_ROOM_DEPARTURE_TIMEOUT_SEC, } from './livekit';
|
|
5
5
|
export { rtmpStreamOutput } from './rtmp';
|
|
6
|
+
export { setJamSpotlight } from './spotlight';
|
|
6
7
|
export { jamRecordingStopQueue, jamRecordingStopWorker, scheduleRecordingAutoStop, cancelRecordingAutoStop, JAM_RECORDING_MAX_DURATION_MS, } from './jobs';
|
|
7
8
|
export * from './waitingRoom';
|
|
8
9
|
export * from './mutations';
|
package/dist/jams/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export { createJamToken, createJamEgressToken } from './token.js';
|
|
|
16
16
|
export { diagnoseLivekit, isLivekitConnected } from './health.js';
|
|
17
17
|
export { startRecording, stopRecording, startRtmpStream, stopRtmpStream, stopEgress, listParticipantIds, reclaimOrphanJamRoom, finishRecording, getJamRecordingUrl, getJamObserverPath, JAM_ROOM_EMPTY_TIMEOUT_SEC, JAM_ROOM_DEPARTURE_TIMEOUT_SEC, } from './livekit.js';
|
|
18
18
|
export { rtmpStreamOutput } from './rtmp.js';
|
|
19
|
+
export { setJamSpotlight } from './spotlight.js';
|
|
19
20
|
export { jamRecordingStopQueue, jamRecordingStopWorker, scheduleRecordingAutoStop, cancelRecordingAutoStop, JAM_RECORDING_MAX_DURATION_MS, } from './jobs.js';
|
|
20
21
|
export * from './waitingRoom.js';
|
|
21
22
|
export * from './mutations.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PostWithMeta } from '@openpeepshq/common/types';
|
|
2
|
+
/**
|
|
3
|
+
* Sets or clears the room-wide spotlight in LiveKit room metadata.
|
|
4
|
+
*
|
|
5
|
+
* Recording/RTMP web egress joins the room after the spotlight was set, so a
|
|
6
|
+
* one-shot data packet never reaches it. Room metadata is replayed to every
|
|
7
|
+
* (re)joining participant, so the egress's observer view sees the spotlight on
|
|
8
|
+
* load and follows live changes via `RoomMetadataChanged`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const setJamSpotlight: (jamEvent: PostWithMeta, identity: string | null, recurrenceId?: string) => Promise<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jamRoomName } from '@openpeepshq/common/lib';
|
|
2
|
+
import { logger } from '../log/index.js';
|
|
3
|
+
import { roomService } from './livekit.js';
|
|
4
|
+
const log = logger('app:jams:spotlight');
|
|
5
|
+
const isRoomMetadata = (value) => {
|
|
6
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const record = value;
|
|
10
|
+
return (('instanceDomain' in record
|
|
11
|
+
? typeof record.instanceDomain === 'string'
|
|
12
|
+
: true) &&
|
|
13
|
+
('spotlightIdentity' in record
|
|
14
|
+
? typeof record.spotlightIdentity === 'string' ||
|
|
15
|
+
record.spotlightIdentity === null
|
|
16
|
+
: true));
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Sets or clears the room-wide spotlight in LiveKit room metadata.
|
|
20
|
+
*
|
|
21
|
+
* Recording/RTMP web egress joins the room after the spotlight was set, so a
|
|
22
|
+
* one-shot data packet never reaches it. Room metadata is replayed to every
|
|
23
|
+
* (re)joining participant, so the egress's observer view sees the spotlight on
|
|
24
|
+
* load and follows live changes via `RoomMetadataChanged`.
|
|
25
|
+
*/
|
|
26
|
+
export const setJamSpotlight = async (jamEvent, identity, recurrenceId) => {
|
|
27
|
+
const roomName = jamRoomName(jamEvent.id, recurrenceId);
|
|
28
|
+
const rs = await roomService();
|
|
29
|
+
if (rs === undefined) {
|
|
30
|
+
log.warn(`Cannot set spotlight for jam ${jamEvent.id}: LiveKit is not configured`);
|
|
31
|
+
return { success: false };
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const rooms = await rs.listRooms([roomName]);
|
|
35
|
+
const room = rooms[0];
|
|
36
|
+
if (!room) {
|
|
37
|
+
log.warn(`Cannot set spotlight for jam ${jamEvent.id}: room ${roomName} is not open`);
|
|
38
|
+
return { success: false };
|
|
39
|
+
}
|
|
40
|
+
const parsed = room.metadata ? JSON.parse(room.metadata) : {};
|
|
41
|
+
if (!isRoomMetadata(parsed)) {
|
|
42
|
+
log.warn(`Cannot set spotlight for jam ${jamEvent.id}: room ${roomName} has malformed metadata`);
|
|
43
|
+
return { success: false };
|
|
44
|
+
}
|
|
45
|
+
await rs.updateRoomMetadata(roomName, JSON.stringify({ ...parsed, spotlightIdentity: identity }));
|
|
46
|
+
return { success: true };
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
log.warn(`Failed to set spotlight for jam ${jamEvent.id}: ${e.message}`);
|
|
50
|
+
return { success: false };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -7,6 +7,17 @@ export declare const loadBlockIds: (db: PgDb, profileId: string) => Promise<{
|
|
|
7
7
|
}>;
|
|
8
8
|
export declare const insertBlock: (db: PgDb, fromId: string, toId: string) => Promise<void>;
|
|
9
9
|
export declare const deleteBlock: (db: PgDb, fromId: string, toId: string) => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Delete both directions of follow edges and pending follow requests between
|
|
12
|
+
* two profiles. Called from `blockProfile`.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately local-only (#241): blocking a profile we federally follow does
|
|
15
|
+
* NOT emit `followDeleted`, so no `Undo(Follow)` is fanned out to remote
|
|
16
|
+
* inboxes — the dropped outbound follow rows would otherwise leave remote
|
|
17
|
+
* hosts believing we still follow. Fan-out Undos on block would add remote
|
|
18
|
+
* calls with no correctness value; the edge is removed locally, which is what
|
|
19
|
+
* the block is for.
|
|
20
|
+
*/
|
|
10
21
|
export declare const dropFollowsBetween: (db: PgDb, a: string, b: string) => Promise<void>;
|
|
11
22
|
export declare const areBlocked: (db: PgDb, a: string, b: string) => Promise<boolean>;
|
|
12
23
|
export declare const hasBlockAmong: (db: PgDb, ids: string[]) => Promise<boolean>;
|
package/dist/profiles/blocks.js
CHANGED
|
@@ -44,6 +44,17 @@ export const deleteBlock = async (db, fromId, toId) => {
|
|
|
44
44
|
};
|
|
45
45
|
const eitherDirection = (a, b) => or(and(eq(follows.fromId, a), eq(follows.toId, b)), and(eq(follows.fromId, b), eq(follows.toId, a)));
|
|
46
46
|
const eitherFollowRequest = (a, b) => or(and(eq(requestsFollow.fromId, a), eq(requestsFollow.toId, b)), and(eq(requestsFollow.fromId, b), eq(requestsFollow.toId, a)));
|
|
47
|
+
/**
|
|
48
|
+
* Delete both directions of follow edges and pending follow requests between
|
|
49
|
+
* two profiles. Called from `blockProfile`.
|
|
50
|
+
*
|
|
51
|
+
* Deliberately local-only (#241): blocking a profile we federally follow does
|
|
52
|
+
* NOT emit `followDeleted`, so no `Undo(Follow)` is fanned out to remote
|
|
53
|
+
* inboxes — the dropped outbound follow rows would otherwise leave remote
|
|
54
|
+
* hosts believing we still follow. Fan-out Undos on block would add remote
|
|
55
|
+
* calls with no correctness value; the edge is removed locally, which is what
|
|
56
|
+
* the block is for.
|
|
57
|
+
*/
|
|
47
58
|
export const dropFollowsBetween = async (db, a, b) => {
|
|
48
59
|
await Promise.all([
|
|
49
60
|
db.delete(follows).where(eitherDirection(a, b)),
|
|
@@ -2,6 +2,7 @@ import { Profile, ProfileWithMeta, Role } from '@openpeepshq/common/types';
|
|
|
2
2
|
import type { PgDb } from '../db/pg/client';
|
|
3
3
|
export declare const followConnector: (db: PgDb, from: Profile, to: Profile, data?: {
|
|
4
4
|
uri?: string | undefined;
|
|
5
|
+
handle?: string | undefined;
|
|
5
6
|
reblogs?: boolean | undefined;
|
|
6
7
|
notify?: boolean | undefined;
|
|
7
8
|
languages?: string[] | undefined;
|
|
@@ -9,6 +10,7 @@ export declare const followConnector: (db: PgDb, from: Profile, to: Profile, dat
|
|
|
9
10
|
id?: string;
|
|
10
11
|
}) => Promise<import("../db/pg/map").WithId<{
|
|
11
12
|
uri?: string | undefined;
|
|
13
|
+
handle?: string | undefined;
|
|
12
14
|
reblogs?: boolean | undefined;
|
|
13
15
|
notify?: boolean | undefined;
|
|
14
16
|
languages?: string[] | undefined;
|
|
@@ -145,6 +145,7 @@ export const followDesignatedProfiles = async (profile, handles) => {
|
|
|
145
145
|
export const unfollow = async (follower, followed) => {
|
|
146
146
|
const { db } = await allpeepDb();
|
|
147
147
|
await followDisconnector(db, follower, followed);
|
|
148
|
+
await hub.emit('followDeleted', follower, followed);
|
|
148
149
|
await Promise.all([clearProfileCache(follower), clearProfileCache(followed)]);
|
|
149
150
|
};
|
|
150
151
|
export const blockProfile = async (blocker, blocked) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@sentry/node": "^10.78.0",
|
|
10
10
|
"apns2": "^12.2.0",
|
|
11
11
|
"archiver": "^8.0.0",
|
|
12
|
-
"bcrypt": "^
|
|
12
|
+
"bcrypt": "^6.0.0",
|
|
13
13
|
"bullmq": "^5.81.5",
|
|
14
14
|
"cache-manager": "^7.2.4",
|
|
15
15
|
"cacheable": "^2.1.1",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"type-fest": "^4.31.0",
|
|
38
38
|
"uuidv7": "^1.0.2",
|
|
39
39
|
"web-push": "^3.6.7",
|
|
40
|
-
"@openpeepshq/common": "0.
|
|
41
|
-
"@openpeepshq/geocoder": "^0.1.2",
|
|
40
|
+
"@openpeepshq/common": "0.29.0",
|
|
42
41
|
"@openpeepshq/fetch-client": "^0.3.0",
|
|
43
|
-
"@openpeepshq/i18n": "^0.
|
|
42
|
+
"@openpeepshq/i18n": "^0.30.0",
|
|
43
|
+
"@openpeepshq/geocoder": "^0.1.2"
|
|
44
44
|
},
|
|
45
45
|
"main": "dist/index.js",
|
|
46
46
|
"types": "dist/index.d.ts",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
],
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/archiver": "^8.0.0",
|
|
56
|
-
"@types/bcrypt": "^
|
|
56
|
+
"@types/bcrypt": "^6.0.0",
|
|
57
57
|
"@types/express": "^5.0.6",
|
|
58
58
|
"@types/fluent-ffmpeg": "^2.1.27",
|
|
59
59
|
"@types/fs-extra": "^11.0.4",
|