feat: pending follows and logic for remote users, #12938

This commit is contained in:
Julian Lam
2024-12-11 13:27:34 -05:00
parent fcf0f79987
commit 2851e56bdc
4 changed files with 13 additions and 0 deletions

View File

@@ -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!",

View File

@@ -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') {

View File

@@ -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]),

View File

@@ -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;