Skip to content
Open
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
9 changes: 8 additions & 1 deletion account.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<a href='https://github.com/ckolderup/postmarks' target='_blank' rel='nofollow noopener noreferrer me'>https://github.com/ckolderup/postmarks</a>"
}
]
}
4 changes: 4 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
});
3 changes: 2 additions & 1 deletion src/activity-pub-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],

Expand All @@ -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`,
Expand Down
29 changes: 29 additions & 0 deletions src/activitypub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Comment on lines +291 to +296
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this gets merged in, this should be swapped out to properly grab the user's (or instance's) inbox (in case, as in Postmark's case, the user's inbox is not located at {user}/inbox)

Related: #208

}

export function synthesizeActivity(note) {
return {
// Fake activity URI adds a "a-" prefix to the Note/message guid
Expand Down
18 changes: 15 additions & 3 deletions src/pages/about.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@
{{else}}
<div class="bio">
<img class="avatar" src="{{actorInfo.avatar}}" />
<p>
{{actorInfo.description}}
</p>
<div>
<p>
{{{actorInfo.description}}}
</p>
<table class="attachments">
<tbody>
{{#each actorInfo.attachment}}
<tr>
<td>{{name}}: </td>
<td>{{{value}}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>
<h2>
Follow on the Fediverse
Expand Down