Update context menu, add mute/block/unfollow actions and update relationship store accordingly

This commit is contained in:
Daniel Supernault 2024-04-06 02:27:22 -06:00
parent b8e96a5ff3
commit 81d1e0fdab
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
2 changed files with 951 additions and 715 deletions

View file

@ -10,79 +10,136 @@
body-class="list-group-flush p-0 rounded"> body-class="list-group-flush p-0 rounded">
<div class="list-group text-center"> <div class="list-group text-center">
<div <div v-if="status.visibility !== 'archived'" class="list-group-item d-flex p-0 m-0">
v-if="status.visibility !== 'archived'" <div class="border-right p-2 w-50">
class="list-group-item rounded cursor-pointer font-weight-bold" <a
@click="ctxMenuGoToPost()"> v-if="status"
{{ $t('menu.viewPost') }} class="menu-option"
:href="status.url"
@click.prevent="ctxMenuGoToPost()">
<div class="action-icon-link">
<div class="icon"><i class="fal fa-images fa-lg"></i></div>
<p class="mb-0">{{ $t('menu.viewPost') }}</p>
</div>
</a>
</div> </div>
<div <div class="p-2 flex-grow-1">
v-if="status.visibility !== 'archived'" <a
class="list-group-item rounded cursor-pointer font-weight-bold" v-if="status"
@click="ctxMenuGoToProfile()"> class="menu-option"
{{ $t('menu.viewProfile') }} :href="status.account.url"
@click.prevent="ctxMenuGoToProfile()">
<div class="action-icon-link">
<div class="icon"><i class="fal fa-user fa-lg"></i></div>
<p class="mb-0">{{ $t('menu.viewProfile') }}</p>
</div>
</a>
</div>
</div> </div>
<div <template v-if="ctxMenuRelationship">
<a
v-if="ctxMenuRelationship.following"
class="list-group-item menu-option text-danger"
href="#"
@click.prevent="handleUnfollow">
{{ $t('profile.unfollow') }}
</a>
<div v-else class="d-flex">
<div class="p-3 border-right w-50 text-center">
<a
class="small menu-option text-muted"
href="#"
@click.prevent="handleMute">
<div class="action-icon-link-inline">
<div class="icon"><i class="far" :class="[ ctxMenuRelationship.muting ? 'fa-eye' : 'fa-eye-slash' ]"></i></div>
<p class="text-muted mb-0">{{ ctxMenuRelationship.muting ? 'Unmute' : 'Mute' }}</p>
</div>
</a>
</div>
<div class="p-3 w-50">
<a
class="small menu-option text-danger"
href="#"
@click.prevent="handleBlock">
<div class="action-icon-link-inline">
<div class="icon"><i class="far fa-shield-alt"></i></div>
<p class="text-danger mb-0">Block</p>
</div>
</a>
</div>
</div>
</template>
<a
v-if="status.visibility !== 'archived'" v-if="status.visibility !== 'archived'"
class="list-group-item rounded cursor-pointer font-weight-bold" class="list-group-item menu-option"
@click="ctxMenuShare()"> href="#"
@click.prevent="ctxMenuShare()">
{{ $t('common.share') }} {{ $t('common.share') }}
</div> </a>
<div <a
v-if="status && profile && profile.is_admin == true && status.visibility !== 'archived'" v-if="status && profile && profile.is_admin == true && status.visibility !== 'archived'"
class="list-group-item rounded cursor-pointer font-weight-bold" class="list-group-item menu-option"
@click="ctxModMenuShow()"> href="#"
@click.prevent="ctxModMenuShow()">
{{ $t('menu.moderationTools') }} {{ $t('menu.moderationTools') }}
</div> </a>
<div <a
v-if="status && status.account.id != profile.id" v-if="status && status.account.id != profile.id"
class="list-group-item rounded cursor-pointer text-danger font-weight-bold" class="list-group-item menu-option text-danger"
@click="ctxMenuReportPost()"> href="#"
@click.prevent="ctxMenuReportPost()">
{{ $t('menu.report') }} {{ $t('menu.report') }}
</div> </a>
<div <a
v-if="status && profile.id == status.account.id && status.visibility !== 'archived'" v-if="status && profile.id == status.account.id && status.visibility !== 'archived'"
class="list-group-item rounded cursor-pointer text-danger font-weight-bold" class="list-group-item menu-option text-danger"
@click="archivePost(status)"> href="#"
@click.prevent="archivePost(status)">
{{ $t('menu.archive') }} {{ $t('menu.archive') }}
</div> </a>
<div <a
v-if="status && profile.id == status.account.id && status.visibility == 'archived'" v-if="status && profile.id == status.account.id && status.visibility == 'archived'"
class="list-group-item rounded cursor-pointer text-danger font-weight-bold" class="list-group-item menu-option text-danger"
@click="unarchivePost(status)"> href="#"
@click.prevent="unarchivePost(status)">
{{ $t('menu.unarchive') }} {{ $t('menu.unarchive') }}
</div> </a>
<div <a
v-if="config.ab.pue && status && profile.id == status.account.id && status.visibility !== 'archived'" v-if="config.ab.pue && status && profile.id == status.account.id && status.visibility !== 'archived'"
class="list-group-item rounded cursor-pointer text-danger font-weight-bold" class="list-group-item menu-option text-danger"
@click="editPost(status)"> href="#"
@click.prevent="editPost(status)">
Edit Edit
</div> </a>
<div <a
v-if="status && (profile.is_admin || profile.id == status.account.id) && status.visibility !== 'archived'" v-if="status && (profile.is_admin || profile.id == status.account.id) && status.visibility !== 'archived'"
class="list-group-item rounded cursor-pointer text-danger font-weight-bold" class="list-group-item menu-option text-danger"
@click="deletePost(status)"> href="#"
@click.prevent="deletePost(status)">
<div v-if="isDeleting" class="spinner-border spinner-border-sm" role="status"> <div v-if="isDeleting" class="spinner-border spinner-border-sm" role="status">
<span class="sr-only">Loading...</span> <span class="sr-only">Loading...</span>
</div> </div>
<div v-else> <div v-else>
{{ $t('common.delete') }} {{ $t('common.delete') }}
</div> </div>
</div> </a>
<div <a
class="list-group-item rounded cursor-pointer text-lighter font-weight-bold" class="list-group-item menu-option text-lighter"
@click="closeCtxMenu()"> href="#"
@click.prevent="closeCtxMenu()">
{{ $t('common.cancel') }} {{ $t('common.cancel') }}
</div> </a>
</div> </div>
</b-modal> </b-modal>
@ -98,7 +155,7 @@
<div class="list-group text-center"> <div class="list-group text-center">
<p class="py-2 px-3 mb-0"> <p class="py-2 px-3 mb-0">
<div <div
class="text-center font-weight-bold text-danger"> class="text-center menu-option text-danger">
{{ $t('menu.moderationTools') }} {{ $t('menu.moderationTools') }}
</div> </div>
@ -107,38 +164,43 @@
</div> </div>
</p> </p>
<div <a
class="list-group-item rounded cursor-pointer" class="list-group-item menu-option"
@click="moderatePost(status, 'unlist')"> href="#"
@click.prevent="moderatePost(status, 'unlist')">
{{ $t('menu.unlistFromTimelines') }} {{ $t('menu.unlistFromTimelines') }}
</div> </a>
<div <a
v-if="status.sensitive" v-if="status.sensitive"
class="list-group-item rounded cursor-pointer" class="list-group-item menu-option"
@click="moderatePost(status, 'remcw')"> href="#"
@click.prevent="moderatePost(status, 'remcw')">
{{ $t('menu.removeCW') }} {{ $t('menu.removeCW') }}
</div> </a>
<div <a
v-else v-else
class="list-group-item rounded cursor-pointer" class="list-group-item menu-option"
@click="moderatePost(status, 'addcw')"> href="#"
@click.prevent="moderatePost(status, 'addcw')">
{{ $t('menu.addCW') }} {{ $t('menu.addCW') }}
</div> </a>
<div <a
class="list-group-item rounded cursor-pointer" class="list-group-item menu-option"
@click="moderatePost(status, 'spammer')"> href="#"
@click.prevent="moderatePost(status, 'spammer')">
{{ $t('menu.markAsSpammer') }}<br /> {{ $t('menu.markAsSpammer') }}<br />
<span class="small">{{ $t('menu.markAsSpammerText') }}</span> <span class="small">{{ $t('menu.markAsSpammerText') }}</span>
</div> </a>
<div <a
class="list-group-item rounded cursor-pointer text-lighter" class="list-group-item menu-option text-lighter"
@click="ctxModMenuClose()"> href="#"
@click.prevent="ctxModMenuClose()">
{{ $t('common.cancel') }} {{ $t('common.cancel') }}
</div> </a>
</div> </div>
</b-modal> </b-modal>
@ -170,10 +232,26 @@
rounded rounded
size="sm" size="sm"
body-class="list-group-flush p-0 rounded text-center"> body-class="list-group-flush p-0 rounded text-center">
<div class="list-group-item rounded cursor-pointer" @click="shareStatus(status, $event)">{{status.reblogged ? 'Unshare' : 'Share'}} {{ $t('menu.toFollowers') }}</div> <a
<div class="list-group-item rounded cursor-pointer" @click="ctxMenuCopyLink()">{{ $t('common.copyLink') }}</div> class="list-group-item menu-option"
<div v-if="status && status.local == true && !status.in_reply_to_id" class="list-group-item rounded cursor-pointer" @click="ctxMenuEmbed()">{{ $t('menu.embed') }}</div> href="#"
<div class="list-group-item rounded cursor-pointer text-lighter" @click="closeCtxShareMenu()">{{ $t('common.cancel') }}</div> @click.prevent="ctxMenuCopyLink()">
{{ $t('common.copyLink') }}
</a>
<a
v-if="status && status.local == true && !status.in_reply_to_id"
class="list-group-item menu-option"
@click.prevent="ctxMenuEmbed()">
{{ $t('menu.embed') }}
</a>
<a
class="list-group-item menu-option text-lighter"
href="#"
@click.prevent="closeCtxShareMenu()">
{{ $t('common.cancel') }}
</a>
</b-modal> </b-modal>
<b-modal ref="ctxEmbedModal" <b-modal ref="ctxEmbedModal"
@ -339,19 +417,19 @@
ctxMenu() { ctxMenu() {
this.ctxMenuStatus = this.status; this.ctxMenuStatus = this.status;
this.ctxEmbedPayload = window.App.util.embed.post(this.status.url); this.ctxEmbedPayload = window.App.util.embed.post(this.status.url);
// if(this.status.account.id == this.profile.id) { if(this.status.account.id == this.profile.id) {
this.ctxMenuRelationship = false; this.ctxMenuRelationship = false;
this.$refs.ctxModal.show(); this.$refs.ctxModal.show();
// } else { } else {
// axios.get('/api/pixelfed/v1/accounts/relationships', { axios.get('/api/v1/accounts/relationships', {
// params: { params: {
// 'id[]': this.status.account.id 'id[]': this.status.account.id
// } }
// }).then(res => { }).then(res => {
// this.ctxMenuRelationship = res.data[0]; this.ctxMenuRelationship = res.data[0];
// this.$refs.ctxModal.show(); this.$refs.ctxModal.show();
// }); });
// } }
}, },
closeCtxMenu() { closeCtxMenu() {
@ -667,28 +745,6 @@
} }
}, },
shareStatus(status, $event) {
if($('body').hasClass('loggedIn') == false) {
return;
}
this.closeModals();
axios.post('/i/share', {
item: status.id
}).then(res => {
status.reblogs_count = res.data.count;
status.reblogged = !status.reblogged;
// if(status.reblogged) {
// swal('Success', 'You shared this post', 'success');
// } else {
// swal('Success', 'You unshared this post', 'success');
// }
}).catch(err => {
swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
});
},
statusUrl(status) { statusUrl(status) {
if(status.account.local == true) { if(status.account.local == true) {
this.$router.push({ this.$router.push({
@ -741,10 +797,18 @@
return; return;
} }
if(window.confirm(this.$t('menu.deletePostConfirm')) == false) { swal({
return; title: 'Confirm Delete',
} text: 'Are you sure you want to delete this post?',
icon: "warning",
buttons: true,
dangerMode: true,
})
.then(res => {
if(!res) {
this.closeModals();
this.isDeleting = false;
} else {
axios.post('/i/delete', { axios.post('/i/delete', {
type: 'status', type: 'status',
item: status.id item: status.id
@ -753,8 +817,12 @@
this.closeModals(); this.closeModals();
this.isDeleting = false; this.isDeleting = false;
}).catch(err => { }).catch(err => {
this.closeModals();
this.isDeleting = false;
swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error'); swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
}); });
}
})
}, },
owner(status) { owner(status) {
@ -776,7 +844,7 @@
axios.post('/api/pixelfed/v2/status/' + status.id + '/archive') axios.post('/api/pixelfed/v2/status/' + status.id + '/archive')
.then(res => { .then(res => {
this.$emit('status-delete', status.id); this.$emit('delete', status.id);
this.$emit('archived', status.id); this.$emit('archived', status.id);
this.closeModals(); this.closeModals();
}); });
@ -797,7 +865,157 @@
editPost(status) { editPost(status) {
this.closeModals(); this.closeModals();
this.$emit('edit', status); this.$emit('edit', status);
},
handleMute() {
if(!this.ctxMenuRelationship) {
return;
} }
let curState = this.ctxMenuRelationship.muting;
swal({
title: curState ? 'Confirm Unmute' : 'Confirm Mute',
text: curState ? 'Are you sure you want to unmute this account?' : 'Are you sure you want to mute this account?',
icon: "warning",
buttons: true,
dangerMode: true,
})
.then(res => {
if(!res) {
this.closeModals();
} else {
let url = curState ?
`/api/v1/accounts/${this.status.account.id}/unmute` :
`/api/v1/accounts/${this.status.account.id}/mute`;
axios.post(url)
.then(res => {
this.closeModals();
this.$emit('muted', this.status);
this.$store.commit('updateRelationship', [res.data]);
})
.catch(err => {
this.closeModals();
if(err && err.response && err.response.data && err.response.data.error) {
swal('Error', err.response.data.error, 'error');
} else {
swal('Oops!', 'An error occured, please try again later.', 'error');
}
})
}
})
},
handleBlock() {
if(!this.ctxMenuRelationship) {
return;
}
let curState = this.ctxMenuRelationship.blocking;
swal({
title: curState ? 'Confirm Unblock' : 'Confirm Block',
text: curState ? 'Are you sure you want to unblock this account?' : 'Are you sure you want to block this account?',
icon: "warning",
buttons: true,
dangerMode: true,
})
.then(res => {
if(!res) {
this.closeModals();
} else {
let url = curState ?
`/api/v1/accounts/${this.status.account.id}/unblock` :
`/api/v1/accounts/${this.status.account.id}/block`;
axios.post(url)
.then(res => {
this.closeModals();
this.$store.commit('updateRelationship', [res.data]);
this.$emit('muted', this.status);
})
.catch(err => {
this.closeModals();
if(err && err.response && err.response.data && err.response.data.error) {
swal('Error', err.response.data.error, 'error');
} else {
swal('Oops!', 'An error occured, please try again later.', 'error');
}
})
}
})
},
handleUnfollow() {
if(!this.ctxMenuRelationship) {
return;
}
swal({
title: 'Unfollow',
text: 'Are you sure you want to unfollow ' + this.status.account.username + '?',
icon: "warning",
buttons: true,
dangerMode: true,
})
.then(res => {
if(!res) {
this.closeModals();
} else {
axios.post(`/api/v1/accounts/${this.status.account.id}/unfollow`)
.then(res => {
this.closeModals();
this.$store.commit('updateRelationship', [res.data]);
this.$emit('unfollow', this.status);
})
.catch(err => {
this.closeModals();
if(err && err.response && err.response.data && err.response.data.error) {
swal('Error', err.response.data.error, 'error');
} else {
swal('Oops!', 'An error occured, please try again later.', 'error');
}
})
}
})
},
} }
} }
</script> </script>
<style lang="scss" scoped>
.menu-option {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
text-decoration: none;
font-weight: 500;
color: var(--dark);
}
.list-group-item {
border-color: var(--border-color);
}
.action-icon-link {
display: flex;
flex-direction: column;
.icon {
opacity: 0.5;
margin-bottom: 5px;
}
p {
font-weight: 600;
font-size: 11px;
}
&-inline {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
gap: 8px;
p {
font-weight: bold;
}
}
}
</style>

View file

@ -91,6 +91,8 @@
v-on:delete="deletePost" v-on:delete="deletePost"
v-on:report-modal="handleReport" v-on:report-modal="handleReport"
v-on:edit="handleEdit" v-on:edit="handleEdit"
v-on:muted="handleMuted"
v-on:unfollow="handleUnfollow"
/> />
<likes-modal <likes-modal
@ -543,6 +545,7 @@
deletePost() { deletePost() {
this.feed.splice(this.postIndex, 1); this.feed.splice(this.postIndex, 1);
this.forceUpdateIdx++;
}, },
counterChange(index, type) { counterChange(index, type) {
@ -788,6 +791,21 @@
.then(res => { .then(res => {
}) })
}, },
handleMuted(post) {
this.feed = this.feed.filter(p => {
return p.account.id !== post.account.id;
});
},
handleUnfollow(post) {
if(this.scope === 'home') {
this.feed = this.feed.filter(p => {
return p.account.id !== post.account.id;
});
}
this.updateProfile({ following_count: this.profile.following_count - 1 });
},
}, },
watch: { watch: {