mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 12:31:33 +01:00
feat: ability to query remote users by webfinger handle
This commit is contained in:
@@ -31,10 +31,8 @@ Actors.assert = async (ids, options = {}) => {
|
|||||||
// Translate webfinger handles to uris
|
// Translate webfinger handles to uris
|
||||||
ids = (await Promise.all(ids.map(async (id) => {
|
ids = (await Promise.all(ids.map(async (id) => {
|
||||||
const originalId = id;
|
const originalId = id;
|
||||||
const isUri = activitypub.helpers.isUri(id);
|
if (activitypub.helpers.isWebfinger(id)) {
|
||||||
// only look up webfinger if the id is not a supported URI
|
const host = id.split('@')[1];
|
||||||
if (id.includes('@') && !isUri) {
|
|
||||||
const host = isUri ? new URL(id).host : id.split('@')[1];
|
|
||||||
if (host === nconf.get('url_parsed').host) { // do not assert loopback ids
|
if (host === nconf.get('url_parsed').host) { // do not assert loopback ids
|
||||||
return 'loopback';
|
return 'loopback';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const ttl = require('../cache/ttl');
|
|||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
const activitypub = require('.');
|
const activitypub = require('.');
|
||||||
|
|
||||||
|
const webfingerRegex = /^(@|acct:)?\w+@.+$/;
|
||||||
const webfingerCache = ttl({ ttl: 1000 * 60 * 60 * 24 }); // 24 hours
|
const webfingerCache = ttl({ ttl: 1000 * 60 * 60 * 24 }); // 24 hours
|
||||||
|
|
||||||
const Helpers = module.exports;
|
const Helpers = module.exports;
|
||||||
@@ -33,6 +34,21 @@ Helpers.isUri = (value) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Helpers.isWebfinger = (value) => {
|
||||||
|
// N.B. returns normalized handle, so truthy check!
|
||||||
|
if (webfingerRegex.test(value) && !Helpers.isUri(value)) {
|
||||||
|
if (value.startsWith('@')) {
|
||||||
|
return value.slice(1);
|
||||||
|
} else if (value.startsWith('acct:')) {
|
||||||
|
return value.slice(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
Helpers.query = async (id) => {
|
Helpers.query = async (id) => {
|
||||||
const isUri = Helpers.isUri(id);
|
const isUri = Helpers.isUri(id);
|
||||||
// username@host ids use acct: URI schema
|
// username@host ids use acct: URI schema
|
||||||
|
|||||||
@@ -41,12 +41,15 @@ module.exports = function (User) {
|
|||||||
} else if (searchBy === 'uid') {
|
} else if (searchBy === 'uid') {
|
||||||
uids = [query];
|
uids = [query];
|
||||||
} else {
|
} else {
|
||||||
if (!data.findUids && data.uid && activitypub.helpers.isUri(data.query)) {
|
if (!data.findUids && data.uid) {
|
||||||
const assertion = await activitypub.actors.assert([data.query]);
|
const handle = activitypub.helpers.isWebfinger(data.query);
|
||||||
if (assertion === true) {
|
if (handle || activitypub.helpers.isUri(data.query)) {
|
||||||
uids = [query];
|
const assertion = await activitypub.actors.assert([handle || data.query]);
|
||||||
} else if (Array.isArray(assertion) && assertion.length) {
|
if (assertion === true) {
|
||||||
uids = assertion.map(u => u.id);
|
uids = [handle ? await User.getUidByUserslug(handle) : query];
|
||||||
|
} else if (Array.isArray(assertion) && assertion.length) {
|
||||||
|
uids = assertion.map(u => u.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user