@openpeepshq/core 0.1.31 → 0.1.33
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/helpers.d.ts +2 -2
- package/dist/accessTokens/tokens.js +14 -7
- package/dist/accounts/mutations.d.ts +2 -2
- package/dist/analytics/cache.js +12 -7
- package/dist/analytics/clicks.d.ts +20 -0
- package/dist/analytics/clicks.js +194 -0
- package/dist/analytics/index.d.ts +1 -0
- package/dist/analytics/index.js +1 -0
- package/dist/analytics/metrics.d.ts +1 -0
- package/dist/analytics/metrics.js +5 -0
- package/dist/analytics/pdfReport.d.ts +1 -0
- package/dist/analytics/pdfReport.js +7 -5
- package/dist/analytics/privacy.d.ts +18 -0
- package/dist/analytics/privacy.js +10 -0
- package/dist/analytics/read.js +74 -16
- package/dist/analytics/report.d.ts +32 -1
- package/dist/analytics/report.js +9 -2
- package/dist/backups/index.js +13 -5
- package/dist/backups/metadata.d.ts +7 -0
- package/dist/config/defaults/community.js +0 -6
- package/dist/config/defaults/core.js +1 -0
- package/dist/config/defaults/db.d.ts +0 -2
- package/dist/config/defaults/db.js +0 -2
- package/dist/config/index.d.ts +20 -9
- package/dist/db/helpers.d.ts +6 -28
- package/dist/db/helpers.js +19 -149
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.js +4 -0
- package/dist/db/init.js +3 -2
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -54
- package/dist/db/migration/importCollections.d.ts +1 -1
- package/dist/db/migration/importCollections.js +22 -6
- package/dist/db/migration/shared.d.ts +0 -4
- package/dist/db/migration/shared.js +0 -7
- package/dist/db/migration/transform.d.ts +2 -0
- package/dist/db/migration/transform.js +23 -0
- package/dist/db/pg/client.js +4 -0
- package/dist/db/pg/filters/edges.d.ts +1 -1
- package/dist/db/pg/filters/edges.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +1 -0
- package/dist/db/pg/filters/posts.js +11 -1
- package/dist/db/pg/map/filters.js +5 -0
- package/dist/db/pg/map/relations.d.ts +1 -1
- package/dist/db/pg/map/relations.js +89 -41
- package/dist/db/pg/migrate.d.ts +23 -0
- package/dist/db/pg/migrate.js +87 -1
- package/dist/db/pg/queries/derived.d.ts +5 -0
- package/dist/db/pg/queries/derived.js +21 -0
- package/dist/db/pg/schema/analytics.d.ts +76 -0
- package/dist/db/pg/schema/analytics.js +11 -1
- package/dist/db/pg/schema/documents.d.ts +143 -0
- package/dist/db/pg/schema/documents.js +22 -1
- package/dist/db/pg/schema/edges.d.ts +1 -0
- package/dist/db/pg/schema/edges.js +1 -0
- package/dist/db/pg/schema/index.d.ts +218 -0
- package/dist/db/pg/sql/0005_open_power_man.sql +9 -0
- package/dist/db/pg/sql/0006_fine_trish_tilby.sql +8 -0
- package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
- package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
- package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
- package/dist/db/pg/sql/meta/0004_snapshot.json +1 -1
- package/dist/db/pg/sql/meta/0005_snapshot.json +4179 -0
- package/dist/db/pg/sql/meta/0006_snapshot.json +4200 -0
- package/dist/db/pg/sql/meta/0007_snapshot.json +4179 -0
- package/dist/db/pg/sql/meta/0009_snapshot.json +4299 -0
- package/dist/db/pg/sql/meta/_journal.json +35 -0
- package/dist/db/replaceOrigin.d.ts +11 -0
- package/dist/db/replaceOrigin.js +116 -0
- package/dist/db/types.d.ts +0 -4
- package/dist/events/index.d.ts +2 -1
- package/dist/events/index.js +54 -33
- package/dist/groups/finders.d.ts +2 -2
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/groups/mapping.d.ts +4 -4
- package/dist/groups/mapping.js +2 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/inviteLinks/helpers.d.ts +4 -4
- package/dist/jams/cache.d.ts +1 -1
- package/dist/jams/cache.js +2 -1
- package/dist/jams/finders.d.ts +2 -1
- package/dist/jams/finders.js +18 -7
- package/dist/jams/helpers.d.ts +8 -4
- package/dist/jams/index.d.ts +4 -3
- package/dist/jams/index.js +23 -12
- package/dist/jams/livekit.d.ts +46 -8
- package/dist/jams/livekit.js +103 -21
- package/dist/jams/mapping.d.ts +14 -4
- package/dist/jams/mutations.d.ts +2 -0
- package/dist/jams/rtmp.d.ts +5 -0
- package/dist/jams/rtmp.js +8 -0
- package/dist/jams/token.d.ts +3 -3
- package/dist/jams/token.js +15 -12
- package/dist/jams/waitingRoom.d.ts +6 -4
- package/dist/jams/waitingRoom.js +33 -24
- package/dist/migration/index.d.ts +4 -0
- package/dist/migration/index.js +4 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
- package/dist/notifications/helpers.js +6 -2
- package/dist/notifications/jobs.js +13 -2
- package/dist/notifications/push.js +11 -4
- package/dist/plugins/helpers.d.ts +6 -2
- package/dist/plugins/helpers.js +22 -10
- package/dist/plugins/index.d.ts +6 -1
- package/dist/plugins/index.js +54 -13
- package/dist/plugins/install.d.ts +20 -0
- package/dist/plugins/install.js +223 -0
- package/dist/plugins/state.d.ts +4 -0
- package/dist/plugins/state.js +29 -0
- package/dist/posts/contextClosure.d.ts +2 -1
- package/dist/posts/contextClosure.js +6 -1
- package/dist/posts/conversationQueries.d.ts +23 -0
- package/dist/posts/conversationQueries.js +135 -0
- package/dist/posts/eventAgenda.d.ts +165 -0
- package/dist/posts/eventAgenda.js +120 -0
- package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
- package/dist/posts/eventOccurrenceJobs.js +23 -0
- package/dist/posts/eventOccurrences.d.ts +4 -0
- package/dist/posts/eventOccurrences.js +40 -0
- package/dist/posts/finders.d.ts +39 -13
- package/dist/posts/finders.js +51 -66
- package/dist/posts/helpers/filters.js +1 -1
- package/dist/posts/helpers/index.d.ts +120 -34
- package/dist/posts/helpers/index.js +34 -21
- package/dist/posts/index.d.ts +4 -0
- package/dist/posts/index.js +4 -0
- package/dist/posts/mapping.d.ts +454 -0
- package/dist/posts/mapping.js +43 -9
- package/dist/posts/mutations.d.ts +4 -2
- package/dist/posts/mutations.js +49 -16
- package/dist/posts/rsvpConfirmationEmail.js +2 -1
- package/dist/posts/unseenCounts.d.ts +12 -0
- package/dist/posts/unseenCounts.js +98 -0
- package/dist/profiles/cache.d.ts +5 -1
- package/dist/profiles/cache.js +27 -1
- package/dist/profiles/helpers.d.ts +5 -5
- package/dist/profiles/index.d.ts +1 -0
- package/dist/profiles/index.js +1 -0
- package/dist/profiles/mapping.d.ts +45 -4
- package/dist/profiles/mapping.js +24 -0
- package/dist/profiles/mutations.js +12 -14
- package/dist/pushSubscriptions/helpers.d.ts +2 -2
- package/dist/pushSubscriptions/mutations.js +13 -1
- package/dist/reports/helpers.d.ts +6 -6
- package/dist/reports/helpers.js +2 -1
- package/dist/reports/mapping.js +6 -2
- package/dist/roles/defaults.js +1 -0
- package/dist/roles/mutations.d.ts +3 -3
- package/dist/roles/mutations.js +5 -3
- package/dist/server/index.d.ts +15 -7
- package/dist/server/index.js +15 -8
- package/dist/session/index.d.ts +28 -0
- package/dist/session/index.js +79 -0
- package/dist/stats/finders.d.ts +1912 -362
- package/dist/stats/mapping.d.ts +26 -5
- package/package.json +7 -12
- package/dist/db/arango.d.ts +0 -2
- package/dist/db/arango.js +0 -110
- package/dist/db/migration/autoMigrate.d.ts +0 -2
- package/dist/db/migration/autoMigrate.js +0 -111
- package/dist/db/migration/cli.d.ts +0 -1
- package/dist/db/migration/cli.js +0 -56
- package/dist/db/migration/exportArango.d.ts +0 -4
- package/dist/db/migration/exportArango.js +0 -80
- package/dist/db/replaceHostname.d.ts +0 -1
- package/dist/db/replaceHostname.js +0 -88
package/dist/posts/mutations.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { allpeepDb } from '../db/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { uuidv7 } from 'uuidv7';
|
|
3
|
+
import { nowIso } from '../db/pg/mappers.js';
|
|
4
|
+
import { postSeen } from '../db/pg/schema/edges.js';
|
|
5
|
+
import { audienceConnector, bookmarkConnector, bookmarkDisconnector, entryConnector, extractHashtags, groupConnector, hashtagConnector, hashtagDisconnector, mentionConnector, reactionConnector, reactionDisconnector, replyConnector, repostConnector, resolveMentionsForPost, transformPost, } from './helpers/index.js';
|
|
3
6
|
import { postsMapping, repostRelation } from './mapping.js';
|
|
4
7
|
import { findGroup } from '../groups/finders.js';
|
|
5
8
|
import { findOrCreateHashtag } from '../hashtags/index.js';
|
|
6
9
|
import { hub } from '../events/index.js';
|
|
7
|
-
import {
|
|
8
|
-
import { canManageEventRsvps, countYesRsvps, eventDataForDbUpdate, getEffectiveRsvp, normalizeEventDataForSave, passThroughUndefined, } from '@openpeepshq/common/lib';
|
|
10
|
+
import { listUnseenGroupPostIds } from './unseenCounts.js';
|
|
11
|
+
import { canManageEventRsvps, countYesRsvps, eventDataForDbUpdate, getEffectiveRsvp, normalizeEventDataForSave, passThroughUndefined, sameRecurrenceId, } from '@openpeepshq/common/lib';
|
|
9
12
|
import { forbidden, unprocessableRequest } from '../errors/index.js';
|
|
13
|
+
import { rebuildEventOccurrences, clearEventOccurrences, } from './eventOccurrences.js';
|
|
10
14
|
export const createPost = async (data, profile, postData, relations = {}) => {
|
|
15
|
+
var _a;
|
|
11
16
|
if (data.type === 'event') {
|
|
12
17
|
data = normalizeEventDataForSave(data);
|
|
13
18
|
}
|
|
@@ -53,13 +58,19 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
53
58
|
if (mentions.length) {
|
|
54
59
|
await Promise.all(mentions.map(async (mention) => mentionConnector(db, post, mention.profile, { text: mention.text })));
|
|
55
60
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
const audienceToLink = ((_a = relations.audience) === null || _a === void 0 ? void 0 : _a.length)
|
|
62
|
+
? relations.audience
|
|
63
|
+
: repliedToPost === null || repliedToPost === void 0 ? void 0 : repliedToPost.audience;
|
|
64
|
+
if (audienceToLink === null || audienceToLink === void 0 ? void 0 : audienceToLink.length) {
|
|
65
|
+
await Promise.all(audienceToLink.map(async (member) => {
|
|
66
|
+
await audienceConnector(db, post, member);
|
|
59
67
|
}));
|
|
60
68
|
}
|
|
61
69
|
const newPost = await postsMapping.find(db, post.id);
|
|
62
70
|
const transformedPost = await transformPost(newPost);
|
|
71
|
+
if (data.type === 'event') {
|
|
72
|
+
await rebuildEventOccurrences(transformedPost.id, data);
|
|
73
|
+
}
|
|
63
74
|
hub.emit('postCreated', transformedPost);
|
|
64
75
|
return transformedPost;
|
|
65
76
|
};
|
|
@@ -87,6 +98,9 @@ export const updatePost = async (post, profile, data) => {
|
|
|
87
98
|
const newPost = await postsMapping
|
|
88
99
|
.find(db, post.id)
|
|
89
100
|
.then(passThroughUndefined(transformPost));
|
|
101
|
+
if (normalized.type === 'event') {
|
|
102
|
+
await rebuildEventOccurrences(post.id, normalized);
|
|
103
|
+
}
|
|
90
104
|
hub.emit('postUpdated', newPost);
|
|
91
105
|
return newPost;
|
|
92
106
|
};
|
|
@@ -95,19 +109,27 @@ export const retractReaction = async (post, profile) => allpeepDb().then(({ db }
|
|
|
95
109
|
export const bookmarkPost = async (post, profile) => allpeepDb().then(({ db }) => bookmarkConnector(db, profile, post).then(() => hub.emit('bookmarkCreated', profile, post)));
|
|
96
110
|
export const unbookmarkPost = async (post, profile) => allpeepDb().then(({ db }) => bookmarkDisconnector(db, profile, post));
|
|
97
111
|
export const markPostsSeen = async (posts, profile) => {
|
|
112
|
+
if (posts.length === 0)
|
|
113
|
+
return;
|
|
98
114
|
const { db } = await allpeepDb();
|
|
99
|
-
|
|
115
|
+
const ts = nowIso();
|
|
116
|
+
await db.insert(postSeen).values(posts.map((post) => ({
|
|
117
|
+
id: uuidv7(),
|
|
118
|
+
fromId: profile.id,
|
|
119
|
+
toId: post.id,
|
|
120
|
+
body: {},
|
|
121
|
+
createdAt: ts,
|
|
122
|
+
updatedAt: ts,
|
|
123
|
+
})));
|
|
100
124
|
};
|
|
101
125
|
export const markGroupPostsSeen = async (authData, groupId) => {
|
|
102
126
|
if (!authData.profile) {
|
|
103
127
|
throw new Error('Profile required');
|
|
104
128
|
}
|
|
105
129
|
const profile = authData.profile;
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
await markPostsSeen(unseen, profile);
|
|
110
|
-
}
|
|
130
|
+
const { db } = await allpeepDb();
|
|
131
|
+
const unseenIds = await listUnseenGroupPostIds(db, profile.id, groupId);
|
|
132
|
+
await markPostsSeen(unseenIds.map((id) => ({ id })), profile);
|
|
111
133
|
};
|
|
112
134
|
export const deletePost = async (post, profile) => {
|
|
113
135
|
const { db } = await allpeepDb();
|
|
@@ -122,6 +144,9 @@ export const deletePost = async (post, profile) => {
|
|
|
122
144
|
}));
|
|
123
145
|
await postsMapping.deleteRelations(db, post.id, Object.assign(Object.assign({}, repostRelation), { direction: 'INBOUND' }));
|
|
124
146
|
await postsMapping.delete(db, post.id);
|
|
147
|
+
if (post.type === 'event') {
|
|
148
|
+
await clearEventOccurrences(post.id);
|
|
149
|
+
}
|
|
125
150
|
return postsMapping.find(db, post.id);
|
|
126
151
|
};
|
|
127
152
|
export const vote = (profile, post, data) => allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
|
|
@@ -153,9 +178,9 @@ export const rsvpRespond = async (profile, post, data) => {
|
|
|
153
178
|
});
|
|
154
179
|
}
|
|
155
180
|
if (data.response === 'yes') {
|
|
156
|
-
const currentRsvp = getEffectiveRsvp(post, profile.id);
|
|
181
|
+
const currentRsvp = getEffectiveRsvp(post, profile.id, data.recurrenceId);
|
|
157
182
|
if ((currentRsvp === null || currentRsvp === void 0 ? void 0 : currentRsvp.response) !== 'yes' &&
|
|
158
|
-
countYesRsvps(post) >= maxAttendees) {
|
|
183
|
+
countYesRsvps(post, data.recurrenceId) >= maxAttendees) {
|
|
159
184
|
throw unprocessableRequest({ errorKey: 'error.eventAtCapacity' });
|
|
160
185
|
}
|
|
161
186
|
}
|
|
@@ -163,6 +188,10 @@ export const rsvpRespond = async (profile, post, data) => {
|
|
|
163
188
|
const { db } = await allpeepDb();
|
|
164
189
|
const previousResponse = (_d = [...((_c = post.rsvps) !== null && _c !== void 0 ? _c : [])]
|
|
165
190
|
.filter((rsvp) => rsvp.profile.id === profile.id)
|
|
191
|
+
.filter((rsvp) => data.recurrenceId
|
|
192
|
+
? sameRecurrenceId(rsvp.recurrenceId, data.recurrenceId) ||
|
|
193
|
+
!rsvp.recurrenceId
|
|
194
|
+
: !rsvp.recurrenceId)
|
|
166
195
|
.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]) === null || _d === void 0 ? void 0 : _d.response;
|
|
167
196
|
await entryConnector(db, profile, post, {
|
|
168
197
|
type: 'rsvp',
|
|
@@ -174,7 +203,7 @@ export const rsvpRespond = async (profile, post, data) => {
|
|
|
174
203
|
previousResponse,
|
|
175
204
|
});
|
|
176
205
|
};
|
|
177
|
-
export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post, response) => {
|
|
206
|
+
export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post, response, recurrenceId) => {
|
|
178
207
|
var _a, _b;
|
|
179
208
|
if (!canManageEventRsvps(actingProfile, post)) {
|
|
180
209
|
throw forbidden({ errorKey: 'forbidden' });
|
|
@@ -185,10 +214,14 @@ export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post,
|
|
|
185
214
|
if (post.type !== 'event') {
|
|
186
215
|
throw unprocessableRequest({ errorKey: 'error.unprocessableRequest' });
|
|
187
216
|
}
|
|
188
|
-
const data = { response };
|
|
217
|
+
const data = { response, recurrenceId };
|
|
189
218
|
const { db } = await allpeepDb();
|
|
190
219
|
const previousResponse = (_b = [...((_a = post.rsvps) !== null && _a !== void 0 ? _a : [])]
|
|
191
220
|
.filter((rsvp) => rsvp.profile.id === targetProfile.id)
|
|
221
|
+
.filter((rsvp) => recurrenceId
|
|
222
|
+
? sameRecurrenceId(rsvp.recurrenceId, recurrenceId) ||
|
|
223
|
+
!rsvp.recurrenceId
|
|
224
|
+
: !rsvp.recurrenceId)
|
|
192
225
|
.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]) === null || _b === void 0 ? void 0 : _b.response;
|
|
193
226
|
await entryConnector(db, targetProfile, post, {
|
|
194
227
|
type: 'rsvp',
|
|
@@ -13,7 +13,7 @@ const attendingResponses = ['yes', 'tentative'];
|
|
|
13
13
|
* avoid re-sending when someone toggles between yes/maybe.
|
|
14
14
|
*/
|
|
15
15
|
const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
|
|
16
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
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;
|
|
@@ -59,6 +59,7 @@ const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
|
|
|
59
59
|
end: (_d = event.end) !== null && _d !== void 0 ? _d : null,
|
|
60
60
|
location: (_f = (_e = event.physicalLocation) === null || _e === void 0 ? void 0 : _e.text) !== null && _f !== void 0 ? _f : null,
|
|
61
61
|
allDay: (_g = event.wholeDay) !== null && _g !== void 0 ? _g : false,
|
|
62
|
+
timeZone: (_h = event.timeZone) !== null && _h !== void 0 ? _h : null,
|
|
62
63
|
},
|
|
63
64
|
attachments: [
|
|
64
65
|
{
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { UnseenPostCounts } from '@openpeepshq/common/types';
|
|
2
|
+
import type { PgDb } from '../db/pg/client';
|
|
3
|
+
/** Group unseen counts via anti-join (no post hydration). */
|
|
4
|
+
export declare const countUnseenGroupPosts: (db: PgDb, profileId: string, groupIds: string[]) => Promise<Record<string, number>>;
|
|
5
|
+
/** Same posts as {@link countUnseenGroupPosts} for one group (mark-all-read). */
|
|
6
|
+
export declare const listUnseenGroupPostIds: (db: PgDb, profileId: string, groupId: string) => Promise<string[]>;
|
|
7
|
+
/**
|
|
8
|
+
* Direct-message unread counts keyed by conversation root.
|
|
9
|
+
* Walks reply_to to roots without hydrating posts.
|
|
10
|
+
*/
|
|
11
|
+
export declare const countUnseenDirectPosts: (db: PgDb, profileId: string) => Promise<Record<string, number>>;
|
|
12
|
+
export declare const queryUnseenPostCounts: (db: PgDb, profileId: string, groupIds: string[]) => Promise<UnseenPostCounts>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
/** Shared predicates for group unseen count and mark-all-read. */
|
|
3
|
+
const unseenGroupPostMatch = (profileId) => sql `
|
|
4
|
+
p.visibility <> 'direct'
|
|
5
|
+
AND p.creator_id <> ${profileId}
|
|
6
|
+
AND NOT EXISTS (
|
|
7
|
+
SELECT 1
|
|
8
|
+
FROM post_seen ps
|
|
9
|
+
WHERE ps.from_id = ${profileId}
|
|
10
|
+
AND ps.to_id = p.id::text
|
|
11
|
+
)
|
|
12
|
+
`;
|
|
13
|
+
/** Group unseen counts via anti-join (no post hydration). */
|
|
14
|
+
export const countUnseenGroupPosts = async (db, profileId, groupIds) => {
|
|
15
|
+
const counts = Object.fromEntries(groupIds.map((groupId) => [groupId, 0]));
|
|
16
|
+
if (groupIds.length === 0)
|
|
17
|
+
return counts;
|
|
18
|
+
const result = (await db.execute(sql `
|
|
19
|
+
SELECT pg.to_id AS group_id, count(*)::int AS cnt
|
|
20
|
+
FROM post_groups pg
|
|
21
|
+
INNER JOIN posts p
|
|
22
|
+
ON p.id::text = pg.from_id
|
|
23
|
+
AND p.deleted_at IS NULL
|
|
24
|
+
WHERE pg.to_id IN (${sql.join(groupIds.map((id) => sql `${id}`), sql `, `)})
|
|
25
|
+
AND ${unseenGroupPostMatch(profileId)}
|
|
26
|
+
GROUP BY pg.to_id
|
|
27
|
+
`));
|
|
28
|
+
for (const row of result.rows) {
|
|
29
|
+
const groupId = row.group_id;
|
|
30
|
+
if (groupId in counts) {
|
|
31
|
+
counts[groupId] = Number(row.cnt) || 0;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return counts;
|
|
35
|
+
};
|
|
36
|
+
/** Same posts as {@link countUnseenGroupPosts} for one group (mark-all-read). */
|
|
37
|
+
export const listUnseenGroupPostIds = async (db, profileId, groupId) => {
|
|
38
|
+
const result = (await db.execute(sql `
|
|
39
|
+
SELECT p.id::text AS post_id
|
|
40
|
+
FROM post_groups pg
|
|
41
|
+
INNER JOIN posts p
|
|
42
|
+
ON p.id::text = pg.from_id
|
|
43
|
+
AND p.deleted_at IS NULL
|
|
44
|
+
WHERE pg.to_id = ${groupId}
|
|
45
|
+
AND ${unseenGroupPostMatch(profileId)}
|
|
46
|
+
`));
|
|
47
|
+
return result.rows.map((row) => row.post_id).filter((id) => !!id);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Direct-message unread counts keyed by conversation root.
|
|
51
|
+
* Walks reply_to to roots without hydrating posts.
|
|
52
|
+
*/
|
|
53
|
+
export const countUnseenDirectPosts = async (db, profileId) => {
|
|
54
|
+
const result = (await db.execute(sql `
|
|
55
|
+
WITH RECURSIVE my_direct AS (
|
|
56
|
+
SELECT p.id::text AS post_id, p.creator_id
|
|
57
|
+
FROM audience a
|
|
58
|
+
INNER JOIN posts p
|
|
59
|
+
ON p.id::text = a.from_id
|
|
60
|
+
AND p.deleted_at IS NULL
|
|
61
|
+
WHERE a.to_id = ${profileId}
|
|
62
|
+
AND p.visibility = 'direct'
|
|
63
|
+
),
|
|
64
|
+
walk AS (
|
|
65
|
+
SELECT d.post_id, d.post_id AS node_id, 0 AS depth
|
|
66
|
+
FROM my_direct d
|
|
67
|
+
UNION ALL
|
|
68
|
+
SELECT walk.post_id, rt.to_id, walk.depth + 1
|
|
69
|
+
FROM reply_to rt
|
|
70
|
+
INNER JOIN walk ON rt.from_id = walk.node_id
|
|
71
|
+
),
|
|
72
|
+
roots AS (
|
|
73
|
+
SELECT DISTINCT ON (post_id) post_id, node_id AS root_id
|
|
74
|
+
FROM walk
|
|
75
|
+
ORDER BY post_id, depth DESC
|
|
76
|
+
)
|
|
77
|
+
SELECT roots.root_id, count(*)::int AS cnt
|
|
78
|
+
FROM my_direct d
|
|
79
|
+
INNER JOIN roots ON roots.post_id = d.post_id
|
|
80
|
+
WHERE d.creator_id <> ${profileId}
|
|
81
|
+
AND NOT EXISTS (
|
|
82
|
+
SELECT 1
|
|
83
|
+
FROM post_seen ps
|
|
84
|
+
WHERE ps.from_id = ${profileId}
|
|
85
|
+
AND ps.to_id = d.post_id
|
|
86
|
+
)
|
|
87
|
+
GROUP BY roots.root_id
|
|
88
|
+
HAVING count(*) > 0
|
|
89
|
+
`));
|
|
90
|
+
return Object.fromEntries(result.rows.map((row) => [row.root_id, Number(row.cnt) || 0]));
|
|
91
|
+
};
|
|
92
|
+
export const queryUnseenPostCounts = async (db, profileId, groupIds) => {
|
|
93
|
+
const [groups, direct] = await Promise.all([
|
|
94
|
+
countUnseenGroupPosts(db, profileId, groupIds),
|
|
95
|
+
countUnseenDirectPosts(db, profileId),
|
|
96
|
+
]);
|
|
97
|
+
return { groups, direct };
|
|
98
|
+
};
|
package/dist/profiles/cache.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { ProfileWithMeta } from '@openpeepshq/common/types';
|
|
1
|
+
import { Profile, ProfileWithMeta } from '@openpeepshq/common/types';
|
|
2
2
|
export declare const profilesCache: import("cache-manager").Cache;
|
|
3
|
+
export declare const publicProfilesCache: import("cache-manager").Cache;
|
|
4
|
+
export declare const clearProfileCache: (profile: Pick<Profile, "id" | "handle">) => Promise<void>;
|
|
3
5
|
export declare const getProfile: (id: string, ignoreSoftDelete?: boolean) => Promise<ProfileWithMeta | undefined>;
|
|
6
|
+
/** Lean profile for post/feed hydrate — no followers/following trees. */
|
|
7
|
+
export declare const getPublicProfile: (id: string, ignoreSoftDelete?: boolean) => Promise<ProfileWithMeta | undefined>;
|
|
4
8
|
export declare const getProfileByHandle: (handle: string, ignoreSoftDelete?: boolean) => Promise<ProfileWithMeta | undefined>;
|
|
5
9
|
export declare const getProfiles: (ids: string[]) => Promise<ProfileWithMeta[]>;
|
package/dist/profiles/cache.js
CHANGED
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
import { createCache } from 'cache-manager';
|
|
2
2
|
import { allpeepDb } from '../db/index.js';
|
|
3
|
-
import { profilesMapping } from './mapping.js';
|
|
3
|
+
import { profilesMapping, publicProfilesMapping } from './mapping.js';
|
|
4
4
|
export const profilesCache = createCache({
|
|
5
5
|
ttl: 60 * 60 * 1000,
|
|
6
6
|
refreshThreshold: 60 * 1000,
|
|
7
7
|
});
|
|
8
|
+
export const publicProfilesCache = createCache({
|
|
9
|
+
ttl: 60 * 60 * 1000,
|
|
10
|
+
refreshThreshold: 60 * 1000,
|
|
11
|
+
});
|
|
12
|
+
export const clearProfileCache = async (profile) => {
|
|
13
|
+
await Promise.all([
|
|
14
|
+
profilesCache.del(profile.id),
|
|
15
|
+
profilesCache.del(profile.handle),
|
|
16
|
+
publicProfilesCache.del(profile.id),
|
|
17
|
+
publicProfilesCache.del(`all:${profile.id}`),
|
|
18
|
+
]);
|
|
19
|
+
};
|
|
20
|
+
const withEmptyFollowGraphs = (profile) => {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
return (Object.assign(Object.assign({}, profile), { roles: (_a = profile.roles) !== null && _a !== void 0 ? _a : [], followers: [], following: [], controllers: (_b = profile.controllers) !== null && _b !== void 0 ? _b : [], memberships: (_c = profile.memberships) !== null && _c !== void 0 ? _c : [], profileStats: (_d = profile.profileStats) !== null && _d !== void 0 ? _d : {
|
|
23
|
+
followersCount: 0,
|
|
24
|
+
followingCount: 0,
|
|
25
|
+
} }));
|
|
26
|
+
};
|
|
8
27
|
export const getProfile = async (id, ignoreSoftDelete = false) => profilesCache.wrap(id, () => allpeepDb().then(({ db }) => ignoreSoftDelete
|
|
9
28
|
? profilesMapping.ignoreSoftDelete().find(db, id)
|
|
10
29
|
: profilesMapping.find(db, id)));
|
|
30
|
+
/** Lean profile for post/feed hydrate — no followers/following trees. */
|
|
31
|
+
export const getPublicProfile = async (id, ignoreSoftDelete = false) => {
|
|
32
|
+
const profile = await publicProfilesCache.wrap(`${ignoreSoftDelete ? 'all:' : ''}${id}`, () => allpeepDb().then(({ db }) => ignoreSoftDelete
|
|
33
|
+
? publicProfilesMapping.ignoreSoftDelete().find(db, id)
|
|
34
|
+
: publicProfilesMapping.find(db, id)));
|
|
35
|
+
return profile ? withEmptyFollowGraphs(profile) : undefined;
|
|
36
|
+
};
|
|
11
37
|
export const getProfileByHandle = async (handle, ignoreSoftDelete = false) => profilesCache.wrap(handle, () => allpeepDb().then(({ db }) => ignoreSoftDelete
|
|
12
38
|
? profilesMapping
|
|
13
39
|
.ignoreSoftDelete()
|
|
@@ -14,11 +14,11 @@ export declare const followConnector: (db: import("../db").PgDb, from: Profile,
|
|
|
14
14
|
_to: string;
|
|
15
15
|
}>>;
|
|
16
16
|
export declare const followDisconnector: (db: import("../db").PgDb, from: Profile, to: Profile) => Promise<void>;
|
|
17
|
-
export declare const followFinder: (db: import("../db").PgDb, from: Profile, to: Profile) => Promise<
|
|
17
|
+
export declare const followFinder: (db: import("../db").PgDb, from: Profile, to: Profile) => Promise<Record<string, unknown> | undefined>;
|
|
18
18
|
export declare const expandProfiles: (profiles: Profile[]) => Promise<ProfileWithMeta[]>;
|
|
19
|
-
export declare const roleAssigner: (db: import("../db").PgDb, from: Profile, to: Role, data?: {
|
|
19
|
+
export declare const roleAssigner: (db: import("../db").PgDb, from: Profile, to: Role, data?: object & {
|
|
20
20
|
id?: string;
|
|
21
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
21
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
22
22
|
_from: string;
|
|
23
23
|
_to: string;
|
|
24
24
|
}>>;
|
|
@@ -27,9 +27,9 @@ export declare const giveControl: (db: import("../db").PgDb, from: {
|
|
|
27
27
|
id: string;
|
|
28
28
|
}, to: {
|
|
29
29
|
id: string;
|
|
30
|
-
}, data?: {
|
|
30
|
+
}, data?: object & {
|
|
31
31
|
id?: string;
|
|
32
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
32
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
33
33
|
_from: string;
|
|
34
34
|
_to: string;
|
|
35
35
|
}>>;
|
package/dist/profiles/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export * from './mapping';
|
|
|
2
2
|
export * from './mutations';
|
|
3
3
|
export * from './finders';
|
|
4
4
|
export * from './export';
|
|
5
|
+
export { getProfile, getPublicProfile, getProfiles, clearProfileCache, } from './cache';
|
|
5
6
|
export declare const findNewFreeHandle: (seed: string) => Promise<string>;
|
package/dist/profiles/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from './mapping.js';
|
|
|
3
3
|
export * from './mutations.js';
|
|
4
4
|
export * from './finders.js';
|
|
5
5
|
export * from './export.js';
|
|
6
|
+
export { getProfile, getPublicProfile, getProfiles, clearProfileCache, } from './cache.js';
|
|
6
7
|
const sanitizeHandle = (name) => name.replace(/[^a-zA-Z0-9]/g, '-');
|
|
7
8
|
export const findNewFreeHandle = async (seed) => {
|
|
8
9
|
let counter = 2;
|
|
@@ -35,7 +35,7 @@ export declare const baseProfilesMapping: import("../db/pg/map").Mapping<{
|
|
|
35
35
|
guestData?: {
|
|
36
36
|
email?: string | undefined;
|
|
37
37
|
resource?: {
|
|
38
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "
|
|
38
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
|
|
39
39
|
id?: string | undefined;
|
|
40
40
|
} | undefined;
|
|
41
41
|
} | undefined;
|
|
@@ -73,7 +73,48 @@ export declare const publicProfilesSearchMapping: import("../db/pg/map").Mapping
|
|
|
73
73
|
guestData?: {
|
|
74
74
|
email?: string | undefined;
|
|
75
75
|
resource?: {
|
|
76
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "
|
|
76
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
|
|
77
|
+
id?: string | undefined;
|
|
78
|
+
} | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
}, ProfileWithMeta, ProfileWithMeta>;
|
|
81
|
+
/**
|
|
82
|
+
* Lean public profile for feed/API hydrate — memberships + SQL follower
|
|
83
|
+
* counts, no followers/following trees.
|
|
84
|
+
*/
|
|
85
|
+
export declare const publicProfilesMapping: import("../db/pg/map").Mapping<{
|
|
86
|
+
handle: string;
|
|
87
|
+
type: "guest" | "local" | "federated";
|
|
88
|
+
deletedHandle?: string | undefined;
|
|
89
|
+
avatar?: string | null | undefined;
|
|
90
|
+
header?: string | null | undefined;
|
|
91
|
+
displayName?: string | undefined;
|
|
92
|
+
bio?: string | undefined;
|
|
93
|
+
timeZone?: string | undefined;
|
|
94
|
+
location?: {
|
|
95
|
+
text: string;
|
|
96
|
+
coordinates?: {
|
|
97
|
+
lat: number;
|
|
98
|
+
lng: number;
|
|
99
|
+
alt?: number | undefined;
|
|
100
|
+
} | undefined;
|
|
101
|
+
} | undefined;
|
|
102
|
+
locked?: boolean | undefined;
|
|
103
|
+
bot?: boolean | undefined;
|
|
104
|
+
discoverable?: boolean | undefined;
|
|
105
|
+
hideSocialGraph?: boolean | undefined;
|
|
106
|
+
indexable?: boolean | undefined;
|
|
107
|
+
fields?: {
|
|
108
|
+
name: string;
|
|
109
|
+
value: string;
|
|
110
|
+
}[] | undefined;
|
|
111
|
+
activityPub?: {
|
|
112
|
+
domain: string;
|
|
113
|
+
} | undefined;
|
|
114
|
+
guestData?: {
|
|
115
|
+
email?: string | undefined;
|
|
116
|
+
resource?: {
|
|
117
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
|
|
77
118
|
id?: string | undefined;
|
|
78
119
|
} | undefined;
|
|
79
120
|
} | undefined;
|
|
@@ -110,7 +151,7 @@ export declare const profilesMapping: import("../db/pg/map").Mapping<{
|
|
|
110
151
|
guestData?: {
|
|
111
152
|
email?: string | undefined;
|
|
112
153
|
resource?: {
|
|
113
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "
|
|
154
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
|
|
114
155
|
id?: string | undefined;
|
|
115
156
|
} | undefined;
|
|
116
157
|
} | undefined;
|
|
@@ -147,7 +188,7 @@ export declare const membersExportMapping: import("../db/pg/map").Mapping<{
|
|
|
147
188
|
guestData?: {
|
|
148
189
|
email?: string | undefined;
|
|
149
190
|
resource?: {
|
|
150
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "
|
|
191
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
|
|
151
192
|
id?: string | undefined;
|
|
152
193
|
} | undefined;
|
|
153
194
|
} | undefined;
|
package/dist/profiles/mapping.js
CHANGED
|
@@ -85,6 +85,30 @@ export const publicProfilesSearchMapping = map({
|
|
|
85
85
|
},
|
|
86
86
|
],
|
|
87
87
|
});
|
|
88
|
+
/**
|
|
89
|
+
* Lean public profile for feed/API hydrate — memberships + SQL follower
|
|
90
|
+
* counts, no followers/following trees.
|
|
91
|
+
*/
|
|
92
|
+
export const publicProfilesMapping = map({
|
|
93
|
+
collection: 'profiles',
|
|
94
|
+
softDelete: true,
|
|
95
|
+
postFilterRelations: [
|
|
96
|
+
{
|
|
97
|
+
alias: 'memberships',
|
|
98
|
+
edgeCollection: 'userGroups',
|
|
99
|
+
vertexAlias: 'group',
|
|
100
|
+
direction: 'OUTBOUND',
|
|
101
|
+
cardinality: 'many',
|
|
102
|
+
mapping: groupsMapping.data(),
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
postFilterDerivedProperties: [
|
|
106
|
+
{
|
|
107
|
+
alias: 'profileStats',
|
|
108
|
+
resolve: profileDerived.profileStatsCounts,
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
});
|
|
88
112
|
export const profilesMapping = map({
|
|
89
113
|
collection: 'profiles',
|
|
90
114
|
postFilterRelations: profileRelations,
|
|
@@ -4,7 +4,7 @@ import { followConnector, followDisconnector, giveControl, roleAssigner, roleUna
|
|
|
4
4
|
import { hub } from '../events/index.js';
|
|
5
5
|
import { randomString } from '@openpeepshq/common/lib';
|
|
6
6
|
import { deleteAccessTokensForProfile } from '../accessTokens/helpers.js';
|
|
7
|
-
import { profilesCache, getProfile } from './cache.js';
|
|
7
|
+
import { profilesCache, getProfile, clearProfileCache } from './cache.js';
|
|
8
8
|
import { accountsCache } from '../accounts/cache.js';
|
|
9
9
|
import { assertProfileCapacity } from './capacity.js';
|
|
10
10
|
export const createProfile = async (data, controllingAccount) => {
|
|
@@ -54,19 +54,17 @@ export const deleteProfile = async (profileId) => {
|
|
|
54
54
|
await deleteAccessTokensForProfile(db, profileId);
|
|
55
55
|
return profilesMapping.delete(db, profileId);
|
|
56
56
|
};
|
|
57
|
-
export const follow = async (follower, followed, followData) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
profilesCache.del(followed.id);
|
|
69
|
-
});
|
|
57
|
+
export const follow = async (follower, followed, followData) => {
|
|
58
|
+
const { db } = await allpeepDb();
|
|
59
|
+
await followConnector(db, follower, followed, followData);
|
|
60
|
+
await Promise.all([clearProfileCache(follower), clearProfileCache(followed)]);
|
|
61
|
+
await hub.emit('followCreated', follower, followed);
|
|
62
|
+
};
|
|
63
|
+
export const unfollow = async (follower, followed) => {
|
|
64
|
+
const { db } = await allpeepDb();
|
|
65
|
+
await followDisconnector(db, follower, followed);
|
|
66
|
+
await Promise.all([clearProfileCache(follower), clearProfileCache(followed)]);
|
|
67
|
+
};
|
|
70
68
|
export const assignRole = (profile, role) => allpeepDb()
|
|
71
69
|
.then(({ db }) => roleAssigner(db, profile, role))
|
|
72
70
|
.then(() => profilesCache.del(profile.id));
|
|
@@ -91,9 +91,9 @@ export declare const pushSubscriptionAccountConnector: (db: import("../db").PgDb
|
|
|
91
91
|
};
|
|
92
92
|
} | undefined;
|
|
93
93
|
deletedAt?: string | null | undefined;
|
|
94
|
-
}, data?: {
|
|
94
|
+
}, data?: object & {
|
|
95
95
|
id?: string;
|
|
96
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
96
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
97
97
|
_from: string;
|
|
98
98
|
_to: string;
|
|
99
99
|
}>>;
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { pushSubscriptionsMapping } from './mapping.js';
|
|
2
2
|
import { allpeepDb } from '../db/index.js';
|
|
3
3
|
import { pushSubscriptionAccountConnector } from './helpers.js';
|
|
4
|
+
const uniqueCredential = (data) => {
|
|
5
|
+
switch (data.type) {
|
|
6
|
+
case 'web':
|
|
7
|
+
return { type: data.type, endpoint: data.endpoint };
|
|
8
|
+
case 'webhook':
|
|
9
|
+
return { type: data.type, url: data.url };
|
|
10
|
+
case 'apn':
|
|
11
|
+
return { type: data.type, apnToken: data.apnToken };
|
|
12
|
+
case 'fcm':
|
|
13
|
+
return { type: data.type, fcmToken: data.fcmToken };
|
|
14
|
+
}
|
|
15
|
+
};
|
|
4
16
|
export const createPushSubscription = async (account, data) => {
|
|
5
17
|
const db = await allpeepDb().then((db) => db.db);
|
|
6
18
|
const existingPushSubscription = await pushSubscriptionsMapping
|
|
7
19
|
.filter({
|
|
8
|
-
matches: data,
|
|
20
|
+
matches: uniqueCredential(data),
|
|
9
21
|
})
|
|
10
22
|
.first(db);
|
|
11
23
|
if (existingPushSubscription) {
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { PostWithMeta, ReportWithMeta, ProfileWithMeta } from '@openpeepshq/common/types';
|
|
2
2
|
export declare const transformReport: (report: ReportWithMeta) => Promise<ReportWithMeta>;
|
|
3
3
|
export declare const transformReports: (reports: ReportWithMeta[]) => Promise<ReportWithMeta[]>;
|
|
4
|
-
export declare const createdReportConnector: (db: import("../db").PgDb, from: ProfileWithMeta, to: ReportWithMeta, data?: {
|
|
4
|
+
export declare const createdReportConnector: (db: import("../db").PgDb, from: ProfileWithMeta, to: ReportWithMeta, data?: object & {
|
|
5
5
|
id?: string;
|
|
6
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
6
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
7
7
|
_from: string;
|
|
8
8
|
_to: string;
|
|
9
9
|
}>>;
|
|
10
|
-
export declare const reportedProfileConnector: (db: import("../db").PgDb, from: ReportWithMeta, to: ProfileWithMeta, data?: {
|
|
10
|
+
export declare const reportedProfileConnector: (db: import("../db").PgDb, from: ReportWithMeta, to: ProfileWithMeta, data?: object & {
|
|
11
11
|
id?: string;
|
|
12
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
12
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
13
13
|
_from: string;
|
|
14
14
|
_to: string;
|
|
15
15
|
}>>;
|
|
16
|
-
export declare const reportedPostsConnector: (db: import("../db").PgDb, from: ReportWithMeta, to: PostWithMeta, data?: {
|
|
16
|
+
export declare const reportedPostsConnector: (db: import("../db").PgDb, from: ReportWithMeta, to: PostWithMeta, data?: object & {
|
|
17
17
|
id?: string;
|
|
18
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
18
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
19
19
|
_from: string;
|
|
20
20
|
_to: string;
|
|
21
21
|
}>>;
|
package/dist/reports/helpers.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { connector } from '../db/helpers.js';
|
|
2
2
|
import { collectionInfos } from '../db/index.js';
|
|
3
|
+
import { tombstoneProfileWithMetaIfDeleted } from '@openpeepshq/common/lib';
|
|
3
4
|
import { transformPost } from '../posts/index.js';
|
|
4
5
|
export const transformReport = async (report) => {
|
|
5
6
|
var _a;
|
|
6
7
|
const rawPosts = ((_a = report.reportedPosts) !== null && _a !== void 0 ? _a : []);
|
|
7
|
-
return Object.assign(Object.assign({}, report), { reportedPosts: await Promise.all(rawPosts.map((post) => transformPost(post))) });
|
|
8
|
+
return Object.assign(Object.assign({}, report), { reporterProfile: tombstoneProfileWithMetaIfDeleted(report.reporterProfile), reportedProfile: tombstoneProfileWithMetaIfDeleted(report.reportedProfile), reportedPosts: await Promise.all(rawPosts.map((post) => transformPost(post))) });
|
|
8
9
|
};
|
|
9
10
|
export const transformReports = async (reports) => Promise.all(reports.map(transformReport));
|
|
10
11
|
export const createdReportConnector = connector(collectionInfos.profilesCollection, collectionInfos.reportsCollection, collectionInfos.createdReportCollection);
|
package/dist/reports/mapping.js
CHANGED
|
@@ -2,13 +2,17 @@ import { collectionInfos } from '../db/index.js';
|
|
|
2
2
|
import { postsMapping } from '../posts/mapping.js';
|
|
3
3
|
import { profilesMapping } from '../profiles/mapping.js';
|
|
4
4
|
import { map } from '../db/pg/map/index.js';
|
|
5
|
+
// Keep reporter/reported profiles even after the account is soft-deleted so
|
|
6
|
+
// historical reports still resolve (and serialize) — `transformReport`
|
|
7
|
+
// tombstones the deleted profile. Without this the relation resolves to
|
|
8
|
+
// `undefined`, fails output validation, and blanks the whole moderation queue.
|
|
5
9
|
const reportRelations = [
|
|
6
10
|
{
|
|
7
11
|
alias: 'reporterProfile',
|
|
8
12
|
edgeCollection: collectionInfos.createdReportCollection.name,
|
|
9
13
|
direction: 'INBOUND',
|
|
10
14
|
cardinality: 'one',
|
|
11
|
-
mapping: profilesMapping.data(),
|
|
15
|
+
mapping: profilesMapping.ignoreSoftDelete().data(),
|
|
12
16
|
skipEdge: true,
|
|
13
17
|
},
|
|
14
18
|
{
|
|
@@ -16,7 +20,7 @@ const reportRelations = [
|
|
|
16
20
|
edgeCollection: collectionInfos.isReportedProfileCollection.name,
|
|
17
21
|
direction: 'OUTBOUND',
|
|
18
22
|
cardinality: 'one',
|
|
19
|
-
mapping: profilesMapping.data(),
|
|
23
|
+
mapping: profilesMapping.ignoreSoftDelete().data(),
|
|
20
24
|
skipEdge: true,
|
|
21
25
|
},
|
|
22
26
|
{
|