@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
package/dist/posts/mutations.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
1
2
|
import { allpeepDb } from '../db/index.js';
|
|
2
3
|
import { uuidv7 } from 'uuidv7';
|
|
3
4
|
import { nowIso } from '../db/pg/mappers.js';
|
|
4
5
|
import { postSeen } from '../db/pg/schema/edges.js';
|
|
5
|
-
import { audienceConnector, bookmarkConnector, bookmarkDisconnector, entryConnector, extractHashtags, groupConnector, hashtagConnector, hashtagDisconnector, mentionConnector,
|
|
6
|
+
import { audienceConnector, bookmarkConnector, bookmarkDisconnector, entryConnector, extractHashtags, groupConnector, hashtagConnector, hashtagDisconnector, mentionConnector, replyConnector, repostConnector, resolveMentionsForPost, transformPost, } from './helpers/index.js';
|
|
6
7
|
import { postsMapping, repostRelation } from './mapping.js';
|
|
8
|
+
import { bumpConversationActivity } from './activity.js';
|
|
7
9
|
import { findGroup } from '../groups/finders.js';
|
|
10
|
+
import { findLatestThreadPostId } from './conversationQueries.js';
|
|
11
|
+
import { findPostsForAuth } from './finders.js';
|
|
12
|
+
import { profilesCache } from '../profiles/cache.js';
|
|
8
13
|
import { findOrCreateHashtag } from '../hashtags/index.js';
|
|
9
14
|
import { hub } from '../events/index.js';
|
|
10
15
|
import { listUnseenGroupPostIds } from './unseenCounts.js';
|
|
11
|
-
import { canManageEventRsvps, countYesRsvps, eventDataForDbUpdate, getEffectiveRsvp, normalizeEventDataForSave, passThroughUndefined, sameRecurrenceId, } from '@openpeepshq/common/lib';
|
|
16
|
+
import { AP_LIKE_REACTION, canManageEventRsvps, countYesRsvps, eventDataForDbUpdate, getEffectiveRsvp, instanceRsvpIdsForProfile, overlaySeriesRsvpEntries, normalizeEventDataForSave, passThroughUndefined, rsvpCancelNotice, sameRecurrenceId, seriesYesBlockedByCapacity, } from '@openpeepshq/common/lib';
|
|
12
17
|
import { forbidden, unprocessableRequest } from '../errors/index.js';
|
|
18
|
+
import { areBlocked, hasBlockAmong } from '../profiles/blocks.js';
|
|
13
19
|
import { rebuildEventOccurrences, clearEventOccurrences, } from './eventOccurrences.js';
|
|
20
|
+
import { cancelPollEnd, schedulePollEnd } from './pollEndJobs.js';
|
|
21
|
+
import { config } from '../config/index.js';
|
|
22
|
+
import { localObjectScalars } from '../federation/identity.js';
|
|
14
23
|
export const createPost = async (data, profile, postData, relations = {}) => {
|
|
15
|
-
var _a;
|
|
16
24
|
if (data.type === 'event') {
|
|
17
25
|
data = normalizeEventDataForSave(data);
|
|
18
26
|
}
|
|
@@ -26,23 +34,43 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
26
34
|
if (repliedToPost) {
|
|
27
35
|
postData.visibility = repliedToPost.visibility;
|
|
28
36
|
}
|
|
29
|
-
|
|
37
|
+
if (repliedToPost &&
|
|
38
|
+
(await areBlocked(db, profile.id, repliedToPost.creatorId))) {
|
|
39
|
+
throw forbidden({ errorKey: 'error.cannotInteractBlocked' });
|
|
40
|
+
}
|
|
41
|
+
const audienceIds = [
|
|
42
|
+
profile.id,
|
|
43
|
+
...(relations.audience ?? []).map((member) => member.id),
|
|
44
|
+
];
|
|
45
|
+
if (await hasBlockAmong(db, audienceIds)) {
|
|
46
|
+
throw forbidden({ errorKey: 'error.cannotInteractBlocked' });
|
|
47
|
+
}
|
|
48
|
+
const group = await (repliedToPost?.group ||
|
|
30
49
|
(relations.groupId ? findGroup(relations.groupId) : undefined));
|
|
31
50
|
// Group-linked posts always use visibility=group so community/local feeds
|
|
32
51
|
// (which only include public/local) never surface them incorrectly.
|
|
33
52
|
if (group) {
|
|
34
|
-
postData =
|
|
53
|
+
postData = { ...postData, visibility: 'group' };
|
|
35
54
|
}
|
|
36
55
|
const hashtags = extractHashtags(data);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
56
|
+
const id = uuidv7();
|
|
57
|
+
const domain = (await config()).activityPub.defaultDomain;
|
|
58
|
+
const object = localObjectScalars(id, domain, relations.inReplyToId);
|
|
59
|
+
const post = await postsMapping.removeDefaultFilter().create(db, {
|
|
60
|
+
id,
|
|
61
|
+
...postData,
|
|
62
|
+
...object,
|
|
63
|
+
data,
|
|
64
|
+
type: data.type,
|
|
65
|
+
creatorId: profile.id,
|
|
66
|
+
});
|
|
40
67
|
await entryConnector(db, profile, post, {
|
|
41
68
|
type: 'create',
|
|
42
69
|
data,
|
|
43
70
|
});
|
|
44
71
|
if (repliedToPost) {
|
|
45
72
|
await replyConnector(db, post, repliedToPost);
|
|
73
|
+
await bumpConversationActivity(db, post.id);
|
|
46
74
|
}
|
|
47
75
|
if (group) {
|
|
48
76
|
await groupConnector(db, post, group);
|
|
@@ -58,10 +86,10 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
58
86
|
if (mentions.length) {
|
|
59
87
|
await Promise.all(mentions.map(async (mention) => mentionConnector(db, post, mention.profile, { text: mention.text })));
|
|
60
88
|
}
|
|
61
|
-
const audienceToLink =
|
|
89
|
+
const audienceToLink = relations.audience?.length
|
|
62
90
|
? relations.audience
|
|
63
|
-
: repliedToPost
|
|
64
|
-
if (audienceToLink
|
|
91
|
+
: repliedToPost?.audience;
|
|
92
|
+
if (audienceToLink?.length) {
|
|
65
93
|
await Promise.all(audienceToLink.map(async (member) => {
|
|
66
94
|
await audienceConnector(db, post, member);
|
|
67
95
|
}));
|
|
@@ -71,12 +99,14 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
71
99
|
if (data.type === 'event') {
|
|
72
100
|
await rebuildEventOccurrences(transformedPost.id, data);
|
|
73
101
|
}
|
|
102
|
+
if (data.type === 'question') {
|
|
103
|
+
await schedulePollEnd(transformedPost.id, data.expiresAt);
|
|
104
|
+
}
|
|
74
105
|
hub.emit('postCreated', transformedPost);
|
|
75
106
|
return transformedPost;
|
|
76
107
|
};
|
|
77
108
|
export const updatePost = async (post, profile, data) => {
|
|
78
|
-
|
|
79
|
-
const previousEvent = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
109
|
+
const previousEvent = post.data?.type === 'event' ? post.data : undefined;
|
|
80
110
|
const normalized = data.type === 'event' ? normalizeEventDataForSave(data) : data;
|
|
81
111
|
const dataForDb = normalized.type === 'event'
|
|
82
112
|
? eventDataForDbUpdate(previousEvent, normalized)
|
|
@@ -101,11 +131,28 @@ export const updatePost = async (post, profile, data) => {
|
|
|
101
131
|
if (normalized.type === 'event') {
|
|
102
132
|
await rebuildEventOccurrences(post.id, normalized);
|
|
103
133
|
}
|
|
134
|
+
if (normalized.type === 'question') {
|
|
135
|
+
await schedulePollEnd(post.id, normalized.expiresAt);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
await cancelPollEnd(post.id);
|
|
139
|
+
}
|
|
104
140
|
hub.emit('postUpdated', newPost);
|
|
105
141
|
return newPost;
|
|
106
142
|
};
|
|
107
|
-
export const reactToPost = async (post, profile, data) => allpeepDb().then(({ db }) =>
|
|
108
|
-
|
|
143
|
+
export const reactToPost = async (post, profile, data) => allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
|
|
144
|
+
type: 'reaction',
|
|
145
|
+
data: { reaction: data.reaction },
|
|
146
|
+
})
|
|
147
|
+
.then(() => bumpConversationActivity(db, post.id))
|
|
148
|
+
.then(() => hub.emit('reactionCreated', profile, post, {
|
|
149
|
+
type: 'reaction',
|
|
150
|
+
...data,
|
|
151
|
+
})));
|
|
152
|
+
export const retractReaction = async (post, profile) => allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
|
|
153
|
+
type: 'unreaction',
|
|
154
|
+
data: { reaction: AP_LIKE_REACTION },
|
|
155
|
+
}));
|
|
109
156
|
export const bookmarkPost = async (post, profile) => allpeepDb().then(({ db }) => bookmarkConnector(db, profile, post).then(() => hub.emit('bookmarkCreated', profile, post)));
|
|
110
157
|
export const unbookmarkPost = async (post, profile) => allpeepDb().then(({ db }) => bookmarkDisconnector(db, profile, post));
|
|
111
158
|
export const markPostsSeen = async (posts, profile) => {
|
|
@@ -139,26 +186,36 @@ export const deletePost = async (post, profile) => {
|
|
|
139
186
|
type: 'tombstone',
|
|
140
187
|
},
|
|
141
188
|
});
|
|
142
|
-
await
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
189
|
+
await postsMapping.deleteRelations(db, post.id, {
|
|
190
|
+
...repostRelation,
|
|
191
|
+
direction: 'INBOUND',
|
|
192
|
+
});
|
|
146
193
|
await postsMapping.delete(db, post.id);
|
|
147
194
|
if (post.type === 'event') {
|
|
148
195
|
await clearEventOccurrences(post.id);
|
|
149
196
|
}
|
|
197
|
+
if (post.type === 'question') {
|
|
198
|
+
await cancelPollEnd(post.id);
|
|
199
|
+
}
|
|
150
200
|
return postsMapping.find(db, post.id);
|
|
151
201
|
};
|
|
152
202
|
export const vote = (profile, post, data) => allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
|
|
153
203
|
type: 'answer',
|
|
154
204
|
data,
|
|
155
205
|
}).then(() => hub.emit('entryCreated', profile, post, { type: 'answer', data })));
|
|
206
|
+
const attendingRsvp = (response) => response === 'yes' || response === 'tentative';
|
|
207
|
+
const rsvpOccurrenceIds = (data) => {
|
|
208
|
+
if (data.recurrenceIds?.length)
|
|
209
|
+
return data.recurrenceIds;
|
|
210
|
+
if (data.recurrenceId)
|
|
211
|
+
return [data.recurrenceId];
|
|
212
|
+
return undefined;
|
|
213
|
+
};
|
|
156
214
|
export const rsvpRespond = async (profile, post, data) => {
|
|
157
|
-
var _a, _b, _c, _d;
|
|
158
215
|
if (profile.id === post.profile.id) {
|
|
159
216
|
return;
|
|
160
217
|
}
|
|
161
|
-
if (post.type !== 'event' ||
|
|
218
|
+
if (post.type !== 'event' || post.data?.type !== 'event') {
|
|
162
219
|
throw unprocessableRequest({ errorKey: 'error.unprocessableRequest' });
|
|
163
220
|
}
|
|
164
221
|
// `removed` is an organizer-only status; users cannot set it on themselves,
|
|
@@ -167,9 +224,10 @@ export const rsvpRespond = async (profile, post, data) => {
|
|
|
167
224
|
if (data.response === 'removed') {
|
|
168
225
|
throw forbidden({ errorKey: 'error.rsvpRemovedForbidden' });
|
|
169
226
|
}
|
|
170
|
-
if (
|
|
227
|
+
if (getEffectiveRsvp(post, profile.id)?.response === 'removed') {
|
|
171
228
|
throw forbidden({ errorKey: 'error.rsvpRemoved' });
|
|
172
229
|
}
|
|
230
|
+
const occurrenceIds = rsvpOccurrenceIds(data);
|
|
173
231
|
const maxAttendees = post.data.maxAttendees;
|
|
174
232
|
if (maxAttendees) {
|
|
175
233
|
if (data.response === 'tentative') {
|
|
@@ -178,33 +236,62 @@ export const rsvpRespond = async (profile, post, data) => {
|
|
|
178
236
|
});
|
|
179
237
|
}
|
|
180
238
|
if (data.response === 'yes') {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
239
|
+
if (!occurrenceIds && post.data.recurrence) {
|
|
240
|
+
if (seriesYesBlockedByCapacity(post, profile.id)) {
|
|
241
|
+
throw unprocessableRequest({ errorKey: 'error.eventAtCapacity' });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
const ids = occurrenceIds ?? [undefined];
|
|
246
|
+
for (const recurrenceId of ids) {
|
|
247
|
+
const currentRsvp = getEffectiveRsvp(post, profile.id, recurrenceId);
|
|
248
|
+
if (currentRsvp?.response !== 'yes' &&
|
|
249
|
+
countYesRsvps(post, recurrenceId) >= maxAttendees) {
|
|
250
|
+
throw unprocessableRequest({ errorKey: 'error.eventAtCapacity' });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
185
253
|
}
|
|
186
254
|
}
|
|
187
255
|
}
|
|
188
256
|
const { db } = await allpeepDb();
|
|
189
|
-
const
|
|
190
|
-
.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
257
|
+
const previousResponses = occurrenceIds
|
|
258
|
+
? occurrenceIds.map((id) => getEffectiveRsvp(post, profile.id, id)?.response)
|
|
259
|
+
: undefined;
|
|
260
|
+
const previousResponse = previousResponses
|
|
261
|
+
? previousResponses.every(attendingRsvp)
|
|
262
|
+
? previousResponses[0]
|
|
263
|
+
: previousResponses.find((response) => !attendingRsvp(response))
|
|
264
|
+
: [...(post.rsvps ?? [])]
|
|
265
|
+
.filter((rsvp) => rsvp.profile.id === profile.id)
|
|
266
|
+
.filter((rsvp) => !rsvp.recurrenceId)
|
|
267
|
+
.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]?.response;
|
|
268
|
+
const writes = occurrenceIds
|
|
269
|
+
? occurrenceIds.map((recurrenceId) => ({
|
|
270
|
+
response: data.response,
|
|
271
|
+
recurrenceId,
|
|
272
|
+
}))
|
|
273
|
+
: overlaySeriesRsvpEntries(data.response, instanceRsvpIdsForProfile(post, profile.id));
|
|
274
|
+
for (const entry of writes) {
|
|
275
|
+
await entryConnector(db, profile, post, {
|
|
276
|
+
type: 'rsvp',
|
|
277
|
+
data: entry,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
const cancel = rsvpCancelNotice(post, profile.id, data.response, occurrenceIds);
|
|
200
281
|
hub.emit('rsvpCreated', profile, post, {
|
|
201
282
|
type: 'rsvp',
|
|
202
|
-
data
|
|
283
|
+
data: {
|
|
284
|
+
response: data.response,
|
|
285
|
+
...(occurrenceIds?.length === 1
|
|
286
|
+
? { recurrenceId: occurrenceIds[0] }
|
|
287
|
+
: {}),
|
|
288
|
+
},
|
|
289
|
+
occurrenceIds,
|
|
203
290
|
previousResponse,
|
|
291
|
+
...(cancel ? { cancel } : {}),
|
|
204
292
|
});
|
|
205
293
|
};
|
|
206
294
|
export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post, response, recurrenceId) => {
|
|
207
|
-
var _a, _b;
|
|
208
295
|
if (!canManageEventRsvps(actingProfile, post)) {
|
|
209
296
|
throw forbidden({ errorKey: 'forbidden' });
|
|
210
297
|
}
|
|
@@ -216,13 +303,13 @@ export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post,
|
|
|
216
303
|
}
|
|
217
304
|
const data = { response, recurrenceId };
|
|
218
305
|
const { db } = await allpeepDb();
|
|
219
|
-
const previousResponse =
|
|
306
|
+
const previousResponse = [...(post.rsvps ?? [])]
|
|
220
307
|
.filter((rsvp) => rsvp.profile.id === targetProfile.id)
|
|
221
308
|
.filter((rsvp) => recurrenceId
|
|
222
309
|
? sameRecurrenceId(rsvp.recurrenceId, recurrenceId) ||
|
|
223
310
|
!rsvp.recurrenceId
|
|
224
311
|
: !rsvp.recurrenceId)
|
|
225
|
-
.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]
|
|
312
|
+
.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]?.response;
|
|
226
313
|
await entryConnector(db, targetProfile, post, {
|
|
227
314
|
type: 'rsvp',
|
|
228
315
|
data,
|
|
@@ -233,3 +320,54 @@ export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post,
|
|
|
233
320
|
previousResponse,
|
|
234
321
|
});
|
|
235
322
|
};
|
|
323
|
+
/**
|
|
324
|
+
* Remove a profile from a direct-message conversation thread.
|
|
325
|
+
*
|
|
326
|
+
* - Creates a system "X left" post (empty content) with the *remaining*
|
|
327
|
+
* participants as audience. The leaving user is excluded so future
|
|
328
|
+
* replies (which inherit the audience) won't notify them, and the thread
|
|
329
|
+
* disappears from their inbox.
|
|
330
|
+
* - MessageInThread detects the leave via the audience diff: the leaving
|
|
331
|
+
* user was in the previous post's audience but not in the left-post's.
|
|
332
|
+
* - The conversation post-creation endpoint detects leavers (author not in
|
|
333
|
+
* their own post's audience) to block further posting and exclude them
|
|
334
|
+
* from future replies' audience.
|
|
335
|
+
* - For 1:1 DMs (no remaining participants), removes the user from every
|
|
336
|
+
* post's audience so the thread vanishes from their inbox.
|
|
337
|
+
* - The leaving user can still find the thread in the "Archived" conversations
|
|
338
|
+
* tab, detected by posts they authored but are not in.
|
|
339
|
+
*/
|
|
340
|
+
export const leaveConversation = async (rootPost, profile) => {
|
|
341
|
+
const { db } = await allpeepDb();
|
|
342
|
+
const lastPostId = await findLatestThreadPostId(rootPost.id);
|
|
343
|
+
const [lastPost] = lastPostId === rootPost.id
|
|
344
|
+
? [rootPost]
|
|
345
|
+
: await findPostsForAuth([lastPostId]);
|
|
346
|
+
if (!lastPost)
|
|
347
|
+
return;
|
|
348
|
+
const remainingAudience = lastPost.audience?.filter((p) => p.id !== profile.id) ?? [];
|
|
349
|
+
if (remainingAudience.length > 0) {
|
|
350
|
+
await createPost({ type: 'note', content: '' }, profile, { type: 'note', visibility: 'direct', creatorId: profile.id }, {
|
|
351
|
+
inReplyToId: lastPost.id,
|
|
352
|
+
audience: remainingAudience,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
// 1:1 DM — remove the user from every post's audience so the
|
|
357
|
+
// thread no longer appears in their inbox.
|
|
358
|
+
await db.execute(sql `
|
|
359
|
+
WITH RECURSIVE t AS (
|
|
360
|
+
SELECT ${rootPost.id}::text AS id, 0 AS depth
|
|
361
|
+
UNION ALL
|
|
362
|
+
SELECT rt.from_id::text, t.depth + 1
|
|
363
|
+
FROM reply_to rt
|
|
364
|
+
INNER JOIN t ON rt.to_id = t.id
|
|
365
|
+
WHERE t.depth < 9999
|
|
366
|
+
)
|
|
367
|
+
DELETE FROM audience
|
|
368
|
+
WHERE from_id IN (SELECT id FROM t)
|
|
369
|
+
AND to_id = ${profile.id}
|
|
370
|
+
`);
|
|
371
|
+
}
|
|
372
|
+
await profilesCache.del(profile.id);
|
|
373
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PostWithMeta } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const pollEndDelayMs: (expiresAt: string, now?: number) => number;
|
|
3
|
+
export declare const shouldEmitPollEnded: (post: PostWithMeta | undefined, scheduledExpiresAt: string) => post is PostWithMeta;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface PollEndJobData {
|
|
2
|
+
postId: string;
|
|
3
|
+
expiresAt: string;
|
|
4
|
+
}
|
|
5
|
+
declare const pollEndQueue: () => import("bullmq").Queue, pollEndWorker: () => import("bullmq").Worker;
|
|
6
|
+
export declare const schedulePollEnd: (postId: string, expiresAt?: string) => Promise<void>;
|
|
7
|
+
export declare const cancelPollEnd: (postId: string) => Promise<void>;
|
|
8
|
+
export { pollEndQueue, pollEndWorker };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { queueAndWorker } from '../jobs/index.js';
|
|
2
|
+
import { logger } from '../log/index.js';
|
|
3
|
+
import { hub } from '../events/index.js';
|
|
4
|
+
import { findPost } from './finders.js';
|
|
5
|
+
import { pollEndDelayMs, shouldEmitPollEnded } from './pollEnd.js';
|
|
6
|
+
const log = logger('app:posts:pollEnd');
|
|
7
|
+
const pollEndJobId = (postId) => `poll-end:${postId}`;
|
|
8
|
+
const [pollEndQueue, pollEndWorker] = queueAndWorker('poll-end', async (job) => {
|
|
9
|
+
const post = await findPost(job.data.postId);
|
|
10
|
+
if (!shouldEmitPollEnded(post, job.data.expiresAt)) {
|
|
11
|
+
log.info(`Skipping poll-end for ${job.data.postId}`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
log.info(`Poll ended ${job.data.postId}`);
|
|
15
|
+
await hub.emit('pollEnded', post);
|
|
16
|
+
}, {
|
|
17
|
+
defaultJobOptions: {
|
|
18
|
+
removeOnComplete: { age: 86400 },
|
|
19
|
+
removeOnFail: { age: 86400 * 7, count: 50 },
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
export const schedulePollEnd = async (postId, expiresAt) => {
|
|
23
|
+
try {
|
|
24
|
+
const queue = pollEndQueue();
|
|
25
|
+
const jobId = pollEndJobId(postId);
|
|
26
|
+
await queue.remove(jobId).catch(() => undefined);
|
|
27
|
+
if (!expiresAt) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const delay = pollEndDelayMs(expiresAt);
|
|
31
|
+
if (delay <= 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await queue.add('end', { postId, expiresAt }, { jobId, delay });
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
log.error({ err, postId }, 'Failed to schedule poll-end job');
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const cancelPollEnd = async (postId) => {
|
|
41
|
+
try {
|
|
42
|
+
const queue = pollEndQueue();
|
|
43
|
+
await queue.remove(pollEndJobId(postId));
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
log.error({ err, postId }, 'Failed to cancel poll-end job');
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export { pollEndQueue, pollEndWorker };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PgDb } from '../db/pg/client';
|
|
2
|
+
export declare const CONTEXT_NODE_CAP = 100;
|
|
3
|
+
type ClosureDirection = 'ancestors' | 'descendents';
|
|
4
|
+
/** Collect reply-graph ids via one recursive CTE (capped). */
|
|
5
|
+
export declare const collectReplyClosureIds: (db: PgDb, startId: string, direction: ClosureDirection, { maxDepth, limit, newestFirst, }?: {
|
|
6
|
+
maxDepth?: number;
|
|
7
|
+
limit?: number;
|
|
8
|
+
newestFirst?: boolean;
|
|
9
|
+
}) => Promise<string[]>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
export const CONTEXT_NODE_CAP = 100;
|
|
3
|
+
/** Collect reply-graph ids via one recursive CTE (capped). */
|
|
4
|
+
export const collectReplyClosureIds = async (db, startId, direction, { maxDepth = 9999, limit = CONTEXT_NODE_CAP,
|
|
5
|
+
/** Newest-first by uuidv7 id (useful for long DM threads). */
|
|
6
|
+
newestFirst = false, } = {}) => {
|
|
7
|
+
if (!startId || limit <= 0)
|
|
8
|
+
return [];
|
|
9
|
+
const orderClause = newestFirst ? sql `ORDER BY id DESC` : sql ``;
|
|
10
|
+
const query = direction === 'ancestors'
|
|
11
|
+
? sql `
|
|
12
|
+
WITH RECURSIVE t AS (
|
|
13
|
+
SELECT to_id AS id, 1 AS depth
|
|
14
|
+
FROM reply_to
|
|
15
|
+
WHERE from_id = ${startId}
|
|
16
|
+
UNION ALL
|
|
17
|
+
SELECT r.to_id, t.depth + 1
|
|
18
|
+
FROM reply_to r
|
|
19
|
+
INNER JOIN t ON r.from_id = t.id
|
|
20
|
+
WHERE t.depth < ${maxDepth}
|
|
21
|
+
)
|
|
22
|
+
SELECT id FROM t
|
|
23
|
+
${orderClause}
|
|
24
|
+
LIMIT ${limit}
|
|
25
|
+
`
|
|
26
|
+
: sql `
|
|
27
|
+
WITH RECURSIVE t AS (
|
|
28
|
+
SELECT from_id AS id, 1 AS depth
|
|
29
|
+
FROM reply_to
|
|
30
|
+
WHERE to_id = ${startId}
|
|
31
|
+
UNION ALL
|
|
32
|
+
SELECT r.from_id, t.depth + 1
|
|
33
|
+
FROM reply_to r
|
|
34
|
+
INNER JOIN t ON r.to_id = t.id
|
|
35
|
+
WHERE t.depth < ${maxDepth}
|
|
36
|
+
)
|
|
37
|
+
SELECT id FROM t
|
|
38
|
+
${orderClause}
|
|
39
|
+
LIMIT ${limit}
|
|
40
|
+
`;
|
|
41
|
+
const result = (await db.execute(query));
|
|
42
|
+
return result.rows.map((row) => row.id);
|
|
43
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rsvpConfirmationContent } from '@openpeepshq/common/lib';
|
|
2
2
|
import { hub } from '../events/index.js';
|
|
3
3
|
import { emailService } from '../email/index.js';
|
|
4
4
|
import { findByProfile } from '../accounts/index.js';
|
|
5
|
+
import { findProfileSettings } from '../profileSettings/index.js';
|
|
5
6
|
import { serverRootUrl } from '../server/index.js';
|
|
6
7
|
import { logger } from '../log/index.js';
|
|
7
8
|
const log = logger('openpeeps:rsvp-email');
|
|
@@ -13,14 +14,13 @@ const attendingResponses = ['yes', 'tentative'];
|
|
|
13
14
|
* avoid re-sending when someone toggles between yes/maybe.
|
|
14
15
|
*/
|
|
15
16
|
const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
|
|
16
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
17
17
|
const profile = profileArg;
|
|
18
18
|
const post = postArg;
|
|
19
19
|
const payload = payloadArg;
|
|
20
|
-
if (
|
|
20
|
+
if (payload?.type !== 'rsvp') {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
const response =
|
|
23
|
+
const response = payload.data?.response;
|
|
24
24
|
if (!response || !attendingResponses.includes(response)) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
@@ -28,21 +28,26 @@ const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
|
|
|
28
28
|
attendingResponses.includes(payload.previousResponse)) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
if (post.type !== 'event' ||
|
|
31
|
+
if (post.type !== 'event' || post.data?.type !== 'event') {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
const rootUrl = await serverRootUrl();
|
|
35
35
|
const postUrl = `${rootUrl}/posts/${post.id}`;
|
|
36
|
-
const
|
|
37
|
-
|
|
36
|
+
const occurrenceIds = payload.occurrenceIds ??
|
|
37
|
+
(payload.data.recurrenceId ? [payload.data.recurrenceId] : undefined);
|
|
38
|
+
const confirmation = rsvpConfirmationContent(post, {
|
|
39
|
+
postUrl,
|
|
40
|
+
occurrenceIds,
|
|
41
|
+
});
|
|
42
|
+
if (!confirmation) {
|
|
38
43
|
return;
|
|
39
44
|
}
|
|
40
45
|
const accounts = await findByProfile(profile);
|
|
41
46
|
if (!accounts.length) {
|
|
42
47
|
return;
|
|
43
48
|
}
|
|
44
|
-
const event = post.data;
|
|
45
49
|
const mailer = await emailService();
|
|
50
|
+
const profileSettings = await findProfileSettings(profile.id);
|
|
46
51
|
for (const account of accounts) {
|
|
47
52
|
if (!account.email) {
|
|
48
53
|
continue;
|
|
@@ -52,19 +57,22 @@ const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
|
|
|
52
57
|
to: account.email,
|
|
53
58
|
template: 'eventRsvpConfirmation',
|
|
54
59
|
locals: {
|
|
55
|
-
eventName:
|
|
60
|
+
eventName: confirmation.eventName,
|
|
56
61
|
eventUrl: postUrl,
|
|
57
62
|
response,
|
|
58
|
-
start:
|
|
59
|
-
end:
|
|
60
|
-
location:
|
|
61
|
-
allDay:
|
|
62
|
-
|
|
63
|
+
start: confirmation.start,
|
|
64
|
+
end: confirmation.end,
|
|
65
|
+
location: confirmation.location,
|
|
66
|
+
allDay: confirmation.allDay,
|
|
67
|
+
occurrenceCount: confirmation.occurrenceCount,
|
|
68
|
+
...(profileSettings?.timeZone
|
|
69
|
+
? { timeZone: profileSettings.timeZone }
|
|
70
|
+
: {}),
|
|
63
71
|
},
|
|
64
72
|
attachments: [
|
|
65
73
|
{
|
|
66
74
|
filename: 'event.ics',
|
|
67
|
-
content: ics,
|
|
75
|
+
content: confirmation.ics,
|
|
68
76
|
contentType: 'text/calendar; method=PUBLISH; charset=utf-8',
|
|
69
77
|
},
|
|
70
78
|
],
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DbPost } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const THREAD_PREVIEW_LIMIT = 3;
|
|
3
|
+
export declare const loadThreadPreviewReplies: (rootId: string, currentProfile?: {
|
|
4
|
+
id: string;
|
|
5
|
+
}) => Promise<{
|
|
6
|
+
replies: DbPost[];
|
|
7
|
+
hasMore: boolean;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { allpeepDb } from '../db/index.js';
|
|
2
|
+
import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
|
|
3
|
+
import { collectReplyClosureIds } from './replyClosure.js';
|
|
4
|
+
import { EMBEDDED_LATEST_REPLIES_LIMIT, threadPreviewMappingForProfile, } from './mapping.js';
|
|
5
|
+
export const THREAD_PREVIEW_LIMIT = EMBEDDED_LATEST_REPLIES_LIMIT;
|
|
6
|
+
export const loadThreadPreviewReplies = async (rootId, currentProfile) => {
|
|
7
|
+
if (!rootId)
|
|
8
|
+
return { replies: [], hasMore: false };
|
|
9
|
+
const { db } = await allpeepDb();
|
|
10
|
+
const ids = await collectReplyClosureIds(db, rootId, 'descendents', {
|
|
11
|
+
newestFirst: true,
|
|
12
|
+
limit: THREAD_PREVIEW_LIMIT + 1,
|
|
13
|
+
});
|
|
14
|
+
const hasMore = ids.length > THREAD_PREVIEW_LIMIT;
|
|
15
|
+
const previewIds = ids.slice(0, THREAD_PREVIEW_LIMIT);
|
|
16
|
+
if (!previewIds.length)
|
|
17
|
+
return { replies: [], hasMore: false };
|
|
18
|
+
const mapData = threadPreviewMappingForProfile(currentProfile).data();
|
|
19
|
+
const rows = await fetchRowsByIds(db, mapData.collection, previewIds, mapData.softDelete);
|
|
20
|
+
const hydrated = (await hydrateMapData(db, mapData, rows));
|
|
21
|
+
const byPreviewId = new Map(hydrated.map((post) => [post.id, post]));
|
|
22
|
+
const parentIds = [
|
|
23
|
+
...new Set(hydrated
|
|
24
|
+
.map((post) => post.inReplyToId)
|
|
25
|
+
.filter((id) => !!id && id !== rootId && !byPreviewId.has(id))),
|
|
26
|
+
];
|
|
27
|
+
let parents = [];
|
|
28
|
+
if (parentIds.length) {
|
|
29
|
+
const parentRows = await fetchRowsByIds(db, mapData.collection, parentIds, mapData.softDelete);
|
|
30
|
+
parents = (await hydrateMapData(db, mapData, parentRows));
|
|
31
|
+
}
|
|
32
|
+
const byId = new Map([...hydrated, ...parents].map((post) => [post.id, post]));
|
|
33
|
+
const replies = previewIds
|
|
34
|
+
.map((id) => byPreviewId.get(id))
|
|
35
|
+
.filter((post) => !!post)
|
|
36
|
+
.map((post) => {
|
|
37
|
+
const parentId = post.inReplyToId;
|
|
38
|
+
if (!parentId || parentId === rootId)
|
|
39
|
+
return post;
|
|
40
|
+
const parent = byId.get(parentId);
|
|
41
|
+
return parent ? { ...post, replyTo: parent } : post;
|
|
42
|
+
});
|
|
43
|
+
return { replies, hasMore };
|
|
44
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { sql } from 'drizzle-orm';
|
|
2
|
-
/** Shared predicates for group unseen count and mark-all-read.
|
|
2
|
+
/** Shared predicates for group unseen count and mark-all-read.
|
|
3
|
+
* Includes replies to group posts, not just top-level posts — replies carry
|
|
4
|
+
* the same groupId and should contribute to the group unread badge.
|
|
5
|
+
*/
|
|
3
6
|
const unseenGroupPostMatch = (profileId) => sql `
|
|
4
7
|
p.visibility <> 'direct'
|
|
5
8
|
AND p.creator_id <> ${profileId}
|
|
@@ -3,12 +3,12 @@ import { allpeepDb } from '../db/index.js';
|
|
|
3
3
|
import { sorts } from '../db/pg/queries/index.js';
|
|
4
4
|
const HISTORY_SAMPLE_SIZE = 50;
|
|
5
5
|
const FILETYPE_DEFAULTS_MS = {
|
|
6
|
-
image:
|
|
7
|
-
audio:
|
|
8
|
-
video:
|
|
9
|
-
document:
|
|
6
|
+
image: 2_000,
|
|
7
|
+
audio: 8_000,
|
|
8
|
+
video: 30_000,
|
|
9
|
+
document: 1_500,
|
|
10
10
|
};
|
|
11
|
-
const GENERIC_DEFAULT_MS =
|
|
11
|
+
const GENERIC_DEFAULT_MS = 5_000;
|
|
12
12
|
const median = (values) => {
|
|
13
13
|
if (!values.length)
|
|
14
14
|
return 0;
|
|
@@ -27,7 +27,6 @@ const findRecent = async (filter) => {
|
|
|
27
27
|
.all(db);
|
|
28
28
|
};
|
|
29
29
|
export const estimateProcessingDuration = async ({ filetype, filesize, }) => {
|
|
30
|
-
var _a;
|
|
31
30
|
const lower = filesize * 0.5;
|
|
32
31
|
const upper = filesize * 2;
|
|
33
32
|
const sized = await findRecent({ filetype })
|
|
@@ -42,5 +41,5 @@ export const estimateProcessingDuration = async ({ filetype, filesize, }) => {
|
|
|
42
41
|
if (scaledMedian > 0)
|
|
43
42
|
return scaledMedian;
|
|
44
43
|
}
|
|
45
|
-
return
|
|
44
|
+
return FILETYPE_DEFAULTS_MS[filetype] ?? GENERIC_DEFAULT_MS;
|
|
46
45
|
};
|