Add 'Mute conversation' menu item

This commit is contained in:
Lim Chee Aun 2023-04-10 00:30:32 +08:00
parent 6fcbff73bd
commit 60cfeea89f

View file

@ -175,10 +175,12 @@ function Status({
const createdAtDate = new Date(createdAt); const createdAtDate = new Date(createdAt);
const editedAtDate = new Date(editedAt); const editedAtDate = new Date(editedAt);
const currentAccount = useMemo(() => {
return store.session.get('currentAccount');
}, []);
const isSelf = useMemo(() => { const isSelf = useMemo(() => {
const currentAccount = store.session.get('currentAccount');
return currentAccount && currentAccount === accountId; return currentAccount && currentAccount === accountId;
}, [accountId]); }, [accountId, currentAccount]);
let inReplyToAccountRef = mentions?.find( let inReplyToAccountRef = mentions?.find(
(mention) => mention.id === inReplyToAccountId, (mention) => mention.id === inReplyToAccountId,
@ -200,6 +202,9 @@ function Status({
.catch((e) => {}); .catch((e) => {});
} }
} }
const mentionSelf =
inReplyToAccountId === currentAccount ||
mentions?.find((mention) => mention.id === currentAccount);
const showSpoiler = !!snapStates.spoilers[id] || false; const showSpoiler = !!snapStates.spoilers[id] || false;
@ -570,9 +575,41 @@ function Status({
</MenuItem> </MenuItem>
)} )}
</div> </div>
{(isSelf || mentionSelf) && <MenuDivider />}
{(isSelf || mentionSelf) && (
<MenuItem
onClick={async () => {
try {
const newStatus = await masto.v1.statuses[
muted ? 'unmute' : 'mute'
](id);
saveStatus(newStatus, instance);
showToast(muted ? 'Conversation unmuted' : 'Conversation muted');
} catch (e) {
console.error(e);
showToast(
muted
? 'Unable to unmute conversation'
: 'Unable to mute conversation',
);
}
}}
>
{muted ? (
<>
<Icon icon="unmute" />
<span>Unmute conversation</span>
</>
) : (
<>
<Icon icon="mute" />
<span>Mute conversation</span>
</>
)}
</MenuItem>
)}
{isSelf && ( {isSelf && (
<> <>
<MenuDivider />
<MenuItem <MenuItem
onClick={() => { onClick={() => {
states.showCompose = { states.showCompose = {