diff --git a/account.json.example b/account.json.example index e095d76..7525986 100644 --- a/account.json.example +++ b/account.json.example @@ -2,5 +2,12 @@ "username": "bookmarks", "avatar": "https://cdn.glitch.global/8eaf209c-2fa9-4353-9b99-e8d8f3a5f8d4/postmarks-logo-white-small.png?v=1693610556689", "displayName": "Postmarks", - "description": "An ActivityPub bookmarking and sharing site built with Postmarks" + "description": "An ActivityPub bookmarking and sharing site built with Postmarks", + "attachment": [ + { + "type": "PropertyValue", + "name": "Source Code", + "value": "https://github.com/ckolderup/postmarks" + } + ] } diff --git a/server.js b/server.js index cd31faa..da0be6b 100644 --- a/server.js +++ b/server.js @@ -10,6 +10,7 @@ import * as bookmarksDb from './src/bookmarks-db.js'; import * as apDb from './src/activity-pub-db.js'; import routes from './src/routes/index.js'; +import { updateProfile } from './src/activitypub.js'; dotenv.config(); @@ -132,3 +133,6 @@ app.use('/nodeinfo/2.1', routes.nodeinfo); app.use('/opensearch.xml', routes.opensearch); app.listen(PORT, () => console.log(`App listening on port ${PORT}`)); +app.on('listening', function () { + // updateProfile(apDb, account, domain); +}); diff --git a/src/activity-pub-db.js b/src/activity-pub-db.js index f26fdf3..d68cb08 100644 --- a/src/activity-pub-db.js +++ b/src/activity-pub-db.js @@ -15,7 +15,7 @@ import { account, domain, actorInfo } from './util.js'; const dbFile = './.data/activitypub.db'; let db; -function actorJson(pubkey) { +export function actorJson(pubkey) { return { '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'], @@ -33,6 +33,7 @@ function actorJson(pubkey) { outbox: `https://${domain}/u/${account}/outbox`, followers: `https://${domain}/u/${account}/followers`, following: `https://${domain}/u/${account}/following`, + attachment: actorInfo.attachment, publicKey: { id: `https://${domain}/u/${account}#main-key`, diff --git a/src/activitypub.js b/src/activitypub.js index 09fd880..c2d80bd 100644 --- a/src/activitypub.js +++ b/src/activitypub.js @@ -267,6 +267,35 @@ export async function broadcastMessage(bookmark, action, db, account, domain) { } } +export async function updateProfile(db, account, domain) { + if (actorInfo.disabled) { + return; // no fediverse setup + } + const publicKey = await db.getPublicKey(); + const actorRecord = db.actorJson(publicKey); + + const guidUpdate = crypto.randomBytes(16).toString('hex'); + const updateMessage = { + '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'], + type: 'Update', + id: `https://${domain}/m/${guidUpdate}`, + actor: `https://${domain}/u/${account}`, + to: ['https://www.w3.org/ns/activitystreams#Public'], + object: actorRecord, + }; + + db.insertMessage(guidUpdate, null, JSON.stringify(updateMessage)); + const result = await db.getFollowers(); + const followers = JSON.parse(result); + // eslint-disable-next-line no-restricted-syntax + for (const follower of followers) { + const myURL = new URL(follower); + const targetDomain = myURL.host; + const inbox = `https://${targetDomain}/inbox`; + signAndSend(updateMessage, account, domain, db, targetDomain, inbox); + } +} + export function synthesizeActivity(note) { return { // Fake activity URI adds a "a-" prefix to the Note/message guid diff --git a/src/pages/about.hbs b/src/pages/about.hbs index b6a26d2..3ba8f5c 100644 --- a/src/pages/about.hbs +++ b/src/pages/about.hbs @@ -11,9 +11,21 @@ {{else}}
-

- {{actorInfo.description}} -

+
+

+ {{{actorInfo.description}}} +

+ + + {{#each actorInfo.attachment}} + + + + + {{/each}} + +
{{name}}: {{{value}}}
+

Follow on the Fediverse