2019-04-22 05:07:48 +00:00
|
|
|
<template>
|
2019-12-24 06:46:29 +00:00
|
|
|
<div>
|
|
|
|
<transition name="fade">
|
2019-07-21 05:29:53 +00:00
|
|
|
<div class="card notification-card shadow-none border">
|
2021-06-02 03:01:00 +00:00
|
|
|
<div v-if="loading" class="card-body loader text-center" style="height: 240px;">
|
2019-04-22 05:07:48 +00:00
|
|
|
<div class="spinner-border" role="status">
|
|
|
|
<span class="sr-only">Loading...</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-02 03:01:00 +00:00
|
|
|
<div v-if="!loading && notifications.length > 0" class="card-body px-0 py-0 contents" style="height: 240px; overflow-y: scroll;">
|
2020-04-28 03:23:13 +00:00
|
|
|
<div v-if="profile.locked" class="media align-items-center mt-n2 px-3 py-2 border-bottom border-lighter bg-light cursor-pointer" @click="redirect('/account/follow-requests')">
|
|
|
|
<div class="media-body font-weight-light pt-2 small d-flex align-items-center justify-content-between">
|
|
|
|
<p class="mb-0 text-lighter"><i class="fas fa-cog text-light"></i></p>
|
2021-12-15 05:16:13 +00:00
|
|
|
<p class="text-center pt-1 mb-1 text-dark font-weight-bold"><strong>{{ followRequests && followRequests.hasOwnProperty('count') ? followRequests.count : 0 }}</strong> Follow Requests</p>
|
2020-04-28 03:23:13 +00:00
|
|
|
<p class="mb-0 text-lighter"><i class="fas fa-chevron-right"></i></p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-07-21 05:29:53 +00:00
|
|
|
<div v-if="notifications.length > 0" class="media align-items-center px-3 py-2 border-bottom border-light" v-for="(n, index) in notifications">
|
2019-12-05 06:33:58 +00:00
|
|
|
<img class="mr-2 rounded-circle" style="border:1px solid #ccc" :src="n.account.avatar" alt="" width="32px" height="32px" onerror="this.onerror=null;this.src='/storage/avatars/default.png';">
|
2019-04-22 05:07:48 +00:00
|
|
|
<div class="media-body font-weight-light small">
|
|
|
|
<div v-if="n.type == 'favourite'">
|
|
|
|
<p class="my-0">
|
2021-06-08 07:29:44 +00:00
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> liked your
|
2021-07-25 08:14:41 +00:00
|
|
|
<span v-if="n.status && n.status.hasOwnProperty('media_attachments')">
|
2021-06-08 07:29:44 +00:00
|
|
|
<a class="font-weight-bold" v-bind:href="getPostUrl(n.status)" :id="'fvn-' + n.id">post</a>.
|
2020-05-29 05:27:27 +00:00
|
|
|
<b-popover :target="'fvn-' + n.id" title="" triggers="hover" placement="top" boundary="window">
|
2020-06-19 05:04:40 +00:00
|
|
|
<img :src="notificationPreview(n)" width="100px" height="100px" style="object-fit: cover;">
|
2020-05-29 05:27:27 +00:00
|
|
|
</b-popover>
|
|
|
|
</span>
|
|
|
|
<span v-else>
|
2021-06-08 07:29:44 +00:00
|
|
|
<a class="font-weight-bold" v-bind:href="getPostUrl(n.status)">post</a>.
|
2020-05-29 05:27:27 +00:00
|
|
|
</span>
|
2019-04-22 05:07:48 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="n.type == 'comment'">
|
|
|
|
<p class="my-0">
|
2021-06-08 07:29:44 +00:00
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> commented on your <a class="font-weight-bold" v-bind:href="getPostUrl(n.status)">post</a>.
|
2019-04-22 05:07:48 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2021-08-31 07:30:21 +00:00
|
|
|
<div v-else-if="n.type == 'group:comment'">
|
|
|
|
<p class="my-0">
|
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> commented on your <a class="font-weight-bold" v-bind:href="n.group_post_url">group post</a>.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="n.type == 'story:react'">
|
|
|
|
<p class="my-0">
|
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> reacted to your <a class="font-weight-bold" v-bind:href="'/account/direct/t/'+n.account.id">story</a>.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="n.type == 'story:comment'">
|
|
|
|
<p class="my-0">
|
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> commented on your <a class="font-weight-bold" v-bind:href="'/account/direct/t/'+n.account.id">story</a>.
|
|
|
|
</p>
|
|
|
|
</div>
|
2019-04-22 05:07:48 +00:00
|
|
|
<div v-else-if="n.type == 'mention'">
|
|
|
|
<p class="my-0">
|
2021-06-08 07:29:44 +00:00
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> <a class="font-weight-bold" v-bind:href="mentionUrl(n.status)">mentioned</a> you.
|
2019-04-22 05:07:48 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="n.type == 'follow'">
|
|
|
|
<p class="my-0">
|
2021-06-08 07:29:44 +00:00
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> followed you.
|
2019-04-22 05:07:48 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="n.type == 'share'">
|
|
|
|
<p class="my-0">
|
2021-06-08 07:29:44 +00:00
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> shared your <a class="font-weight-bold" v-bind:href="getPostUrl(n.status)">post</a>.
|
2019-04-22 05:07:48 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2020-02-22 04:00:00 +00:00
|
|
|
<div v-else-if="n.type == 'modlog'">
|
|
|
|
<p class="my-0">
|
2021-06-08 07:29:44 +00:00
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{truncate(n.account.username)}}</a> updated a <a class="font-weight-bold" v-bind:href="n.modlog.url">modlog</a>.
|
2020-02-22 04:00:00 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2020-07-14 23:07:04 +00:00
|
|
|
<div v-else-if="n.type == 'tagged'">
|
|
|
|
<p class="my-0">
|
2021-06-08 07:29:44 +00:00
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> tagged you in a <a class="font-weight-bold" v-bind:href="n.tagged.post_url">post</a>.
|
2020-07-14 23:07:04 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2020-11-18 21:19:02 +00:00
|
|
|
<div v-else-if="n.type == 'direct'">
|
|
|
|
<p class="my-0">
|
2021-06-08 07:29:44 +00:00
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> sent a <a class="font-weight-bold" v-bind:href="'/account/direct/t/'+n.account.id">dm</a>.
|
2020-11-18 21:19:02 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2021-12-15 05:16:13 +00:00
|
|
|
|
|
|
|
<div v-else-if="n.type == 'group.join.approved'">
|
|
|
|
<p class="my-0">
|
|
|
|
Your application to join the <a :href="n.group.url" class="font-weight-bold text-dark word-break" :title="n.group.name">{{truncate(n.group.name)}}</a> group was approved!
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-else-if="n.type == 'group.join.rejected'">
|
|
|
|
<p class="my-0">
|
|
|
|
Your application to join <a :href="n.group.url" class="font-weight-bold text-dark word-break" :title="n.group.name">{{truncate(n.group.name)}}</a> was rejected.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-else-if="n.type == 'group:invite'">
|
|
|
|
<p class="my-0">
|
|
|
|
<a :href="getProfileUrl(n.account)" class="font-weight-bold text-dark word-break" :title="n.account.username">{{n.account.local == false ? '@':''}}{{truncate(n.account.username)}}</a> invited you to join <a :href="n.group.url + '/invite/claim'" class="font-weight-bold text-dark word-break" :title="n.group.name">{{n.group.name}}</a>.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
2020-07-14 23:07:04 +00:00
|
|
|
<div v-else>
|
|
|
|
<p class="my-0">
|
|
|
|
We cannot display this notification at this time.
|
|
|
|
</p>
|
|
|
|
</div>
|
2019-04-22 05:07:48 +00:00
|
|
|
</div>
|
2019-07-21 05:29:53 +00:00
|
|
|
<div class="small text-muted font-weight-bold" :title="n.created_at">{{timeAgo(n.created_at)}}</div>
|
2019-04-22 05:07:48 +00:00
|
|
|
</div>
|
|
|
|
<div v-if="notifications.length">
|
|
|
|
<infinite-loading @infinite="infiniteNotifications">
|
|
|
|
<div slot="no-results" class="font-weight-bold"></div>
|
|
|
|
<div slot="no-more" class="font-weight-bold"></div>
|
|
|
|
</infinite-loading>
|
|
|
|
</div>
|
|
|
|
<div v-if="notifications.length == 0" class="text-lighter text-center py-3">
|
|
|
|
<p class="mb-0"><i class="fas fa-inbox fa-3x"></i></p>
|
|
|
|
<p class="mb-0 small font-weight-bold">0 Notifications!</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-02 03:01:00 +00:00
|
|
|
<div v-if="!loading && !notifications.length" class="card-body px-0 py-0" style="height: 240px;">
|
2021-05-27 02:29:33 +00:00
|
|
|
<div class="text-lighter text-center py-3">
|
|
|
|
<p class="mb-0"><i class="fas fa-inbox fa-3x"></i></p>
|
|
|
|
<p class="mb-0 small font-weight-bold">No notifications yet</p>
|
2021-07-25 09:33:47 +00:00
|
|
|
<p v-if="showRefresh && !attemptedRefresh" class="mt-2 small font-weight-bold text-primary cursor-pointer" @click="refreshNotifications"><i class="fas fa-redo"></i> Refresh</p>
|
2021-05-27 02:29:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-04-22 05:07:48 +00:00
|
|
|
</div>
|
2019-12-24 06:46:29 +00:00
|
|
|
</transition>
|
|
|
|
</div>
|
2019-04-22 05:07:48 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<style type="text/css" scoped></style>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2021-06-02 03:01:00 +00:00
|
|
|
loading: true,
|
2019-04-22 05:07:48 +00:00
|
|
|
notifications: {},
|
2019-05-05 19:23:34 +00:00
|
|
|
notificationCursor: 2,
|
|
|
|
notificationMaxId: 0,
|
2020-04-28 03:23:13 +00:00
|
|
|
profile: {
|
|
|
|
locked: false
|
|
|
|
},
|
2021-07-25 09:33:47 +00:00
|
|
|
followRequests: null,
|
|
|
|
showRefresh: false,
|
|
|
|
attemptedRefresh: false
|
2019-04-22 05:07:48 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2020-04-28 03:23:13 +00:00
|
|
|
let self = this;
|
2019-06-03 19:15:38 +00:00
|
|
|
this.fetchNotifications();
|
2020-04-28 03:23:13 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
self.profile = window._sharedData.curUser;
|
|
|
|
self.fetchFollowRequests();
|
2021-07-23 15:47:14 +00:00
|
|
|
}, 1500);
|
2019-04-22 05:07:48 +00:00
|
|
|
},
|
|
|
|
|
2019-04-23 03:50:06 +00:00
|
|
|
updated() {
|
|
|
|
},
|
|
|
|
|
2019-04-22 05:07:48 +00:00
|
|
|
methods: {
|
|
|
|
fetchNotifications() {
|
2021-12-15 05:16:13 +00:00
|
|
|
axios.get('/api/v1/notifications?pg=true')
|
2019-04-22 05:07:48 +00:00
|
|
|
.then(res => {
|
2021-06-18 11:29:37 +00:00
|
|
|
let data = res.data.filter(n => {
|
2021-07-09 04:20:28 +00:00
|
|
|
if(n.type == 'share' && !n.status) {
|
2021-06-18 11:29:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-09 04:20:28 +00:00
|
|
|
if(n.type == 'comment' && !n.status) {
|
2021-06-18 11:29:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-09 04:20:28 +00:00
|
|
|
if(n.type == 'mention' && !n.status) {
|
2021-06-18 11:29:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-25 08:14:41 +00:00
|
|
|
if(n.type == 'favourite' && !n.status) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(n.type == 'follow' && !n.account) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-18 11:29:37 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
let ids = data.map(n => n.id);
|
2019-07-21 05:29:53 +00:00
|
|
|
this.notificationMaxId = Math.min(...ids);
|
2019-04-22 05:07:48 +00:00
|
|
|
this.notifications = data;
|
2021-06-02 03:01:00 +00:00
|
|
|
this.loading = false;
|
2021-07-25 09:33:47 +00:00
|
|
|
if(data.length == 0 && !this.attemptedRefresh) {
|
|
|
|
this.showRefresh = true;
|
|
|
|
}
|
2019-07-21 05:29:53 +00:00
|
|
|
//this.notificationPoll();
|
2019-04-22 05:07:48 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
infiniteNotifications($state) {
|
2019-07-21 05:29:53 +00:00
|
|
|
if(this.notificationCursor > 5) {
|
2019-04-22 05:07:48 +00:00
|
|
|
$state.complete();
|
|
|
|
return;
|
|
|
|
}
|
2019-09-16 00:06:04 +00:00
|
|
|
axios.get('/api/pixelfed/v1/notifications', {
|
2019-04-22 05:07:48 +00:00
|
|
|
params: {
|
2021-07-23 15:47:14 +00:00
|
|
|
max_id: this.notificationMaxId
|
2019-04-22 05:07:48 +00:00
|
|
|
}
|
|
|
|
}).then(res => {
|
|
|
|
if(res.data.length) {
|
|
|
|
let data = res.data.filter(n => {
|
2021-07-09 04:20:28 +00:00
|
|
|
if(n.type == 'share' && !n.status) {
|
2019-04-22 05:07:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-09 04:20:28 +00:00
|
|
|
if(n.type == 'comment' && !n.status) {
|
2021-06-18 11:29:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-09 04:20:28 +00:00
|
|
|
if(n.type == 'mention' && !n.status) {
|
2021-06-18 11:29:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-25 08:14:41 +00:00
|
|
|
if(n.type == 'favourite' && !n.status) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(n.type == 'follow' && !n.account) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-21 05:29:53 +00:00
|
|
|
if(_.find(this.notifications, {id: n.id})) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-22 05:07:48 +00:00
|
|
|
return true;
|
|
|
|
});
|
2021-06-18 11:29:37 +00:00
|
|
|
let ids = data.map(n => n.id);
|
|
|
|
this.notificationMaxId = Math.min(...ids);
|
2019-04-22 05:07:48 +00:00
|
|
|
this.notifications.push(...data);
|
|
|
|
this.notificationCursor++;
|
|
|
|
$state.loaded();
|
|
|
|
} else {
|
|
|
|
$state.complete();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2019-04-23 03:50:06 +00:00
|
|
|
|
|
|
|
truncate(text) {
|
|
|
|
if(text.length <= 15) {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
return text.slice(0,15) + '...'
|
2019-05-01 04:37:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
timeAgo(ts) {
|
2020-04-28 03:23:13 +00:00
|
|
|
return window.App.util.format.timeAgo(ts);
|
2019-05-01 04:37:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
mentionUrl(status) {
|
|
|
|
let username = status.account.username;
|
|
|
|
let id = status.id;
|
|
|
|
return '/p/' + username + '/' + id;
|
2019-05-05 19:23:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
notificationPoll() {
|
|
|
|
let interval = this.notifications.length > 5 ? 15000 : 120000;
|
|
|
|
let self = this;
|
|
|
|
setInterval(function() {
|
2019-09-16 00:06:04 +00:00
|
|
|
axios.get('/api/pixelfed/v1/notifications')
|
2019-05-05 19:23:34 +00:00
|
|
|
.then(res => {
|
|
|
|
let data = res.data.filter(n => {
|
|
|
|
if(n.type == 'share' || self.notificationMaxId >= n.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
if(data.length) {
|
|
|
|
let ids = data.map(n => n.id);
|
|
|
|
self.notificationMaxId = Math.max(...ids);
|
|
|
|
|
|
|
|
self.notifications.unshift(...data);
|
|
|
|
let beep = new Audio('/static/beep.mp3');
|
|
|
|
beep.volume = 0.7;
|
|
|
|
beep.play();
|
|
|
|
$('.notification-card .far.fa-bell').addClass('fas text-danger').removeClass('far text-muted');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, interval);
|
2020-02-22 04:00:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
refreshNotifications() {
|
|
|
|
let self = this;
|
|
|
|
axios.get('/api/pixelfed/v1/notifications')
|
|
|
|
.then(res => {
|
|
|
|
let data = res.data.filter(n => {
|
|
|
|
if(n.type == 'share' || self.notificationMaxId >= n.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
if(data.length > 0) {
|
|
|
|
let ids = data.map(n => n.id);
|
|
|
|
let max = Math.max(ids);
|
|
|
|
if(max <= self.notificationMaxId) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
self.notificationMaxId = max;
|
|
|
|
self.notifications = data;
|
|
|
|
let beep = new Audio('/static/beep.mp3');
|
|
|
|
beep.volume = 0.7;
|
|
|
|
beep.play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-04-28 03:23:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
fetchFollowRequests() {
|
|
|
|
if(window._sharedData.curUser.locked == true) {
|
|
|
|
axios.get('/account/follow-requests.json')
|
|
|
|
.then(res => {
|
|
|
|
this.followRequests = res.data;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
redirect(url) {
|
|
|
|
window.location.href = url;
|
2020-05-29 05:27:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
notificationPreview(n) {
|
2021-07-25 08:14:41 +00:00
|
|
|
if(!n.status || !n.status.hasOwnProperty('media_attachments') || !n.status.media_attachments.length) {
|
2020-05-29 05:27:27 +00:00
|
|
|
return '/storage/no-preview.png';
|
|
|
|
}
|
|
|
|
return n.status.media_attachments[0].preview_url;
|
2021-06-08 07:29:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getProfileUrl(account) {
|
|
|
|
if(account.local == true) {
|
|
|
|
return account.url;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '/i/web/profile/_/' + account.id;
|
|
|
|
},
|
|
|
|
|
|
|
|
getPostUrl(status) {
|
2021-07-25 08:14:41 +00:00
|
|
|
if(!status) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!status.hasOwnProperty('local') || status.local == true) {
|
2021-06-08 07:29:44 +00:00
|
|
|
return status.url;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '/i/web/post/_/' + status.account.id + '/' + status.id;
|
2021-07-25 09:33:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
refreshNotifications() {
|
2021-07-25 12:15:10 +00:00
|
|
|
this.loading = true;
|
2021-07-25 09:33:47 +00:00
|
|
|
this.attemptedRefresh = true;
|
|
|
|
this.fetchNotifications();
|
2019-04-23 03:50:06 +00:00
|
|
|
}
|
2019-04-22 05:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-27 02:29:33 +00:00
|
|
|
</script>
|