pixelfed/resources/assets/js/components/PostComponent.vue

681 lines
25 KiB
Vue
Raw Normal View History

2018-11-05 01:48:58 +00:00
<style>
2018-12-02 04:57:43 +00:00
#l-modal .modal-body,
#s-modal .modal-body {
max-height: 70vh;
overflow-y: scroll;
}
2018-12-09 22:34:05 +00:00
.status-comments,
.reactions,
.col-md-4 {
background: #fff;
}
.postPresenterContainer {
2018-12-10 04:03:26 +00:00
background: #000;
2018-12-09 22:34:05 +00:00
min-height: 600px;
}
2018-11-05 01:48:58 +00:00
</style>
<template>
2018-12-02 04:57:43 +00:00
<div class="postComponent d-none">
2018-11-05 01:48:58 +00:00
<div class="container px-0 mt-md-4">
<div class="card card-md-rounded-0 status-container orientation-unknown">
2018-12-09 22:34:05 +00:00
<div class="row px-0 mx-0">
2018-11-05 01:48:58 +00:00
<div class="d-flex d-md-none align-items-center justify-content-between card-header bg-white w-100">
<a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
<div class="status-avatar mr-2">
<img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
</div>
<div class="username">
<span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
</div>
</a>
<div class="float-right">
2018-12-03 20:23:22 +00:00
<div class="post-actions">
2018-11-20 02:45:27 +00:00
<div class="dropdown">
2018-11-05 01:48:58 +00:00
<button class="btn btn-link text-dark no-caret dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Post options">
<span class="fas fa-ellipsis-v text-muted"></span>
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
2018-12-03 20:23:22 +00:00
<span class="menu-user d-none">
<a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
<a class="dropdown-item font-weight-bold" v-on:click="muteProfile">Mute Profile</a>
<a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a>
</span>
<span class="menu-author d-none">
<a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
<a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a>
</span>
2018-11-20 02:45:27 +00:00
</div>
2018-11-05 01:48:58 +00:00
</div>
2018-11-20 02:45:27 +00:00
</div>
2018-11-05 01:48:58 +00:00
</div>
</div>
2018-12-09 22:34:05 +00:00
<div class="col-12 col-md-8 status-photo px-0 mx-0">
2018-11-05 01:48:58 +00:00
<div class="postPresenterLoader text-center">
<div class="lds-ring"><div></div><div></div><div></div><div></div></div>
</div>
<div class="postPresenterContainer d-none">
</div>
</div>
<div class="col-12 col-md-4 px-0 d-flex flex-column border-left border-md-left-0">
<div class="d-md-flex d-none align-items-center justify-content-between card-header py-3 bg-white">
<a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
<div class="status-avatar mr-2">
<img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
</div>
<div class="username">
<span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
</div>
</a>
<div class="float-right">
2018-12-03 20:23:22 +00:00
<div class="post-actions">
2018-11-05 01:48:58 +00:00
<div class="dropdown">
<button class="btn btn-link text-dark no-caret dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Post options">
<span class="fas fa-ellipsis-v text-muted"></span>
</button>
2018-11-20 02:45:27 +00:00
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
2018-12-03 20:23:22 +00:00
<span class="menu-user d-none">
<a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
<a class="dropdown-item font-weight-bold" v-on:click="muteProfile">Mute Profile</a>
<a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a>
</span>
<span class="menu-author d-none">
<a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
<a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a>
</span>
2018-11-20 02:45:27 +00:00
</div>
2018-11-05 01:48:58 +00:00
</div>
</div>
</div>
</div>
<div class="d-flex flex-md-column flex-column-reverse h-100">
<div class="card-body status-comments">
<div class="status-comment">
2018-11-13 19:47:43 +00:00
<p class="mb-1 read-more" style="overflow: hidden;">
2018-11-05 01:48:58 +00:00
<span class="font-weight-bold pr-1">{{statusUsername}}</span>
2018-12-02 04:57:43 +00:00
<span class="comment-text" :id="status.id + '-status-readmore'" v-html="status.content"></span>
2018-11-05 01:48:58 +00:00
</p>
2018-11-22 20:21:36 +00:00
<post-comments :user="this.user" :post-id="statusId" :post-username="statusUsername"></post-comments>
2018-11-05 01:48:58 +00:00
</div>
</div>
<div class="card-body flex-grow-0 py-1">
<div class="reactions my-1">
2018-12-03 20:23:22 +00:00
<h3 v-bind:class="[reactions.liked ? 'fas fa-heart text-danger pr-3 m-0' : 'far fa-heart pr-3 m-0 like-btn']" title="Like" v-on:click="likeStatus"></h3>
2018-11-25 05:36:17 +00:00
<h3 class="far fa-comment pr-3 m-0" title="Comment" v-on:click="commentFocus"></h3>
2018-12-03 20:23:22 +00:00
<h3 v-bind:class="[reactions.shared ? 'far fa-share-square pr-3 m-0 text-primary' : 'far fa-share-square pr-3 m-0 share-btn']" title="Share" v-on:click="shareStatus"></h3>
<h3 v-bind:class="[reactions.bookmarked ? 'fas fa-bookmark text-warning m-0 float-right' : 'far fa-bookmark m-0 float-right']" title="Bookmark" v-on:click="bookmarkStatus"></h3>
2018-11-05 01:48:58 +00:00
</div>
2018-12-02 04:57:43 +00:00
<div class="reaction-counts font-weight-bold mb-0">
<span style="cursor:pointer;" v-on:click="likesModal">
<span class="like-count">{{status.favourites_count || 0}}</span> likes
</span>
<span class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
<span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
</span>
2018-11-05 01:48:58 +00:00
</div>
<div class="timestamp">
<a v-bind:href="statusUrl" class="small text-muted">
2018-11-20 01:05:50 +00:00
{{timestampFormat()}}
2018-11-05 01:48:58 +00:00
</a>
</div>
</div>
</div>
<div class="card-footer bg-white sticky-md-bottom">
2018-11-20 02:45:27 +00:00
<div class="comment-form-guest">
<a href="/login">Login</a> to like or comment.
</div>
<form class="comment-form d-none" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
2018-11-09 05:01:28 +00:00
<input type="hidden" name="_token" value="">
2018-11-05 01:48:58 +00:00
<input type="hidden" name="item" :value="statusId">
<input class="form-control" name="comment" placeholder="Add a comment..." autocomplete="off">
</form>
</div>
</div>
</div>
</div>
</div>
2018-12-03 20:23:22 +00:00
2018-12-02 04:57:43 +00:00
<b-modal ref="likesModal"
id="l-modal"
hide-footer
centered
title="Likes"
body-class="list-group-flush p-0">
<div class="list-group">
<div class="list-group-item border-0" v-for="user in likes">
<div class="media">
<a :href="user.url">
<img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '\'s avatar'" width="30px">
</a>
<div class="media-body">
<p class="mb-0" style="font-size: 14px">
<a :href="user.url" class="font-weight-bold text-dark">
{{user.username}}
</a>
</p>
<p class="text-muted mb-0" style="font-size: 14px">
{{user.display_name}}
</a>
</p>
</div>
</div>
</div>
<infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
<div slot="no-more"></div>
<div slot="no-results"></div>
</infinite-loading>
</div>
</b-modal>
<b-modal ref="sharesModal"
id="s-modal"
hide-footer
centered
title="Shares"
body-class="list-group-flush p-0">
<div class="list-group">
<div class="list-group-item border-0" v-for="user in shares">
<div class="media">
<a :href="user.url">
<img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '\'s avatar'" width="30px">
</a>
<div class="media-body">
<p class="mb-0" style="font-size: 14px">
<a :href="user.url" class="font-weight-bold text-dark">
{{user.username}}
</a>
</p>
<p class="text-muted mb-0" style="font-size: 14px">
{{user.display_name}}
</a>
</p>
</div>
</div>
</div>
<infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
<div slot="no-more"></div>
<div slot="no-results"></div>
</infinite-loading>
</div>
</b-modal>
2018-11-05 01:48:58 +00:00
</div>
</template>
<script>
pixelfed.postComponent = {};
2018-12-03 20:23:22 +00:00
2018-11-05 01:48:58 +00:00
pixelfed.presenter = {
show: {
2018-12-05 02:49:15 +00:00
image: function(container, media, status) {
2018-11-25 05:36:17 +00:00
$('.status-container')
.removeClass('orientation-unknown')
.addClass('orientation-' + media[0]['orientation']);
2018-11-05 01:48:58 +00:00
let wrapper = $('<div>');
2018-12-09 22:34:05 +00:00
container.addClass('d-flex align-items-center');
if(media[0]['filter_class']) {
wrapper.addClass(media[0]['filter_class']);
}
2018-11-05 01:48:58 +00:00
let el = $('<img>');
el.attr('src', media[0]['url']);
el.attr('title', media[0]['description']);
wrapper.append(el);
2018-12-05 02:49:15 +00:00
if(status.sensitive == true) {
let spoilerText = status.spoiler_text ? status.spoiler_text : 'CW / NSFW / Hidden Media';
2018-12-09 22:34:05 +00:00
let cw = $('<details>').addClass('details-animated w-100');
2018-12-05 02:49:15 +00:00
let summary = $('<summary>');
let text = $('<p>').addClass('mb-0 lead font-weight-bold').text(spoilerText);
let direction = $('<p>').addClass('font-weight-light').text('(click to show)');
summary.append(text, direction);
cw.append(summary, wrapper);
container.append(cw);
} else {
container.append(wrapper);
}
2018-11-05 01:48:58 +00:00
},
2018-12-05 02:49:15 +00:00
video: function(container, media, status) {
2018-11-05 01:48:58 +00:00
let wrapper = $('<div>');
2018-12-09 22:34:05 +00:00
container.addClass('d-flex align-items-center');
2018-11-05 01:48:58 +00:00
let el = $('<video>');
el.addClass('embed-responsive-item');
el.attr('controls', '');
2018-11-30 20:36:05 +00:00
el.attr('loop', '');
2018-11-05 01:48:58 +00:00
el.attr('src', media[0]['url']);
el.attr('title', media[0]['description']);
wrapper.append(el);
2018-12-05 02:49:15 +00:00
if(status.sensitive == true) {
let spoilerText = status.spoiler_text ? status.spoiler_text : 'CW / NSFW / Hidden Media';
2018-12-09 22:34:05 +00:00
let cw = $('<details>').addClass('details-animated w-100');
2018-12-05 02:49:15 +00:00
let summary = $('<summary>');
let text = $('<p>').addClass('mb-0 lead font-weight-bold').text(spoilerText);
let direction = $('<p>').addClass('font-weight-light').text('(click to show)');
summary.append(text, direction);
cw.append(summary, wrapper);
container.append(cw);
} else {
container.append(wrapper);
}
2018-11-30 20:36:05 +00:00
const player = new Plyr(el, {
controls: [
'restart', // Restart playback
'play', // Play/pause playback
'progress', // The progress bar and scrubber for playback and buffering
'current-time', // The current time of playback
'duration', // The full duration of the media
'volume', // Volume control
'captions', // Toggle captions
'settings', // Settings menu
'fullscreen', // Toggle fullscreen
]
});
player.volume = 0.75;
2018-11-05 01:48:58 +00:00
},
2018-11-25 05:36:17 +00:00
imageAlbum: function(container, media, status) {
$('.status-container')
.removeClass('orientation-unknown')
.addClass('orientation-' + media[0]['orientation']);
let id = 'photo-carousel-wrapper-' + status.id;
2018-11-05 01:48:58 +00:00
let wrapper = $('<div>');
2018-12-09 22:34:05 +00:00
container.addClass('d-flex align-items-center');
2018-11-25 05:36:17 +00:00
wrapper.addClass('carousel slide carousel-fade');
wrapper.attr('data-ride', 'carousel');
wrapper.attr('id', id);
let indicators = $('<ol>');
indicators.addClass('carousel-indicators');
let prev = $('<a>');
prev.addClass('carousel-control-prev');
prev.attr('href', '#' + id);
prev.attr('role', 'button');
prev.attr('data-slide', 'prev');
let prevIcon = $('<span>').addClass('carousel-control-prev-icon').attr('aria-hidden', 'true');
let prevSr = $('<span>').addClass('sr-only');
prev.append(prevIcon, prevSr);
let next = $('<a>');
next.addClass('carousel-control-next');
next.attr('href', '#' + id);
next.attr('role', 'button');
next.attr('data-slide', 'next');
let nextIcon = $('<span>').addClass('carousel-control-next-icon').attr('aria-hidden', 'true');
let nextSr = $('<span>').addClass('sr-only');
let inner = $('<div>').addClass('carousel-inner');
next.append(nextIcon, nextSr);
for(let i = 0; i < media.length; i++) {
let li = $('<li>');
li.attr('data-target', '#' + id);
li.attr('data-slide-to', i);
if(i == 0) {
li.addClass('active');
}
indicators.append(li);
2018-11-05 01:48:58 +00:00
let item = media[i];
2018-11-25 05:36:17 +00:00
let carouselItem = $('<div>').addClass('carousel-item');
if(i == 0) {
carouselItem.addClass('active');
}
let figure = $('<figure>');
if(item['filter_class']) {
figure.addClass(item['filter_class']);
}
let badge = $('<span>');
badge.addClass('float-right mr-3 badge badge-dark');
badge.style = 'position:fixed;top:8px;right:0;margin-bottom:-20px;';
badge.text(i+1 + '/' + media.length);
2018-11-05 01:48:58 +00:00
let img = $('<img>');
2018-11-25 05:36:17 +00:00
img.addClass('d-block w-100');
2018-11-05 01:48:58 +00:00
img.attr('src', item['url']);
2018-11-25 05:36:17 +00:00
figure.append(badge, img);
carouselItem.append(figure);
inner.append(carouselItem);
2018-11-05 01:48:58 +00:00
}
2018-11-25 05:36:17 +00:00
wrapper.append(indicators, inner, prev, next);
2018-12-05 02:49:15 +00:00
if(status.sensitive == true) {
let spoilerText = status.spoiler_text ? status.spoiler_text : 'CW / NSFW / Hidden Media';
2018-12-09 22:34:05 +00:00
let cw = $('<details>').addClass('details-animated w-100');
2018-12-05 02:49:15 +00:00
let summary = $('<summary>');
let text = $('<p>').addClass('mb-0 lead font-weight-bold').text(spoilerText);
let direction = $('<p>').addClass('font-weight-light').text('(click to show)');
summary.append(text, direction);
cw.append(summary, wrapper);
container.append(cw);
} else {
container.append(wrapper);
}
2018-11-05 01:48:58 +00:00
}
}
};
export default {
props: ['status-id', 'status-username', 'status-template', 'status-url', 'status-profile-url', 'status-avatar'],
data() {
return {
status: {},
2018-11-20 02:45:27 +00:00
media: {},
2018-11-25 05:36:17 +00:00
user: {},
2018-12-03 20:23:22 +00:00
reactions: {
liked: false,
shared: false
},
2018-12-02 04:57:43 +00:00
likes: {},
likesPage: 1,
shares: {},
sharesPage: 1,
2018-11-05 01:48:58 +00:00
}
},
2018-12-02 04:57:43 +00:00
2018-11-05 01:48:58 +00:00
mounted() {
2018-12-03 20:23:22 +00:00
this.fetchData();
this.authCheck();
2018-11-09 05:01:28 +00:00
let token = $('meta[name="csrf-token"]').attr('content');
$('input[name="_token"]').each(function(k, v) {
let el = $(v);
el.val(token);
});
2018-11-05 01:48:58 +00:00
},
2018-12-02 04:57:43 +00:00
2018-11-25 05:36:17 +00:00
updated() {
$('.carousel').carousel();
2018-12-02 04:57:43 +00:00
2018-11-25 05:36:17 +00:00
if(this.reactions) {
if(this.reactions.bookmarked == true) {
$('.far.fa-bookmark').removeClass('far').addClass('fas text-warning');
}
if(this.reactions.shared == true) {
$('.far.fa-share-square').addClass('text-primary');
}
if(this.reactions.liked == true) {
$('.far.fa-heart ').removeClass('far text-dark').addClass('fas text-danger');
}
}
2018-12-02 04:57:43 +00:00
if(this.status) {
let title = this.status.account.username + ' posted a photo: ' + this.status.favourites_count + ' likes';
$('head title').text(title);
}
2018-11-25 05:36:17 +00:00
},
2018-12-09 22:34:05 +00:00
2018-11-05 01:48:58 +00:00
methods: {
2018-11-20 02:45:27 +00:00
authCheck() {
let authed = $('body').hasClass('loggedIn');
if(authed == true) {
$('.comment-form-guest').addClass('d-none');
$('.comment-form').removeClass('d-none');
}
},
2018-12-03 20:23:22 +00:00
2018-11-20 02:45:27 +00:00
showMuteBlock() {
let sid = this.status.account.id;
let uid = this.user.id;
2018-12-03 20:23:22 +00:00
if(sid == uid) {
$('.post-actions .menu-author').removeClass('d-none');
} else {
$('.post-actions .menu-user').removeClass('d-none');
2018-11-20 02:45:27 +00:00
}
},
2018-12-02 04:57:43 +00:00
2018-11-20 02:45:27 +00:00
reportUrl() {
return '/i/report?type=post&id=' + this.status.id;
},
2018-12-02 04:57:43 +00:00
2018-12-03 20:23:22 +00:00
editUrl() {
return this.status.url + '/edit';
},
2018-11-20 01:05:50 +00:00
timestampFormat() {
let ts = new Date(this.status.created_at);
2018-11-25 05:36:17 +00:00
return ts.toDateString() + ' ' + ts.toLocaleTimeString();
2018-11-20 01:05:50 +00:00
},
2018-12-02 04:57:43 +00:00
2018-11-05 01:48:58 +00:00
fetchData() {
2018-12-02 04:57:43 +00:00
let loader = this.$loading.show({
'opacity': 0,
'background-color': '#f5f8fa'
});
axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
2018-11-05 01:48:58 +00:00
.then(response => {
let self = this;
self.status = response.data.status;
2018-11-20 02:45:27 +00:00
self.user = response.data.user;
2018-11-05 01:48:58 +00:00
self.media = self.status.media_attachments;
2018-11-25 05:36:17 +00:00
self.reactions = response.data.reactions;
2018-12-02 04:57:43 +00:00
self.likes = response.data.likes;
self.shares = response.data.shares;
self.likesPage = 2;
self.sharesPage = 2;
2018-11-05 01:48:58 +00:00
this.buildPresenter();
2018-11-20 02:45:27 +00:00
this.showMuteBlock();
2018-12-02 04:57:43 +00:00
loader.hide();
$('.postComponent').removeClass('d-none');
2018-11-05 01:48:58 +00:00
}).catch(error => {
if(!error.response) {
$('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occured, cannot fetch media. Please try again later.');
} else {
switch(error.response.status) {
case 401:
$('.postPresenterLoader .lds-ring')
.attr('style','width:100%')
.addClass('pt-4 font-weight-bold text-muted')
.text('Please login to view.');
break;
default:
$('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occured, cannot fetch media. Please try again later.');
break;
}
}
});
},
2018-12-02 04:57:43 +00:00
2018-11-25 05:36:17 +00:00
commentFocus() {
$('.comment-form input[name="comment"]').focus();
},
2018-12-02 04:57:43 +00:00
likesModal() {
if(this.status.favourites_count == 0 || $('body').hasClass('loggedIn') == false) {
return;
}
this.$refs.likesModal.show();
},
sharesModal() {
if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
return;
}
this.$refs.sharesModal.show();
},
infiniteLikesHandler($state) {
let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
axios.get(api, {
params: {
page: this.likesPage,
},
}).then(({ data }) => {
if (data.data.length) {
this.likesPage += 1;
this.likes.push(...data.data);
$state.loaded();
} else {
$state.complete();
}
});
},
infiniteSharesHandler($state) {
axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
params: {
page: this.sharesPage,
},
}).then(({ data }) => {
if (data.data.length) {
this.sharesPage += 1;
this.shares.push(...data.data);
$state.loaded();
} else {
$state.complete();
}
});
},
2018-11-05 01:48:58 +00:00
buildPresenter() {
let container = $('.postPresenterContainer');
let status = this.status;
let media = this.media;
2018-11-20 02:45:27 +00:00
$('input[name="item"]').each(function(k, v) {
let el = $(v);
el.val(status.account.id);
});
2018-11-05 01:48:58 +00:00
if(container.children().length != 0) {
return;
}
2018-12-03 20:23:22 +00:00
let template = this.status.pf_type ? this.status.pf_type : this.statusTemplate;
switch(template) {
2018-11-05 01:48:58 +00:00
case 'image':
2018-12-03 20:23:22 +00:00
case 'photo':
2018-12-05 02:49:15 +00:00
pixelfed.presenter.show.image(container, media, this.status);
2018-11-05 01:48:58 +00:00
break;
case 'album':
2018-12-03 20:23:22 +00:00
case 'photo:album':
2018-11-25 05:36:17 +00:00
pixelfed.presenter.show.imageAlbum(container, media, this.status);
2018-11-05 01:48:58 +00:00
break;
case 'video':
2018-12-05 02:49:15 +00:00
pixelfed.presenter.show.video(container, media, this.status);
2018-11-05 01:48:58 +00:00
break;
2018-12-03 20:23:22 +00:00
case 'video:album':
case 'photo:video:album':
$('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('We cannot load this post properly. We\'re working on a fix!');
return;
break;
2018-11-05 01:48:58 +00:00
default:
$('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occured, cannot fetch media. Please try again later.');
break;
}
if(container.children().length == 0) {
$('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occured, cannot fetch media. Please try again later.');
return;
}
2018-11-13 19:47:43 +00:00
pixelfed.readmore();
2018-11-05 01:48:58 +00:00
$('.postPresenterLoader').addClass('d-none');
$('.postPresenterContainer').removeClass('d-none');
2018-11-11 03:17:02 +00:00
},
2018-12-03 20:23:22 +00:00
likeStatus(event) {
if($('body').hasClass('loggedIn') == false) {
return;
}
axios.post('/i/like', {
item: this.status.id
}).then(res => {
this.status.favourites_count = res.data.count;
if(this.reactions.liked == true) {
this.reactions.liked = false;
} else {
this.reactions.liked = true;
}
}).catch(err => {
swal('Error', 'Something went wrong, please try again later.', 'error');
});
},
shareStatus() {
if($('body').hasClass('loggedIn') == false) {
return;
}
axios.post('/i/share', {
item: this.status.id
}).then(res => {
this.status.reblogs_count = res.data.count;
if(this.reactions.shared == true) {
this.reactions.shared = false;
} else {
this.reactions.shared = true;
}
}).catch(err => {
swal('Error', 'Something went wrong, please try again later.', 'error');
});
},
bookmarkStatus() {
if($('body').hasClass('loggedIn') == false) {
return;
}
axios.post('/i/bookmark', {
item: this.status.id
}).then(res => {
if(this.reactions.bookmarked == true) {
this.reactions.bookmarked = false;
} else {
this.reactions.bookmarked = true;
}
}).catch(err => {
swal('Error', 'Something went wrong, please try again later.', 'error');
});
},
muteProfile() {
if($('body').hasClass('loggedIn') == false) {
return;
}
axios.post('/i/mute', {
type: 'user',
item: this.status.account.id
}).then(res => {
swal('Success', 'You have successfully muted ' + this.status.account.acct, 'success');
}).catch(err => {
swal('Error', 'Something went wrong. Please try again later.', 'error');
});
},
blockProfile() {
if($('body').hasClass('loggedIn') == false) {
return;
}
axios.post('/i/block', {
type: 'user',
item: this.status.account.id
}).then(res => {
swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
}).catch(err => {
swal('Error', 'Something went wrong. Please try again later.', 'error');
});
},
deletePost() {
if($('body').hasClass('loggedIn') == false) {
return;
}
axios.post('/i/delete', {
type: 'status',
item: this.status.id
}).then(res => {
swal('Success', 'You have successfully deleted this post', 'success');
}).catch(err => {
swal('Error', 'Something went wrong. Please try again later.', 'error');
});
}
2018-11-05 01:48:58 +00:00
}
}
</script>