forked from AkkomaGang/akkoma-fe
Merge branch 'notifications' into 'develop'
Support qvitter api notifications Closes #129 See merge request pleroma/pleroma-fe!306
This commit is contained in:
commit
673f0fca3f
14 changed files with 275 additions and 190 deletions
|
@ -12,7 +12,7 @@
|
||||||
<div class="name-and-action">
|
<div class="name-and-action">
|
||||||
<span class="username" v-if="!!notification.action.user.name_html" :title="'@'+notification.action.user.screen_name" v-html="notification.action.user.name_html"></span>
|
<span class="username" v-if="!!notification.action.user.name_html" :title="'@'+notification.action.user.screen_name" v-html="notification.action.user.name_html"></span>
|
||||||
<span class="username" v-else :title="'@'+notification.action.user.screen_name">{{ notification.action.user.name }}</span>
|
<span class="username" v-else :title="'@'+notification.action.user.screen_name">{{ notification.action.user.name }}</span>
|
||||||
<span v-if="notification.type === 'favorite'">
|
<span v-if="notification.type === 'like'">
|
||||||
<i class="fa icon-star lit"></i>
|
<i class="fa icon-star lit"></i>
|
||||||
<small>{{$t('notifications.favorited_you')}}</small>
|
<small>{{$t('notifications.favorited_you')}}</small>
|
||||||
</span>
|
</span>
|
||||||
|
@ -25,12 +25,17 @@
|
||||||
<small>{{$t('notifications.followed_you')}}</small>
|
<small>{{$t('notifications.followed_you')}}</small>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<small class="timeago"><router-link :to="{ name: 'conversation', params: { id: notification.status.id } }"><timeago :since="notification.action.created_at" :auto-update="240"></timeago></router-link></small>
|
<small class="timeago"><router-link v-if="notification.status" :to="{ name: 'conversation', params: { id: notification.status.id } }"><timeago :since="notification.action.created_at" :auto-update="240"></timeago></router-link></small>
|
||||||
</span>
|
</span>
|
||||||
<div class="follow-text" v-if="notification.type === 'follow'">
|
<div class="follow-text" v-if="notification.type === 'follow'">
|
||||||
<router-link :to="{ name: 'user-profile', params: { id: notification.action.user.id } }">@{{notification.action.user.screen_name}}</router-link>
|
<router-link :to="{ name: 'user-profile', params: { id: notification.action.user.id } }">@{{notification.action.user.screen_name}}</router-link>
|
||||||
</div>
|
</div>
|
||||||
<status v-else class="faint" :compact="true" :statusoid="notification.status" :noHeading="true"></status>
|
<template v-else>
|
||||||
|
<status v-if="notification.status" class="faint" :compact="true" :statusoid="notification.status" :noHeading="true"></status>
|
||||||
|
<div class="broken-favorite" v-else>
|
||||||
|
{{$t('notifications.broken_favorite')}}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
import Notification from '../notification/notification.vue'
|
import Notification from '../notification/notification.vue'
|
||||||
|
import notificationsFetcher from '../../services/notifications_fetcher/notifications_fetcher.service.js'
|
||||||
|
|
||||||
import { sortBy, take, filter } from 'lodash'
|
import { sortBy, filter } from 'lodash'
|
||||||
|
|
||||||
const Notifications = {
|
const Notifications = {
|
||||||
data () {
|
created () {
|
||||||
return {
|
const store = this.$store
|
||||||
visibleNotificationCount: 20
|
const credentials = store.state.users.currentUser.credentials
|
||||||
}
|
|
||||||
|
notificationsFetcher.startFetching({ store, credentials })
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
notifications () {
|
notifications () {
|
||||||
return this.$store.state.statuses.notifications
|
return this.$store.state.statuses.notifications.data
|
||||||
|
},
|
||||||
|
error () {
|
||||||
|
return this.$store.state.statuses.notifications.error
|
||||||
},
|
},
|
||||||
unseenNotifications () {
|
unseenNotifications () {
|
||||||
return filter(this.notifications, ({seen}) => !seen)
|
return filter(this.notifications, ({seen}) => !seen)
|
||||||
|
@ -19,7 +24,7 @@ const Notifications = {
|
||||||
// Don't know why, but sortBy([seen, -action.id]) doesn't work.
|
// Don't know why, but sortBy([seen, -action.id]) doesn't work.
|
||||||
let sortedNotifications = sortBy(this.notifications, ({action}) => -action.id)
|
let sortedNotifications = sortBy(this.notifications, ({action}) => -action.id)
|
||||||
sortedNotifications = sortBy(sortedNotifications, 'seen')
|
sortedNotifications = sortBy(sortedNotifications, 'seen')
|
||||||
return take(sortedNotifications, this.visibleNotificationCount)
|
return sortedNotifications
|
||||||
},
|
},
|
||||||
unseenCount () {
|
unseenCount () {
|
||||||
return this.unseenNotifications.length
|
return this.unseenNotifications.length
|
||||||
|
@ -40,6 +45,15 @@ const Notifications = {
|
||||||
methods: {
|
methods: {
|
||||||
markAsSeen () {
|
markAsSeen () {
|
||||||
this.$store.commit('markNotificationsAsSeen', this.visibleNotifications)
|
this.$store.commit('markNotificationsAsSeen', this.visibleNotifications)
|
||||||
|
},
|
||||||
|
fetchOlderNotifications () {
|
||||||
|
const store = this.$store
|
||||||
|
const credentials = store.state.users.currentUser.credentials
|
||||||
|
notificationsFetcher.fetchAndUpdate({
|
||||||
|
store,
|
||||||
|
credentials,
|
||||||
|
older: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
// a bit of a hack to allow scrolling below notifications
|
// a bit of a hack to allow scrolling below notifications
|
||||||
padding-bottom: 15em;
|
padding-bottom: 15em;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
.panel {
|
.panel {
|
||||||
background: $fallback--bg;
|
background: $fallback--bg;
|
||||||
background: var(--bg, $fallback--bg)
|
background: var(--bg, $fallback--bg)
|
||||||
|
@ -22,6 +26,8 @@
|
||||||
background: var(--btn, $fallback--btn);
|
background: var(--btn, $fallback--btn);
|
||||||
color: $fallback--fg;
|
color: $fallback--fg;
|
||||||
color: var(--fg, $fallback--fg);
|
color: var(--fg, $fallback--fg);
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
.read-button {
|
.read-button {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0.7em;
|
right: 0.7em;
|
||||||
|
@ -44,6 +50,19 @@
|
||||||
line-height: 1.3em;
|
line-height: 1.3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loadmore-error {
|
||||||
|
position: absolute;
|
||||||
|
right: 0.6em;
|
||||||
|
font-size: 14px;
|
||||||
|
min-width: 6em;
|
||||||
|
font-family: sans-serif;
|
||||||
|
text-align: center;
|
||||||
|
padding: 0 0.25em 0 0.25em;
|
||||||
|
margin: 0;
|
||||||
|
color: $fallback--fg;
|
||||||
|
color: var(--fg, $fallback--fg);
|
||||||
|
}
|
||||||
|
|
||||||
.unseen {
|
.unseen {
|
||||||
box-shadow: inset 4px 0 0 var(--cRed, $fallback--cRed);
|
box-shadow: inset 4px 0 0 var(--cRed, $fallback--cRed);
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
|
@ -56,6 +75,16 @@
|
||||||
border-bottom: 1px solid;
|
border-bottom: 1px solid;
|
||||||
border-bottom-color: inherit;
|
border-bottom-color: inherit;
|
||||||
|
|
||||||
|
.broken-favorite {
|
||||||
|
border-radius: $fallback--tooltipRadius;
|
||||||
|
border-radius: var(--tooltipRadius, $fallback--tooltipRadius);
|
||||||
|
color: $fallback--faint;
|
||||||
|
color: var(--faint, $fallback--faint);
|
||||||
|
background-color: $fallback--cAlertRed;
|
||||||
|
background-color: var(--cAlertRed, $fallback--cAlertRed);
|
||||||
|
padding: 2px .5em
|
||||||
|
}
|
||||||
|
|
||||||
.avatar-compact {
|
.avatar-compact {
|
||||||
width: 32px;
|
width: 32px;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
|
@ -69,7 +98,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover .animated.avatar {
|
&:hover .animated.avatar-compact {
|
||||||
canvas {
|
canvas {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
@ -145,6 +174,13 @@
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
vertical-align: middle;
|
||||||
|
object-fit: contain
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.timeago {
|
.timeago {
|
||||||
float: right;
|
float: right;
|
||||||
|
@ -194,15 +230,4 @@
|
||||||
margin-bottom: 0.3em;
|
margin-bottom: 0.3em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ugly as heck
|
|
||||||
&:last-child {
|
|
||||||
border-bottom: none;
|
|
||||||
border-radius: 0 0 $fallback--panelRadius $fallback--panelRadius;
|
|
||||||
border-radius: 0 0 var(--panelRadius, $fallback--panelRadius) var(--panelRadius, $fallback--panelRadius);
|
|
||||||
.status-el {
|
|
||||||
border-radius: 0 0 $fallback--panelRadius $fallback--panelRadius;
|
|
||||||
border-radius: 0 0 var(--panelRadius, $fallback--panelRadius) var(--panelRadius, $fallback--panelRadius);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<span class="unseen-count" v-if="unseenCount">{{unseenCount}}</span>
|
<span class="unseen-count" v-if="unseenCount">{{unseenCount}}</span>
|
||||||
{{$t('notifications.notifications')}}
|
<div class="title"> {{$t('notifications.notifications')}}</div>
|
||||||
|
<div @click.prevent class="loadmore-error alert error" v-if="error">
|
||||||
|
{{$t('timeline.error_fetching')}}
|
||||||
|
</div>
|
||||||
<button v-if="unseenCount" @click.prevent="markAsSeen" class="read-button">{{$t('notifications.read')}}</button>
|
<button v-if="unseenCount" @click.prevent="markAsSeen" class="read-button">{{$t('notifications.read')}}</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
|
@ -11,6 +14,12 @@
|
||||||
<notification :notification="notification"></notification>
|
<notification :notification="notification"></notification>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="panel-footer">
|
||||||
|
<a href="#" v-on:click.prevent='fetchOlderNotifications()' v-if="!notifications.loading">
|
||||||
|
<div class="new-status-notification text-center panel-footer">{{$t('notifications.load_older')}}</div>
|
||||||
|
</a>
|
||||||
|
<div class="new-status-notification text-center panel-footer" v-else>...</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -357,7 +357,9 @@ const en = {
|
||||||
read: 'Read!',
|
read: 'Read!',
|
||||||
followed_you: 'followed you',
|
followed_you: 'followed you',
|
||||||
favorited_you: 'favorited your status',
|
favorited_you: 'favorited your status',
|
||||||
repeated_you: 'repeated your status'
|
repeated_you: 'repeated your status',
|
||||||
|
broken_favorite: 'Unknown status, searching for it...',
|
||||||
|
load_older: 'Load older notifications'
|
||||||
},
|
},
|
||||||
login: {
|
login: {
|
||||||
login: 'Log in',
|
login: 'Log in',
|
||||||
|
@ -1694,7 +1696,9 @@ const ru = {
|
||||||
read: 'Прочесть',
|
read: 'Прочесть',
|
||||||
followed_you: 'начал(а) читать вас',
|
followed_you: 'начал(а) читать вас',
|
||||||
favorited_you: 'нравится ваш статус',
|
favorited_you: 'нравится ваш статус',
|
||||||
repeated_you: 'повторил(а) ваш статус'
|
repeated_you: 'повторил(а) ваш статус',
|
||||||
|
broken_favorite: 'Неизвестный статус, ищем...',
|
||||||
|
load_older: 'Загрузить старые уведомления'
|
||||||
},
|
},
|
||||||
login: {
|
login: {
|
||||||
login: 'Войти',
|
login: 'Войти',
|
||||||
|
|
|
@ -60,7 +60,8 @@ const persistedStateOptions = {
|
||||||
'config.loopVideoSilentOnly',
|
'config.loopVideoSilentOnly',
|
||||||
'config.pauseOnUnfocused',
|
'config.pauseOnUnfocused',
|
||||||
'config.stopGifs',
|
'config.stopGifs',
|
||||||
'users.lastLoginName'
|
'users.lastLoginName',
|
||||||
|
'statuses.notifications.maxSavedId'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,9 @@ const api = {
|
||||||
store.commit('addFetcher', {timeline, fetcher})
|
store.commit('addFetcher', {timeline, fetcher})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
fetchOldPost (store, { postId }) {
|
||||||
|
store.state.backendInteractor.fetchOldPost({ store, postId })
|
||||||
|
},
|
||||||
stopFetching (store, timeline) {
|
stopFetching (store, timeline) {
|
||||||
const fetcher = store.state.fetchers[timeline]
|
const fetcher = store.state.fetchers[timeline]
|
||||||
window.clearInterval(fetcher)
|
window.clearInterval(fetcher)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash'
|
import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash'
|
||||||
|
import { set } from 'vue'
|
||||||
import apiService from '../services/api/api.service.js'
|
import apiService from '../services/api/api.service.js'
|
||||||
// import parse from '../services/status_parser/status_parser.js'
|
// import parse from '../services/status_parser/status_parser.js'
|
||||||
|
|
||||||
|
@ -22,13 +23,22 @@ export const defaultState = {
|
||||||
allStatuses: [],
|
allStatuses: [],
|
||||||
allStatusesObject: {},
|
allStatusesObject: {},
|
||||||
maxId: 0,
|
maxId: 0,
|
||||||
notifications: [],
|
notifications: {
|
||||||
|
desktopNotificationSilence: true,
|
||||||
|
maxId: 0,
|
||||||
|
maxSavedId: 0,
|
||||||
|
minId: Number.POSITIVE_INFINITY,
|
||||||
|
data: [],
|
||||||
|
error: false,
|
||||||
|
brokenFavorites: {}
|
||||||
|
},
|
||||||
favorites: new Set(),
|
favorites: new Set(),
|
||||||
error: false,
|
error: false,
|
||||||
timelines: {
|
timelines: {
|
||||||
mentions: emptyTl(),
|
mentions: emptyTl(),
|
||||||
public: emptyTl(),
|
public: emptyTl(),
|
||||||
user: emptyTl(),
|
user: emptyTl(),
|
||||||
|
own: emptyTl(),
|
||||||
publicAndExternal: emptyTl(),
|
publicAndExternal: emptyTl(),
|
||||||
friends: emptyTl(),
|
friends: emptyTl(),
|
||||||
tag: emptyTl()
|
tag: emptyTl()
|
||||||
|
@ -134,11 +144,13 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
const result = mergeOrAdd(allStatuses, allStatusesObject, status)
|
const result = mergeOrAdd(allStatuses, allStatusesObject, status)
|
||||||
status = result.item
|
status = result.item
|
||||||
|
|
||||||
if (result.new) {
|
const brokenFavorites = state.notifications.brokenFavorites[status.id] || []
|
||||||
if (statusType(status) === 'retweet' && status.retweeted_status.user.id === user.id) {
|
brokenFavorites.forEach((fav) => {
|
||||||
addNotification({ type: 'repeat', status: status, action: status })
|
fav.status = status
|
||||||
}
|
})
|
||||||
|
delete state.notifications.brokenFavorites[status.id]
|
||||||
|
|
||||||
|
if (result.new) {
|
||||||
// We are mentioned in a post
|
// We are mentioned in a post
|
||||||
if (statusType(status) === 'status' && find(status.attentions, { id: user.id })) {
|
if (statusType(status) === 'status' && find(status.attentions, { id: user.id })) {
|
||||||
const mentions = state.timelines.mentions
|
const mentions = state.timelines.mentions
|
||||||
|
@ -150,10 +162,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
|
|
||||||
sortTimeline(mentions)
|
sortTimeline(mentions)
|
||||||
}
|
}
|
||||||
// Don't add notification for self-mention
|
|
||||||
if (status.user.id !== user.id) {
|
|
||||||
addNotification({ type: 'mention', status, action: status })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,33 +184,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
const addNotification = ({type, status, action}) => {
|
const favoriteStatus = (favorite, counter) => {
|
||||||
// Only add a new notification if we don't have one for the same action
|
|
||||||
if (!find(state.notifications, (oldNotification) => oldNotification.action.id === action.id)) {
|
|
||||||
state.notifications.push({ type, status, action, seen: false })
|
|
||||||
|
|
||||||
if ('Notification' in window && window.Notification.permission === 'granted') {
|
|
||||||
const title = action.user.name
|
|
||||||
const result = {}
|
|
||||||
result.icon = action.user.profile_image_url
|
|
||||||
result.body = action.text // there's a problem that it doesn't put a space before links tho
|
|
||||||
|
|
||||||
// Shows first attached non-nsfw image, if any. Should add configuration for this somehow...
|
|
||||||
if (action.attachments && action.attachments.length > 0 && !action.nsfw &&
|
|
||||||
action.attachments[0].mimetype.startsWith('image/')) {
|
|
||||||
result.image = action.attachments[0].url
|
|
||||||
}
|
|
||||||
|
|
||||||
let notification = new window.Notification(title, result)
|
|
||||||
|
|
||||||
// Chrome is known for not closing notifications automatically
|
|
||||||
// according to MDN, anyway.
|
|
||||||
setTimeout(notification.close.bind(notification), 5000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const favoriteStatus = (favorite) => {
|
|
||||||
const status = find(allStatuses, { id: toInteger(favorite.in_reply_to_status_id) })
|
const status = find(allStatuses, { id: toInteger(favorite.in_reply_to_status_id) })
|
||||||
if (status) {
|
if (status) {
|
||||||
status.fave_num += 1
|
status.fave_num += 1
|
||||||
|
@ -211,11 +193,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
if (favorite.user.id === user.id) {
|
if (favorite.user.id === user.id) {
|
||||||
status.favorited = true
|
status.favorited = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a notification if the user's status is favorited
|
|
||||||
if (status.user.id === user.id) {
|
|
||||||
addNotification({type: 'favorite', status, action: favorite})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
@ -253,13 +230,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
favoriteStatus(favorite)
|
favoriteStatus(favorite)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'follow': (status) => {
|
|
||||||
let re = new RegExp(`started following ${user.name} \\(${user.statusnet_profile_url}\\)`)
|
|
||||||
let repleroma = new RegExp(`started following ${user.screen_name}$`)
|
|
||||||
if (status.text.match(re) || status.text.match(repleroma)) {
|
|
||||||
addNotification({ type: 'follow', status: status, action: status })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'deletion': (deletion) => {
|
'deletion': (deletion) => {
|
||||||
const uri = deletion.uri
|
const uri = deletion.uri
|
||||||
|
|
||||||
|
@ -269,7 +239,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(state.notifications, ({action: {id}}) => id === status.id)
|
remove(state.notifications.data, ({action: {id}}) => id === status.id)
|
||||||
|
|
||||||
remove(allStatuses, { uri })
|
remove(allStatuses, { uri })
|
||||||
if (timeline) {
|
if (timeline) {
|
||||||
|
@ -298,8 +268,69 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addNewNotifications = (state, { dispatch, notifications, older }) => {
|
||||||
|
const allStatuses = state.allStatuses
|
||||||
|
const allStatusesObject = state.allStatusesObject
|
||||||
|
each(notifications, (notification) => {
|
||||||
|
const result = mergeOrAdd(allStatuses, allStatusesObject, notification.notice)
|
||||||
|
const action = result.item
|
||||||
|
// Only add a new notification if we don't have one for the same action
|
||||||
|
if (!find(state.notifications.data, (oldNotification) => oldNotification.action.id === action.id)) {
|
||||||
|
state.notifications.maxId = Math.max(notification.id, state.notifications.maxId)
|
||||||
|
state.notifications.minId = Math.min(notification.id, state.notifications.minId)
|
||||||
|
|
||||||
|
const fresh = !older && !notification.is_seen && notification.id > state.notifications.maxSavedId
|
||||||
|
const status = notification.ntype === 'like'
|
||||||
|
? find(allStatuses, { id: action.in_reply_to_status_id })
|
||||||
|
: action
|
||||||
|
|
||||||
|
const result = {
|
||||||
|
type: notification.ntype,
|
||||||
|
status,
|
||||||
|
action,
|
||||||
|
// Always assume older notifications as seen
|
||||||
|
seen: !fresh
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notification.ntype === 'like' && !status) {
|
||||||
|
let broken = state.notifications.brokenFavorites[action.in_reply_to_status_id]
|
||||||
|
if (broken) {
|
||||||
|
broken.push(result)
|
||||||
|
} else {
|
||||||
|
dispatch('fetchOldPost', { postId: action.in_reply_to_status_id })
|
||||||
|
broken = [ result ]
|
||||||
|
state.notifications.brokenFavorites[action.in_reply_to_status_id] = broken
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state.notifications.data.push(result)
|
||||||
|
|
||||||
|
if ('Notification' in window && window.Notification.permission === 'granted') {
|
||||||
|
const title = action.user.name
|
||||||
|
const result = {}
|
||||||
|
result.icon = action.user.profile_image_url
|
||||||
|
result.body = action.text // there's a problem that it doesn't put a space before links tho
|
||||||
|
|
||||||
|
// Shows first attached non-nsfw image, if any. Should add configuration for this somehow...
|
||||||
|
if (action.attachments && action.attachments.length > 0 && !action.nsfw &&
|
||||||
|
action.attachments[0].mimetype.startsWith('image/')) {
|
||||||
|
result.image = action.attachments[0].url
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fresh && !state.notifications.desktopNotificationSilence) {
|
||||||
|
let notification = new window.Notification(title, result)
|
||||||
|
// Chrome is known for not closing notifications automatically
|
||||||
|
// according to MDN, anyway.
|
||||||
|
setTimeout(notification.close.bind(notification), 5000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
addNewStatuses,
|
addNewStatuses,
|
||||||
|
addNewNotifications,
|
||||||
showNewStatuses (state, { timeline }) {
|
showNewStatuses (state, { timeline }) {
|
||||||
const oldTimeline = (state.timelines[timeline])
|
const oldTimeline = (state.timelines[timeline])
|
||||||
|
|
||||||
|
@ -334,6 +365,12 @@ export const mutations = {
|
||||||
setError (state, { value }) {
|
setError (state, { value }) {
|
||||||
state.error = value
|
state.error = value
|
||||||
},
|
},
|
||||||
|
setNotificationsError (state, { value }) {
|
||||||
|
state.notifications.error = value
|
||||||
|
},
|
||||||
|
setNotificationsSilence (state, { value }) {
|
||||||
|
state.notifications.desktopNotificationSilence = value
|
||||||
|
},
|
||||||
setProfileView (state, { v }) {
|
setProfileView (state, { v }) {
|
||||||
// load followers / friends only when needed
|
// load followers / friends only when needed
|
||||||
state.timelines['user'].viewing = v
|
state.timelines['user'].viewing = v
|
||||||
|
@ -345,6 +382,7 @@ export const mutations = {
|
||||||
state.timelines['user'].followers = followers
|
state.timelines['user'].followers = followers
|
||||||
},
|
},
|
||||||
markNotificationsAsSeen (state, notifications) {
|
markNotificationsAsSeen (state, notifications) {
|
||||||
|
set(state.notifications, 'maxSavedId', state.notifications.maxId)
|
||||||
each(notifications, (notification) => {
|
each(notifications, (notification) => {
|
||||||
notification.seen = true
|
notification.seen = true
|
||||||
})
|
})
|
||||||
|
@ -360,9 +398,18 @@ const statuses = {
|
||||||
addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false }) {
|
addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false }) {
|
||||||
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser })
|
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser })
|
||||||
},
|
},
|
||||||
|
addNewNotifications ({ rootState, commit, dispatch }, { notifications, older }) {
|
||||||
|
commit('addNewNotifications', { dispatch, notifications, older })
|
||||||
|
},
|
||||||
setError ({ rootState, commit }, { value }) {
|
setError ({ rootState, commit }, { value }) {
|
||||||
commit('setError', { value })
|
commit('setError', { value })
|
||||||
},
|
},
|
||||||
|
setNotificationsError ({ rootState, commit }, { value }) {
|
||||||
|
commit('setNotificationsError', { value })
|
||||||
|
},
|
||||||
|
setNotificationsSilence ({ rootState, commit }, { value }) {
|
||||||
|
commit('setNotificationsSilence', { value })
|
||||||
|
},
|
||||||
addFriends ({ rootState, commit }, { friends }) {
|
addFriends ({ rootState, commit }, { friends }) {
|
||||||
commit('addFriends', { friends })
|
commit('addFriends', { friends })
|
||||||
},
|
},
|
||||||
|
|
|
@ -107,6 +107,8 @@ const users = {
|
||||||
|
|
||||||
// Start getting fresh tweets.
|
// Start getting fresh tweets.
|
||||||
store.dispatch('startFetching', 'friends')
|
store.dispatch('startFetching', 'friends')
|
||||||
|
// Start getting our own posts, only really needed for mitigating broken favorites
|
||||||
|
store.dispatch('startFetching', ['own', user.id])
|
||||||
|
|
||||||
// Get user mutes and follower info
|
// Get user mutes and follower info
|
||||||
store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
|
store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
|
||||||
|
|
|
@ -27,6 +27,7 @@ const BANNER_UPDATE_URL = '/api/account/update_profile_banner.json'
|
||||||
const PROFILE_UPDATE_URL = '/api/account/update_profile.json'
|
const PROFILE_UPDATE_URL = '/api/account/update_profile.json'
|
||||||
const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json'
|
const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json'
|
||||||
const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json'
|
const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json'
|
||||||
|
const QVITTER_USER_NOTIFICATIONS_URL = '/api/qvitter/statuses/notifications.json'
|
||||||
const BLOCKING_URL = '/api/blocks/create.json'
|
const BLOCKING_URL = '/api/blocks/create.json'
|
||||||
const UNBLOCKING_URL = '/api/blocks/destroy.json'
|
const UNBLOCKING_URL = '/api/blocks/destroy.json'
|
||||||
const USER_URL = '/api/users/show.json'
|
const USER_URL = '/api/users/show.json'
|
||||||
|
@ -303,8 +304,12 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use
|
||||||
public: PUBLIC_TIMELINE_URL,
|
public: PUBLIC_TIMELINE_URL,
|
||||||
friends: FRIENDS_TIMELINE_URL,
|
friends: FRIENDS_TIMELINE_URL,
|
||||||
mentions: MENTIONS_URL,
|
mentions: MENTIONS_URL,
|
||||||
|
notifications: QVITTER_USER_NOTIFICATIONS_URL,
|
||||||
'publicAndExternal': PUBLIC_AND_EXTERNAL_TIMELINE_URL,
|
'publicAndExternal': PUBLIC_AND_EXTERNAL_TIMELINE_URL,
|
||||||
user: QVITTER_USER_TIMELINE_URL,
|
user: QVITTER_USER_TIMELINE_URL,
|
||||||
|
// separate timeline for own posts, so it won't break due to user timeline bugs
|
||||||
|
// really needed only for broken favorites
|
||||||
|
own: QVITTER_USER_TIMELINE_URL,
|
||||||
tag: TAG_TIMELINE_URL
|
tag: TAG_TIMELINE_URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,16 @@ const backendInteractorService = (credentials) => {
|
||||||
return timelineFetcherService.startFetching({timeline, store, credentials, userId})
|
return timelineFetcherService.startFetching({timeline, store, credentials, userId})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchOldPost = ({store, postId}) => {
|
||||||
|
return timelineFetcherService.fetchAndUpdate({
|
||||||
|
store,
|
||||||
|
credentials,
|
||||||
|
timeline: 'own',
|
||||||
|
older: true,
|
||||||
|
until: postId + 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const setUserMute = ({id, muted = true}) => {
|
const setUserMute = ({id, muted = true}) => {
|
||||||
return apiService.setUserMute({id, muted, credentials})
|
return apiService.setUserMute({id, muted, credentials})
|
||||||
}
|
}
|
||||||
|
@ -86,6 +96,7 @@ const backendInteractorService = (credentials) => {
|
||||||
fetchAllFollowing,
|
fetchAllFollowing,
|
||||||
verifyCredentials: apiService.verifyCredentials,
|
verifyCredentials: apiService.verifyCredentials,
|
||||||
startFetching,
|
startFetching,
|
||||||
|
fetchOldPost,
|
||||||
setUserMute,
|
setUserMute,
|
||||||
fetchMutes,
|
fetchMutes,
|
||||||
register,
|
register,
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
import apiService from '../api/api.service.js'
|
||||||
|
|
||||||
|
const update = ({store, notifications, older}) => {
|
||||||
|
store.dispatch('setNotificationsError', { value: false })
|
||||||
|
|
||||||
|
store.dispatch('addNewNotifications', { notifications, older })
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchAndUpdate = ({store, credentials, older = false}) => {
|
||||||
|
const args = { credentials }
|
||||||
|
const rootState = store.rootState || store.state
|
||||||
|
const timelineData = rootState.statuses.notifications
|
||||||
|
|
||||||
|
if (older) {
|
||||||
|
if (timelineData.minId !== Number.POSITIVE_INFINITY) {
|
||||||
|
args['until'] = timelineData.minId
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
args['since'] = timelineData.maxId
|
||||||
|
}
|
||||||
|
|
||||||
|
args['timeline'] = 'notifications'
|
||||||
|
|
||||||
|
return apiService.fetchTimeline(args)
|
||||||
|
.then((notifications) => {
|
||||||
|
update({store, notifications, older})
|
||||||
|
}, () => store.dispatch('setNotificationsError', { value: true }))
|
||||||
|
.catch(() => store.dispatch('setNotificationsError', { value: true }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const startFetching = ({credentials, store}) => {
|
||||||
|
fetchAndUpdate({ credentials, store })
|
||||||
|
const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
|
||||||
|
// Initially there's set flag to silence all desktop notifications so
|
||||||
|
// that there won't spam of them when user just opened up the FE we
|
||||||
|
// reset that flag after a while to show new notifications once again.
|
||||||
|
setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000)
|
||||||
|
return setInterval(boundFetchAndUpdate, 10000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const notificationsFetcher = {
|
||||||
|
fetchAndUpdate,
|
||||||
|
startFetching
|
||||||
|
}
|
||||||
|
|
||||||
|
export default notificationsFetcher
|
|
@ -14,13 +14,13 @@ const update = ({store, statuses, timeline, showImmediately}) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false, userId = false, tag = false}) => {
|
const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false, userId = false, tag = false, until}) => {
|
||||||
const args = { timeline, credentials }
|
const args = { timeline, credentials }
|
||||||
const rootState = store.rootState || store.state
|
const rootState = store.rootState || store.state
|
||||||
const timelineData = rootState.statuses.timelines[camelCase(timeline)]
|
const timelineData = rootState.statuses.timelines[camelCase(timeline)]
|
||||||
|
|
||||||
if (older) {
|
if (older) {
|
||||||
args['until'] = timelineData.minVisibleId
|
args['until'] = until || timelineData.minVisibleId
|
||||||
} else {
|
} else {
|
||||||
args['since'] = timelineData.maxId
|
args['since'] = timelineData.maxId
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,40 +286,6 @@ describe('The Statuses module', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('notifications', () => {
|
describe('notifications', () => {
|
||||||
it('adds a notfications for retweets if you are the retweetet', () => {
|
|
||||||
const user = { id: 1 }
|
|
||||||
const state = cloneDeep(defaultState)
|
|
||||||
const status = makeMockStatus({id: 1})
|
|
||||||
status.user = user
|
|
||||||
const retweet = makeMockStatus({id: 2, is_post_verb: false})
|
|
||||||
retweet.retweeted_status = status
|
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [retweet], user })
|
|
||||||
|
|
||||||
expect(state.notifications.length).to.eql(1)
|
|
||||||
expect(state.notifications[0].status).to.eql(retweet)
|
|
||||||
expect(state.notifications[0].action).to.eql(retweet)
|
|
||||||
expect(state.notifications[0].type).to.eql('repeat')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('adds a notification when you are mentioned', () => {
|
|
||||||
const user = { id: 1 }
|
|
||||||
const state = cloneDeep(defaultState)
|
|
||||||
const status = makeMockStatus({id: 1})
|
|
||||||
const mentionedStatus = makeMockStatus({id: 2})
|
|
||||||
mentionedStatus.attentions = [user]
|
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [status], user })
|
|
||||||
|
|
||||||
expect(state.notifications.length).to.eql(0)
|
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [mentionedStatus], user })
|
|
||||||
expect(state.notifications.length).to.eql(1)
|
|
||||||
expect(state.notifications[0].status).to.eql(mentionedStatus)
|
|
||||||
expect(state.notifications[0].action).to.eql(mentionedStatus)
|
|
||||||
expect(state.notifications[0].type).to.eql('mention')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('removes a notification when the notice gets removed', () => {
|
it('removes a notification when the notice gets removed', () => {
|
||||||
const user = { id: 1 }
|
const user = { id: 1 }
|
||||||
const state = cloneDeep(defaultState)
|
const state = cloneDeep(defaultState)
|
||||||
|
@ -335,92 +301,39 @@ describe('The Statuses module', () => {
|
||||||
deletion.uri = 'xxx'
|
deletion.uri = 'xxx'
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [status, otherStatus], user })
|
mutations.addNewStatuses(state, { statuses: [status, otherStatus], user })
|
||||||
|
mutations.addNewNotifications(
|
||||||
|
state,
|
||||||
|
{
|
||||||
|
notifications: [{
|
||||||
|
ntype: 'mention',
|
||||||
|
status: otherStatus,
|
||||||
|
notice: otherStatus,
|
||||||
|
is_seen: false
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
|
||||||
expect(state.notifications.length).to.eql(1)
|
expect(state.notifications.data.length).to.eql(1)
|
||||||
|
mutations.addNewNotifications(
|
||||||
|
state,
|
||||||
|
{
|
||||||
|
notifications: [{
|
||||||
|
ntype: 'mention',
|
||||||
|
status: mentionedStatus,
|
||||||
|
notice: mentionedStatus,
|
||||||
|
is_seen: false
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [mentionedStatus], user })
|
mutations.addNewStatuses(state, { statuses: [mentionedStatus], user })
|
||||||
expect(state.allStatuses.length).to.eql(3)
|
expect(state.allStatuses.length).to.eql(3)
|
||||||
expect(state.notifications.length).to.eql(2)
|
expect(state.notifications.data.length).to.eql(2)
|
||||||
expect(state.notifications[1].status).to.eql(mentionedStatus)
|
expect(state.notifications.data[1].status).to.eql(mentionedStatus)
|
||||||
expect(state.notifications[1].action).to.eql(mentionedStatus)
|
expect(state.notifications.data[1].action).to.eql(mentionedStatus)
|
||||||
expect(state.notifications[1].type).to.eql('mention')
|
expect(state.notifications.data[1].type).to.eql('mention')
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [deletion], user })
|
mutations.addNewStatuses(state, { statuses: [deletion], user })
|
||||||
expect(state.allStatuses.length).to.eql(2)
|
expect(state.allStatuses.length).to.eql(2)
|
||||||
expect(state.notifications.length).to.eql(1)
|
expect(state.notifications.data.length).to.eql(1)
|
||||||
})
|
|
||||||
|
|
||||||
it('adds the message to mentions when you are mentioned', () => {
|
|
||||||
const user = { id: 1 }
|
|
||||||
const state = cloneDeep(defaultState)
|
|
||||||
const status = makeMockStatus({id: 1})
|
|
||||||
const mentionedStatus = makeMockStatus({id: 2})
|
|
||||||
mentionedStatus.attentions = [user]
|
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [status], user })
|
|
||||||
|
|
||||||
expect(state.timelines.mentions.statuses).to.have.length(0)
|
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [mentionedStatus], user })
|
|
||||||
expect(state.timelines.mentions.statuses).to.have.length(1)
|
|
||||||
expect(state.timelines.mentions.statuses).to.eql([mentionedStatus])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('adds a notfication when one of the user\'s status is favorited', () => {
|
|
||||||
const state = cloneDeep(defaultState)
|
|
||||||
const status = makeMockStatus({id: 1})
|
|
||||||
const user = {id: 1}
|
|
||||||
status.user = user
|
|
||||||
|
|
||||||
const favorite = {
|
|
||||||
id: 2,
|
|
||||||
is_post_verb: false,
|
|
||||||
in_reply_to_status_id: '1', // The API uses strings here...
|
|
||||||
uri: 'tag:shitposter.club,2016-08-21:fave:3895:note:773501:2016-08-21T16:52:15+00:00',
|
|
||||||
text: 'a favorited something by b',
|
|
||||||
user: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public', user })
|
|
||||||
mutations.addNewStatuses(state, { statuses: [favorite], showImmediately: true, timeline: 'public', user })
|
|
||||||
|
|
||||||
expect(state.notifications).to.have.length(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('adds a notification when the user is followed', () => {
|
|
||||||
const state = cloneDeep(defaultState)
|
|
||||||
const user = {id: 1, screen_name: 'b'}
|
|
||||||
const follower = {id: 2, screen_name: 'a'}
|
|
||||||
|
|
||||||
const follow = {
|
|
||||||
id: 3,
|
|
||||||
is_post_verb: false,
|
|
||||||
activity_type: 'follow',
|
|
||||||
text: 'a started following b',
|
|
||||||
user: follower
|
|
||||||
}
|
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [follow], showImmediately: true, timeline: 'public', user })
|
|
||||||
|
|
||||||
expect(state.notifications).to.have.length(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('does not add a notification when an other user is followed', () => {
|
|
||||||
const state = cloneDeep(defaultState)
|
|
||||||
const user = {id: 1, screen_name: 'b'}
|
|
||||||
const follower = {id: 2, screen_name: 'a'}
|
|
||||||
|
|
||||||
const follow = {
|
|
||||||
id: 3,
|
|
||||||
is_post_verb: false,
|
|
||||||
activity_type: 'follow',
|
|
||||||
text: 'a started following b@shitposter.club',
|
|
||||||
user: follower
|
|
||||||
}
|
|
||||||
|
|
||||||
mutations.addNewStatuses(state, { statuses: [follow], showImmediately: true, timeline: 'public', user })
|
|
||||||
|
|
||||||
expect(state.notifications).to.have.length(0)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue