@openpeepshq/core 0.1.33 → 0.1.34
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/accounts/mutations.js +33 -35
- package/dist/analytics/compile.js +16 -10
- package/dist/analytics/read.js +52 -9
- package/dist/analytics/report.d.ts +20 -0
- package/dist/backups/index.js +75 -15
- package/dist/backups/metadata.d.ts +2 -3
- package/dist/backups/metadata.js +6 -2
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +7 -3
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +3 -0
- package/dist/config/index.d.ts +21 -0
- package/dist/config/index.js +7 -1
- package/dist/db/helpers.d.ts +1 -0
- package/dist/db/helpers.js +11 -3
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -0
- package/dist/db/init.js +2 -3
- package/dist/db/migration/importCollections.d.ts +14 -9
- package/dist/db/migration/importCollections.js +114 -164
- package/dist/db/migration/shared.d.ts +2 -33
- package/dist/db/migration/shared.js +2 -52
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/posts.d.ts +10 -0
- package/dist/db/pg/filters/posts.js +28 -4
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/map/filters.js +32 -2
- package/dist/db/pg/map/mutations.js +13 -8
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +64 -24
- package/dist/db/pg/map/relations.js +9 -5
- package/dist/db/pg/migrate.d.ts +1 -2
- package/dist/db/pg/migrate.js +6 -6
- package/dist/db/pg/queries/activity.js +3 -3
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +4 -0
- package/dist/db/pg/schema/documents.d.ts +279 -41
- package/dist/db/pg/schema/documents.js +21 -8
- package/dist/db/pg/schema/edges.d.ts +116 -7
- package/dist/db/pg/schema/edges.js +2 -1
- package/dist/db/pg/schema/index.d.ts +362 -15
- package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
- package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
- package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
- package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
- package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
- package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
- package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
- package/dist/db/pg/sql/meta/_journal.json +43 -1
- package/dist/email/render.js +11 -3
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +1 -0
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +26 -0
- package/dist/federation/identity.d.ts +16 -0
- package/dist/federation/identity.js +52 -0
- package/dist/federation/index.d.ts +4 -0
- package/dist/federation/index.js +3 -0
- package/dist/federation/profiles.d.ts +3 -0
- package/dist/federation/profiles.js +14 -0
- package/dist/groups/finders.d.ts +2 -1
- package/dist/groups/helpers.d.ts +18 -0
- package/dist/groups/mapping.d.ts +4 -2
- package/dist/hashtags/finders.d.ts +6 -3
- package/dist/hashtags/finders.js +2 -0
- package/dist/hashtags/helpers.d.ts +8 -0
- package/dist/hashtags/helpers.js +4 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mutations.d.ts +3 -0
- package/dist/hashtags/mutations.js +13 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +3 -1
- package/dist/i18n/pluginLocales.d.ts +6 -0
- package/dist/i18n/pluginLocales.js +15 -0
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +60 -0
- package/dist/jams/health.d.ts +8 -0
- package/dist/jams/health.js +46 -0
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/index.d.ts +2 -0
- package/dist/jams/index.js +23 -16
- package/dist/jams/jobs.js +1 -1
- package/dist/jams/livekit.d.ts +49 -4
- package/dist/jams/livekit.js +56 -39
- package/dist/jams/mapping.d.ts +3 -3
- package/dist/jams/mutations.d.ts +1 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +32 -0
- package/dist/jams/token.d.ts +13 -1
- package/dist/jams/token.js +18 -7
- package/dist/jams/waitingRoom.js +1 -1
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +6 -1
- package/dist/jobs/jobDetail.js +1 -6
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +23 -8
- package/dist/media/processing.js +18 -7
- package/dist/notifications/defaultNotifications/follow/index.js +2 -2
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +12 -6
- package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +18 -0
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +7 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +75 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/jobs.js +3 -1
- package/dist/notifications/mutations.js +4 -0
- package/dist/plugins/index.js +37 -1
- package/dist/plugins/install.d.ts +28 -9
- package/dist/plugins/install.js +281 -49
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +10 -6
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +35 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +15 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -2
- package/dist/posts/eventAgenda.d.ts +1 -0
- package/dist/posts/eventAgenda.js +10 -4
- package/dist/posts/eventOccurrenceJobs.js +7 -2
- package/dist/posts/eventOccurrences.d.ts +6 -0
- package/dist/posts/eventOccurrences.js +21 -0
- package/dist/posts/finders.d.ts +15 -8
- package/dist/posts/finders.js +67 -18
- package/dist/posts/helpers/filters.js +13 -8
- package/dist/posts/helpers/index.d.ts +27 -14
- package/dist/posts/helpers/index.js +34 -14
- package/dist/posts/index.d.ts +5 -2
- package/dist/posts/index.js +5 -2
- package/dist/posts/mapping.d.ts +216 -13
- package/dist/posts/mapping.js +14 -13
- package/dist/posts/mutations.d.ts +440 -3
- package/dist/posts/mutations.js +155 -32
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +7 -0
- package/dist/posts/pollEndJobs.d.ts +8 -0
- package/dist/posts/pollEndJobs.js +49 -0
- package/dist/posts/replyClosure.d.ts +10 -0
- package/dist/posts/replyClosure.js +43 -0
- package/dist/posts/rsvpConfirmationEmail.js +14 -16
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.js +4 -1
- package/dist/profileSettings/cache.js +22 -5
- package/dist/profileSettings/mapping.d.ts +2 -0
- package/dist/profiles/activityQueries.d.ts +5 -0
- package/dist/profiles/activityQueries.js +85 -0
- package/dist/profiles/activitySummary.d.ts +3 -0
- package/dist/profiles/activitySummary.js +87 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +1 -0
- package/dist/profiles/cache.js +19 -6
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +8 -3
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/index.d.ts +2 -0
- package/dist/profiles/index.js +2 -0
- package/dist/profiles/mapping.d.ts +10 -5
- package/dist/profiles/mapping.js +13 -1
- package/dist/profiles/mutations.d.ts +8 -4
- package/dist/profiles/mutations.js +31 -2
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/roles/index.d.ts +1 -1
- package/dist/roles/index.js +1 -1
- package/dist/roles/mapping.d.ts +1 -0
- package/dist/roles/mutations.js +86 -3
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/server/index.d.ts +18 -0
- package/dist/server/index.js +24 -12
- package/dist/server/stablePublicServerInfo.d.ts +17 -0
- package/dist/server/stablePublicServerInfo.js +37 -0
- package/dist/server/status.d.ts +25 -0
- package/dist/server/status.js +98 -0
- package/dist/stats/finders.d.ts +1 -17681
- package/dist/stats/finders.js +9 -5
- package/dist/stats/mapping.d.ts +0 -1
- package/dist/stats/mapping.js +0 -3
- package/package.json +4 -5
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -33
- package/dist/db/migration/importPostgres.d.ts +0 -3
- package/dist/db/migration/importPostgres.js +0 -18
- package/dist/db/migration/transform.d.ts +0 -20
- package/dist/db/migration/transform.js +0 -232
- package/dist/db/migration/validate.d.ts +0 -18
- package/dist/db/migration/validate.js +0 -69
- package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
- package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
- package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
- package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
- package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
- package/dist/mastodon/index.d.ts +0 -4
- package/dist/mastodon/index.js +0 -51
- package/dist/mastodon/types.d.ts +0 -7579
- package/dist/mastodon/types.js +0 -523
- package/dist/mastodon/typescript.d.ts +0 -1578
- package/dist/mastodon/typescript.js +0 -1
- package/dist/migration/index.d.ts +0 -4
- package/dist/migration/index.js +0 -4
- package/dist/roles/defaults.d.ts +0 -2
- package/dist/roles/defaults.js +0 -95
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { postActivityScoreExpr } from '../db/pg/queries/index.js';
|
|
3
|
+
import { posts } from '../db/pg/schema/documents.js';
|
|
4
|
+
import { bookmarks, entries, replyTo, repost, userGroups, } from '../db/pg/schema/edges.js';
|
|
5
|
+
export const TOP_POSTS_LIMIT = 5;
|
|
6
|
+
export const TOP_POST_CANDIDATE_LIMIT = 25;
|
|
7
|
+
const isReplySql = sql `EXISTS (
|
|
8
|
+
SELECT 1 FROM ${replyTo} WHERE ${replyTo.fromId} = ${posts.id}::text
|
|
9
|
+
)`;
|
|
10
|
+
export const profileActivityCountsSql = (profileId) => sql `
|
|
11
|
+
SELECT
|
|
12
|
+
COUNT(*) FILTER (WHERE NOT ${isReplySql})::int AS posts_count,
|
|
13
|
+
COUNT(*) FILTER (WHERE ${isReplySql})::int AS replies_count,
|
|
14
|
+
COUNT(*) FILTER (
|
|
15
|
+
WHERE ${posts.type} = 'event' AND NOT ${isReplySql}
|
|
16
|
+
)::int AS events_count,
|
|
17
|
+
(
|
|
18
|
+
SELECT COUNT(*)::int FROM ${entries}
|
|
19
|
+
WHERE ${entries.fromId} = ${profileId}
|
|
20
|
+
AND ${entries.body}->>'type' = 'reaction'
|
|
21
|
+
) AS reactions_given,
|
|
22
|
+
(
|
|
23
|
+
SELECT COUNT(*)::int
|
|
24
|
+
FROM ${entries}
|
|
25
|
+
INNER JOIN ${posts} received_posts
|
|
26
|
+
ON received_posts.id::text = ${entries.toId}
|
|
27
|
+
WHERE received_posts.creator_id = ${profileId}
|
|
28
|
+
AND received_posts.deleted_at IS NULL
|
|
29
|
+
AND received_posts.visibility <> 'direct'
|
|
30
|
+
AND ${entries.body}->>'type' = 'reaction'
|
|
31
|
+
) AS reactions_received,
|
|
32
|
+
(
|
|
33
|
+
SELECT COUNT(*)::int FROM ${repost}
|
|
34
|
+
WHERE ${repost.fromId} = ${profileId}
|
|
35
|
+
) AS reposts_count,
|
|
36
|
+
(
|
|
37
|
+
SELECT COUNT(*)::int
|
|
38
|
+
FROM ${repost}
|
|
39
|
+
INNER JOIN ${posts} reposted_posts
|
|
40
|
+
ON reposted_posts.id::text = ${repost.toId}
|
|
41
|
+
WHERE reposted_posts.creator_id = ${profileId}
|
|
42
|
+
AND reposted_posts.deleted_at IS NULL
|
|
43
|
+
AND reposted_posts.visibility <> 'direct'
|
|
44
|
+
) AS reposts_received,
|
|
45
|
+
(
|
|
46
|
+
SELECT COUNT(*)::int
|
|
47
|
+
FROM ${replyTo}
|
|
48
|
+
INNER JOIN ${posts} reply_child_posts
|
|
49
|
+
ON reply_child_posts.id::text = ${replyTo.fromId}
|
|
50
|
+
INNER JOIN ${posts} parent_posts
|
|
51
|
+
ON parent_posts.id::text = ${replyTo.toId}
|
|
52
|
+
WHERE parent_posts.creator_id = ${profileId}
|
|
53
|
+
AND parent_posts.deleted_at IS NULL
|
|
54
|
+
AND parent_posts.visibility <> 'direct'
|
|
55
|
+
AND reply_child_posts.deleted_at IS NULL
|
|
56
|
+
) AS replies_received,
|
|
57
|
+
(
|
|
58
|
+
SELECT COUNT(*)::int FROM ${entries}
|
|
59
|
+
WHERE ${entries.fromId} = ${profileId}
|
|
60
|
+
AND ${entries.body}->>'type' = 'rsvp'
|
|
61
|
+
) AS rsvps_count,
|
|
62
|
+
(
|
|
63
|
+
SELECT COUNT(*)::int FROM ${bookmarks}
|
|
64
|
+
WHERE ${bookmarks.fromId} = ${profileId}
|
|
65
|
+
) AS bookmarks_count,
|
|
66
|
+
(
|
|
67
|
+
SELECT COUNT(*)::int FROM ${userGroups}
|
|
68
|
+
WHERE ${userGroups.fromId} = ${profileId}
|
|
69
|
+
) AS groups_count
|
|
70
|
+
FROM ${posts}
|
|
71
|
+
WHERE ${posts.creatorId} = ${profileId}
|
|
72
|
+
AND ${posts.deletedAt} IS NULL
|
|
73
|
+
AND ${posts.visibility} <> 'direct'
|
|
74
|
+
`;
|
|
75
|
+
export const profileTopPostScoresSql = (profileId) => sql `
|
|
76
|
+
SELECT ${posts.id}::text AS id, (${postActivityScoreExpr(posts)})::int AS activity_score
|
|
77
|
+
FROM ${posts}
|
|
78
|
+
WHERE ${posts.creatorId} = ${profileId}
|
|
79
|
+
AND ${posts.deletedAt} IS NULL
|
|
80
|
+
AND ${posts.visibility} <> 'direct'
|
|
81
|
+
AND NOT ${isReplySql}
|
|
82
|
+
ORDER BY activity_score DESC, ${posts.id} DESC
|
|
83
|
+
LIMIT ${TOP_POST_CANDIDATE_LIMIT}
|
|
84
|
+
`;
|
|
85
|
+
export const takeTopReadablePosts = (ordered, isReadable) => ordered.filter(isReadable).slice(0, TOP_POSTS_LIMIT);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AuthorizationData, ProfileActivitySummary, type AdminProfileSummary } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const getProfileActivitySummary: (authData: AuthorizationData, profileId: string) => Promise<ProfileActivitySummary>;
|
|
3
|
+
export declare const getAdminProfileSummary: (authData: AuthorizationData, profileId: string) => Promise<AdminProfileSummary>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { adminProfileSummarySchema, profileActivitySummarySchema, publicPostWithActivityScoreSchema, publicProfileSchema, } from '@openpeepshq/common/types';
|
|
2
|
+
import { allpeepDb } from '../db/index.js';
|
|
3
|
+
import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
|
|
4
|
+
import { capabilitiesConfig } from '../config/index.js';
|
|
5
|
+
import { canReadPost, transformPost } from '../posts/helpers/index.js';
|
|
6
|
+
import { postsMappingForProfile } from '../posts/mapping.js';
|
|
7
|
+
import { listBlockedByIds } from './blocks.js';
|
|
8
|
+
import { findProfile } from './finders.js';
|
|
9
|
+
import { listReportsByReportedProfile } from '../reports/finders.js';
|
|
10
|
+
import { profileActivityCountsSql, profileTopPostScoresSql, takeTopReadablePosts, } from './activityQueries.js';
|
|
11
|
+
const sqlRows = (result) => { var _a; return (_a = result.rows) !== null && _a !== void 0 ? _a : []; };
|
|
12
|
+
const loadPostsByIds = async (db, ids, authData) => {
|
|
13
|
+
if (ids.length === 0)
|
|
14
|
+
return [];
|
|
15
|
+
const mapData = postsMappingForProfile(authData.profile).data();
|
|
16
|
+
const rows = await fetchRowsByIds(db, mapData.collection, ids, mapData.softDelete);
|
|
17
|
+
const hydrated = (await hydrateMapData(db, mapData, rows));
|
|
18
|
+
const byId = new Map(await Promise.all(hydrated.map(async (post) => {
|
|
19
|
+
const transformed = await transformPost(post, authData.profile);
|
|
20
|
+
return [transformed.id, transformed];
|
|
21
|
+
})));
|
|
22
|
+
return ids
|
|
23
|
+
.map((id) => byId.get(id))
|
|
24
|
+
.filter((post) => !!post);
|
|
25
|
+
};
|
|
26
|
+
export const getProfileActivitySummary = async (authData, profileId) => {
|
|
27
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
28
|
+
const { db } = await allpeepDb();
|
|
29
|
+
const [countRow] = sqlRows(await db.execute(profileActivityCountsSql(profileId)));
|
|
30
|
+
const scored = sqlRows(await db.execute(profileTopPostScoresSql(profileId)))
|
|
31
|
+
.map((row) => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
return ({
|
|
34
|
+
id: String((_a = row.id) !== null && _a !== void 0 ? _a : ''),
|
|
35
|
+
activityScore: Number((_b = row.activity_score) !== null && _b !== void 0 ? _b : 0),
|
|
36
|
+
});
|
|
37
|
+
})
|
|
38
|
+
.filter((row) => row.id);
|
|
39
|
+
const scoreById = new Map(scored.map((row) => [row.id, row.activityScore]));
|
|
40
|
+
const loaded = await loadPostsByIds(db, scored.map((row) => row.id), authData);
|
|
41
|
+
const config = await capabilitiesConfig();
|
|
42
|
+
const readable = canReadPost(config, authData);
|
|
43
|
+
const topPosts = takeTopReadablePosts(loaded, readable)
|
|
44
|
+
.map((post) => {
|
|
45
|
+
var _a;
|
|
46
|
+
return publicPostWithActivityScoreSchema.safeParse(Object.assign(Object.assign({}, post), { activityScore: (_a = scoreById.get(post.id)) !== null && _a !== void 0 ? _a : 0 }));
|
|
47
|
+
})
|
|
48
|
+
.filter((result) => result.success)
|
|
49
|
+
.map((result) => result.data);
|
|
50
|
+
return profileActivitySummarySchema.parse({
|
|
51
|
+
postsCount: Number((_a = countRow === null || countRow === void 0 ? void 0 : countRow.posts_count) !== null && _a !== void 0 ? _a : 0),
|
|
52
|
+
repliesCount: Number((_b = countRow === null || countRow === void 0 ? void 0 : countRow.replies_count) !== null && _b !== void 0 ? _b : 0),
|
|
53
|
+
eventsCount: Number((_c = countRow === null || countRow === void 0 ? void 0 : countRow.events_count) !== null && _c !== void 0 ? _c : 0),
|
|
54
|
+
reactionsGiven: Number((_d = countRow === null || countRow === void 0 ? void 0 : countRow.reactions_given) !== null && _d !== void 0 ? _d : 0),
|
|
55
|
+
reactionsReceived: Number((_e = countRow === null || countRow === void 0 ? void 0 : countRow.reactions_received) !== null && _e !== void 0 ? _e : 0),
|
|
56
|
+
repostsCount: Number((_f = countRow === null || countRow === void 0 ? void 0 : countRow.reposts_count) !== null && _f !== void 0 ? _f : 0),
|
|
57
|
+
repostsReceived: Number((_g = countRow === null || countRow === void 0 ? void 0 : countRow.reposts_received) !== null && _g !== void 0 ? _g : 0),
|
|
58
|
+
repliesReceived: Number((_h = countRow === null || countRow === void 0 ? void 0 : countRow.replies_received) !== null && _h !== void 0 ? _h : 0),
|
|
59
|
+
rsvpsCount: Number((_j = countRow === null || countRow === void 0 ? void 0 : countRow.rsvps_count) !== null && _j !== void 0 ? _j : 0),
|
|
60
|
+
bookmarksCount: Number((_k = countRow === null || countRow === void 0 ? void 0 : countRow.bookmarks_count) !== null && _k !== void 0 ? _k : 0),
|
|
61
|
+
groupsCount: Number((_l = countRow === null || countRow === void 0 ? void 0 : countRow.groups_count) !== null && _l !== void 0 ? _l : 0),
|
|
62
|
+
topPosts,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
export const getAdminProfileSummary = async (authData, profileId) => {
|
|
66
|
+
var _a, _b, _c, _d, _e, _f;
|
|
67
|
+
const profile = await findProfile(profileId);
|
|
68
|
+
if (!profile) {
|
|
69
|
+
throw new Error(`Profile with id ${profileId} not found`);
|
|
70
|
+
}
|
|
71
|
+
const activity = await getProfileActivitySummary(authData, profileId);
|
|
72
|
+
const { db } = await allpeepDb();
|
|
73
|
+
const [blockedByIds, reports] = await Promise.all([
|
|
74
|
+
listBlockedByIds(db, profileId),
|
|
75
|
+
listReportsByReportedProfile(profile),
|
|
76
|
+
]);
|
|
77
|
+
return adminProfileSummarySchema.parse({
|
|
78
|
+
profile: publicProfileSchema.parse(profile),
|
|
79
|
+
activity,
|
|
80
|
+
createdAt: profile.createdAt,
|
|
81
|
+
email: (_b = (_a = profile.controllers) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.email,
|
|
82
|
+
followersCount: (_d = (_c = profile.profileStats) === null || _c === void 0 ? void 0 : _c.followersCount) !== null && _d !== void 0 ? _d : 0,
|
|
83
|
+
followingCount: (_f = (_e = profile.profileStats) === null || _e === void 0 ? void 0 : _e.followingCount) !== null && _f !== void 0 ? _f : 0,
|
|
84
|
+
reportsCount: reports.length,
|
|
85
|
+
blockedByCount: blockedByIds.length,
|
|
86
|
+
});
|
|
87
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PgDb } from '../db/pg/client';
|
|
2
|
+
export declare const listBlockingIds: (db: PgDb, profileId: string) => Promise<string[]>;
|
|
3
|
+
export declare const listBlockedByIds: (db: PgDb, profileId: string) => Promise<string[]>;
|
|
4
|
+
export declare const loadBlockIds: (db: PgDb, profileId: string) => Promise<{
|
|
5
|
+
blockingIds: string[];
|
|
6
|
+
blockedByIds: string[];
|
|
7
|
+
}>;
|
|
8
|
+
export declare const insertBlock: (db: PgDb, fromId: string, toId: string) => Promise<void>;
|
|
9
|
+
export declare const deleteBlock: (db: PgDb, fromId: string, toId: string) => Promise<void>;
|
|
10
|
+
export declare const dropFollowsBetween: (db: PgDb, a: string, b: string) => Promise<void>;
|
|
11
|
+
export declare const areBlocked: (db: PgDb, a: string, b: string) => Promise<boolean>;
|
|
12
|
+
export declare const hasBlockAmong: (db: PgDb, ids: string[]) => Promise<boolean>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { and, eq, inArray, or } from 'drizzle-orm';
|
|
2
|
+
import { uuidv7 } from 'uuidv7';
|
|
3
|
+
import { nowIso } from '../db/pg/mappers.js';
|
|
4
|
+
import { blocks, follows, requestsFollow } from '../db/pg/schema/edges.js';
|
|
5
|
+
export const listBlockingIds = async (db, profileId) => {
|
|
6
|
+
const rows = await db
|
|
7
|
+
.select({ toId: blocks.toId })
|
|
8
|
+
.from(blocks)
|
|
9
|
+
.where(eq(blocks.fromId, profileId));
|
|
10
|
+
return rows.map((row) => row.toId);
|
|
11
|
+
};
|
|
12
|
+
export const listBlockedByIds = async (db, profileId) => {
|
|
13
|
+
const rows = await db
|
|
14
|
+
.select({ fromId: blocks.fromId })
|
|
15
|
+
.from(blocks)
|
|
16
|
+
.where(eq(blocks.toId, profileId));
|
|
17
|
+
return rows.map((row) => row.fromId);
|
|
18
|
+
};
|
|
19
|
+
export const loadBlockIds = async (db, profileId) => {
|
|
20
|
+
const [blockingIds, blockedByIds] = await Promise.all([
|
|
21
|
+
listBlockingIds(db, profileId),
|
|
22
|
+
listBlockedByIds(db, profileId),
|
|
23
|
+
]);
|
|
24
|
+
return { blockingIds, blockedByIds };
|
|
25
|
+
};
|
|
26
|
+
export const insertBlock = async (db, fromId, toId) => {
|
|
27
|
+
const ts = nowIso();
|
|
28
|
+
await db
|
|
29
|
+
.insert(blocks)
|
|
30
|
+
.values({
|
|
31
|
+
id: uuidv7(),
|
|
32
|
+
fromId,
|
|
33
|
+
toId,
|
|
34
|
+
body: {},
|
|
35
|
+
createdAt: ts,
|
|
36
|
+
updatedAt: ts,
|
|
37
|
+
})
|
|
38
|
+
.onConflictDoNothing();
|
|
39
|
+
};
|
|
40
|
+
export const deleteBlock = async (db, fromId, toId) => {
|
|
41
|
+
await db
|
|
42
|
+
.delete(blocks)
|
|
43
|
+
.where(and(eq(blocks.fromId, fromId), eq(blocks.toId, toId)));
|
|
44
|
+
};
|
|
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
|
+
const eitherFollowRequest = (a, b) => or(and(eq(requestsFollow.fromId, a), eq(requestsFollow.toId, b)), and(eq(requestsFollow.fromId, b), eq(requestsFollow.toId, a)));
|
|
47
|
+
export const dropFollowsBetween = async (db, a, b) => {
|
|
48
|
+
await Promise.all([
|
|
49
|
+
db.delete(follows).where(eitherDirection(a, b)),
|
|
50
|
+
db.delete(requestsFollow).where(eitherFollowRequest(a, b)),
|
|
51
|
+
]);
|
|
52
|
+
};
|
|
53
|
+
export const areBlocked = async (db, a, b) => {
|
|
54
|
+
if (!a || !b || a === b)
|
|
55
|
+
return false;
|
|
56
|
+
const rows = await db
|
|
57
|
+
.select({ id: blocks.id })
|
|
58
|
+
.from(blocks)
|
|
59
|
+
.where(or(and(eq(blocks.fromId, a), eq(blocks.toId, b)), and(eq(blocks.fromId, b), eq(blocks.toId, a))))
|
|
60
|
+
.limit(1);
|
|
61
|
+
return rows.length > 0;
|
|
62
|
+
};
|
|
63
|
+
export const hasBlockAmong = async (db, ids) => {
|
|
64
|
+
const unique = [...new Set(ids.filter(Boolean))];
|
|
65
|
+
if (unique.length < 2)
|
|
66
|
+
return false;
|
|
67
|
+
const rows = await db
|
|
68
|
+
.select({ id: blocks.id })
|
|
69
|
+
.from(blocks)
|
|
70
|
+
.where(and(inArray(blocks.fromId, unique), inArray(blocks.toId, unique)))
|
|
71
|
+
.limit(1);
|
|
72
|
+
return rows.length > 0;
|
|
73
|
+
};
|
package/dist/profiles/cache.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export declare const clearProfileCache: (profile: Pick<Profile, "id" | "handle">
|
|
|
5
5
|
export declare const getProfile: (id: string, ignoreSoftDelete?: boolean) => Promise<ProfileWithMeta | undefined>;
|
|
6
6
|
/** Lean profile for post/feed hydrate — no followers/following trees. */
|
|
7
7
|
export declare const getPublicProfile: (id: string, ignoreSoftDelete?: boolean) => Promise<ProfileWithMeta | undefined>;
|
|
8
|
+
/** Local handle lookup only — federated paths must use uri or (handle, domain). */
|
|
8
9
|
export declare const getProfileByHandle: (handle: string, ignoreSoftDelete?: boolean) => Promise<ProfileWithMeta | undefined>;
|
|
9
10
|
export declare const getProfiles: (ids: string[]) => Promise<ProfileWithMeta[]>;
|
package/dist/profiles/cache.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createCache } from 'cache-manager';
|
|
2
2
|
import { allpeepDb } from '../db/index.js';
|
|
3
3
|
import { profilesMapping, publicProfilesMapping } from './mapping.js';
|
|
4
|
+
import { loadBlockIds } from './blocks.js';
|
|
4
5
|
export const profilesCache = createCache({
|
|
5
6
|
ttl: 60 * 60 * 1000,
|
|
6
7
|
refreshThreshold: 60 * 1000,
|
|
@@ -18,15 +19,24 @@ export const clearProfileCache = async (profile) => {
|
|
|
18
19
|
]);
|
|
19
20
|
};
|
|
20
21
|
const withEmptyFollowGraphs = (profile) => {
|
|
21
|
-
var _a, _b, _c, _d;
|
|
22
|
+
var _a, _b, _c, _d, _e, _f;
|
|
22
23
|
return (Object.assign(Object.assign({}, profile), { roles: (_a = profile.roles) !== null && _a !== void 0 ? _a : [], followers: [], following: [], controllers: (_b = profile.controllers) !== null && _b !== void 0 ? _b : [], memberships: (_c = profile.memberships) !== null && _c !== void 0 ? _c : [], profileStats: (_d = profile.profileStats) !== null && _d !== void 0 ? _d : {
|
|
23
24
|
followersCount: 0,
|
|
24
25
|
followingCount: 0,
|
|
25
|
-
} }));
|
|
26
|
+
}, blockingIds: (_e = profile.blockingIds) !== null && _e !== void 0 ? _e : [], blockedByIds: (_f = profile.blockedByIds) !== null && _f !== void 0 ? _f : [] }));
|
|
26
27
|
};
|
|
27
|
-
|
|
28
|
+
const withBlockIds = async (profile) => {
|
|
29
|
+
if (!profile)
|
|
30
|
+
return undefined;
|
|
31
|
+
const { db } = await allpeepDb();
|
|
32
|
+
const { blockingIds, blockedByIds } = await loadBlockIds(db, profile.id);
|
|
33
|
+
return Object.assign(Object.assign({}, profile), { blockingIds, blockedByIds });
|
|
34
|
+
};
|
|
35
|
+
export const getProfile = async (id, ignoreSoftDelete = false) => profilesCache.wrap(id, () => allpeepDb()
|
|
36
|
+
.then(({ db }) => ignoreSoftDelete
|
|
28
37
|
? profilesMapping.ignoreSoftDelete().find(db, id)
|
|
29
|
-
: profilesMapping.find(db, id))
|
|
38
|
+
: profilesMapping.find(db, id))
|
|
39
|
+
.then(withBlockIds));
|
|
30
40
|
/** Lean profile for post/feed hydrate — no followers/following trees. */
|
|
31
41
|
export const getPublicProfile = async (id, ignoreSoftDelete = false) => {
|
|
32
42
|
const profile = await publicProfilesCache.wrap(`${ignoreSoftDelete ? 'all:' : ''}${id}`, () => allpeepDb().then(({ db }) => ignoreSoftDelete
|
|
@@ -34,11 +44,14 @@ export const getPublicProfile = async (id, ignoreSoftDelete = false) => {
|
|
|
34
44
|
: publicProfilesMapping.find(db, id)));
|
|
35
45
|
return profile ? withEmptyFollowGraphs(profile) : undefined;
|
|
36
46
|
};
|
|
37
|
-
|
|
47
|
+
/** Local handle lookup only — federated paths must use uri or (handle, domain). */
|
|
48
|
+
export const getProfileByHandle = async (handle, ignoreSoftDelete = false) => profilesCache.wrap(handle, () => allpeepDb()
|
|
49
|
+
.then(({ db }) => ignoreSoftDelete
|
|
38
50
|
? profilesMapping
|
|
39
51
|
.ignoreSoftDelete()
|
|
40
52
|
.findOneBy(db, { matches: { handle } })
|
|
41
|
-
: profilesMapping.findOneBy(db, { matches: { handle } }))
|
|
53
|
+
: profilesMapping.findOneBy(db, { matches: { handle } }))
|
|
54
|
+
.then(withBlockIds));
|
|
42
55
|
export const getProfiles = async (ids) => profilesCache
|
|
43
56
|
.mget(ids)
|
|
44
57
|
.then((profiles) => Promise.all(profiles.map(async (p, index) => p || (await getProfile(ids[index])))))
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Account, GroupMember, GroupWithMeta, Profile, ProfileWithMeta, Role } from '@openpeepshq/common/types';
|
|
2
2
|
export declare const findProfile: (profileId: string) => Promise<ProfileWithMeta | undefined>;
|
|
3
3
|
export declare const findProfileByHandle: (handle: string) => Promise<ProfileWithMeta | undefined>;
|
|
4
|
+
export { findProfileByHandleAndDomain, findProfileByUri, } from '../federation/profiles';
|
|
4
5
|
export declare const existsProfileByHandle: (handle: string) => Promise<boolean>;
|
|
5
|
-
export declare const listProfiles: () => Promise<ProfileWithMeta[]>;
|
|
6
|
+
export declare const listProfiles: (viewer?: ProfileWithMeta) => Promise<ProfileWithMeta[]>;
|
|
6
7
|
export declare const listProfilesByRole: (role: Role) => Promise<ProfileWithMeta[]>;
|
|
7
8
|
export declare const listProfilesByAccount: (account: Account) => Promise<ProfileWithMeta[]>;
|
|
8
9
|
export declare const listProfilesWithCapabilities: (capabilities: string[]) => Promise<ProfileWithMeta[]>;
|
package/dist/profiles/finders.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { accountProfileRelation, baseProfilesMapping, membersRelation, profileRoleRelation, } from './mapping.js';
|
|
2
2
|
import { allpeepDb } from '../db/index.js';
|
|
3
3
|
import { profileFilters } from '../db/pg/filters/index.js';
|
|
4
|
+
import { blockedPairIds, getUniqueBy } from '@openpeepshq/common/lib';
|
|
4
5
|
import { rolesMapping } from '../roles/mapping.js';
|
|
5
6
|
import { findRolesByCapabilities } from '../roles/finders.js';
|
|
6
7
|
import { expandProfiles, followFinder } from './helpers.js';
|
|
@@ -10,9 +11,13 @@ import { listGroups } from '../groups/index.js';
|
|
|
10
11
|
import { getProfile, getProfileByHandle } from './cache.js';
|
|
11
12
|
export const findProfile = (profileId) => getProfile(profileId);
|
|
12
13
|
export const findProfileByHandle = (handle) => getProfileByHandle(handle);
|
|
14
|
+
export { findProfileByHandleAndDomain, findProfileByUri, } from '../federation/profiles.js';
|
|
13
15
|
export const existsProfileByHandle = (handle) => getProfileByHandle(handle, true).then(Boolean);
|
|
14
|
-
export const listProfiles = () => allpeepDb()
|
|
15
|
-
.then(({ db }) => baseProfilesMapping
|
|
16
|
+
export const listProfiles = (viewer) => allpeepDb()
|
|
17
|
+
.then(({ db }) => baseProfilesMapping
|
|
18
|
+
.filter(profileFilters.notGuest())
|
|
19
|
+
.filter(profileFilters.notIdIn(blockedPairIds(viewer)))
|
|
20
|
+
.all(db))
|
|
16
21
|
.then(expandProfiles);
|
|
17
22
|
export const listProfilesByRole = (role) => allpeepDb()
|
|
18
23
|
.then(({ db }) => rolesMapping.relationsFrom(role, profileRoleRelation).all(db))
|
|
@@ -22,7 +27,7 @@ export const listProfilesByAccount = (account) => allpeepDb()
|
|
|
22
27
|
.then(expandProfiles);
|
|
23
28
|
export const listProfilesWithCapabilities = async (capabilities) => findRolesByCapabilities(capabilities)
|
|
24
29
|
.then((roles) => Promise.all(roles.map((role) => listProfilesByRole(role))))
|
|
25
|
-
.then((pp) => pp.flat());
|
|
30
|
+
.then((pp) => getUniqueBy(pp.flat(), (p) => p.id));
|
|
26
31
|
export const follows = (follower, followed) => allpeepDb().then(({ db }) => followFinder(db, follower, followed).then(Boolean));
|
|
27
32
|
export const listGroupMembers = (group) => allpeepDb()
|
|
28
33
|
.then(({ db }) => groupsMapping.relationsFrom(group, membersRelation).all(db))
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Profile, ProfileWithMeta, Role } from '@openpeepshq/common/types';
|
|
2
2
|
export declare const followConnector: (db: import("../db").PgDb, from: Profile, to: Profile, data?: {
|
|
3
|
+
uri?: string | undefined;
|
|
3
4
|
reblogs?: boolean | undefined;
|
|
4
5
|
notify?: boolean | undefined;
|
|
5
6
|
languages?: string[] | undefined;
|
|
6
7
|
} & {
|
|
7
8
|
id?: string;
|
|
8
9
|
}) => Promise<import("../db/pg/map").WithId<{
|
|
10
|
+
uri?: string | undefined;
|
|
9
11
|
reblogs?: boolean | undefined;
|
|
10
12
|
notify?: boolean | undefined;
|
|
11
13
|
languages?: string[] | undefined;
|
package/dist/profiles/index.d.ts
CHANGED
|
@@ -2,5 +2,7 @@ export * from './mapping';
|
|
|
2
2
|
export * from './mutations';
|
|
3
3
|
export * from './finders';
|
|
4
4
|
export * from './export';
|
|
5
|
+
export { getProfileActivitySummary, getAdminProfileSummary, } from './activitySummary';
|
|
5
6
|
export { getProfile, getPublicProfile, getProfiles, clearProfileCache, } from './cache';
|
|
7
|
+
export { areBlocked, hasBlockAmong, loadBlockIds, listBlockingIds, } from './blocks';
|
|
6
8
|
export declare const findNewFreeHandle: (seed: string) => Promise<string>;
|
package/dist/profiles/index.js
CHANGED
|
@@ -3,7 +3,9 @@ export * from './mapping.js';
|
|
|
3
3
|
export * from './mutations.js';
|
|
4
4
|
export * from './finders.js';
|
|
5
5
|
export * from './export.js';
|
|
6
|
+
export { getProfileActivitySummary, getAdminProfileSummary, } from './activitySummary.js';
|
|
6
7
|
export { getProfile, getPublicProfile, getProfiles, clearProfileCache, } from './cache.js';
|
|
8
|
+
export { areBlocked, hasBlockAmong, loadBlockIds, listBlockingIds, } from './blocks.js';
|
|
7
9
|
const sanitizeHandle = (name) => name.replace(/[^a-zA-Z0-9]/g, '-');
|
|
8
10
|
export const findNewFreeHandle = async (seed) => {
|
|
9
11
|
let counter = 2;
|
|
@@ -35,10 +35,11 @@ export declare const baseProfilesMapping: import("../db/pg/map").Mapping<{
|
|
|
35
35
|
guestData?: {
|
|
36
36
|
email?: string | undefined;
|
|
37
37
|
resource?: {
|
|
38
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "
|
|
38
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
|
|
39
39
|
id?: string | undefined;
|
|
40
40
|
} | undefined;
|
|
41
41
|
} | undefined;
|
|
42
|
+
pinnedPostId?: string | undefined;
|
|
42
43
|
}, Profile, Profile>;
|
|
43
44
|
/** Lean mapping for public search results (memberships only). */
|
|
44
45
|
export declare const publicProfilesSearchMapping: import("../db/pg/map").Mapping<{
|
|
@@ -73,10 +74,11 @@ export declare const publicProfilesSearchMapping: import("../db/pg/map").Mapping
|
|
|
73
74
|
guestData?: {
|
|
74
75
|
email?: string | undefined;
|
|
75
76
|
resource?: {
|
|
76
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "
|
|
77
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
|
|
77
78
|
id?: string | undefined;
|
|
78
79
|
} | undefined;
|
|
79
80
|
} | undefined;
|
|
81
|
+
pinnedPostId?: string | undefined;
|
|
80
82
|
}, ProfileWithMeta, ProfileWithMeta>;
|
|
81
83
|
/**
|
|
82
84
|
* Lean public profile for feed/API hydrate — memberships + SQL follower
|
|
@@ -114,10 +116,11 @@ export declare const publicProfilesMapping: import("../db/pg/map").Mapping<{
|
|
|
114
116
|
guestData?: {
|
|
115
117
|
email?: string | undefined;
|
|
116
118
|
resource?: {
|
|
117
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "
|
|
119
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
|
|
118
120
|
id?: string | undefined;
|
|
119
121
|
} | undefined;
|
|
120
122
|
} | undefined;
|
|
123
|
+
pinnedPostId?: string | undefined;
|
|
121
124
|
}, ProfileWithMeta, ProfileWithMeta>;
|
|
122
125
|
export declare const profilesMapping: import("../db/pg/map").Mapping<{
|
|
123
126
|
handle: string;
|
|
@@ -151,10 +154,11 @@ export declare const profilesMapping: import("../db/pg/map").Mapping<{
|
|
|
151
154
|
guestData?: {
|
|
152
155
|
email?: string | undefined;
|
|
153
156
|
resource?: {
|
|
154
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "
|
|
157
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
|
|
155
158
|
id?: string | undefined;
|
|
156
159
|
} | undefined;
|
|
157
160
|
} | undefined;
|
|
161
|
+
pinnedPostId?: string | undefined;
|
|
158
162
|
}, ProfileWithMeta, ProfileWithMeta>;
|
|
159
163
|
export declare const membersExportMapping: import("../db/pg/map").Mapping<{
|
|
160
164
|
handle: string;
|
|
@@ -188,10 +192,11 @@ export declare const membersExportMapping: import("../db/pg/map").Mapping<{
|
|
|
188
192
|
guestData?: {
|
|
189
193
|
email?: string | undefined;
|
|
190
194
|
resource?: {
|
|
191
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "
|
|
195
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
|
|
192
196
|
id?: string | undefined;
|
|
193
197
|
} | undefined;
|
|
194
198
|
} | undefined;
|
|
199
|
+
pinnedPostId?: string | undefined;
|
|
195
200
|
}, Profile, Profile>;
|
|
196
201
|
export declare const membersRelation: RelationWithMapping<ProfileWithMeta, GroupMember>;
|
|
197
202
|
export declare const profileRoleRelation: RelationWithMapping<Profile>;
|
package/dist/profiles/mapping.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { map } from '../db/pg/map/index.js';
|
|
2
2
|
import { groupsMapping } from '../groups/mapping.js';
|
|
3
3
|
import { profileDerived } from '../db/pg/queries/index.js';
|
|
4
|
+
import { edgeFilters } from '../db/pg/filters/index.js';
|
|
4
5
|
const membersExportStatsRelations = [
|
|
5
6
|
{
|
|
6
7
|
alias: 'reactionsCount',
|
|
7
|
-
edgeCollection: '
|
|
8
|
+
edgeCollection: 'entries',
|
|
8
9
|
direction: 'OUTBOUND',
|
|
9
10
|
count: true,
|
|
10
11
|
cardinality: 'one',
|
|
12
|
+
edgeFilter: edgeFilters.entryType('reaction'),
|
|
11
13
|
},
|
|
12
14
|
];
|
|
13
15
|
export const profileAccountRelation = {
|
|
@@ -65,6 +67,16 @@ export const profileRelations = [
|
|
|
65
67
|
relations: baseProfileRelations,
|
|
66
68
|
},
|
|
67
69
|
},
|
|
70
|
+
{
|
|
71
|
+
alias: 'followedHashtags',
|
|
72
|
+
edgeCollection: 'profileHashtags',
|
|
73
|
+
direction: 'OUTBOUND',
|
|
74
|
+
skipEdge: true,
|
|
75
|
+
cardinality: 'many',
|
|
76
|
+
mapping: {
|
|
77
|
+
collection: 'hashtags',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
68
80
|
];
|
|
69
81
|
export const baseProfilesMapping = map({
|
|
70
82
|
collection: 'profiles',
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { Account, FollowData, GuestPassRequest, Profile, ProfileData, Role } from '@openpeepshq/common/types';
|
|
2
|
-
export declare const createProfile: (data: ProfileData, controllingAccount?: Account) => Promise<
|
|
3
|
-
export declare const createGuestProfile: (guestPassRequest: GuestPassRequest) => Promise<
|
|
4
|
-
export declare const updateProfile: (profileId: string, data: Partial<ProfileData>) => Promise<
|
|
1
|
+
import { Account, FollowData, GuestPassRequest, Profile, ProfileData, ProfileWithMeta, Role } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const createProfile: (data: ProfileData, controllingAccount?: Account) => Promise<ProfileWithMeta>;
|
|
3
|
+
export declare const createGuestProfile: (guestPassRequest: GuestPassRequest) => Promise<ProfileWithMeta>;
|
|
4
|
+
export declare const updateProfile: (profileId: string, data: Partial<ProfileData>) => Promise<ProfileWithMeta>;
|
|
5
|
+
export declare const pinPostOnProfile: (profile: Pick<Profile, "id" | "handle">, pinnedPostId: string) => Promise<ProfileWithMeta>;
|
|
5
6
|
export declare const deleteProfile: (profileId: string) => Promise<void>;
|
|
6
7
|
export declare const follow: (follower: Profile, followed: Profile, followData: FollowData) => Promise<void>;
|
|
7
8
|
export declare const unfollow: (follower: Profile, followed: Profile) => Promise<void>;
|
|
9
|
+
export declare const blockProfile: (blocker: Profile, blocked: Profile) => Promise<void>;
|
|
10
|
+
export declare const unblockProfile: (blocker: Profile, blocked: Profile) => Promise<void>;
|
|
11
|
+
export declare const listBlockedProfiles: (profile: Profile) => Promise<ProfileWithMeta[]>;
|
|
8
12
|
export declare const assignRole: (profile: Profile, role: Role) => Promise<boolean>;
|
|
9
13
|
export declare const unassignRole: (profile: Profile, role: Role) => Promise<boolean>;
|
|
@@ -4,13 +4,20 @@ import { followConnector, followDisconnector, giveControl, roleAssigner, roleUna
|
|
|
4
4
|
import { hub } from '../events/index.js';
|
|
5
5
|
import { randomString } from '@openpeepshq/common/lib';
|
|
6
6
|
import { deleteAccessTokensForProfile } from '../accessTokens/helpers.js';
|
|
7
|
-
import { profilesCache, getProfile, clearProfileCache } from './cache.js';
|
|
7
|
+
import { profilesCache, getProfile, getPublicProfile, clearProfileCache, } from './cache.js';
|
|
8
8
|
import { accountsCache } from '../accounts/cache.js';
|
|
9
9
|
import { assertProfileCapacity } from './capacity.js';
|
|
10
|
+
import { deleteBlock, dropFollowsBetween, insertBlock, listBlockingIds, } from './blocks.js';
|
|
11
|
+
import { localActorScalars } from '../federation/identity.js';
|
|
12
|
+
import { uuidv7 } from 'uuidv7';
|
|
10
13
|
export const createProfile = async (data, controllingAccount) => {
|
|
14
|
+
var _a;
|
|
11
15
|
await assertProfileCapacity();
|
|
12
16
|
const db = await allpeepDb().then((db) => db.db);
|
|
13
|
-
const
|
|
17
|
+
const id = uuidv7();
|
|
18
|
+
const domain = (_a = data.activityPub) === null || _a === void 0 ? void 0 : _a.domain;
|
|
19
|
+
const actor = data.type === 'local' && domain ? localActorScalars(id, domain) : {};
|
|
20
|
+
const profile = await profilesMapping.create(db, Object.assign(Object.assign(Object.assign({}, data), { id }), actor));
|
|
14
21
|
if (controllingAccount) {
|
|
15
22
|
await giveControl(db, controllingAccount, profile);
|
|
16
23
|
await accountsCache.del(controllingAccount.id);
|
|
@@ -37,6 +44,11 @@ export const updateProfile = async (profileId, data) => {
|
|
|
37
44
|
}
|
|
38
45
|
return profilesMapping.update(db, profileId, data);
|
|
39
46
|
};
|
|
47
|
+
export const pinPostOnProfile = async (profile, pinnedPostId) => {
|
|
48
|
+
const updated = await updateProfile(profile.id, { pinnedPostId });
|
|
49
|
+
await clearProfileCache(profile);
|
|
50
|
+
return updated;
|
|
51
|
+
};
|
|
40
52
|
export const deleteProfile = async (profileId) => {
|
|
41
53
|
var _a, _b;
|
|
42
54
|
const db = await allpeepDb().then((db) => db.db);
|
|
@@ -65,6 +77,23 @@ export const unfollow = async (follower, followed) => {
|
|
|
65
77
|
await followDisconnector(db, follower, followed);
|
|
66
78
|
await Promise.all([clearProfileCache(follower), clearProfileCache(followed)]);
|
|
67
79
|
};
|
|
80
|
+
export const blockProfile = async (blocker, blocked) => {
|
|
81
|
+
const { db } = await allpeepDb();
|
|
82
|
+
await insertBlock(db, blocker.id, blocked.id);
|
|
83
|
+
await dropFollowsBetween(db, blocker.id, blocked.id);
|
|
84
|
+
await Promise.all([clearProfileCache(blocker), clearProfileCache(blocked)]);
|
|
85
|
+
};
|
|
86
|
+
export const unblockProfile = async (blocker, blocked) => {
|
|
87
|
+
const { db } = await allpeepDb();
|
|
88
|
+
await deleteBlock(db, blocker.id, blocked.id);
|
|
89
|
+
await Promise.all([clearProfileCache(blocker), clearProfileCache(blocked)]);
|
|
90
|
+
};
|
|
91
|
+
export const listBlockedProfiles = async (profile) => {
|
|
92
|
+
const { db } = await allpeepDb();
|
|
93
|
+
const ids = await listBlockingIds(db, profile.id);
|
|
94
|
+
const profiles = await Promise.all(ids.map((id) => getPublicProfile(id)));
|
|
95
|
+
return profiles.filter((item) => !!item);
|
|
96
|
+
};
|
|
68
97
|
export const assignRole = (profile, role) => allpeepDb()
|
|
69
98
|
.then(({ db }) => roleAssigner(db, profile, role))
|
|
70
99
|
.then(() => profilesCache.del(profile.id));
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { RedisClientType } from 'redis';
|
|
2
2
|
export declare const getConnection: () => Promise<RedisClientType>;
|
|
3
3
|
export declare const disconnect: (conn: RedisClientType) => Promise<void>;
|
|
4
|
+
/** CLI exit: hub.on / getSharedConnection leave node-redis sockets open. */
|
|
5
|
+
export declare const closeRedisConnections: () => Promise<void>;
|
|
4
6
|
export declare const getSharedConnection: () => Promise<RedisClientType>;
|
package/dist/redis/connection.js
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import { createClient } from 'redis';
|
|
2
2
|
import { defaultConfig } from '../config/defaults/core.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const clients = new Set();
|
|
4
|
+
export const getConnection = () => {
|
|
5
|
+
const client = createClient({
|
|
6
|
+
url: `redis://${defaultConfig.redis.host}:6379`,
|
|
7
|
+
});
|
|
8
|
+
client.on('error', console.log);
|
|
9
|
+
clients.add(client);
|
|
10
|
+
return client.connect();
|
|
11
|
+
};
|
|
8
12
|
export const disconnect = async (conn) => {
|
|
9
|
-
|
|
13
|
+
if (conn.isOpen) {
|
|
14
|
+
await conn.disconnect().catch(console.error);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/** CLI exit: hub.on / getSharedConnection leave node-redis sockets open. */
|
|
18
|
+
export const closeRedisConnections = async () => {
|
|
19
|
+
connection = undefined;
|
|
20
|
+
await Promise.all([...clients].map(async (conn) => {
|
|
21
|
+
try {
|
|
22
|
+
await conn.disconnect();
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
// already closed
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
clients.clear();
|
|
10
29
|
};
|
|
11
30
|
let connection;
|
|
12
31
|
export const getSharedConnection = async () => {
|
package/dist/roles/index.d.ts
CHANGED