Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Initial ActivityPub / Mastodon Support #460

Open
wants to merge 271 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
271 commits
Select commit Hold shift + click to select a range
99e9ebb
Utility, cleanup, etc.
NuSkooler Jan 3, 2023
127e979
Central check for enable/disabled web handlers, added some utility fu…
NuSkooler Jan 3, 2023
6cea426
More utils, tidy, and activitypub.js added
NuSkooler Jan 4, 2023
d4f7444
Skeleton work
NuSkooler Jan 4, 2023
5055337
Hand back a profile for self
NuSkooler Jan 5, 2023
8026164
Standardize on _enig prefix for internal routes; update all _internal…
NuSkooler Jan 5, 2023
dc7f902
Missing import
NuSkooler Jan 5, 2023
9f33c8b
Added public/private keypairs for user (and hid from logging)
cognitivegears Jan 6, 2023
344d471
Added ability to use .json to get JSON from self URL. Also added some…
cognitivegears Jan 6, 2023
e478665
Added public key to selfUrl
cognitivegears Jan 6, 2023
d615b53
Small fixes to activitypub json output
cognitivegears Jan 6, 2023
848044b
Prettier
NuSkooler Jan 6, 2023
7380ef5
Hopefully formatted correctly
NuSkooler Jan 6, 2023
41867c7
Tidy
NuSkooler Jan 6, 2023
d278307
Durp.
NuSkooler Jan 6, 2023
b252f69
Changes to work with Mastodon. Also fixed variable rename issue
cognitivegears Jan 6, 2023
60238de
Some tidy and log cleanup
NuSkooler Jan 7, 2023
a1e54de
Log cleanup
NuSkooler Jan 7, 2023
23f753e
Web Handlers are now given the parent Web Server directly
NuSkooler Jan 7, 2023
9eb3a1d
eslint fixes as well as fixing a small variable typo
cognitivegears Jan 7, 2023
2c0992b
Added stub activitypub_actor database entries
cognitivegears Jan 7, 2023
55b210e
Steps to allow follow requests
NuSkooler Jan 8, 2023
f9f9208
Merge
NuSkooler Jan 8, 2023
416f86a
Additional notes for devs
NuSkooler Jan 8, 2023
f86d933
Start work on Activity and Actor objects, validation, fetching, etc.
NuSkooler Jan 8, 2023
2370185
Tidy
NuSkooler Jan 8, 2023
e5b2bef
Actor.fromLocalUser()
NuSkooler Jan 8, 2023
3a70cc6
Abilitiy to respond with 'Accept' Activity and ActivityPubSettings us…
NuSkooler Jan 9, 2023
44c67f5
Added HTTP util: postJson(), post Accept Activity to server with signing
NuSkooler Jan 9, 2023
01cd91b
Fix route
NuSkooler Jan 9, 2023
ef11832
Add intiial 'flavor' for ActivityPub messages
NuSkooler Jan 11, 2023
64848b4
Initial 'Note' support for ActivitiyPub/Mastodon, reconition of @User…
NuSkooler Jan 12, 2023
eaadd0a
Persist exported/published messages to ActivityPub
NuSkooler Jan 13, 2023
fc14b5d
Persist exported/published messages to ActivityPub
NuSkooler Jan 13, 2023
67652b1
Prettier
NuSkooler Jan 13, 2023
157b906
Move ActivityPub stuff under activitypub/
NuSkooler Jan 13, 2023
5e5c923
Return a outbox WIP
NuSkooler Jan 13, 2023
33ea963
Removed prettier so eslint output matches NuSkooler's
cognitivegears Jan 13, 2023
4137e93
Added precommit hook and staged checking of linting and formatting
cognitivegears Jan 13, 2023
02eeee9
Added json to list of files to update
cognitivegears Jan 13, 2023
9ad0cab
Test hook
NuSkooler Jan 13, 2023
af1f889
Changed default config to include webFinger and ActivityPub
cognitivegears Jan 13, 2023
1068abc
Changed the key name for the ActivityPub signing key
cognitivegears Jan 13, 2023
84dde6c
Small bugfixes
cognitivegears Jan 13, 2023
c796a85
Bug squashing and refactored inbox
cognitivegears Jan 13, 2023
315d77b
Start Collection, some extra Actor props, start Followers, cleanup/DR…
NuSkooler Jan 14, 2023
3cb4f51
Merge upstream
cognitivegears Jan 14, 2023
4841823
Additional merge changes
cognitivegears Jan 14, 2023
b075e25
Cleanup
NuSkooler Jan 14, 2023
51308a5
Merge branch 'master' of github.com:NuSkooler/enigma-bbs into 459-act…
NuSkooler Jan 16, 2023
930308e
Fix POST to Accept Follow Request
NuSkooler Jan 20, 2023
9517b29
Work on shifting code to generic collections, etc.
NuSkooler Jan 20, 2023
d9e4b66
Cleanup, DRY, logging
NuSkooler Jan 21, 2023
ce7dd8e
Handle Undo
NuSkooler Jan 21, 2023
468f148
Use a Collection for outbox
NuSkooler Jan 22, 2023
3f2dcee
Add avatar support
NuSkooler Jan 22, 2023
c5fb1bd
Add default avatar sprites
NuSkooler Jan 22, 2023
3409c99
Just some basic info so far
NuSkooler Jan 22, 2023
d03718d
Move avatar handler to generic system general handler
NuSkooler Jan 22, 2023
8f13163
Update on recording to outbox
NuSkooler Jan 22, 2023
0fc8ae0
WIP on shared inbox functionality
NuSkooler Jan 22, 2023
d7df066
Object and Note, load of public notes, etc.
NuSkooler Jan 23, 2023
d5446cd
Cleanup and placeholder
NuSkooler Jan 25, 2023
f8b1323
Cleaned up missing ./const
cognitivegears Jan 25, 2023
5b69cdb
Changed activity.js back for WellKnownActivityTypes
cognitivegears Jan 25, 2023
1aa56fb
WIP: Import messages sent to local Actor inboxes to their private mail
NuSkooler Jan 25, 2023
82091c1
pretty
NuSkooler Jan 25, 2023
4f632fd
Many WebFinger improvements, can now round trip private messages
NuSkooler Jan 26, 2023
0bd2c3d
Better handling of to/from HTML and BBS message formats, Note handlin…
NuSkooler Jan 26, 2023
d624871
Split message consts to their own file, fix some HTTP responses, bett…
NuSkooler Jan 26, 2023
8dd28e3
Fixed not-found and similar errors case
cognitivegears Jan 27, 2023
4f6891a
Fix possible BBS crash on undefined text
cognitivegears Jan 27, 2023
9b01124
Re-work of ActivityPub DBs and various account lookups
NuSkooler Jan 28, 2023
2f577fc
Merge branch '459-activitypub-integration' of github.com:NuSkooler/en…
NuSkooler Jan 28, 2023
6dd9fe8
Fix profile query
NuSkooler Jan 28, 2023
0ca67f6
Clean up cache, add missing FK option
NuSkooler Jan 28, 2023
2a75d55
Remove alias cache never used
NuSkooler Jan 28, 2023
3bdce81
Retro style default profile, constant cleanup, some DRY, etc.
NuSkooler Jan 29, 2023
35b7c00
Additionl of WIP NodeInfo2 support, fix content-type for Actor images
NuSkooler Jan 30, 2023
c456c18
Non-dynamic info
NuSkooler Jan 30, 2023
a829905
New convienience functions on toggle menus, allow paths in sys module…
NuSkooler Jan 31, 2023
98d37e9
Fix various Content-Lenght's
NuSkooler Feb 1, 2023
f8d4f49
WIP ActivityPub user config
NuSkooler Feb 1, 2023
835bfbd
Return to prev on save
NuSkooler Feb 1, 2023
45deef3
Placeholder art
NuSkooler Feb 1, 2023
1d1bf68
Added warning to make finding misconfigurations easier
cognitivegears Feb 2, 2023
3be14ec
Start of an actor search screen, finally
cognitivegears Feb 2, 2023
eb9d905
Allow itemFormat/focusItem format on TextViews/Buttons/...
NuSkooler Feb 2, 2023
5f53ef9
itemFormat/focusItemFormat properties in Button
NuSkooler Feb 2, 2023
b94fa6a
WIP theme update
NuSkooler Feb 2, 2023
d286fa2
Merge branch '459-activitypub-integration' of github.com:NuSkooler/en…
NuSkooler Feb 2, 2023
8a4f902
Split out web logging to it's own logger/files/configuration
NuSkooler Feb 2, 2023
5cfacf4
Update WHATSNEW
NuSkooler Feb 2, 2023
95250d2
Added additional fields and some cleanup
cognitivegears Feb 3, 2023
f97d184
Add attachment information to messages, fix duplicate handling to res…
NuSkooler Feb 3, 2023
00e6b41
Fixed focus and minor changes
cognitivegears Feb 3, 2023
1065f14
Merge branch '459-activitypub-integration' of github.com:NuSkooler/en…
NuSkooler Feb 3, 2023
a8e867a
Support 'maxLength' property in MLTEV; Enforce this by default, to 50…
NuSkooler Feb 4, 2023
b20b6cc
Updates on form validation
NuSkooler Feb 4, 2023
21fb688
Tidy up errors
NuSkooler Feb 4, 2023
a24ec5f
Some hardening and Note import improvements for diff systems
NuSkooler Feb 4, 2023
c3335ce
Hopefully better microformat handling outgoing
NuSkooler Feb 4, 2023
877e2ca
Added followers and following
cognitivegears Feb 5, 2023
77b0e6d
Merge branch '459-activitypub-integration' of github.com:NuSkooler/en…
cognitivegears Feb 5, 2023
99ae973
Handle Update of Notes, store Activites as-is, better shared mailbox …
NuSkooler Feb 5, 2023
24de0fa
Merge branch '459-activitypub-integration' of github.com:NuSkooler/en…
NuSkooler Feb 5, 2023
bd2dc27
Add getRemoteCollectionStats() and usage
NuSkooler Feb 5, 2023
41cd0f7
Fix local Actor URLs, add addFollowing() API
NuSkooler Feb 5, 2023
36ebda5
Fix shared inbox delivery for private + public
NuSkooler Feb 5, 2023
0402de7
Ability to send/recv public messages in the AP shared inbox areaTag
NuSkooler Feb 6, 2023
27da2bb
Don't log entire JSON payloads
NuSkooler Feb 6, 2023
834dfd6
Fix a dumb typo
NuSkooler Feb 6, 2023
926f45b
Clean up URLs to use central area, less confusion
NuSkooler Feb 6, 2023
1b684e2
Clean up contexts in objects
NuSkooler Feb 7, 2023
c9b3c9b
Better context check
NuSkooler Feb 7, 2023
39a49f0
Cleanup
NuSkooler Feb 7, 2023
c5f0e0e
Rework most of the ActivityPub routing handling
NuSkooler Feb 8, 2023
9b08cf8
Clean up Actor cache
NuSkooler Feb 9, 2023
fb039c1
Fix dumb bugs
NuSkooler Feb 9, 2023
c0914af
Fix a few more inbox/addressing bugs, cleanup, add methtod to request…
NuSkooler Feb 9, 2023
1fcadef
Fix local-to-local user in public area
NuSkooler Feb 10, 2023
8703496
First steps toward search
cognitivegears Feb 10, 2023
6466220
Revert "First steps toward search"
cognitivegears Feb 11, 2023
a09fe48
Durp
NuSkooler Feb 11, 2023
df55c3f
New MCI for AP subject, show subj and custom info format on config
NuSkooler Feb 12, 2023
b577c1b
Added default connection timeout and new config option outbound.conne…
cognitivegears Feb 12, 2023
194a5b0
Add image URL editor for AcitvityPub user config
NuSkooler Feb 13, 2023
e90f42c
Merge branch '459-activitypub-integration' of github.com:NuSkooler/en…
NuSkooler Feb 13, 2023
69cb0c5
default timeout
NuSkooler Feb 13, 2023
2aec375
Driveby: getItem(x) vs getItems()[x]
NuSkooler Feb 18, 2023
e8c42a9
ActivityPub Social Manager, and many updates to Search functionality
NuSkooler Feb 18, 2023
560d608
Better HTML stripping, fix display of summary, etc.
NuSkooler Feb 18, 2023
6273541
Fix longstanding itemFormat/focusItemFormat issue
NuSkooler Feb 20, 2023
53eff27
Docs
NuSkooler Feb 20, 2023
e963f18
Several cosmetic fixes for off-by-one in padding and display issues w…
cognitivegears Feb 20, 2023
7a189b2
Several cosmetic fixes for off-by-one in padding and display issues w…
cognitivegears Feb 20, 2023
c79bb1e
Added documentation for overflow and made consistent between views
cognitivegears Feb 20, 2023
3d1ac92
Added default overflow to theme
cognitivegears Feb 20, 2023
51c58b5
Fixes
NuSkooler Feb 20, 2023
8668eed
New submenu for activitypub
cognitivegears Feb 20, 2023
036a3dc
Remove actor_cache; use a special collection
NuSkooler Feb 20, 2023
30cb21f
Sync up
NuSkooler Feb 20, 2023
777df9f
Tidy names
NuSkooler Feb 20, 2023
40e07d7
Format HJSON
NuSkooler Feb 20, 2023
c9f9eb9
Fix SQL bug
NuSkooler Feb 21, 2023
ad1ab1f
Default to ActivityPub disabled; +op needs to opt-in
NuSkooler Feb 21, 2023
6e53c25
Default config sets users to AP disabled by default; users can opt-in
NuSkooler Feb 21, 2023
e35fc5b
Fix password scrubbing
NuSkooler Feb 21, 2023
2495430
Fix new user pre-creation event
NuSkooler Feb 21, 2023
f264e48
Fix 'yes'/'no' toggles, consts for well known conf tags/etc.
NuSkooler Feb 21, 2023
ccd229d
Docs, tidy
NuSkooler Feb 21, 2023
43cdaf0
Minor cleanup items
cognitivegears Feb 22, 2023
8822a7c
Tidy
NuSkooler Feb 24, 2023
86d2aeb
Oops, include ActivityPub in confs!
NuSkooler Feb 24, 2023
22349a2
New ACS: SE allows checking if various services are enabled
NuSkooler Feb 24, 2023
0b1794c
Merge branch '459-activitypub-integration' of github.com:NuSkooler/en…
NuSkooler Feb 24, 2023
24645c9
Restored achievements.hjson
cognitivegears Feb 24, 2023
60e8b78
Merge branch '459-activitypub-integration' of github.com:NuSkooler/en…
NuSkooler Feb 24, 2023
5b08d21
Prevent double callback
NuSkooler Feb 25, 2023
a205445
Fix up message header for public AP, Undo following, some bugs around…
NuSkooler Feb 25, 2023
0263d8b
Various fixes:
NuSkooler Feb 25, 2023
0af70b0
Various QoL fixes in UI
NuSkooler Feb 25, 2023
ec68f8c
All modes
NuSkooler Feb 25, 2023
63cfc90
More QoL
NuSkooler Feb 25, 2023
a968f21
A few bugs fixed with Note storage
NuSkooler Feb 27, 2023
65e5fa1
New ACS for ActivtiyPub enabled check
NuSkooler Feb 27, 2023
b0fff20
More updates on Deletes, ActivityPub ACS in menu
NuSkooler Feb 27, 2023
6afbb29
Cleanup
NuSkooler Mar 7, 2023
ea9d826
Updates around Deletes
NuSkooler Mar 12, 2023
3212d80
Better validation for 'Update'
NuSkooler Mar 12, 2023
8b6d564
Handling Update/Delete better
NuSkooler Mar 13, 2023
5314fb4
Browse public messages from AP menu; Fix ACS
NuSkooler Mar 13, 2023
10e2abf
Trim ActivityPub SharedInbox collection (Notes) along with assoc mess…
NuSkooler Mar 15, 2023
8c609b7
oputil updates for AP enabled/disabled, small change to 2FA info
NuSkooler Mar 15, 2023
e915527
oputil ap condition USERNAME
NuSkooler Mar 18, 2023
fb02fc5
Remove need for WebServer in a lot of areas, oputil ap condition func…
NuSkooler Mar 18, 2023
26c44b9
Bunch more removals of unneeded webServer instance
NuSkooler Mar 18, 2023
cca850d
Some docs
NuSkooler Mar 19, 2023
81edff4
WIP doc updates, need sorting
NuSkooler Mar 19, 2023
94842af
Organized and updated upgrade docs
NuSkooler Mar 19, 2023
35c97f7
Ensure AP setup for user if not already at toggle time
NuSkooler Mar 19, 2023
127d09a
Ensure AP setup for user if not already at toggle time (fix)
NuSkooler Mar 19, 2023
cc20ffc
Fix addressed to WFC count
NuSkooler Mar 26, 2023
97f3a1e
Update copyright to 2023
NuSkooler Apr 10, 2023
0b59d0e
Strip codes from auto sig for summary
NuSkooler Apr 10, 2023
d035fc5
Merge branch 'master' of ssh://numinibsd/git/base/enigma-bbs into 459…
NuSkooler Apr 10, 2023
5e4c942
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 10, 2023
84c6478
Minor fixes around images
NuSkooler Apr 10, 2023
7499ffb
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 10, 2023
c4553a0
Fix callback
NuSkooler Apr 14, 2023
999a87c
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 14, 2023
1c27891
Test sig check
NuSkooler Apr 19, 2023
ea3d2cf
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 19, 2023
faf8cca
Updated sig check 2
NuSkooler Apr 19, 2023
22e7689
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 19, 2023
71076c8
Dumb fix
NuSkooler Apr 19, 2023
33dca44
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 19, 2023
32bb0c4
Dumb fix...again
NuSkooler Apr 20, 2023
052c2d5
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 20, 2023
db3387d
Allow application/json
NuSkooler Apr 21, 2023
95c249f
Better to/subject/etc.
NuSkooler Apr 21, 2023
beb28c9
Include message ID in log, fix message
NuSkooler Apr 21, 2023
821d6ce
Use follow-redirects to ensure we follow redirects during Actor looku…
NuSkooler Apr 21, 2023
e5fdc24
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 21, 2023
6dde005
Capture '@' also
NuSkooler Apr 21, 2023
ed7a728
Less restrictive for subject capture
NuSkooler Apr 21, 2023
fa95616
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 21, 2023
dd8ab85
Less restrictive for subject capture...again
NuSkooler Apr 25, 2023
31f10d0
Fixes
NuSkooler Apr 25, 2023
a5a72d8
Split out logging a bit, fix accept header parsing
NuSkooler Apr 25, 2023
60b17a6
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 25, 2023
0c1785c
More log updates
NuSkooler Apr 27, 2023
a5a3a63
Minor sys log updates
NuSkooler Apr 27, 2023
0858916
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 27, 2023
d5bffb1
Fix up warning and update Buffer() to Buffer.from()
NuSkooler Apr 27, 2023
4501140
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Apr 27, 2023
d5a7905
Merge branch 'master' of github.com:NuSkooler/enigma-bbs into 459-act…
NuSkooler May 11, 2023
cded6a5
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler May 11, 2023
4bd55f1
Fixes after merge
NuSkooler Aug 24, 2023
42b1b65
Merge branch 'master' of github.com:NuSkooler/enigma-bbs into 459-act…
NuSkooler Aug 24, 2023
2964c01
Merge branch 'master' of github.com:NuSkooler/enigma-bbs into 459-act…
NuSkooler Aug 24, 2023
0035ef4
Fix HTTPS signing for POSTS
NuSkooler Aug 24, 2023
4d97922
Better gathering of lines; don't add extra line terms
NuSkooler Aug 24, 2023
c25c600
Replys to ActivityPub should start with @someone
NuSkooler Aug 24, 2023
2f9871e
Updates
NuSkooler Aug 24, 2023
7961fa4
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Aug 24, 2023
28832e7
Add scheduledEventOptimizeDatabases()
NuSkooler Aug 24, 2023
6ea3e50
Well, that was dumb; Join without ','
NuSkooler Aug 24, 2023
ea6ab5a
Merge branch '459-activitypub-integration' of ssh://numinibsd/git/bas…
NuSkooler Aug 24, 2023
d5ab53e
Fix a couple MCI code display issues
NuSkooler Aug 24, 2023
460070e
Users can now accept a follow request; Deny and remove next
NuSkooler Aug 27, 2023
65ea019
Reject Follow request support
NuSkooler Aug 27, 2023
fcd961c
Cleanup
NuSkooler Aug 27, 2023
cc42812
Sync up with master
NuSkooler Aug 27, 2023
de4e3a1
Sync up with master
NuSkooler Sep 3, 2023
2bf4540
Sync up with master
NuSkooler Oct 12, 2023
19b6f93
Sync up with master
NuSkooler Oct 13, 2023
bdb7605
Local copy of any-ascii until they support CJS
NuSkooler Dec 30, 2023
0f5bb2c
Use AnyAscci to convert ActivityPub Unicode messages to ASCII-suitable
NuSkooler Dec 30, 2023
51ee664
Properly display Actor info
NuSkooler Dec 31, 2023
1a2030c
Update defaults a bit for AP
NuSkooler Dec 31, 2023
c939412
Don't bail if we can't fetch just one
NuSkooler Dec 31, 2023
e0cbcc1
Force AP in AP area
NuSkooler Dec 31, 2023
81e1b47
Durp, really do it this time
NuSkooler Dec 31, 2023
db5298b
Fill missing subjects when loading message lists
NuSkooler Dec 31, 2023
c6c457a
Fix default menu flow & fallback
NuSkooler Dec 31, 2023
122b5e9
Provide contentMap::en such that messages don't all show up on Mastod…
NuSkooler Jan 1, 2024
5dd3bc5
Add missing function
NuSkooler Jan 14, 2024
0b1dee7
Fix door crash
NuSkooler Jan 15, 2024
5e01a49
Sync up with master
NuSkooler Jan 15, 2024
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
Prev Previous commit
Next Next commit
More utils, tidy, and activitypub.js added
  • Loading branch information
NuSkooler committed Jan 4, 2023
commit 6cea4269b22b777b9be2e065801e8b3f4302dde3
42 changes: 40 additions & 2 deletions core/activitypub_util.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
const { WellKnownLocations } = require('./servers/content/web');
const User = require('./user');
const { Errors } = require('./enig_error');
const UserProps = require('./user_property');

exports.buildSelfUrl = buildSelfUrl;
exports.makeUserUrl = makeUserUrl;
exports.webFingerProfileUrl = webFingerProfileUrl;
exports.selfUrl = selfUrl;
exports.userFromAccount = userFromAccount;

function buildSelfUrl(webServer, user, relPrefix) {
function makeUserUrl(webServer, user, relPrefix) {
return webServer.buildUrl(
WellKnownLocations.Internal + `${relPrefix}${user.username}`
);
}

function webFingerProfileUrl(webServer, user) {
return webServer.buildUrl(WellKnownLocations.Internal + `/wf/@${user.username}`);
}

function selfUrl(webServer, user) {
return makeUserUrl(webServer, user, '/ap/users/');
}

function userFromAccount(accountName, cb) {
User.getUserIdAndName(accountName, (err, userId) => {
if (err) {
return cb(err);
}

User.getUser(userId, (err, user) => {
if (err) {
return cb(err);
}

const accountStatus = user.getPropertyAsNumber(UserProps.AccountStatus);
if (
User.AccountStatus.disabled == accountStatus ||
User.AccountStatus.inactive == accountStatus
) {
return cb(Errors.AccessDenied('Account disabled', ErrorReasons.Disabled));
}

return cb(null, user);
});
});
}
2 changes: 1 addition & 1 deletion core/servers/content/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ exports.getModule = class WebServerModule extends ServerModule {
return nextModule(err);
});
} catch (e) {
logger.log.error(e, 'Exception caught web handler!');
Log.error(e, 'Exception caught web handler!');
return nextModule(e);
}
},
Expand Down
95 changes: 95 additions & 0 deletions core/servers/content/web_handlers/activitypub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const WebHandlerModule = require('../../../web_handler_module');
const {
makeUserUrl,
webFingerProfileUrl,
selfUrl,
userFromAccount,
} = require('../../../activitypub_util');
const UserProps = require('../../../user_property');
const { Errors } = require('../../../enig_error');

exports.moduleInfo = {
name: 'ActivityPub',
desc: 'Provides ActivityPub support',
author: 'NuSkooler, CognitiveGears',
packageName: 'codes.l33t.enigma.web.handler.activitypub',
};

exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
constructor() {
super();
}

init(cb) {
this.webServer = WebHandlerModule.getWebServer();
if (!this.webServer) {
return cb(Errors.UnexpectedState('Cannot access web server!'));
}

this.webServer.addRoute({
method: 'GET',
path: /^\/_enig\/ap\/users\/.+$/,
handler: this._selfUrlRequestHandler.bind(this),
});

return cb(null);
}

_selfUrlRequestHandler(req, resp) {
const accept = req.headers['accept'] || '*/*';
if (accept === 'application/activity+json') {
return this._selfActorHandler(req, resp);
}
}

_selfActorHandler(req, resp) {
const url = new URL(req.url, `https://${req.headers.host}`);
const accountName = url.pathname.substring(url.pathname.lastIndexOf('/') + 1);

userFromAccount(accountName, (err, user) => {
if (err) {
return this._notFound(resp);
}

const body = JSON.stringify({
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
],
id: selfUrl(this.webServer, user),
type: 'Person',
preferredUsername: user.username,
name: user.getSanitizedName('real'),
endpoints: {
sharedInbox: 'TODO',
},
inbox: makeUserUrl(this.webServer, user, '/ap/users') + '/outbox',
outbox: makeUserUrl(this.webServer, user, '/ap/users') + '/inbox',
followers: makeUserUrl(this.webServer, user, '/ap/users') + '/followers',
following: makeUserUrl(this.webServer, user, '/ap/users') + '/following',
summary: user.getProperty(UserProps.AutoSignature) || '',
url: webFingerProfileUrl(this.webServer, user),
publicKey: {},

// :TODO: we can start to define BBS related stuff with the community perhaps
});

const headers = {
'Content-Type': 'application/activity+json',
'Content-Length': body.length,
};

resp.writeHead(200, headers);
return resp.end(body);
});
}

_notFound(resp) {
this.webServer.respondWithError(
resp,
404,
'Resource not found',
'Resource Not Found'
);
}
};
58 changes: 14 additions & 44 deletions core/servers/content/web_handlers/webfinger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ const WebHandlerModule = require('../../../web_handler_module');
const Config = require('../../../config').get;
const { Errors, ErrorReasons } = require('../../../enig_error');
const { WellKnownLocations } = require('../web');
const { buildSelfUrl } = require('../../../activitypub_util');
const {
selfUrl,
webFingerProfileUrl,
userFromAccount,
} = require('../../../activitypub_util');

const _ = require('lodash');
const User = require('../../../user');
Expand Down Expand Up @@ -44,7 +48,7 @@ exports.getModule = class WebFingerWebHandler extends WebHandlerModule {

// we rely on the web server
this.webServer = WebHandlerModule.getWebServer();
if (!this.webServer || !this.webServer.isEnabled()) {
if (!this.webServer) {
return cb(Errors.UnexpectedState('Cannot access web server!'));
}

Expand Down Expand Up @@ -107,13 +111,10 @@ exports.getModule = class WebFingerWebHandler extends WebHandlerModule {

const accountName = resource.substring(userPosition + 1);

this._getUser(accountName, resp, (err, user) => {
userFromAccount(accountName, (err, user) => {
if (err) {
// |resp| already written to
return Log.warn(
{ error: err.message },
`Profile request failed: ${req.url}`
);
Log.warn({ error: err.message }, `Profile request failed: ${req.url}`);
return this._notFound(resp);
}

this._getProfileTemplate((template, mimeType) => {
Expand Down Expand Up @@ -204,10 +205,10 @@ exports.getModule = class WebFingerWebHandler extends WebHandlerModule {
);
}

this._getUser(accountName, resp, (err, user) => {
userFromAccount(accountName, (err, user) => {
if (err) {
// |resp| already written to
return Log.warn({ error: err.message }, `WebFinger failed: ${req.url}`);
Log.warn({ error: err.message }, `WebFinger failed: ${req.url}`);
return this._notFound(resp);
}

const domain = this.webServer.getDomain();
Expand All @@ -233,9 +234,7 @@ exports.getModule = class WebFingerWebHandler extends WebHandlerModule {
}

_profileUrl(user) {
return this.webServer.buildUrl(
WellKnownLocations.Internal + `/wf/@${user.username}`
);
return webFingerProfileUrl(this.webServer, user);
}

_profilePageLink(user) {
Expand All @@ -248,7 +247,7 @@ exports.getModule = class WebFingerWebHandler extends WebHandlerModule {
}

_selfUrl(user) {
return buildSelfUrl(this.webServer, user, '/ap/users/');
return selfUrl(this.webServer, user);
}

// :TODO: only if ActivityPub is enabled
Expand Down Expand Up @@ -288,33 +287,4 @@ exports.getModule = class WebFingerWebHandler extends WebHandlerModule {
'Resource Not Found'
);
}

_getUser(accountName, resp, cb) {
User.getUserIdAndName(accountName, (err, userId) => {
if (err) {
this._notFound(resp);
return cb(err);
}

User.getUser(userId, (err, user) => {
if (err) {
this._notFound(resp);
return cb(err);
}

const accountStatus = user.getPropertyAsNumber(UserProps.AccountStatus);
if (
User.AccountStatus.disabled == accountStatus ||
User.AccountStatus.inactive == accountStatus
) {
this._notFound(resp);
return cb(
Errors.AccessDenied('Account disabled', ErrorReasons.Disabled)
);
}

return cb(null, user);
});
});
}
};