Node.js based forum software built for the modern web
feat: pending follows and logic for remote users, #12938
Julian Lam2851e56bdcef
diff --git a/public/language/en-GB/user.json b/public/language/en-GB/user.jsonindex e91663c50a..ebe78a25cd 100644--- a/public/language/en-GB/user.json+++ b/public/language/en-GB/user.json@@ -64,6 +64,7 @@"profile-flagged": "Already flagged","follow": "Follow","unfollow": "Unfollow",+ "cancel-follow": "Cancel follow request","more": "More","profile-update-success": "Profile has been updated successfully!",diff --git a/src/api/activitypub.js b/src/api/activitypub.jsindex b38f6bbc78..8400b60f98 100644--- a/src/api/activitypub.js+++ b/src/api/activitypub.js@@ -90,6 +90,7 @@ activitypubApi.unfollow = enabledCheck(async (caller, { type, id, actor }) => {if (type === 'uid') {await Promise.all([db.sortedSetRemove(`followingRemote:${id}`, actor),+ db.sortedSetRemove(`followRequests:uid.${id}`, actor),db.decrObjectField(`user:${id}`, 'followingRemoteCount'),]);} else if (type === 'cid') {diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.jsindex dd2e8eac05..3cc4f19832 100644--- a/src/controllers/accounts/helpers.js+++ b/src/controllers/accounts/helpers.js@@ -88,6 +88,7 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID, query = {})userData.canChangePassword = isAdmin || (isSelf && !meta.config['password:disableEdit']);userData.isSelf = isSelf;userData.isFollowing = results.isFollowing;+ userData.isFollowPending = results.isFollowPending;userData.canChat = results.canChat;userData.hasPrivateChat = results.hasPrivateChat;userData.iconBackgrounds = results.iconBackgrounds;@@ -230,6 +231,7 @@ async function getAllData(uid, callerUID) {isGlobalModerator: isGlobalModerator,isModerator: user.isModeratorOfAnyCategory(callerUID),isFollowing: user.isFollowing(callerUID, uid),+ isFollowPending: user.isFollowPending(callerUID, uid),ips: user.getIPs(uid, 4),profile_menu: getProfileMenu(uid, callerUID),groups: groups.getUserGroups([uid]),diff --git a/src/user/follow.js b/src/user/follow.jsindex b2b0bd3d88..c89f90b979 100644--- a/src/user/follow.js+++ b/src/user/follow.js@@ -5,6 +5,7 @@ const notifications = require('../notifications');const plugins = require('../plugins');const activitypub = require('../activitypub');const db = require('../database');+const utils = require('../utils');module.exports = function (User) {User.follow = async function (uid, followuid) {@@ -104,6 +105,14 @@ module.exports = function (User) {return await db.isSortedSetMember(`${setPrefix}:${uid}`, theirid);};+ User.isFollowPending = async function (uid, target) {+ if (utils.isNumber(target)) {+ return false;+ }++ return await db.isSortedSetMember(`followRequests:uid.${uid}`, target);+ };+User.onFollow = async function (uid, targetUid) {const userData = await User.getUserFields(uid, ['username', 'userslug']);const { displayname } = userData;