Skip to content

Commit

Permalink
When resigning as a mod, hide the button afterwards
Browse files Browse the repository at this point in the history
Now checking the community context to see if the logged in user is a mod, instead of `$siteMeta`, as we only update the community context when that happens.

To cover all the bases it also will remove it from siteMeta if the user is resigning, so we hide all the other moderation buttons.
  • Loading branch information
sheodox committed Sep 28, 2023
1 parent 0f9d059 commit 878972b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/lib/CommunitySidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@
$: community = communityView?.community;
$: moderators = $communityRes?.moderators;
$: communityHref = community ? `/${$profile.instance}/c/${nameAtInstance(community)}` : '';
$: userModerates = $siteMeta.my_user?.moderates.some(
(moderates) => community && moderates.community.id === community.id
);
$: userModerates = moderators?.some((mod) => mod.moderator.id === $siteMeta.my_user?.local_user_view.person.id);
$: userIsHeadMod = moderators?.[0]?.moderator.id === $userId;
$: warnModlog = userModerates ? $showModlogWarningModerated : $showModlogWarning;
Expand Down
14 changes: 14 additions & 0 deletions src/lib/mod/ModContext.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
import { showPromptModal, createAutoExpireToast } from 'sheodox-ui';
import { profile } from '$lib/profiles/profiles';
import { getCommunityContext } from '$lib/community-context/community-context';
import { getAppContext } from '$lib/app-context';
$: client = $profile.client;
$: jwt = $profile.jwt;
const { siteMeta } = getAppContext();
const pending = writable(new Set<string>()),
DAY_MS = 1000 * 60 * 60 * 24;
Expand Down Expand Up @@ -316,6 +319,17 @@
communityContext.updateCommunity(await client.getCommunity({ auth: jwt, id: opt.communityId }));
if (opt.personId === $siteMeta.my_user?.local_user_view.person.id && !opt.added) {
// user resigned, remove this community from siteMeta to hide mod actions
siteMeta.update((meta) => {
if (meta.my_user && (meta.my_user?.moderates?.length ?? 0) > 0) {
// filter out that community
meta.my_user.moderates = meta.my_user.moderates.filter((mod) => mod.community.id !== opt.communityId);
}
return meta;
});
}
return res;
} finally {
setPending('add-mod', pendingKey, false);
Expand Down

0 comments on commit 878972b

Please sign in to comment.