chirkle 0.0.0-stage → 0.1.0
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/LICENSE +674 -0
- package/README.md +310 -2
- package/package.json +75 -4
- package/pb_hooks/federation/config.js +276 -0
- package/pb_hooks/federation/inbox.js +316 -0
- package/pb_hooks/federation/messages.js +420 -0
- package/pb_hooks/federation/mirror.js +277 -0
- package/pb_hooks/federation/net.js +247 -0
- package/pb_hooks/federation/peers.js +490 -0
- package/pb_hooks/federation/people.js +376 -0
- package/pb_hooks/federation/rooms.js +552 -0
- package/pb_hooks/federation/worker.js +413 -0
- package/pb_hooks/federation.pb.js +141 -0
- package/pb_hooks/lib/access.js +102 -0
- package/pb_hooks/lib/account.js +31 -0
- package/pb_hooks/lib/anonymous.js +189 -0
- package/pb_hooks/lib/bulk.js +187 -0
- package/pb_hooks/lib/collections.js +587 -0
- package/pb_hooks/lib/dms.js +123 -0
- package/pb_hooks/lib/emoji.js +28 -0
- package/pb_hooks/lib/enrich.js +75 -0
- package/pb_hooks/lib/features.js +31 -0
- package/pb_hooks/lib/files.js +375 -0
- package/pb_hooks/lib/http.js +146 -0
- package/pb_hooks/lib/images.js +160 -0
- package/pb_hooks/lib/keepalive.js +31 -0
- package/pb_hooks/lib/lists.js +173 -0
- package/pb_hooks/lib/media.js +635 -0
- package/pb_hooks/lib/messages.js +519 -0
- package/pb_hooks/lib/moderation.js +128 -0
- package/pb_hooks/lib/outbound.js +116 -0
- package/pb_hooks/lib/pages.js +171 -0
- package/pb_hooks/lib/previews.js +346 -0
- package/pb_hooks/lib/reactions.js +110 -0
- package/pb_hooks/lib/reads.js +181 -0
- package/pb_hooks/lib/records.js +77 -0
- package/pb_hooks/lib/rooms.js +148 -0
- package/pb_hooks/lib/site.js +102 -0
- package/pb_hooks/lib/text.js +110 -0
- package/pb_hooks/lib/users.js +81 -0
- package/pb_hooks/lib/worker.js +159 -0
- package/pb_hooks/main.pb.js +324 -0
- package/pb_hooks/telegram/api.js +128 -0
- package/pb_hooks/telegram/inbound.js +548 -0
- package/pb_hooks/telegram/links.js +157 -0
- package/pb_hooks/telegram/outbound.js +323 -0
- package/pb_hooks/telegram/people.js +166 -0
- package/pb_hooks/telegram/rich.js +192 -0
- package/pb_hooks/telegram/worker.js +181 -0
- package/pb_hooks/telegram.pb.js +47 -0
- package/pb_migrations/1760000000_init.js +150 -0
- package/pb_migrations/1760000001_qa_fixes.js +69 -0
- package/pb_migrations/1760000002_avatars.js +39 -0
- package/pb_migrations/1760000003_direct_messages.js +142 -0
- package/pb_migrations/1760000004_attachments.js +28 -0
- package/pb_migrations/1760000005_file_names.js +16 -0
- package/pb_migrations/1760000006_room_reads.js +41 -0
- package/pb_migrations/1760000007_replies.js +23 -0
- package/pb_migrations/1760000008_lowercase_emails.js +24 -0
- package/pb_migrations/1760000009_reactions.js +32 -0
- package/pb_migrations/1760000010_fit_thumbs.js +18 -0
- package/pb_migrations/1760000011_forwarding.js +39 -0
- package/pb_migrations/1760000012_accounts.js +55 -0
- package/pb_migrations/1760000013_qa_pass5.js +19 -0
- package/pb_migrations/1760000014_room_access.js +96 -0
- package/pb_migrations/1760000015_site.js +46 -0
- package/pb_migrations/1760000016_forward_refs.js +43 -0
- package/pb_migrations/1760000017_no_dms.js +18 -0
- package/pb_migrations/1760000018_attachment_limits.js +24 -0
- package/pb_migrations/1760000019_telegram.js +109 -0
- package/pb_migrations/1760000020_service_messages.js +21 -0
- package/pb_migrations/1760000021_forward_view_index.js +41 -0
- package/pb_migrations/1760000022_link_previews.js +43 -0
- package/pb_migrations/1760000023_room_writers.js +49 -0
- package/pb_migrations/1760000024_message_search.js +51 -0
- package/pb_migrations/1760000025_search_dotted_i.js +16 -0
- package/pb_migrations/1760000026_push.js +67 -0
- package/pb_migrations/1760000027_push_tokens_per_user.js +31 -0
- package/pb_migrations/1760000028_media_grid_thumbs.js +18 -0
- package/pb_migrations/1760000029_media.js +71 -0
- package/pb_migrations/1760000030_collections.js +140 -0
- package/pb_migrations/1760000031_unread_limit.js +20 -0
- package/pb_migrations/1760000032_federation.js +227 -0
- package/pb_migrations/1760000033_federation_requests.js +44 -0
- package/pb_migrations/1760000034_telegram_parts.js +26 -0
- package/pb_migrations/1760000035_telegram_anonymous.js +16 -0
- package/pb_migrations/1760000036_chirkle.js +20 -0
- package/pb_migrations/1760000037_file_dims.js +35 -0
- package/pb_migrations/1760000038_drop_push.js +64 -0
- package/pb_migrations/1760000039_anonymous_rooms.js +40 -0
- package/pb_migrations/1760000040_moderators.js +42 -0
- package/pb_migrations/1760000041_shared_files.js +500 -0
- package/pb_migrations/1760000042_files_src.js +17 -0
- package/pb_public/assets/access-ALBW2MT2.js +2 -0
- package/pb_public/assets/access-ALBW2MT2.js.map +7 -0
- package/pb_public/assets/access-PB77EH4F.css +2 -0
- package/pb_public/assets/access-PB77EH4F.css.map +7 -0
- package/pb_public/assets/app-ECR34OBK.css +2 -0
- package/pb_public/assets/app-ECR34OBK.css.map +7 -0
- package/pb_public/assets/app-SILEBEXB.js +3 -0
- package/pb_public/assets/app-SILEBEXB.js.map +7 -0
- package/pb_public/assets/collections-VEOIOCAW.css +2 -0
- package/pb_public/assets/collections-VEOIOCAW.css.map +7 -0
- package/pb_public/assets/emoji-WSTVXAW5.css +2 -0
- package/pb_public/assets/emoji-WSTVXAW5.css.map +7 -0
- package/pb_public/assets/emoji-picker-QYRX6NYL.js +609 -0
- package/pb_public/assets/emoji-picker-QYRX6NYL.js.map +7 -0
- package/pb_public/assets/inter-cyrillic-JEOLYBOO.woff2 +0 -0
- package/pb_public/assets/inter-cyrillic-ext-IYF56FF6.woff2 +0 -0
- package/pb_public/assets/inter-greek-IRE366VL.woff2 +0 -0
- package/pb_public/assets/inter-latin-NRMW37G5.woff2 +0 -0
- package/pb_public/assets/inter-latin-ext-HA22NDSG.woff2 +0 -0
- package/pb_public/assets/lazy-SCCVSUZO.js +2 -0
- package/pb_public/assets/lazy-SCCVSUZO.js.map +7 -0
- package/pb_public/assets/media-DH7ECZSF.js +2 -0
- package/pb_public/assets/media-DH7ECZSF.js.map +7 -0
- package/pb_public/assets/media-L3EYTHKT.css +2 -0
- package/pb_public/assets/media-L3EYTHKT.css.map +7 -0
- package/pb_public/assets/notify-L6GERFNO.js +2 -0
- package/pb_public/assets/notify-L6GERFNO.js.map +7 -0
- package/pb_public/assets/search-3UT4HMES.js +2 -0
- package/pb_public/assets/search-3UT4HMES.js.map +7 -0
- package/pb_public/assets/switcher-CEUKRLEY.js +2 -0
- package/pb_public/assets/switcher-CEUKRLEY.js.map +7 -0
- package/pb_public/assets/viewer-DXT7SKOU.js +2 -0
- package/pb_public/assets/viewer-DXT7SKOU.js.map +7 -0
- package/pb_public/assets/viewer-P7GYCBYM.css +2 -0
- package/pb_public/assets/viewer-P7GYCBYM.css.map +7 -0
- package/pb_public/icons/apple-touch-icon.png +0 -0
- package/pb_public/icons/icon-192.png +0 -0
- package/pb_public/icons/icon-512.png +0 -0
- package/pb_public/icons/icon.svg +1 -0
- package/pb_public/icons/maskable-512.png +0 -0
- package/pb_public/index.html +21 -0
- package/pb_public/sw.js +1 -0
- package/scripts/fetch-pocketbase.sh +63 -0
- package/scripts/start.mjs +93 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Direct messages (DESIGN.md §16): a DM is a room with kind = "dm" and its two members. Public rooms are
|
|
3
|
+
// unchanged apart from the new `kind`. Only the POST /api/chat/dms route (pb_hooks) creates DMs.
|
|
4
|
+
|
|
5
|
+
const SIGNED_IN = '@request.auth.id != ""';
|
|
6
|
+
const NO_DM_FIELDS = [
|
|
7
|
+
"@request.body.members:isset = false",
|
|
8
|
+
"@request.body.dm_key:isset = false",
|
|
9
|
+
"@request.body.last_message_at:isset = false",
|
|
10
|
+
];
|
|
11
|
+
/** The room in `rel` is public, or the caller is one of its members. */
|
|
12
|
+
const VISIBLE = (/** @type {string} */ rel) => `(${rel}kind = "public" || ${rel}members.id ?= @request.auth.id)`;
|
|
13
|
+
|
|
14
|
+
const RULES = {
|
|
15
|
+
rooms: {
|
|
16
|
+
listRule: `${SIGNED_IN} && ${VISIBLE("")}`,
|
|
17
|
+
viewRule: `${SIGNED_IN} && ${VISIBLE("")}`,
|
|
18
|
+
createRule: [
|
|
19
|
+
SIGNED_IN,
|
|
20
|
+
"@request.body.created_by = @request.auth.id",
|
|
21
|
+
"(@request.body.archived:isset = false || @request.body.archived = false)",
|
|
22
|
+
"@request.body.archived_at:isset = false",
|
|
23
|
+
'(@request.body.kind:isset = false || @request.body.kind = "public")',
|
|
24
|
+
...NO_DM_FIELDS,
|
|
25
|
+
].join(" && "),
|
|
26
|
+
updateRule: [
|
|
27
|
+
"created_by = @request.auth.id",
|
|
28
|
+
'kind = "public"',
|
|
29
|
+
"@request.body.created_by:isset = false",
|
|
30
|
+
"@request.body.archived_at:isset = false",
|
|
31
|
+
"@request.body.kind:isset = false",
|
|
32
|
+
...NO_DM_FIELDS,
|
|
33
|
+
].join(" && "),
|
|
34
|
+
},
|
|
35
|
+
messages: {
|
|
36
|
+
listRule: `${SIGNED_IN} && ${VISIBLE("room.")}`,
|
|
37
|
+
viewRule: `${SIGNED_IN} && ${VISIBLE("room.")}`,
|
|
38
|
+
createRule: [
|
|
39
|
+
SIGNED_IN,
|
|
40
|
+
"@request.body.author = @request.auth.id",
|
|
41
|
+
"@request.body.room.archived = false",
|
|
42
|
+
VISIBLE("@request.body.room."),
|
|
43
|
+
"@request.body.deleted:isset = false",
|
|
44
|
+
"@request.body.deleted_at:isset = false",
|
|
45
|
+
"@request.body.edited_at:isset = false",
|
|
46
|
+
].join(" && "),
|
|
47
|
+
},
|
|
48
|
+
hidden_rooms: {
|
|
49
|
+
createRule: `${SIGNED_IN} && @request.body.user = @request.auth.id && ${VISIBLE("@request.body.room.")}`,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** The MVP rules (1760000000_init.js), restored on down. */
|
|
54
|
+
const MVP_RULES = {
|
|
55
|
+
rooms: {
|
|
56
|
+
listRule: SIGNED_IN,
|
|
57
|
+
viewRule: SIGNED_IN,
|
|
58
|
+
createRule: [
|
|
59
|
+
SIGNED_IN,
|
|
60
|
+
"@request.body.created_by = @request.auth.id",
|
|
61
|
+
"(@request.body.archived:isset = false || @request.body.archived = false)",
|
|
62
|
+
"@request.body.archived_at:isset = false",
|
|
63
|
+
].join(" && "),
|
|
64
|
+
updateRule: ["created_by = @request.auth.id", "@request.body.created_by:isset = false", "@request.body.archived_at:isset = false"].join(
|
|
65
|
+
" && ",
|
|
66
|
+
),
|
|
67
|
+
},
|
|
68
|
+
messages: {
|
|
69
|
+
listRule: SIGNED_IN,
|
|
70
|
+
viewRule: SIGNED_IN,
|
|
71
|
+
createRule: [
|
|
72
|
+
SIGNED_IN,
|
|
73
|
+
"@request.body.author = @request.auth.id",
|
|
74
|
+
"@request.body.room.archived = false",
|
|
75
|
+
"@request.body.deleted:isset = false",
|
|
76
|
+
"@request.body.deleted_at:isset = false",
|
|
77
|
+
"@request.body.edited_at:isset = false",
|
|
78
|
+
].join(" && "),
|
|
79
|
+
},
|
|
80
|
+
hidden_rooms: { createRule: `${SIGNED_IN} && @request.body.user = @request.auth.id` },
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const DM_LIMIT = { label: "POST /api/chat/dms", audience: "", duration: 60, maxRequests: 10 };
|
|
84
|
+
|
|
85
|
+
/** @typedef {Parameters<Parameters<typeof migrate>[0]>[0]} DmMigrationApp */
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {DmMigrationApp} app
|
|
89
|
+
* @param {Record<string, Record<string, string>>} rules
|
|
90
|
+
*/
|
|
91
|
+
function applyRules(app, rules) {
|
|
92
|
+
for (const [name, r] of Object.entries(rules)) {
|
|
93
|
+
const c = app.findCollectionByNameOrId(name);
|
|
94
|
+
Object.assign(c, r);
|
|
95
|
+
app.save(c);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
migrate(
|
|
100
|
+
(app) => {
|
|
101
|
+
const users = app.findCollectionByNameOrId("users");
|
|
102
|
+
const rooms = app.findCollectionByNameOrId("rooms");
|
|
103
|
+
// DMs have no name (the title is the other member's): required only for public rooms, by pb_hooks.
|
|
104
|
+
/** @type {any} */ (rooms.fields.getByName("name")).required = false;
|
|
105
|
+
rooms.fields.add(new SelectField({ name: "kind", required: true, maxSelect: 1, values: ["public", "dm"] }));
|
|
106
|
+
rooms.fields.add(new RelationField({ name: "members", maxSelect: 2, collectionId: users.id, cascadeDelete: false }));
|
|
107
|
+
rooms.fields.add(new TextField({ name: "dm_key", hidden: true, max: 40 }));
|
|
108
|
+
rooms.fields.add(new DateField({ name: "last_message_at" }));
|
|
109
|
+
app.save(rooms);
|
|
110
|
+
|
|
111
|
+
app.db().newQuery("UPDATE rooms SET kind = 'public' WHERE kind = '' OR kind IS NULL").execute();
|
|
112
|
+
|
|
113
|
+
const indexed = app.findCollectionByNameOrId("rooms");
|
|
114
|
+
indexed.addIndex("idx_rooms_dm_key", true, "`dm_key`", "`dm_key` != ''");
|
|
115
|
+
// Every DM's name is "": the case-insensitive unique name index only covers named (public) rooms now.
|
|
116
|
+
indexed.removeIndex("idx_rooms_name");
|
|
117
|
+
indexed.addIndex("idx_rooms_name", true, "`name` COLLATE NOCASE", "`name` != ''");
|
|
118
|
+
app.save(indexed);
|
|
119
|
+
|
|
120
|
+
applyRules(app, RULES);
|
|
121
|
+
|
|
122
|
+
const settings = app.settings();
|
|
123
|
+
const rest = settings.rateLimits.rules.filter((r) => r.label !== DM_LIMIT.label);
|
|
124
|
+
settings.rateLimits.rules = [/** @type {any} */ (DM_LIMIT), ...rest];
|
|
125
|
+
app.save(settings);
|
|
126
|
+
},
|
|
127
|
+
// Rolling back turns existing DMs into nameless rooms visible to everyone: delete them first if that matters.
|
|
128
|
+
(app) => {
|
|
129
|
+
applyRules(app, MVP_RULES);
|
|
130
|
+
const rooms = app.findCollectionByNameOrId("rooms");
|
|
131
|
+
rooms.removeIndex("idx_rooms_dm_key");
|
|
132
|
+
rooms.removeIndex("idx_rooms_name");
|
|
133
|
+
rooms.addIndex("idx_rooms_name", true, "`name` COLLATE NOCASE", "");
|
|
134
|
+
for (const n of ["kind", "members", "dm_key", "last_message_at"]) rooms.fields.removeByName(n);
|
|
135
|
+
/** @type {any} */ (rooms.fields.getByName("name")).required = true;
|
|
136
|
+
app.save(rooms);
|
|
137
|
+
|
|
138
|
+
const settings = app.settings();
|
|
139
|
+
settings.rateLimits.rules = settings.rateLimits.rules.filter((r) => r.label !== DM_LIMIT.label);
|
|
140
|
+
app.save(settings);
|
|
141
|
+
},
|
|
142
|
+
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Attachments (DESIGN.md §17.1): up to 4 protected files per message, 8 MB each, thumbnails for images.
|
|
3
|
+
// Files never change after sending (only the soft delete wipes them, in pb_hooks).
|
|
4
|
+
|
|
5
|
+
const FILES = {
|
|
6
|
+
name: "files",
|
|
7
|
+
maxSelect: 4,
|
|
8
|
+
maxSize: 8 * 1024 * 1024,
|
|
9
|
+
protected: true,
|
|
10
|
+
thumbs: ["480x360", "240x180"],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const NO_FILE_CHANGES = "@request.body.files:isset = false";
|
|
14
|
+
|
|
15
|
+
migrate(
|
|
16
|
+
(app) => {
|
|
17
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
18
|
+
messages.fields.add(new FileField(/** @type {any} */ (FILES)));
|
|
19
|
+
messages.updateRule = `${messages.updateRule} && ${NO_FILE_CHANGES}`;
|
|
20
|
+
app.save(messages);
|
|
21
|
+
},
|
|
22
|
+
(app) => {
|
|
23
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
24
|
+
messages.fields.removeByName("files");
|
|
25
|
+
messages.updateRule = (messages.updateRule ?? "").replace(` && ${NO_FILE_CHANGES}`, "");
|
|
26
|
+
app.save(messages);
|
|
27
|
+
},
|
|
28
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// QA BUG-28: keep attachments' original names. `messages.file_names` maps stored name → original name; only the
|
|
3
|
+
// create hook writes it (from the upload itself), so clients can't forge it.
|
|
4
|
+
|
|
5
|
+
migrate(
|
|
6
|
+
(app) => {
|
|
7
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
8
|
+
messages.fields.add(new JSONField({ name: "file_names", maxSize: 4096 }));
|
|
9
|
+
app.save(messages);
|
|
10
|
+
},
|
|
11
|
+
(app) => {
|
|
12
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
13
|
+
messages.fields.removeByName("file_names");
|
|
14
|
+
app.save(messages);
|
|
15
|
+
},
|
|
16
|
+
);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Unread counts (DESIGN.md §18.1): how far each user has read each room. Users can list their own rows (and get
|
|
3
|
+
// them live); only POST /api/chat/reads (pb_hooks) writes them, so last_read_at only ever moves forward.
|
|
4
|
+
|
|
5
|
+
const READ_LIMIT = { label: "POST /api/chat/reads", audience: "", duration: 60, maxRequests: 120 };
|
|
6
|
+
|
|
7
|
+
migrate(
|
|
8
|
+
(app) => {
|
|
9
|
+
const users = app.findCollectionByNameOrId("users");
|
|
10
|
+
const rooms = app.findCollectionByNameOrId("rooms");
|
|
11
|
+
const reads = new Collection(
|
|
12
|
+
/** @type {any} */ ({
|
|
13
|
+
type: "base",
|
|
14
|
+
name: "room_reads",
|
|
15
|
+
listRule: "user = @request.auth.id",
|
|
16
|
+
viewRule: "user = @request.auth.id",
|
|
17
|
+
createRule: null,
|
|
18
|
+
updateRule: null,
|
|
19
|
+
deleteRule: null,
|
|
20
|
+
fields: [
|
|
21
|
+
{ type: "relation", name: "user", required: true, maxSelect: 1, collectionId: users.id, cascadeDelete: true },
|
|
22
|
+
{ type: "relation", name: "room", required: true, maxSelect: 1, collectionId: rooms.id, cascadeDelete: true },
|
|
23
|
+
{ type: "date", name: "last_read_at", required: true },
|
|
24
|
+
],
|
|
25
|
+
indexes: ["CREATE UNIQUE INDEX `idx_room_reads_user_room` ON `room_reads` (`user`, `room`)"],
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
app.save(reads);
|
|
29
|
+
|
|
30
|
+
const settings = app.settings();
|
|
31
|
+
const rest = settings.rateLimits.rules.filter((r) => r.label !== READ_LIMIT.label);
|
|
32
|
+
settings.rateLimits.rules = [/** @type {any} */ (READ_LIMIT), ...rest];
|
|
33
|
+
app.save(settings);
|
|
34
|
+
},
|
|
35
|
+
(app) => {
|
|
36
|
+
app.delete(app.findCollectionByNameOrId("room_reads"));
|
|
37
|
+
const settings = app.settings();
|
|
38
|
+
settings.rateLimits.rules = settings.rateLimits.rules.filter((r) => r.label !== READ_LIMIT.label);
|
|
39
|
+
app.save(settings);
|
|
40
|
+
},
|
|
41
|
+
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Replies (DESIGN.md §19): `messages.reply_to` points at an earlier message of the same room. Set only on create
|
|
3
|
+
// (pb_hooks checks the room); never changed afterwards. Deleting the original only soft-deletes it, so the
|
|
4
|
+
// relation keeps pointing at its placeholder.
|
|
5
|
+
|
|
6
|
+
const NO_REPLY_CHANGES = "@request.body.reply_to:isset = false";
|
|
7
|
+
|
|
8
|
+
migrate(
|
|
9
|
+
(app) => {
|
|
10
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
11
|
+
messages.fields.add(
|
|
12
|
+
new RelationField(/** @type {any} */ ({ name: "reply_to", maxSelect: 1, collectionId: messages.id, cascadeDelete: false })),
|
|
13
|
+
);
|
|
14
|
+
messages.updateRule = `${messages.updateRule} && ${NO_REPLY_CHANGES}`;
|
|
15
|
+
app.save(messages);
|
|
16
|
+
},
|
|
17
|
+
(app) => {
|
|
18
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
19
|
+
messages.fields.removeByName("reply_to");
|
|
20
|
+
messages.updateRule = (messages.updateRule ?? "").replace(` && ${NO_REPLY_CHANGES}`, "");
|
|
21
|
+
app.save(messages);
|
|
22
|
+
},
|
|
23
|
+
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// QA BUG-47: emails are stored in lower case (pb_hooks lowers new ones), so an address can't make two accounts and
|
|
3
|
+
// logging in doesn't depend on its capitalization. Lower the existing ones, except where two accounts already differ
|
|
4
|
+
// only in case: those keep their emails, and each still logs in with its own as typed.
|
|
5
|
+
|
|
6
|
+
migrate(
|
|
7
|
+
(app) => {
|
|
8
|
+
/** @type {Map<string, string[]>} lowered email → ids */
|
|
9
|
+
const byEmail = new Map();
|
|
10
|
+
for (const u of app.findAllRecords("users")) {
|
|
11
|
+
if (!u) continue;
|
|
12
|
+
const key = u.email().trim().toLowerCase();
|
|
13
|
+
byEmail.set(key, [...(byEmail.get(key) ?? []), u.id]);
|
|
14
|
+
}
|
|
15
|
+
for (const [email, ids] of byEmail) {
|
|
16
|
+
if (ids.length !== 1) continue;
|
|
17
|
+
// Raw SQL: no hooks, and `updated` is left alone.
|
|
18
|
+
app.db().newQuery("UPDATE users SET email = {:email} WHERE id = {:id} AND email != {:email}").bind({ email, id: ids[0] }).execute();
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
() => {
|
|
22
|
+
// Nothing to undo: the original capitalization isn't kept, and lower-case emails work either way.
|
|
23
|
+
},
|
|
24
|
+
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Reactions (DESIGN.md §20.1): `messages.reactions` lists each emoji with who reacted with it. Only
|
|
3
|
+
// POST /api/chat/reactions (pb_hooks) writes it; clients can't set it on create or update.
|
|
4
|
+
|
|
5
|
+
const NO_REACTIONS = "@request.body.reactions:isset = false";
|
|
6
|
+
const REACT_LIMIT = { label: "POST /api/chat/reactions", audience: "", duration: 10, maxRequests: 30 };
|
|
7
|
+
|
|
8
|
+
migrate(
|
|
9
|
+
(app) => {
|
|
10
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
11
|
+
messages.fields.add(new JSONField({ name: "reactions" }));
|
|
12
|
+
messages.createRule = `${messages.createRule} && ${NO_REACTIONS}`;
|
|
13
|
+
messages.updateRule = `${messages.updateRule} && ${NO_REACTIONS}`;
|
|
14
|
+
app.save(messages);
|
|
15
|
+
|
|
16
|
+
const settings = app.settings();
|
|
17
|
+
const rest = settings.rateLimits.rules.filter((r) => r.label !== REACT_LIMIT.label);
|
|
18
|
+
settings.rateLimits.rules = [/** @type {any} */ (REACT_LIMIT), ...rest];
|
|
19
|
+
app.save(settings);
|
|
20
|
+
},
|
|
21
|
+
(app) => {
|
|
22
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
23
|
+
messages.fields.removeByName("reactions");
|
|
24
|
+
messages.createRule = (messages.createRule ?? "").replace(` && ${NO_REACTIONS}`, "");
|
|
25
|
+
messages.updateRule = (messages.updateRule ?? "").replace(` && ${NO_REACTIONS}`, "");
|
|
26
|
+
app.save(messages);
|
|
27
|
+
|
|
28
|
+
const settings = app.settings();
|
|
29
|
+
settings.rateLimits.rules = settings.rateLimits.rules.filter((r) => r.label !== REACT_LIMIT.label);
|
|
30
|
+
app.save(settings);
|
|
31
|
+
},
|
|
32
|
+
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Attachment thumbnails keep the image's aspect ratio (DESIGN.md §17.5): "f" fits the image inside the box rather
|
|
3
|
+
// than cropping it to the box.
|
|
4
|
+
|
|
5
|
+
const FIT = ["800x480f", "480x240f"];
|
|
6
|
+
const CROP = ["480x360", "240x180"];
|
|
7
|
+
|
|
8
|
+
/** @param {any} app @param {string[]} thumbs */
|
|
9
|
+
function setThumbs(app, thumbs) {
|
|
10
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
11
|
+
/** @type {any} */ (messages.fields.getByName("files")).thumbs = thumbs;
|
|
12
|
+
app.save(messages);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
migrate(
|
|
16
|
+
(app) => setThumbs(app, FIT),
|
|
17
|
+
(app) => setThumbs(app, CROP),
|
|
18
|
+
);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Forwarding and deleting several messages at once (DESIGN.md §21). `messages.forwarded_from` names who first wrote a
|
|
3
|
+
// forwarded message. Only POST /api/chat/forward (pb_hooks) sets it; clients can't set or change it.
|
|
4
|
+
|
|
5
|
+
const NO_FORWARD = "@request.body.forwarded_from:isset = false";
|
|
6
|
+
const LIMITS = [
|
|
7
|
+
{ label: "POST /api/chat/forward", audience: "", duration: 60, maxRequests: 20 },
|
|
8
|
+
{ label: "POST /api/chat/delete", audience: "", duration: 60, maxRequests: 20 },
|
|
9
|
+
];
|
|
10
|
+
const LABELS = LIMITS.map((r) => r.label);
|
|
11
|
+
|
|
12
|
+
migrate(
|
|
13
|
+
(app) => {
|
|
14
|
+
const users = app.findCollectionByNameOrId("users");
|
|
15
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
16
|
+
messages.fields.add(
|
|
17
|
+
new RelationField(/** @type {any} */ ({ name: "forwarded_from", maxSelect: 1, collectionId: users.id, cascadeDelete: false })),
|
|
18
|
+
);
|
|
19
|
+
messages.createRule = `${messages.createRule} && ${NO_FORWARD}`;
|
|
20
|
+
messages.updateRule = `${messages.updateRule} && ${NO_FORWARD}`;
|
|
21
|
+
app.save(messages);
|
|
22
|
+
|
|
23
|
+
const settings = app.settings();
|
|
24
|
+
const rest = settings.rateLimits.rules.filter((r) => !LABELS.includes(r.label));
|
|
25
|
+
settings.rateLimits.rules = [.../** @type {any[]} */ (LIMITS), ...rest];
|
|
26
|
+
app.save(settings);
|
|
27
|
+
},
|
|
28
|
+
(app) => {
|
|
29
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
30
|
+
messages.fields.removeByName("forwarded_from");
|
|
31
|
+
messages.createRule = (messages.createRule ?? "").replace(` && ${NO_FORWARD}`, "");
|
|
32
|
+
messages.updateRule = (messages.updateRule ?? "").replace(` && ${NO_FORWARD}`, "");
|
|
33
|
+
app.save(messages);
|
|
34
|
+
|
|
35
|
+
const settings = app.settings();
|
|
36
|
+
settings.rateLimits.rules = settings.rateLimits.rules.filter((r) => !LABELS.includes(r.label));
|
|
37
|
+
app.save(settings);
|
|
38
|
+
},
|
|
39
|
+
);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Accounts (DESIGN.md §22):
|
|
3
|
+
// - users.name_key: display names are unique, compared like room names ("Ada" = "ADA" = "Ada"), set by pb_hooks.
|
|
4
|
+
// - a rate limit for POST /api/chat/password (changing your password, which checks the current one).
|
|
5
|
+
|
|
6
|
+
const ACCOUNT_LIMITS = [{ label: "POST /api/chat/password", audience: "", duration: 60, maxRequests: 5 }];
|
|
7
|
+
const ACCOUNT_LABELS = ACCOUNT_LIMITS.map((r) => r.label);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Same as nameKey() in pb_hooks/lib/text.js (migrations can't load the hooks' modules).
|
|
11
|
+
* @param {string} name
|
|
12
|
+
*/
|
|
13
|
+
function nameKey(name) {
|
|
14
|
+
const s = name.replace(/[----]/g, "");
|
|
15
|
+
return (typeof s.normalize === "function" ? s.normalize("NFKC") : s).toUpperCase().toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
migrate(
|
|
19
|
+
(app) => {
|
|
20
|
+
const users = app.findCollectionByNameOrId("users");
|
|
21
|
+
users.fields.add(new TextField({ name: "name_key", hidden: true, max: 400 }));
|
|
22
|
+
app.save(users);
|
|
23
|
+
|
|
24
|
+
// Backfill with raw SQL (no hooks). Names that already clash keep a key made unique by their id; they may keep
|
|
25
|
+
// their name, but nobody can take it any more.
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
for (const u of app.findAllRecords("users")) {
|
|
28
|
+
if (!u) continue;
|
|
29
|
+
let key = nameKey(u.getString("name"));
|
|
30
|
+
if (key === "") continue;
|
|
31
|
+
if (seen.has(key)) key = `${key}#${u.id}`;
|
|
32
|
+
seen.add(key);
|
|
33
|
+
app.db().newQuery("UPDATE users SET name_key = {:key} WHERE id = {:id}").bind({ key, id: u.id }).execute();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const withIndex = app.findCollectionByNameOrId("users");
|
|
37
|
+
withIndex.addIndex("idx_users_name_key", true, "`name_key`", "`name_key` != ''");
|
|
38
|
+
app.save(withIndex);
|
|
39
|
+
|
|
40
|
+
const settings = app.settings();
|
|
41
|
+
const rest = settings.rateLimits.rules.filter((r) => !ACCOUNT_LABELS.includes(r.label));
|
|
42
|
+
settings.rateLimits.rules = [.../** @type {any[]} */ (ACCOUNT_LIMITS), ...rest];
|
|
43
|
+
app.save(settings);
|
|
44
|
+
},
|
|
45
|
+
(app) => {
|
|
46
|
+
const users = app.findCollectionByNameOrId("users");
|
|
47
|
+
users.removeIndex("idx_users_name_key");
|
|
48
|
+
users.fields.removeByName("name_key");
|
|
49
|
+
app.save(users);
|
|
50
|
+
|
|
51
|
+
const settings = app.settings();
|
|
52
|
+
settings.rateLimits.rules = settings.rateLimits.rules.filter((r) => !ACCOUNT_LABELS.includes(r.label));
|
|
53
|
+
app.save(settings);
|
|
54
|
+
},
|
|
55
|
+
);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Fixes from the fifth QA pass (docs/QA.md):
|
|
3
|
+
// - BUG-53: a password only changes through POST /api/chat/password (§22.2), which is rate limited and checks the new
|
|
4
|
+
// one. PocketBase's own users update also accepted { oldPassword, password, passwordConfirm }, at the generic limit.
|
|
5
|
+
|
|
6
|
+
const NO_PASSWORD = "@request.body.password:isset = false && @request.body.passwordConfirm:isset = false";
|
|
7
|
+
|
|
8
|
+
migrate(
|
|
9
|
+
(app) => {
|
|
10
|
+
const users = app.findCollectionByNameOrId("users");
|
|
11
|
+
users.updateRule = `${users.updateRule} && ${NO_PASSWORD}`;
|
|
12
|
+
app.save(users);
|
|
13
|
+
},
|
|
14
|
+
(app) => {
|
|
15
|
+
const users = app.findCollectionByNameOrId("users");
|
|
16
|
+
users.updateRule = (users.updateRule ?? "").replace(` && ${NO_PASSWORD}`, "");
|
|
17
|
+
app.save(users);
|
|
18
|
+
},
|
|
19
|
+
);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Room access (DESIGN.md §23): a room's creator chooses who can see it.
|
|
3
|
+
// - `rooms.visibility`: "private" (only its members: the people the creator added, and the creator), "public" (every
|
|
4
|
+
// signed-in user, as before) or "open" (Open Air: also readable without an account, while it isn't archived). DMs
|
|
5
|
+
// are "private" to their two members. Existing rooms are backfilled.
|
|
6
|
+
// - `rooms.members` holds a private room's members (up to ROOM_MAX_MEMBERS); only the creator changes them, through the
|
|
7
|
+
// rooms API. The hooks keep it empty for other rooms and always list the creator in a private one.
|
|
8
|
+
// - Guests (no session) can list and read Open Air rooms, their messages and their attachments, and see the profile
|
|
9
|
+
// (name, avatar) of a user whose id they have, so messages show their authors. They can't write anything.
|
|
10
|
+
// - Writing in a room (a message, an edit, hiding it) needs the same access as seeing it, signed in.
|
|
11
|
+
|
|
12
|
+
const AUTHED = '@request.auth.id != ""';
|
|
13
|
+
const ROOM_MAX_MEMBERS = 100;
|
|
14
|
+
|
|
15
|
+
/** Signed in, and the room in `rel` is public or open, or the caller is one of its members (or its creator). */
|
|
16
|
+
const IS_MEMBER = (/** @type {string} */ rel) =>
|
|
17
|
+
`(${AUTHED} && (${rel}visibility != "private" || ${rel}members.id ?= @request.auth.id || ${rel}created_by = @request.auth.id))`;
|
|
18
|
+
/** MEMBER, or the room in `rel` is Open Air (and not archived): anyone can read it. */
|
|
19
|
+
const CAN_SEE = (/** @type {string} */ rel) => `((${rel}visibility = "open" && ${rel}archived = false) || ${IS_MEMBER(rel)})`;
|
|
20
|
+
|
|
21
|
+
/** The visibility conditions of 1760000003_direct_messages.js, replaced in place (later migrations appended to the rules). */
|
|
22
|
+
const OLD_VISIBLE = (/** @type {string} */ rel) => `(${rel}kind = "public" || ${rel}members.id ?= @request.auth.id)`;
|
|
23
|
+
const OLD_SEE = (/** @type {string} */ rel) => `${AUTHED} && ${OLD_VISIBLE(rel)}`;
|
|
24
|
+
|
|
25
|
+
/** @typedef {Parameters<Parameters<typeof migrate>[0]>[0]} AccessMigrationApp */
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Replace `from` by `to` in `rule`, which must contain it (a rule changed by hand would otherwise lose its guard).
|
|
29
|
+
* @param {string | null | undefined} rule
|
|
30
|
+
* @param {string} from
|
|
31
|
+
* @param {string} to
|
|
32
|
+
*/
|
|
33
|
+
function swap(rule, from, to) {
|
|
34
|
+
const r = rule ?? "";
|
|
35
|
+
if (!r.includes(from)) throw new Error(`room access migration: expected ${from} in ${r}`);
|
|
36
|
+
return r.replace(from, to);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {AccessMigrationApp} app
|
|
41
|
+
* @param {boolean} up
|
|
42
|
+
*/
|
|
43
|
+
function setRules(app, up) {
|
|
44
|
+
const see = (/** @type {string} */ rel) => (up ? CAN_SEE(rel) : OLD_SEE(rel));
|
|
45
|
+
const rooms = app.findCollectionByNameOrId("rooms");
|
|
46
|
+
rooms.listRule = see("");
|
|
47
|
+
rooms.viewRule = see("");
|
|
48
|
+
// A room's creator may now set its members (§23.2): the hooks check them.
|
|
49
|
+
const MEMBERS_FIXED = " && @request.body.members:isset = false";
|
|
50
|
+
rooms.updateRule = up ? swap(rooms.updateRule, MEMBERS_FIXED, "") : `${rooms.updateRule}${MEMBERS_FIXED}`;
|
|
51
|
+
app.save(rooms);
|
|
52
|
+
|
|
53
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
54
|
+
messages.listRule = see("room.");
|
|
55
|
+
messages.viewRule = see("room.");
|
|
56
|
+
messages.createRule = up
|
|
57
|
+
? swap(messages.createRule, OLD_VISIBLE("@request.body.room."), IS_MEMBER("@request.body.room."))
|
|
58
|
+
: swap(messages.createRule, IS_MEMBER("@request.body.room."), OLD_VISIBLE("@request.body.room."));
|
|
59
|
+
// Someone taken out of a private room can't edit (or delete) what they wrote there any more: they can't see it.
|
|
60
|
+
const STILL_MEMBER = ` && ${IS_MEMBER("room.")}`;
|
|
61
|
+
messages.updateRule = up ? `${messages.updateRule}${STILL_MEMBER}` : swap(messages.updateRule, STILL_MEMBER, "");
|
|
62
|
+
app.save(messages);
|
|
63
|
+
|
|
64
|
+
const hidden = app.findCollectionByNameOrId("hidden_rooms");
|
|
65
|
+
hidden.createRule = up
|
|
66
|
+
? swap(hidden.createRule, OLD_VISIBLE("@request.body.room."), IS_MEMBER("@request.body.room."))
|
|
67
|
+
: swap(hidden.createRule, IS_MEMBER("@request.body.room."), OLD_VISIBLE("@request.body.room."));
|
|
68
|
+
app.save(hidden);
|
|
69
|
+
|
|
70
|
+
// Guests see who wrote a message (expand=author needs the users view rule). Listing (and so searching) users still
|
|
71
|
+
// needs a session: nobody can enumerate the accounts.
|
|
72
|
+
const users = app.findCollectionByNameOrId("users");
|
|
73
|
+
users.viewRule = up ? "" : AUTHED;
|
|
74
|
+
app.save(users);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
migrate(
|
|
78
|
+
(app) => {
|
|
79
|
+
const rooms = app.findCollectionByNameOrId("rooms");
|
|
80
|
+
rooms.fields.add(new SelectField({ name: "visibility", required: true, maxSelect: 1, values: ["public", "private", "open"] }));
|
|
81
|
+
/** @type {any} */ (rooms.fields.getByName("members")).maxSelect = ROOM_MAX_MEMBERS;
|
|
82
|
+
app.save(rooms);
|
|
83
|
+
app.db().newQuery("UPDATE rooms SET visibility = CASE WHEN kind = 'dm' THEN 'private' ELSE 'public' END").execute();
|
|
84
|
+
setRules(app, true);
|
|
85
|
+
},
|
|
86
|
+
(app) => {
|
|
87
|
+
setRules(app, false);
|
|
88
|
+
// Private rooms would otherwise become visible to everyone: they are deleted with their messages first if that
|
|
89
|
+
// matters. Members beyond a DM's two are dropped.
|
|
90
|
+
app.db().newQuery("UPDATE rooms SET members = '[]' WHERE kind != 'dm'").execute();
|
|
91
|
+
const rooms = app.findCollectionByNameOrId("rooms");
|
|
92
|
+
rooms.fields.removeByName("visibility");
|
|
93
|
+
/** @type {any} */ (rooms.fields.getByName("members")).maxSelect = 2;
|
|
94
|
+
app.save(rooms);
|
|
95
|
+
},
|
|
96
|
+
);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Site settings (DESIGN.md §24): one `site` record, edited by a superuser in the admin UI (Collections → site).
|
|
3
|
+
// - `title` and `logo`: the branding shown in the header, on the login page and in the tab's title.
|
|
4
|
+
// - `invite_only` + `invite_code`: signups need the code (pb_hooks/lib/site.js). Invite-only without a code closes
|
|
5
|
+
// signups. The code is hidden: only superusers see it.
|
|
6
|
+
// Anyone can read the record (guests see the branding and whether signing up needs a code); nobody else can change it.
|
|
7
|
+
|
|
8
|
+
/** @param {Record<string, unknown>} data */
|
|
9
|
+
const siteCollection = (data) => new Collection(/** @type {any} */ (data));
|
|
10
|
+
|
|
11
|
+
migrate(
|
|
12
|
+
(app) => {
|
|
13
|
+
const site = siteCollection({
|
|
14
|
+
type: "base",
|
|
15
|
+
name: "site",
|
|
16
|
+
listRule: "",
|
|
17
|
+
viewRule: "",
|
|
18
|
+
createRule: null,
|
|
19
|
+
updateRule: null,
|
|
20
|
+
deleteRule: null,
|
|
21
|
+
fields: [
|
|
22
|
+
{ type: "text", name: "title", required: true, min: 1, max: 48 },
|
|
23
|
+
{
|
|
24
|
+
type: "file",
|
|
25
|
+
name: "logo",
|
|
26
|
+
maxSelect: 1,
|
|
27
|
+
maxSize: 1024 * 1024,
|
|
28
|
+
mimeTypes: ["image/svg+xml", "image/png", "image/jpeg", "image/webp", "image/gif"],
|
|
29
|
+
protected: false,
|
|
30
|
+
},
|
|
31
|
+
{ type: "bool", name: "invite_only" },
|
|
32
|
+
{ type: "text", name: "invite_code", hidden: true, max: 100 },
|
|
33
|
+
{ type: "autodate", name: "created", onCreate: true, onUpdate: false },
|
|
34
|
+
{ type: "autodate", name: "updated", onCreate: true, onUpdate: true },
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
app.save(site);
|
|
38
|
+
|
|
39
|
+
const rec = new Record(site);
|
|
40
|
+
rec.set("title", "Chat");
|
|
41
|
+
app.save(rec);
|
|
42
|
+
},
|
|
43
|
+
(app) => {
|
|
44
|
+
app.delete(app.findCollectionByNameOrId("site"));
|
|
45
|
+
},
|
|
46
|
+
);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// Forwards point at the original instead of copying it (DESIGN.md §21.3). `messages.forward_of` is the message a
|
|
3
|
+
// forward shows: its text and attachments are the original's as they are now (an edit shows in every forward, a delete
|
|
4
|
+
// empties them), and nothing is copied, so forwarding can't multiply what is stored. Only POST /api/chat/forward
|
|
5
|
+
// (pb_hooks) sets it; clients can't set or change it.
|
|
6
|
+
// - Whoever can see a forward that isn't deleted can view the message it points at, and that message's attachments:
|
|
7
|
+
// the view rule grants it. Nothing else of the original's room: the list rule, which lists a room's messages and
|
|
8
|
+
// feeds their realtime events, is unchanged.
|
|
9
|
+
// - Forwards made before this keep their copies. Going down loses what forwards made since show: they hold nothing.
|
|
10
|
+
|
|
11
|
+
const NO_FORWARD_OF = "@request.body.forward_of:isset = false";
|
|
12
|
+
/** Another message of the collection, joined once so every condition below is about the same one. */
|
|
13
|
+
const F = "@collection.messages:fwd.";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A forward of this message that isn't deleted is in a room the caller can see (CAN_SEE of 1760000014_room_access.js,
|
|
17
|
+
* with the "any of" operators that @collection joins need).
|
|
18
|
+
*/
|
|
19
|
+
const VIA_FORWARD =
|
|
20
|
+
`(${F}forward_of ?= id && ${F}deleted ?= false && ` +
|
|
21
|
+
`((${F}room.visibility ?= "open" && ${F}room.archived ?= false) || ` +
|
|
22
|
+
`(@request.auth.id != "" && (${F}room.visibility ?!= "private" || ${F}room.members.id ?= @request.auth.id || ${F}room.created_by ?= @request.auth.id))))`;
|
|
23
|
+
|
|
24
|
+
migrate(
|
|
25
|
+
(app) => {
|
|
26
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
27
|
+
messages.fields.add(
|
|
28
|
+
new RelationField(/** @type {any} */ ({ name: "forward_of", maxSelect: 1, collectionId: messages.id, cascadeDelete: false })),
|
|
29
|
+
);
|
|
30
|
+
messages.viewRule = `(${messages.listRule}) || ${VIA_FORWARD}`;
|
|
31
|
+
messages.createRule = `${messages.createRule} && ${NO_FORWARD_OF}`;
|
|
32
|
+
messages.updateRule = `${messages.updateRule} && ${NO_FORWARD_OF}`;
|
|
33
|
+
app.save(messages);
|
|
34
|
+
},
|
|
35
|
+
(app) => {
|
|
36
|
+
const messages = app.findCollectionByNameOrId("messages");
|
|
37
|
+
messages.fields.removeByName("forward_of");
|
|
38
|
+
messages.viewRule = messages.listRule;
|
|
39
|
+
messages.createRule = (messages.createRule ?? "").replace(` && ${NO_FORWARD_OF}`, "");
|
|
40
|
+
messages.updateRule = (messages.updateRule ?? "").replace(` && ${NO_FORWARD_OF}`, "");
|
|
41
|
+
app.save(messages);
|
|
42
|
+
},
|
|
43
|
+
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference path="../types/pocketbase.d.ts" />
|
|
2
|
+
// "Doesn't take direct messages" (DESIGN.md §16.7): `users.no_dms`. Nobody can open a DM with such a user, they can't
|
|
3
|
+
// open one either, and messages in a DM they are in are refused (pb_hooks/lib/dms.js, lib/messages.js). Off by
|
|
4
|
+
// default, so existing and new accounts are unchanged. Set for the Telegram bridge's stand-in users; a user may set it
|
|
5
|
+
// on their own record (the update rule allows it), which the profile may offer later.
|
|
6
|
+
|
|
7
|
+
migrate(
|
|
8
|
+
(app) => {
|
|
9
|
+
const users = app.findCollectionByNameOrId("users");
|
|
10
|
+
users.fields.add(new BoolField(/** @type {any} */ ({ name: "no_dms" })));
|
|
11
|
+
app.save(users);
|
|
12
|
+
},
|
|
13
|
+
(app) => {
|
|
14
|
+
const users = app.findCollectionByNameOrId("users");
|
|
15
|
+
users.fields.removeByName("no_dms");
|
|
16
|
+
app.save(users);
|
|
17
|
+
},
|
|
18
|
+
);
|