@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
package/dist/posts/mutations.js
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
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;
|
|
24
|
+
var _a, _b;
|
|
16
25
|
if (data.type === 'event') {
|
|
17
26
|
data = normalizeEventDataForSave(data);
|
|
18
27
|
}
|
|
@@ -26,6 +35,17 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
26
35
|
if (repliedToPost) {
|
|
27
36
|
postData.visibility = repliedToPost.visibility;
|
|
28
37
|
}
|
|
38
|
+
if (repliedToPost &&
|
|
39
|
+
(await areBlocked(db, profile.id, repliedToPost.creatorId))) {
|
|
40
|
+
throw forbidden({ errorKey: 'error.cannotInteractBlocked' });
|
|
41
|
+
}
|
|
42
|
+
const audienceIds = [
|
|
43
|
+
profile.id,
|
|
44
|
+
...((_a = relations.audience) !== null && _a !== void 0 ? _a : []).map((member) => member.id),
|
|
45
|
+
];
|
|
46
|
+
if (await hasBlockAmong(db, audienceIds)) {
|
|
47
|
+
throw forbidden({ errorKey: 'error.cannotInteractBlocked' });
|
|
48
|
+
}
|
|
29
49
|
const group = await ((repliedToPost === null || repliedToPost === void 0 ? void 0 : repliedToPost.group) ||
|
|
30
50
|
(relations.groupId ? findGroup(relations.groupId) : undefined));
|
|
31
51
|
// Group-linked posts always use visibility=group so community/local feeds
|
|
@@ -34,15 +54,17 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
34
54
|
postData = Object.assign(Object.assign({}, postData), { visibility: 'group' });
|
|
35
55
|
}
|
|
36
56
|
const hashtags = extractHashtags(data);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
const id = uuidv7();
|
|
58
|
+
const domain = (await config()).activityPub.defaultDomain;
|
|
59
|
+
const object = localObjectScalars(id, domain, relations.inReplyToId);
|
|
60
|
+
const post = await postsMapping.removeDefaultFilter().create(db, Object.assign(Object.assign(Object.assign({ id }, postData), object), { data, type: data.type, creatorId: profile.id }));
|
|
40
61
|
await entryConnector(db, profile, post, {
|
|
41
62
|
type: 'create',
|
|
42
63
|
data,
|
|
43
64
|
});
|
|
44
65
|
if (repliedToPost) {
|
|
45
66
|
await replyConnector(db, post, repliedToPost);
|
|
67
|
+
await bumpConversationActivity(db, post.id);
|
|
46
68
|
}
|
|
47
69
|
if (group) {
|
|
48
70
|
await groupConnector(db, post, group);
|
|
@@ -58,7 +80,7 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
58
80
|
if (mentions.length) {
|
|
59
81
|
await Promise.all(mentions.map(async (mention) => mentionConnector(db, post, mention.profile, { text: mention.text })));
|
|
60
82
|
}
|
|
61
|
-
const audienceToLink = ((
|
|
83
|
+
const audienceToLink = ((_b = relations.audience) === null || _b === void 0 ? void 0 : _b.length)
|
|
62
84
|
? relations.audience
|
|
63
85
|
: repliedToPost === null || repliedToPost === void 0 ? void 0 : repliedToPost.audience;
|
|
64
86
|
if (audienceToLink === null || audienceToLink === void 0 ? void 0 : audienceToLink.length) {
|
|
@@ -71,6 +93,9 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
71
93
|
if (data.type === 'event') {
|
|
72
94
|
await rebuildEventOccurrences(transformedPost.id, data);
|
|
73
95
|
}
|
|
96
|
+
if (data.type === 'question') {
|
|
97
|
+
await schedulePollEnd(transformedPost.id, data.expiresAt);
|
|
98
|
+
}
|
|
74
99
|
hub.emit('postCreated', transformedPost);
|
|
75
100
|
return transformedPost;
|
|
76
101
|
};
|
|
@@ -101,11 +126,25 @@ export const updatePost = async (post, profile, data) => {
|
|
|
101
126
|
if (normalized.type === 'event') {
|
|
102
127
|
await rebuildEventOccurrences(post.id, normalized);
|
|
103
128
|
}
|
|
129
|
+
if (normalized.type === 'question') {
|
|
130
|
+
await schedulePollEnd(post.id, normalized.expiresAt);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
await cancelPollEnd(post.id);
|
|
134
|
+
}
|
|
104
135
|
hub.emit('postUpdated', newPost);
|
|
105
136
|
return newPost;
|
|
106
137
|
};
|
|
107
|
-
export const reactToPost = async (post, profile, data) => allpeepDb().then(({ db }) =>
|
|
108
|
-
|
|
138
|
+
export const reactToPost = async (post, profile, data) => allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
|
|
139
|
+
type: 'reaction',
|
|
140
|
+
data: { reaction: data.reaction },
|
|
141
|
+
})
|
|
142
|
+
.then(() => bumpConversationActivity(db, post.id))
|
|
143
|
+
.then(() => hub.emit('reactionCreated', profile, post, Object.assign({ type: 'reaction' }, data))));
|
|
144
|
+
export const retractReaction = async (post, profile) => allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
|
|
145
|
+
type: 'unreaction',
|
|
146
|
+
data: { reaction: AP_LIKE_REACTION },
|
|
147
|
+
}));
|
|
109
148
|
export const bookmarkPost = async (post, profile) => allpeepDb().then(({ db }) => bookmarkConnector(db, profile, post).then(() => hub.emit('bookmarkCreated', profile, post)));
|
|
110
149
|
export const unbookmarkPost = async (post, profile) => allpeepDb().then(({ db }) => bookmarkDisconnector(db, profile, post));
|
|
111
150
|
export const markPostsSeen = async (posts, profile) => {
|
|
@@ -139,20 +178,29 @@ export const deletePost = async (post, profile) => {
|
|
|
139
178
|
type: 'tombstone',
|
|
140
179
|
},
|
|
141
180
|
});
|
|
142
|
-
await Promise.all(post.reactions.map(async (reaction) => {
|
|
143
|
-
await reactionDisconnector(db, reaction.profile, post);
|
|
144
|
-
}));
|
|
145
181
|
await postsMapping.deleteRelations(db, post.id, Object.assign(Object.assign({}, repostRelation), { direction: 'INBOUND' }));
|
|
146
182
|
await postsMapping.delete(db, post.id);
|
|
147
183
|
if (post.type === 'event') {
|
|
148
184
|
await clearEventOccurrences(post.id);
|
|
149
185
|
}
|
|
186
|
+
if (post.type === 'question') {
|
|
187
|
+
await cancelPollEnd(post.id);
|
|
188
|
+
}
|
|
150
189
|
return postsMapping.find(db, post.id);
|
|
151
190
|
};
|
|
152
191
|
export const vote = (profile, post, data) => allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
|
|
153
192
|
type: 'answer',
|
|
154
193
|
data,
|
|
155
194
|
}).then(() => hub.emit('entryCreated', profile, post, { type: 'answer', data })));
|
|
195
|
+
const attendingRsvp = (response) => response === 'yes' || response === 'tentative';
|
|
196
|
+
const rsvpOccurrenceIds = (data) => {
|
|
197
|
+
var _a;
|
|
198
|
+
if ((_a = data.recurrenceIds) === null || _a === void 0 ? void 0 : _a.length)
|
|
199
|
+
return data.recurrenceIds;
|
|
200
|
+
if (data.recurrenceId)
|
|
201
|
+
return [data.recurrenceId];
|
|
202
|
+
return undefined;
|
|
203
|
+
};
|
|
156
204
|
export const rsvpRespond = async (profile, post, data) => {
|
|
157
205
|
var _a, _b, _c, _d;
|
|
158
206
|
if (profile.id === post.profile.id) {
|
|
@@ -170,6 +218,7 @@ export const rsvpRespond = async (profile, post, data) => {
|
|
|
170
218
|
if (((_b = getEffectiveRsvp(post, profile.id)) === null || _b === void 0 ? void 0 : _b.response) === 'removed') {
|
|
171
219
|
throw forbidden({ errorKey: 'error.rsvpRemoved' });
|
|
172
220
|
}
|
|
221
|
+
const occurrenceIds = rsvpOccurrenceIds(data);
|
|
173
222
|
const maxAttendees = post.data.maxAttendees;
|
|
174
223
|
if (maxAttendees) {
|
|
175
224
|
if (data.response === 'tentative') {
|
|
@@ -178,30 +227,52 @@ export const rsvpRespond = async (profile, post, data) => {
|
|
|
178
227
|
});
|
|
179
228
|
}
|
|
180
229
|
if (data.response === 'yes') {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
230
|
+
if (!occurrenceIds && post.data.recurrence) {
|
|
231
|
+
if (seriesYesBlockedByCapacity(post, profile.id)) {
|
|
232
|
+
throw unprocessableRequest({ errorKey: 'error.eventAtCapacity' });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
const ids = occurrenceIds !== null && occurrenceIds !== void 0 ? occurrenceIds : [undefined];
|
|
237
|
+
for (const recurrenceId of ids) {
|
|
238
|
+
const currentRsvp = getEffectiveRsvp(post, profile.id, recurrenceId);
|
|
239
|
+
if ((currentRsvp === null || currentRsvp === void 0 ? void 0 : currentRsvp.response) !== 'yes' &&
|
|
240
|
+
countYesRsvps(post, recurrenceId) >= maxAttendees) {
|
|
241
|
+
throw unprocessableRequest({ errorKey: 'error.eventAtCapacity' });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
185
244
|
}
|
|
186
245
|
}
|
|
187
246
|
}
|
|
188
247
|
const { db } = await allpeepDb();
|
|
189
|
-
const
|
|
190
|
-
.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
248
|
+
const previousResponses = occurrenceIds
|
|
249
|
+
? occurrenceIds.map((id) => { var _a; return (_a = getEffectiveRsvp(post, profile.id, id)) === null || _a === void 0 ? void 0 : _a.response; })
|
|
250
|
+
: undefined;
|
|
251
|
+
const previousResponse = previousResponses
|
|
252
|
+
? previousResponses.every(attendingRsvp)
|
|
253
|
+
? previousResponses[0]
|
|
254
|
+
: previousResponses.find((response) => !attendingRsvp(response))
|
|
255
|
+
: (_d = [...((_c = post.rsvps) !== null && _c !== void 0 ? _c : [])]
|
|
256
|
+
.filter((rsvp) => rsvp.profile.id === profile.id)
|
|
257
|
+
.filter((rsvp) => !rsvp.recurrenceId)
|
|
258
|
+
.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]) === null || _d === void 0 ? void 0 : _d.response;
|
|
259
|
+
const writes = occurrenceIds
|
|
260
|
+
? occurrenceIds.map((recurrenceId) => ({
|
|
261
|
+
response: data.response,
|
|
262
|
+
recurrenceId,
|
|
263
|
+
}))
|
|
264
|
+
: overlaySeriesRsvpEntries(data.response, instanceRsvpIdsForProfile(post, profile.id));
|
|
265
|
+
for (const entry of writes) {
|
|
266
|
+
await entryConnector(db, profile, post, {
|
|
267
|
+
type: 'rsvp',
|
|
268
|
+
data: entry,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
const cancel = rsvpCancelNotice(post, profile.id, data.response, occurrenceIds);
|
|
272
|
+
hub.emit('rsvpCreated', profile, post, Object.assign({ type: 'rsvp', data: Object.assign({ response: data.response }, ((occurrenceIds === null || occurrenceIds === void 0 ? void 0 : occurrenceIds.length) === 1
|
|
273
|
+
? { recurrenceId: occurrenceIds[0] }
|
|
274
|
+
: {})), occurrenceIds,
|
|
275
|
+
previousResponse }, (cancel ? { cancel } : {})));
|
|
205
276
|
};
|
|
206
277
|
export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post, response, recurrenceId) => {
|
|
207
278
|
var _a, _b;
|
|
@@ -233,3 +304,55 @@ export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post,
|
|
|
233
304
|
previousResponse,
|
|
234
305
|
});
|
|
235
306
|
};
|
|
307
|
+
/**
|
|
308
|
+
* Remove a profile from a direct-message conversation thread.
|
|
309
|
+
*
|
|
310
|
+
* - Creates a system "X left" post (empty content) with the *remaining*
|
|
311
|
+
* participants as audience. The leaving user is excluded so future
|
|
312
|
+
* replies (which inherit the audience) won't notify them, and the thread
|
|
313
|
+
* disappears from their inbox.
|
|
314
|
+
* - MessageInThread detects the leave via the audience diff: the leaving
|
|
315
|
+
* user was in the previous post's audience but not in the left-post's.
|
|
316
|
+
* - The conversation post-creation endpoint detects leavers (author not in
|
|
317
|
+
* their own post's audience) to block further posting and exclude them
|
|
318
|
+
* from future replies' audience.
|
|
319
|
+
* - For 1:1 DMs (no remaining participants), removes the user from every
|
|
320
|
+
* post's audience so the thread vanishes from their inbox.
|
|
321
|
+
* - The leaving user can still find the thread in the "Archived" conversations
|
|
322
|
+
* tab, detected by posts they authored but are not in.
|
|
323
|
+
*/
|
|
324
|
+
export const leaveConversation = async (rootPost, profile) => {
|
|
325
|
+
var _a, _b;
|
|
326
|
+
const { db } = await allpeepDb();
|
|
327
|
+
const lastPostId = await findLatestThreadPostId(rootPost.id);
|
|
328
|
+
const [lastPost] = lastPostId === rootPost.id
|
|
329
|
+
? [rootPost]
|
|
330
|
+
: await findPostsForAuth([lastPostId]);
|
|
331
|
+
if (!lastPost)
|
|
332
|
+
return;
|
|
333
|
+
const remainingAudience = (_b = (_a = lastPost.audience) === null || _a === void 0 ? void 0 : _a.filter((p) => p.id !== profile.id)) !== null && _b !== void 0 ? _b : [];
|
|
334
|
+
if (remainingAudience.length > 0) {
|
|
335
|
+
await createPost({ type: 'note', content: '' }, profile, { type: 'note', visibility: 'direct', creatorId: profile.id }, {
|
|
336
|
+
inReplyToId: lastPost.id,
|
|
337
|
+
audience: remainingAudience,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
// 1:1 DM — remove the user from every post's audience so the
|
|
342
|
+
// thread no longer appears in their inbox.
|
|
343
|
+
await db.execute(sql `
|
|
344
|
+
WITH RECURSIVE t AS (
|
|
345
|
+
SELECT ${rootPost.id}::text AS id, 0 AS depth
|
|
346
|
+
UNION ALL
|
|
347
|
+
SELECT rt.from_id::text, t.depth + 1
|
|
348
|
+
FROM reply_to rt
|
|
349
|
+
INNER JOIN t ON rt.to_id = t.id
|
|
350
|
+
WHERE t.depth < 9999
|
|
351
|
+
)
|
|
352
|
+
DELETE FROM audience
|
|
353
|
+
WHERE from_id IN (SELECT id FROM t)
|
|
354
|
+
AND to_id = ${profile.id}
|
|
355
|
+
`);
|
|
356
|
+
}
|
|
357
|
+
await profilesCache.del(profile.id);
|
|
358
|
+
};
|
|
@@ -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,7 @@
|
|
|
1
|
+
export const pollEndDelayMs = (expiresAt, now = Date.now()) => new Date(expiresAt).getTime() - now;
|
|
2
|
+
export const shouldEmitPollEnded = (post, scheduledExpiresAt) => {
|
|
3
|
+
var _a;
|
|
4
|
+
return !!post &&
|
|
5
|
+
((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'question' &&
|
|
6
|
+
post.data.expiresAt === scheduledExpiresAt;
|
|
7
|
+
};
|
|
@@ -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,7 +14,7 @@ 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
|
|
17
|
+
var _a, _b, _c;
|
|
17
18
|
const profile = profileArg;
|
|
18
19
|
const post = postArg;
|
|
19
20
|
const payload = payloadArg;
|
|
@@ -33,16 +34,20 @@ const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
|
|
|
33
34
|
}
|
|
34
35
|
const rootUrl = await serverRootUrl();
|
|
35
36
|
const postUrl = `${rootUrl}/posts/${post.id}`;
|
|
36
|
-
const
|
|
37
|
-
|
|
37
|
+
const occurrenceIds = (_c = payload.occurrenceIds) !== null && _c !== void 0 ? _c : (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;
|
|
@@ -51,20 +56,13 @@ const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
|
|
|
51
56
|
.send({
|
|
52
57
|
to: account.email,
|
|
53
58
|
template: 'eventRsvpConfirmation',
|
|
54
|
-
locals: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
response,
|
|
58
|
-
start: event.start,
|
|
59
|
-
end: (_d = event.end) !== null && _d !== void 0 ? _d : null,
|
|
60
|
-
location: (_f = (_e = event.physicalLocation) === null || _e === void 0 ? void 0 : _e.text) !== null && _f !== void 0 ? _f : null,
|
|
61
|
-
allDay: (_g = event.wholeDay) !== null && _g !== void 0 ? _g : false,
|
|
62
|
-
timeZone: (_h = event.timeZone) !== null && _h !== void 0 ? _h : null,
|
|
63
|
-
},
|
|
59
|
+
locals: Object.assign({ eventName: confirmation.eventName, eventUrl: postUrl, response, start: confirmation.start, end: confirmation.end, location: confirmation.location, allDay: confirmation.allDay, occurrenceCount: confirmation.occurrenceCount }, ((profileSettings === null || profileSettings === void 0 ? void 0 : profileSettings.timeZone)
|
|
60
|
+
? { timeZone: profileSettings.timeZone }
|
|
61
|
+
: {})),
|
|
64
62
|
attachments: [
|
|
65
63
|
{
|
|
66
64
|
filename: 'event.ics',
|
|
67
|
-
content: ics,
|
|
65
|
+
content: confirmation.ics,
|
|
68
66
|
contentType: 'text/calendar; method=PUBLISH; charset=utf-8',
|
|
69
67
|
},
|
|
70
68
|
],
|
|
@@ -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 ? Object.assign(Object.assign({}, 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}
|
|
@@ -11,14 +11,31 @@ export const profileSettingsCache = createCache({
|
|
|
11
11
|
hub.on('profileSettingsUpdated', (profileId) => {
|
|
12
12
|
void profileSettingsCache.del(profileId);
|
|
13
13
|
});
|
|
14
|
+
const uniqueViolation = (error) => {
|
|
15
|
+
var _a;
|
|
16
|
+
const current = error;
|
|
17
|
+
return current.code === '23505' || ((_a = current.cause) === null || _a === void 0 ? void 0 : _a.code) === '23505';
|
|
18
|
+
};
|
|
19
|
+
const readProfileSettings = async (db, id) =>
|
|
20
|
+
// Include soft-deleted rows: the profile_id unique index still covers them,
|
|
21
|
+
// so a miss here would insert and fail with 23505.
|
|
22
|
+
profileSettingsMapping.find(db, id, { ignoreSoftDelete: true });
|
|
14
23
|
export const getProfileSettings = async (id) => profileSettingsCache.wrap(id, async () => {
|
|
15
24
|
const { db } = await allpeepDb();
|
|
16
|
-
const foundSettings = await
|
|
25
|
+
const foundSettings = await readProfileSettings(db, id);
|
|
17
26
|
if (foundSettings) {
|
|
18
27
|
return foundSettings;
|
|
19
28
|
}
|
|
20
|
-
|
|
21
|
-
id
|
|
22
|
-
}
|
|
23
|
-
|
|
29
|
+
try {
|
|
30
|
+
return await profileSettingsMapping.create(db, { id });
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
// Another request created the row between the read and this insert.
|
|
34
|
+
if (!uniqueViolation(error))
|
|
35
|
+
throw error;
|
|
36
|
+
const raced = await readProfileSettings(db, id);
|
|
37
|
+
if (raced)
|
|
38
|
+
return raced;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
24
41
|
});
|
|
@@ -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[];
|