Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Custom PocketBase build. Behaves like the stock binary (JS hooks in
// pb_hooks, JS migrations in pb_migrations, static frontend from pb_public)
// with one addition: Web Push delivery for the `notifications` collection,
// which the stock binary can't do because the JSVM lacks the required crypto.
// with native Web Push delivery and event hooks for notifications.
// See webpush.go.
package main

Expand Down
69 changes: 0 additions & 69 deletions pb_hooks/notifications.pb.js

This file was deleted.

18 changes: 0 additions & 18 deletions pb_hooks/recurring.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,6 @@ function createExpense(app, template, group, splits, dueDate, baseAmount) {
return expense;
}

// Nobody "acted" on an automatic expense, so every member gets notified,
// including the payer. The notifications.pb.js hook only fires for API
// requests, so this is done here for records created by the cron.
function notifyMembers(app, group, expense) {
const collection = app.findCollectionByNameOrId("notifications");
const amount = expense.get("amount");
const currency = (expense.get("currency") || "").toUpperCase();
for (const memberId of group.get("members") || []) {
const notification = new Record(collection);
notification.set("user", memberId);
notification.set("title", group.get("name"));
notification.set("body", `Recurring expense "${expense.get("title")}" — ${amount} ${currency}`);
notification.set("url", `/group/${group.id}`);
app.save(notification);
}
}

/**
* Create every occurrence of one template that is due at `now`, advancing
* `nextDate` past them and deactivating the template once `endDate` is
Expand Down Expand Up @@ -203,7 +186,6 @@ function materializeTemplate(app, template, now) {
throw new Error(`no exchange rate for ${currency}->${base} on ${dayOf(nextDate)}`);
}
const expense = createExpense(tx, template, group, splits, nextDate, baseAmount);
notifyMembers(tx, group, expense);
created++;

const following = nextOccurrence(nextDate, anchor, frequency, interval);
Expand Down
6 changes: 3 additions & 3 deletions pb_hooks/recurringExpenses.pb.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// <reference path="../pb_data/types.d.ts" />

// Turns due `recurring_expenses` templates into regular expenses (plus splits
// and notifications). The logic lives in ./recurring.js — see there for the
// data model — and is require()'d inside each handler because handlers run in
// Turns due `recurring_expenses` templates into regular expenses (plus splits).
// Push notifications are delivered by Go hooks on `expenses`. The logic lives
// in ./recurring.js — see there for the data model — and is require()'d inside
// isolated contexts that cannot see top-level functions of this file.
//
// Runs hourly: templates are compared against "now", so the exact hour does
Expand Down
117 changes: 117 additions & 0 deletions pb_migrations/1790974011_deleted_notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("pbc_1685465007");

return app.delete(collection);
}, (app) => {
const collection = new Collection({
"createRule": null,
"deleteRule": null,
"fields": [
{
"autogeneratePattern": "[a-z0-9]{15}",
"help": "",
"hidden": false,
"id": "text3208210256",
"max": 15,
"min": 15,
"name": "id",
"pattern": "^[a-z0-9]+$",
"presentable": false,
"primaryKey": true,
"required": true,
"system": true,
"type": "text"
},
{
"cascadeDelete": true,
"collectionId": "_pb_users_auth_",
"help": "",
"hidden": false,
"id": "relation2375276105",
"maxSelect": 1,
"minSelect": 0,
"name": "user",
"presentable": false,
"required": true,
"system": false,
"type": "relation"
},
{
"autogeneratePattern": "",
"help": "",
"hidden": false,
"id": "text724990059",
"max": 0,
"min": 0,
"name": "title",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text"
},
{
"autogeneratePattern": "",
"help": "",
"hidden": false,
"id": "text3182418120",
"max": 0,
"min": 0,
"name": "body",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
},
{
"autogeneratePattern": "",
"help": "",
"hidden": false,
"id": "text4101391790",
"max": 0,
"min": 0,
"name": "url",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
},
{
"hidden": false,
"id": "autodate2990389176",
"name": "created",
"onCreate": true,
"onUpdate": false,
"presentable": false,
"system": false,
"type": "autodate"
},
{
"hidden": false,
"id": "autodate3332085495",
"name": "updated",
"onCreate": true,
"onUpdate": true,
"presentable": false,
"system": false,
"type": "autodate"
}
],
"id": "pbc_1685465007",
"indexes": [],
"listRule": null,
"name": "notifications",
"system": false,
"type": "base",
"updateRule": null,
"viewRule": null
});

return app.save(collection);
})
14 changes: 0 additions & 14 deletions src/types/pocketbase-types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const Collections = {
Expenses: "expenses",
Groups: "groups",
Invites: "invites",
Notifications: "notifications",
Projects: "projects",
PushSubscriptions: "push_subscriptions",
Rates: "rates",
Expand Down Expand Up @@ -156,16 +155,6 @@ export type InvitesRecord = {
updated: IsoAutoDateString
}

export type NotificationsRecord = {
body?: string
created: IsoAutoDateString
id: string
title: string
updated: IsoAutoDateString
url?: string
user: RecordIdString
}

export type ProjectsRecord = {
created: IsoAutoDateString
group: RecordIdString
Expand Down Expand Up @@ -277,7 +266,6 @@ export type CurrenciesResponse<Texpand = unknown> = Required<CurrenciesRecord> &
export type ExpensesResponse<Texpand = unknown> = Required<ExpensesRecord> & BaseSystemFields<Texpand>
export type GroupsResponse<Texpand = unknown> = Required<GroupsRecord> & BaseSystemFields<Texpand>
export type InvitesResponse<Texpand = unknown> = Required<InvitesRecord> & BaseSystemFields<Texpand>
export type NotificationsResponse<Texpand = unknown> = Required<NotificationsRecord> & BaseSystemFields<Texpand>
export type ProjectsResponse<Texpand = unknown> = Required<ProjectsRecord> & BaseSystemFields<Texpand>
export type PushSubscriptionsResponse<Texpand = unknown> = Required<PushSubscriptionsRecord> & BaseSystemFields<Texpand>
export type RatesResponse<Trates = unknown, Texpand = unknown> = Required<RatesRecord<Trates>> & BaseSystemFields<Texpand>
Expand All @@ -300,7 +288,6 @@ export type CollectionRecords = {
expenses: ExpensesRecord
groups: GroupsRecord
invites: InvitesRecord
notifications: NotificationsRecord
projects: ProjectsRecord
push_subscriptions: PushSubscriptionsRecord
rates: RatesRecord
Expand All @@ -322,7 +309,6 @@ export type CollectionResponses = {
expenses: ExpensesResponse
groups: GroupsResponse
invites: InvitesResponse
notifications: NotificationsResponse
projects: ProjectsResponse
push_subscriptions: PushSubscriptionsResponse
rates: RatesResponse
Expand Down
Loading
Loading