Skip to content

Node.js based forum software built for the modern web

feat: show category followers in category federation ACP page

Julian Lam7313d5c614f7
diff --git a/public/language/en-GB/admin/manage/categories.json b/public/language/en-GB/admin/manage/categories.json
index 77e39a2d0d..a5c0253dae 100644
--- a/public/language/en-GB/admin/manage/categories.json
+++ b/public/language/en-GB/admin/manage/categories.json
@@ -90,6 +90,10 @@
"federation.syncing-actorUri": "Actor",
"federation.syncing-follow": "Follow",
"federation.syncing-unfollow": "Unfollow",
+ "federation.followers": "Remote users following this category",
+ "federation.followers-handle": "Handle",
+ "federation.followers-id": "ID",
+ "federation.followers-none": "No followers.",
"alert.created": "Created",
"alert.create-success": "Category successfully created!",
diff --git a/public/src/admin/manage/category-federation.js b/public/src/admin/manage/category-federation.js
index f22143d92f..44c52c6ac0 100644
--- a/public/src/admin/manage/category-federation.js
+++ b/public/src/admin/manage/category-federation.js
@@ -36,6 +36,11 @@ export function init() {
break;
}
+
+ case 'autofill': {
+ const uid = $(this).parents('[data-uid]').attr('data-uid');
+ $('#syncing-add').val(uid);
+ }
}
});
}
diff --git a/src/controllers/admin/categories.js b/src/controllers/admin/categories.js
index 99bc2cffd2..7d9eb61a18 100644
--- a/src/controllers/admin/categories.js
+++ b/src/controllers/admin/categories.js
@@ -3,11 +3,13 @@
const _ = require('lodash');
const nconf = require('nconf');
const db = require('../../database');
+const user = require('../../user');
const categories = require('../../categories');
const analytics = require('../../analytics');
const plugins = require('../../plugins');
const translator = require('../../translator');
const meta = require('../../meta');
+const activitypub = require('../../activitypub');
const helpers = require('../helpers');
const pagination = require('../../pagination');
@@ -149,9 +151,10 @@ categoriesController.getAnalytics = async function (req, res) {
categoriesController.getFederation = async function (req, res) {
const cid = req.params.category_id;
- const [_following, pending, name, { selectedCategory }] = await Promise.all([
+ let [_following, pending, followers, name, { selectedCategory }] = await Promise.all([
db.getSortedSetMembers(`cid:${cid}:following`),
db.getSortedSetMembers(`followRequests:cid.${cid}`),
+ activitypub.notes.getCategoryFollowers(cid),
categories.getCategoryField(cid, 'name'),
helpers.getSelectedCategory(cid),
]);
@@ -161,11 +164,15 @@ categoriesController.getFederation = async function (req, res) {
approved: !pending.includes(entry),
}));
+ await activitypub.actors.assert(followers);
+ followers = await user.getUsersFields(followers, ['userslug', 'picture']);
+
res.render('admin/manage/category-federation', {
cid: cid,
enabled: meta.config.activitypubEnabled,
name,
selectedCategory,
following,
+ followers,
});
};
diff --git a/src/views/admin/manage/category-federation.tpl b/src/views/admin/manage/category-federation.tpl
index c2858e3d7e..9d8f1d632f 100644
--- a/src/views/admin/manage/category-federation.tpl
+++ b/src/views/admin/manage/category-federation.tpl
@@ -58,6 +58,39 @@
<button data-action="follow" type="button" class="btn btn-primary">[[admin/manage/categories:federation.syncing-follow]]</button>
</div>
</div>
+
+ <hr />
+
+ <div class="mb-3">
+ <p>[[admin/manage/categories:federation.followers]]</p>
+ <table class="table small">
+ <tr>
+ <th>[[admin/manage/categories:federation.followers-handle]]</th>
+ <th>[[admin/manage/categories:federation.followers-id]]</th>
+ </tr>
+ {{{ if !followers.length}}}
+ <tr>
+ <td class="text-center border-0" colspan="2">
+ <em>[[admin/manage/categories:federation.followers-none]]</em>
+ </td>
+ </tr>
+ {{{ end }}}
+ {{{ each followers }}}
+ <tr data-uid="{./uid}">
+ <td>
+ {buildAvatar(followers, "24px", true)}
+ {./userslug}
+ </td>
+ <td>
+ <code>{./uid}</code>
+ <button type="button" class="btn btn-link" data-action="autofill">
+ <i class="fa fa-exchange-alt"></i>
+ </button>
+ </td>
+ </tr>
+ {{{ end }}}
+ </table>
+ </div>
</form>
</div>
</div>