@openpeepshq/core 0.1.33 → 0.1.35
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/accessTokens/finders.js +5 -6
- package/dist/accessTokens/mutations.js +1 -1
- package/dist/accessTokens/tokens.js +8 -11
- package/dist/accounts/helpers.js +6 -2
- package/dist/accounts/mutations.js +36 -33
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +17 -12
- package/dist/analytics/dateRange.js +3 -5
- package/dist/analytics/jobs.js +3 -4
- package/dist/analytics/pdfReport.js +45 -61
- package/dist/analytics/privacy.js +1 -1
- package/dist/analytics/read.js +164 -140
- package/dist/analytics/report.d.ts +22 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +82 -25
- package/dist/backups/metadata.d.ts +2 -3
- package/dist/backups/metadata.js +6 -2
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +8 -3
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +16 -8
- package/dist/config/index.d.ts +22 -0
- package/dist/config/index.js +15 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.d.ts +1 -0
- package/dist/db/helpers.js +25 -7
- 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 +121 -174
- package/dist/db/migration/shared.d.ts +2 -33
- package/dist/db/migration/shared.js +17 -87
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +12 -0
- package/dist/db/pg/filters/posts.js +30 -4
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +40 -10
- package/dist/db/pg/map/helpers.js +5 -1
- package/dist/db/pg/map/index.js +46 -51
- package/dist/db/pg/map/mutations.js +65 -25
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +133 -56
- package/dist/db/pg/map/relations.js +76 -68
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.d.ts +1 -2
- package/dist/db/pg/migrate.js +8 -9
- package/dist/db/pg/queries/activity.js +5 -5
- package/dist/db/pg/queries/derived.js +8 -12
- 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 +136 -22
- package/dist/db/pg/schema/edges.d.ts +116 -7
- package/dist/db/pg/schema/edges.js +9 -2
- package/dist/db/pg/schema/index.d.ts +362 -15
- package/dist/db/pg/schema/index.js +5 -1
- 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/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
- package/dist/db/pg/sql/meta/_journal.json +49 -0
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +14 -3
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +1 -0
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +25 -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/helpers.js +1 -2
- package/dist/groups/mapping.d.ts +4 -2
- package/dist/groups/mutations.js +1 -1
- 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/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +58 -0
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +10 -0
- package/dist/jams/health.js +50 -0
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.d.ts +2 -0
- package/dist/jams/index.js +25 -18
- package/dist/jams/jobs.js +2 -3
- package/dist/jams/livekit.d.ts +49 -4
- package/dist/jams/livekit.js +62 -45
- 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 +33 -1
- package/dist/jams/token.d.ts +13 -1
- package/dist/jams/token.js +25 -18
- package/dist/jams/waitingRoom.js +1 -1
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +9 -3
- package/dist/jobs/jobDetail.js +6 -12
- package/dist/jobs/jobLog.js +2 -3
- package/dist/lib/streams.js +4 -39
- package/dist/lib/zodDeepPartial.d.ts +1 -1
- package/dist/lib/zodDeepPartial.js +1 -1
- package/dist/log/index.js +13 -29
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +73 -12
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +25 -11
- package/dist/media/streaming.js +5 -5
- package/dist/media/streamingCleanupJobs.js +1 -2
- package/dist/media/streamingJobs.js +3 -4
- package/dist/media/streamingPrewarm.js +7 -11
- package/dist/mediaAttachments/index.js +6 -2
- package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
- package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
- package/dist/notifications/defaultNotifications/follow/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
- package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
- package/dist/notifications/defaultNotifications/mention/index.js +20 -24
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +11 -6
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- 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 +17 -0
- package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
- package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
- package/dist/notifications/defaultNotifications/reply/index.js +21 -22
- package/dist/notifications/defaultNotifications/repost/index.js +16 -20
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.js +13 -10
- package/dist/notifications/jobs.js +10 -5
- package/dist/notifications/mutations.js +8 -1
- package/dist/notifications/push.js +11 -16
- package/dist/performance/index.js +3 -3
- package/dist/plugins/helpers.js +3 -6
- package/dist/plugins/index.js +39 -4
- package/dist/plugins/install.d.ts +28 -9
- package/dist/plugins/install.js +302 -56
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +13 -10
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +34 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +14 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -4
- package/dist/posts/eventAgenda.d.ts +1 -0
- package/dist/posts/eventAgenda.js +17 -8
- package/dist/posts/eventOccurrenceJobs.js +7 -2
- package/dist/posts/eventOccurrences.d.ts +6 -0
- package/dist/posts/eventOccurrences.js +22 -1
- package/dist/posts/finders.d.ts +56 -9
- package/dist/posts/finders.js +84 -23
- package/dist/posts/helpers/filters.js +13 -9
- package/dist/posts/helpers/index.d.ts +179 -14
- package/dist/posts/helpers/index.js +70 -34
- package/dist/posts/index.d.ts +5 -2
- package/dist/posts/index.js +5 -2
- package/dist/posts/mapping.d.ts +765 -30
- package/dist/posts/mapping.js +74 -31
- package/dist/posts/mutations.d.ts +516 -3
- package/dist/posts/mutations.js +179 -41
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +4 -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 +23 -15
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.js +4 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +21 -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 +82 -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 +30 -10
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +15 -8
- 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 -4
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/reports/helpers.js +7 -3
- 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 +85 -3
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/sentry/index.js +9 -11
- package/dist/seo/index.d.ts +50 -0
- package/dist/seo/index.js +145 -0
- package/dist/seo/route.d.ts +18 -0
- package/dist/seo/route.js +19 -0
- package/dist/server/index.d.ts +19 -0
- package/dist/server/index.js +31 -14
- 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 +97 -0
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.d.ts +1 -17681
- package/dist/stats/finders.js +22 -9
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +39 -2
- package/dist/stats/mapping.js +8 -4
- package/dist/stripe/cache.js +5 -6
- package/dist/stripe/connection.js +3 -4
- package/dist/stripe/helpers.js +15 -20
- package/package.json +5 -7
- 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
|
@@ -11,14 +11,30 @@ export const profileSettingsCache = createCache({
|
|
|
11
11
|
hub.on('profileSettingsUpdated', (profileId) => {
|
|
12
12
|
void profileSettingsCache.del(profileId);
|
|
13
13
|
});
|
|
14
|
+
const uniqueViolation = (error) => {
|
|
15
|
+
const current = error;
|
|
16
|
+
return current.code === '23505' || current.cause?.code === '23505';
|
|
17
|
+
};
|
|
18
|
+
const readProfileSettings = async (db, id) =>
|
|
19
|
+
// Include soft-deleted rows: the profile_id unique index still covers them,
|
|
20
|
+
// so a miss here would insert and fail with 23505.
|
|
21
|
+
profileSettingsMapping.find(db, id, { ignoreSoftDelete: true });
|
|
14
22
|
export const getProfileSettings = async (id) => profileSettingsCache.wrap(id, async () => {
|
|
15
23
|
const { db } = await allpeepDb();
|
|
16
|
-
const foundSettings = await
|
|
24
|
+
const foundSettings = await readProfileSettings(db, id);
|
|
17
25
|
if (foundSettings) {
|
|
18
26
|
return foundSettings;
|
|
19
27
|
}
|
|
20
|
-
|
|
21
|
-
id
|
|
22
|
-
}
|
|
23
|
-
|
|
28
|
+
try {
|
|
29
|
+
return await profileSettingsMapping.create(db, { id });
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
// Another request created the row between the read and this insert.
|
|
33
|
+
if (!uniqueViolation(error))
|
|
34
|
+
throw error;
|
|
35
|
+
const raced = await readProfileSettings(db, id);
|
|
36
|
+
if (raced)
|
|
37
|
+
return raced;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
24
40
|
});
|
|
@@ -2,6 +2,7 @@ import { ProfileSettings } from '@openpeepshq/common/types';
|
|
|
2
2
|
export declare const profileSettingsMapping: import("../db/pg/map").Mapping<{
|
|
3
3
|
id: string;
|
|
4
4
|
language?: string | undefined;
|
|
5
|
+
timeZone?: string | undefined;
|
|
5
6
|
theme?: "light" | "dark" | "community" | "system" | undefined;
|
|
6
7
|
defaults?: {
|
|
7
8
|
privacy?: "public" | "unlisted" | "private" | undefined;
|
|
@@ -31,6 +32,7 @@ export declare const profileSettingsMapping: import("../db/pg/map").Mapping<{
|
|
|
31
32
|
customerId?: string | undefined;
|
|
32
33
|
} | undefined;
|
|
33
34
|
feedSettings?: {
|
|
35
|
+
format?: "threaded" | "linear" | undefined;
|
|
34
36
|
communityFeed?: {
|
|
35
37
|
showGroupPosts?: boolean | undefined;
|
|
36
38
|
} | undefined;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const TOP_POSTS_LIMIT = 5;
|
|
2
|
+
export declare const TOP_POST_CANDIDATE_LIMIT = 25;
|
|
3
|
+
export declare const profileActivityCountsSql: (profileId: string) => import("drizzle-orm").SQL<unknown>;
|
|
4
|
+
export declare const profileTopPostScoresSql: (profileId: string) => import("drizzle-orm").SQL<unknown>;
|
|
5
|
+
export declare const takeTopReadablePosts: <T>(ordered: T[], isReadable: (item: T) => boolean) => T[];
|
|
@@ -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,82 @@
|
|
|
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) => result.rows ?? [];
|
|
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
|
+
const { db } = await allpeepDb();
|
|
28
|
+
const [countRow] = sqlRows(await db.execute(profileActivityCountsSql(profileId)));
|
|
29
|
+
const scored = sqlRows(await db.execute(profileTopPostScoresSql(profileId)))
|
|
30
|
+
.map((row) => ({
|
|
31
|
+
id: String(row.id ?? ''),
|
|
32
|
+
activityScore: Number(row.activity_score ?? 0),
|
|
33
|
+
}))
|
|
34
|
+
.filter((row) => row.id);
|
|
35
|
+
const scoreById = new Map(scored.map((row) => [row.id, row.activityScore]));
|
|
36
|
+
const loaded = await loadPostsByIds(db, scored.map((row) => row.id), authData);
|
|
37
|
+
const config = await capabilitiesConfig();
|
|
38
|
+
const readable = canReadPost(config, authData);
|
|
39
|
+
const topPosts = takeTopReadablePosts(loaded, readable)
|
|
40
|
+
.map((post) => publicPostWithActivityScoreSchema.safeParse({
|
|
41
|
+
...post,
|
|
42
|
+
activityScore: scoreById.get(post.id) ?? 0,
|
|
43
|
+
}))
|
|
44
|
+
.filter((result) => result.success)
|
|
45
|
+
.map((result) => result.data);
|
|
46
|
+
return profileActivitySummarySchema.parse({
|
|
47
|
+
postsCount: Number(countRow?.posts_count ?? 0),
|
|
48
|
+
repliesCount: Number(countRow?.replies_count ?? 0),
|
|
49
|
+
eventsCount: Number(countRow?.events_count ?? 0),
|
|
50
|
+
reactionsGiven: Number(countRow?.reactions_given ?? 0),
|
|
51
|
+
reactionsReceived: Number(countRow?.reactions_received ?? 0),
|
|
52
|
+
repostsCount: Number(countRow?.reposts_count ?? 0),
|
|
53
|
+
repostsReceived: Number(countRow?.reposts_received ?? 0),
|
|
54
|
+
repliesReceived: Number(countRow?.replies_received ?? 0),
|
|
55
|
+
rsvpsCount: Number(countRow?.rsvps_count ?? 0),
|
|
56
|
+
bookmarksCount: Number(countRow?.bookmarks_count ?? 0),
|
|
57
|
+
groupsCount: Number(countRow?.groups_count ?? 0),
|
|
58
|
+
topPosts,
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
export const getAdminProfileSummary = async (authData, profileId) => {
|
|
62
|
+
const profile = await findProfile(profileId);
|
|
63
|
+
if (!profile) {
|
|
64
|
+
throw new Error(`Profile with id ${profileId} not found`);
|
|
65
|
+
}
|
|
66
|
+
const activity = await getProfileActivitySummary(authData, profileId);
|
|
67
|
+
const { db } = await allpeepDb();
|
|
68
|
+
const [blockedByIds, reports] = await Promise.all([
|
|
69
|
+
listBlockedByIds(db, profileId),
|
|
70
|
+
listReportsByReportedProfile(profile),
|
|
71
|
+
]);
|
|
72
|
+
return adminProfileSummarySchema.parse({
|
|
73
|
+
profile: publicProfileSchema.parse(profile),
|
|
74
|
+
activity,
|
|
75
|
+
createdAt: profile.createdAt,
|
|
76
|
+
email: profile.controllers?.[0]?.email,
|
|
77
|
+
followersCount: profile.profileStats?.followersCount ?? 0,
|
|
78
|
+
followingCount: profile.profileStats?.followingCount ?? 0,
|
|
79
|
+
reportsCount: reports.length,
|
|
80
|
+
blockedByCount: blockedByIds.length,
|
|
81
|
+
});
|
|
82
|
+
};
|
|
@@ -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,
|
|
@@ -17,16 +18,32 @@ export const clearProfileCache = async (profile) => {
|
|
|
17
18
|
publicProfilesCache.del(`all:${profile.id}`),
|
|
18
19
|
]);
|
|
19
20
|
};
|
|
20
|
-
const withEmptyFollowGraphs = (profile) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const withEmptyFollowGraphs = (profile) => ({
|
|
22
|
+
...profile,
|
|
23
|
+
roles: profile.roles ?? [],
|
|
24
|
+
followers: [],
|
|
25
|
+
following: [],
|
|
26
|
+
controllers: profile.controllers ?? [],
|
|
27
|
+
memberships: profile.memberships ?? [],
|
|
28
|
+
profileStats: profile.profileStats ?? {
|
|
29
|
+
followersCount: 0,
|
|
30
|
+
followingCount: 0,
|
|
31
|
+
},
|
|
32
|
+
blockingIds: profile.blockingIds ?? [],
|
|
33
|
+
blockedByIds: profile.blockedByIds ?? [],
|
|
34
|
+
});
|
|
35
|
+
const withBlockIds = async (profile) => {
|
|
36
|
+
if (!profile)
|
|
37
|
+
return undefined;
|
|
38
|
+
const { db } = await allpeepDb();
|
|
39
|
+
const { blockingIds, blockedByIds } = await loadBlockIds(db, profile.id);
|
|
40
|
+
return { ...profile, blockingIds, blockedByIds };
|
|
26
41
|
};
|
|
27
|
-
export const getProfile = async (id, ignoreSoftDelete = false) => profilesCache.wrap(id, () => allpeepDb()
|
|
42
|
+
export const getProfile = async (id, ignoreSoftDelete = false) => profilesCache.wrap(id, () => allpeepDb()
|
|
43
|
+
.then(({ db }) => ignoreSoftDelete
|
|
28
44
|
? profilesMapping.ignoreSoftDelete().find(db, id)
|
|
29
|
-
: profilesMapping.find(db, id))
|
|
45
|
+
: profilesMapping.find(db, id))
|
|
46
|
+
.then(withBlockIds));
|
|
30
47
|
/** Lean profile for post/feed hydrate — no followers/following trees. */
|
|
31
48
|
export const getPublicProfile = async (id, ignoreSoftDelete = false) => {
|
|
32
49
|
const profile = await publicProfilesCache.wrap(`${ignoreSoftDelete ? 'all:' : ''}${id}`, () => allpeepDb().then(({ db }) => ignoreSoftDelete
|
|
@@ -34,11 +51,14 @@ export const getPublicProfile = async (id, ignoreSoftDelete = false) => {
|
|
|
34
51
|
: publicProfilesMapping.find(db, id)));
|
|
35
52
|
return profile ? withEmptyFollowGraphs(profile) : undefined;
|
|
36
53
|
};
|
|
37
|
-
|
|
54
|
+
/** Local handle lookup only — federated paths must use uri or (handle, domain). */
|
|
55
|
+
export const getProfileByHandle = async (handle, ignoreSoftDelete = false) => profilesCache.wrap(handle, () => allpeepDb()
|
|
56
|
+
.then(({ db }) => ignoreSoftDelete
|
|
38
57
|
? profilesMapping
|
|
39
58
|
.ignoreSoftDelete()
|
|
40
59
|
.findOneBy(db, { matches: { handle } })
|
|
41
|
-
: profilesMapping.findOneBy(db, { matches: { handle } }))
|
|
60
|
+
: profilesMapping.findOneBy(db, { matches: { handle } }))
|
|
61
|
+
.then(withBlockIds));
|
|
42
62
|
export const getProfiles = async (ids) => profilesCache
|
|
43
63
|
.mget(ids)
|
|
44
64
|
.then((profiles) => Promise.all(profiles.map(async (p, index) => p || (await getProfile(ids[index])))))
|
package/dist/profiles/export.js
CHANGED
|
@@ -9,14 +9,11 @@ const emptyStats = () => ({
|
|
|
9
9
|
reactionsCount: 0,
|
|
10
10
|
lastSeen: null,
|
|
11
11
|
});
|
|
12
|
-
const toMemberExportStats = (row) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
lastSeen: (_c = row === null || row === void 0 ? void 0 : row.lastSeen) !== null && _c !== void 0 ? _c : null,
|
|
18
|
-
});
|
|
19
|
-
};
|
|
12
|
+
const toMemberExportStats = (row) => ({
|
|
13
|
+
postsCount: row?.postsCount ?? 0,
|
|
14
|
+
reactionsCount: row?.reactionsCount ?? 0,
|
|
15
|
+
lastSeen: row?.lastSeen ?? null,
|
|
16
|
+
});
|
|
20
17
|
export const listMembersForExport = async () => {
|
|
21
18
|
const { db } = await allpeepDb();
|
|
22
19
|
const [profiles, statsRows] = await Promise.all([
|
|
@@ -24,22 +21,19 @@ export const listMembersForExport = async () => {
|
|
|
24
21
|
membersExportMapping.filter(guestFilter).all(db),
|
|
25
22
|
]);
|
|
26
23
|
const statsById = new Map(statsRows.map((row) => [row.id, toMemberExportStats(row)]));
|
|
27
|
-
return profiles.map((profile) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
24
|
+
return profiles.map((profile) => ({
|
|
25
|
+
...profile,
|
|
26
|
+
...(statsById.get(profile.id) ?? emptyStats()),
|
|
27
|
+
}));
|
|
31
28
|
};
|
|
32
29
|
const formatCustomFields = (fields) => formatMemberExportCustomFields(fields);
|
|
33
30
|
const formatEmailVerified = (controllers) => {
|
|
34
|
-
|
|
35
|
-
const validated = (_a = controllers[0]) === null || _a === void 0 ? void 0 : _a.emailValidated;
|
|
31
|
+
const validated = controllers[0]?.emailValidated;
|
|
36
32
|
return validated == null ? '' : validated ? 'yes' : 'no';
|
|
37
33
|
};
|
|
38
|
-
const formatGroups = (memberships) =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
const formatRoles = (roles) => { var _a; return (_a = roles === null || roles === void 0 ? void 0 : roles.map((role) => role.displayName || role.key).join('; ')) !== null && _a !== void 0 ? _a : ''; };
|
|
34
|
+
const formatGroups = (memberships) => memberships?.map((membership) => membership.group.displayName).join('; ') ??
|
|
35
|
+
'';
|
|
36
|
+
const formatRoles = (roles) => roles?.map((role) => role.displayName || role.key).join('; ') ?? '';
|
|
43
37
|
const memberExportHeaders = [
|
|
44
38
|
'Email',
|
|
45
39
|
'Email Verified',
|
|
@@ -61,25 +55,22 @@ export const exportMembersCsv = async () => {
|
|
|
61
55
|
const members = await listMembersForExport();
|
|
62
56
|
return [
|
|
63
57
|
toCsvRow([...memberExportHeaders]),
|
|
64
|
-
...members.map((member) =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
member.profileStats.followingCount,
|
|
82
|
-
]);
|
|
83
|
-
}),
|
|
58
|
+
...members.map((member) => toCsvRow([
|
|
59
|
+
member.controllers[0]?.email ?? '',
|
|
60
|
+
formatEmailVerified(member.controllers),
|
|
61
|
+
member.createdAt,
|
|
62
|
+
member.handle,
|
|
63
|
+
member.displayName ?? '',
|
|
64
|
+
formatRoles(member.roles),
|
|
65
|
+
member.bio ?? '',
|
|
66
|
+
member.location?.text ?? '',
|
|
67
|
+
formatCustomFields(member.fields),
|
|
68
|
+
formatGroups(member.memberships),
|
|
69
|
+
member.lastSeen ?? '',
|
|
70
|
+
member.postsCount,
|
|
71
|
+
member.reactionsCount,
|
|
72
|
+
member.profileStats.followersCount,
|
|
73
|
+
member.profileStats.followingCount,
|
|
74
|
+
])),
|
|
84
75
|
].join('\n');
|
|
85
76
|
};
|
|
@@ -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,18 +27,20 @@ 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))
|
|
29
34
|
.then((members) => Promise.all(members
|
|
30
|
-
.filter((m) =>
|
|
31
|
-
.map(async (m) => (
|
|
35
|
+
.filter((m) => m.profile?.id)
|
|
36
|
+
.map(async (m) => ({
|
|
37
|
+
...m,
|
|
38
|
+
profile: (await getProfile(m.profile.id)),
|
|
39
|
+
}))))
|
|
32
40
|
.then((members) => members.filter((m) => !!m.profile));
|
|
33
41
|
export const listCommonGroups = async (profile1, profile2) => {
|
|
34
|
-
var _a, _b;
|
|
35
42
|
const groups = await listGroups({ profile: profile1, scopes: [] });
|
|
36
|
-
const profile1GroupIds = new Set(
|
|
37
|
-
const profile2GroupIds = new Set(
|
|
43
|
+
const profile1GroupIds = new Set(profile1.memberships?.map((m) => m.group.id) || []);
|
|
44
|
+
const profile2GroupIds = new Set(profile2.memberships?.map((m) => m.group.id) || []);
|
|
38
45
|
return groups.filter((group) => profile1GroupIds.has(group.id) && profile2GroupIds.has(group.id));
|
|
39
46
|
};
|
|
@@ -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;
|