Fix ProfileFeed bookmark, likes and shares. Closes #5879

pull/5914/head
Daniel Supernault 8 months ago
parent 8082c004bc
commit a25afa0442
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1

@ -270,14 +270,14 @@
:key="'prs'+s.id+':'+index" :key="'prs'+s.id+':'+index"
:profile="user" :profile="user"
:status="s" :status="s"
v-on:like="likeStatus(index)" v-on:like="likeStatus(index, 'feed')"
v-on:unlike="unlikeStatus(index)" v-on:unlike="unlikeStatus(index, 'feed')"
v-on:share="shareStatus(index)" v-on:share="shareStatus(index, 'feed')"
v-on:unshare="unshareStatus(index)" v-on:unshare="unshareStatus(index, 'feed')"
v-on:menu="openContextMenu(index)" v-on:menu="openContextMenu(index, 'feed')"
v-on:counter-change="counterChange(index, $event)" v-on:counter-change="counterChange(index, $event)"
v-on:likes-modal="openLikesModal(index)" v-on:likes-modal="openLikesModal(index, 'feed')"
v-on:shares-modal="openSharesModal(index)" v-on:shares-modal="openSharesModal(index, 'feed')"
v-on:comment-likes-modal="openCommentLikesModal" v-on:comment-likes-modal="openCommentLikesModal"
v-on:bookmark="handleBookmark(index)" v-on:bookmark="handleBookmark(index)"
v-on:handle-report="handleReport" /> v-on:handle-report="handleReport" />
@ -361,12 +361,15 @@
:key="'prs'+s.id+':'+index" :key="'prs'+s.id+':'+index"
:profile="user" :profile="user"
:status="s" :status="s"
v-on:like="likeStatus(index)" v-on:like="likeStatus(index, 'likes')"
v-on:unlike="unlikeStatus(index)" v-on:unlike="unlikeStatus(index, 'likes')"
v-on:share="shareStatus(index)" v-on:menu="openContextMenu(index, 'likes')"
v-on:unshare="unshareStatus(index)" v-on:share="shareStatus(index, 'likes')"
v-on:unshare="unshareStatus(index, 'likes')"
v-on:counter-change="counterChange(index, $event)" v-on:counter-change="counterChange(index, $event)"
v-on:likes-modal="openLikesModal(index)" v-on:likes-modal="openLikesModal(index, 'likes')"
v-on:shares-modal="openSharesModal(index, 'likes')"
v-on:bookmark="handleBookmark(index, 'likes')"
v-on:comment-likes-modal="openCommentLikesModal" v-on:comment-likes-modal="openCommentLikesModal"
v-on:handle-report="handleReport" /> v-on:handle-report="handleReport" />
</div> </div>
@ -395,10 +398,15 @@
:profile="user" :profile="user"
:new-reactions="true" :new-reactions="true"
:status="s" :status="s"
v-on:menu="openContextMenu(index)" v-on:like="likeStatus(index, 'bookmarks')"
v-on:unlike="unlikeStatus(index, 'bookmarks')"
v-on:menu="openContextMenu(index, 'bookmarks')"
v-on:counter-change="counterChange(index, $event)" v-on:counter-change="counterChange(index, $event)"
v-on:likes-modal="openLikesModal(index)" v-on:share="shareStatus(index, 'bookmarks')"
v-on:bookmark="handleBookmark(index)" v-on:unshare="unshareStatus(index, 'bookmarks')"
v-on:likes-modal="openLikesModal(index, 'bookmarks')"
v-on:bookmark="handleBookmark(index, 'bookmarks')"
v-on:shares-modal="openSharesModal(index, 'bookmarks')"
v-on:comment-likes-modal="openCommentLikesModal" v-on:comment-likes-modal="openCommentLikesModal"
v-on:handle-report="handleReport" /> v-on:handle-report="handleReport" />
</div> </div>
@ -556,7 +564,8 @@
archivesLoaded: false, archivesLoaded: false,
archivesPage: 1, archivesPage: 1,
canLoadMoreArchives: false, canLoadMoreArchives: false,
contextMenuPost: {} contextMenuPost: {},
contextMenuType: undefined,
} }
}, },
@ -888,64 +897,113 @@
return App.util.format.timeAgo(ts); return App.util.format.timeAgo(ts);
}, },
likeStatus(index) { likeStatus(index, source = 'feed') {
let status = this.feed[index]; const sourceMap = {
let state = status.favourited; 'feed': this.feed,
let count = status.favourites_count; 'likes': this.favourites,
this.feed[index].favourites_count = count + 1; 'bookmarks': this.bookmarks
this.feed[index].favourited = !status.favourited; };
axios.post('/api/v1/statuses/' + status.id + '/favourite') const sourceArray = sourceMap[source] || this.feed;
.catch(err => { const status = sourceArray[index];
this.feed[index].favourites_count = count; const originalFavourited = status.favourited;
this.feed[index].favourited = false; const originalCount = status.favourites_count;
})
sourceArray[index].favourites_count = originalCount + 1;
sourceArray[index].favourited = !originalFavourited;
axios.post(`/api/v1/statuses/${status.id}/favourite`)
.catch(err => {
sourceArray[index].favourites_count = originalCount;
sourceArray[index].favourited = originalFavourited;
});
}, },
unlikeStatus(index) { unlikeStatus(index, source = 'feed') {
let status = this.feed[index]; const sourceMap = {
let state = status.favourited; 'feed': this.feed,
let count = status.favourites_count; 'likes': this.favourites,
this.feed[index].favourites_count = count - 1; 'bookmarks': this.bookmarks
this.feed[index].favourited = !status.favourited; };
axios.post('/api/v1/statuses/' + status.id + '/unfavourite') const sourceArray = sourceMap[source] || this.feed;
.catch(err => { const status = sourceArray[index];
this.feed[index].favourites_count = count; const originalFavourited = status.favourited;
this.feed[index].favourited = false; const originalCount = status.favourites_count;
})
sourceArray[index].favourites_count = originalCount - 1;
sourceArray[index].favourited = !originalFavourited;
axios.post(`/api/v1/statuses/${status.id}/unfavourite`)
.catch(err => {
sourceArray[index].favourites_count = originalCount;
sourceArray[index].favourited = originalFavourited;
});
}, },
openContextMenu(idx, type = 'feed') { openContextMenu(idx, type = 'feed') {
switch(type) { const sourceMap = {
case 'feed': 'feed': this.feed,
this.postIndex = idx; 'likes': this.favourites,
this.contextMenuPost = this.feed[idx]; 'bookmarks': this.bookmarks,
break; 'archive': this.archives
};
case 'archive': const sourceArray = sourceMap[type] || this.feed;
this.postIndex = idx;
this.contextMenuPost = this.archives[idx]; this.postIndex = idx;
break; this.contextMenuPost = sourceArray[idx];
} this.contextMenuType = type;
this.showMenu = true; this.showMenu = true;
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.contextMenu.open(); this.$refs.contextMenu.open();
}); });
}, },
openLikesModal(idx) { openLikesModal(idx, source = 'feed') {
this.postIndex = idx; this.postIndex = idx;
this.likesModalPost = this.feed[this.postIndex]; switch(source) {
case 'feed':
this.likesModalPost = this.feed[this.postIndex];
break;
case 'likes':
this.likesModalPost = this.favourites[this.postIndex];
break;
case 'bookmarks':
this.likesModalPost = this.bookmarks[this.postIndex];
break;
default:
this.likesModalPost = this.feed[this.postIndex];
break;
}
this.showLikesModal = true; this.showLikesModal = true;
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.likesModal.open(); this.$refs.likesModal.open();
}); });
}, },
openSharesModal(idx) { openSharesModal(idx, source = 'feed') {
this.postIndex = idx; this.postIndex = idx;
this.sharesModalPost = this.feed[this.postIndex]; switch(source) {
case 'feed':
this.sharesModalPost = this.feed[this.postIndex];
break;
case 'likes':
this.sharesModalPost = this.favourites[this.postIndex];
break;
case 'bookmarks':
this.sharesModalPost = this.bookmarks[this.postIndex];
break;
default:
this.sharesModalPost = this.feed[this.postIndex];
break;
}
this.showSharesModal = true; this.showSharesModal = true;
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.sharesModal.open(); this.$refs.sharesModal.open();
@ -955,23 +1013,32 @@
commitModeration(type) { commitModeration(type) {
let idx = this.postIndex; let idx = this.postIndex;
const sourceMap = {
'feed': this.feed,
'likes': this.favourites,
'bookmarks': this.bookmarks,
'archive': this.archives
};
const sourceType = this.contextMenuType;
switch(type) { switch(type) {
case 'addcw': case 'addcw':
this.feed[idx].sensitive = true; sourceMap[sourceType][idx].sensitive = true;
break; break;
case 'remcw': case 'remcw':
this.feed[idx].sensitive = false; sourceMap[sourceType][idx].sensitive = false;
break; break;
case 'unlist': case 'unlist':
this.feed.splice(idx, 1); sourceMap[sourceType].splice(idx, 1);
break; break;
case 'spammer': case 'spammer':
let id = this.feed[idx].account.id; let id = sourceMap[sourceType][idx].account.id;
this.feed = this.feed.filter(post => { sourceMap[sourceType] = sourceMap[sourceType].filter(post => {
return post.account.id != id; return post.account.id != id;
}); });
break; break;
@ -998,32 +1065,48 @@
}); });
}, },
shareStatus(index) { shareStatus(index, source = 'feed') {
let status = this.feed[index]; const sourceMap = {
let state = status.reblogged; 'feed': this.feed,
let count = status.reblogs_count; 'likes': this.favourites,
this.feed[index].reblogs_count = count + 1; 'bookmarks': this.bookmarks
this.feed[index].reblogged = !status.reblogged; };
axios.post('/api/v1/statuses/' + status.id + '/reblog') const sourceArray = sourceMap[source] || this.feed;
.catch(err => { const status = sourceArray[index];
this.feed[index].reblogs_count = count; const originalReblogged = status.reblogged;
this.feed[index].reblogged = false; const originalCount = status.reblogs_count;
})
sourceArray[index].reblogs_count = originalCount + 1;
sourceArray[index].reblogged = !originalReblogged;
axios.post(`/api/v1/statuses/${status.id}/reblog`)
.catch(err => {
sourceArray[index].reblogs_count = originalCount;
sourceArray[index].reblogged = originalReblogged;
});
}, },
unshareStatus(index) { unshareStatus(index, source = 'feed') {
let status = this.feed[index]; const sourceMap = {
let state = status.reblogged; 'feed': this.feed,
let count = status.reblogs_count; 'likes': this.favourites,
this.feed[index].reblogs_count = count - 1; 'bookmarks': this.bookmarks
this.feed[index].reblogged = !status.reblogged; };
axios.post('/api/v1/statuses/' + status.id + '/unreblog') const sourceArray = sourceMap[source] || this.feed;
.catch(err => { const status = sourceArray[index];
this.feed[index].reblogs_count = count; const originalReblogged = status.reblogged;
this.feed[index].reblogged = false; const originalCount = status.reblogs_count;
})
sourceArray[index].reblogs_count = originalCount - 1;
sourceArray[index].reblogged = !originalReblogged;
axios.post(`/api/v1/statuses/${status.id}/unreblog`)
.catch(err => {
sourceArray[index].reblogs_count = originalCount;
sourceArray[index].reblogged = originalReblogged;
});
}, },
handleReport(post) { handleReport(post) {
@ -1069,25 +1152,29 @@
}) })
}, },
handleBookmark(index) { handleBookmark(index, source = 'feed') {
if(!window.confirm('Are you sure you want to unbookmark this post?')) { this.postIndex = index;
return;
} const sourceMap = {
'feed': this.feed,
'likes': this.favourites,
'bookmarks': this.bookmarks
};
let p = this.bookmarks[index]; const sourceArray = sourceMap[source] || this.feed;
const item = sourceArray[this.postIndex];
if(item.bookmarked) {
if(!window.confirm('Are you sure you want to unbookmark this post?')) {
return;
}
}
axios.post('/i/bookmark', { axios.post('/i/bookmark', {
item: p.id item: item.id
}) })
.then(res => { .then(res => {
this.bookmarks = this.bookmarks.map(post => { item.bookmarked = !item.bookmarked;
if(post.id == p.id) {
post.bookmarked = false;
delete post.bookmarked_at;
}
return post;
});
this.bookmarks.splice(index, 1);
}) })
.catch(err => { .catch(err => {
this.$bvToast.toast('Cannot bookmark post at this time.', { this.$bvToast.toast('Cannot bookmark post at this time.', {
@ -1097,7 +1184,6 @@
}); });
}); });
}, },
} }
} }
</script> </script>

Loading…
Cancel
Save