logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe
commit: 673f0fca3f7898641cdc488e6e6cc9033ca51777
parent: 55650ff7ea9867cdb8adf7077b36bbb8c7bfcb75
Author: kaniini <nenolod@gmail.com>
Date:   Fri, 24 Aug 2018 23:04:36 +0000

Merge branch 'notifications' into 'develop'

Support qvitter api notifications

Closes #129

See merge request pleroma/pleroma-fe!306

Diffstat:

Msrc/components/notification/notification.vue11++++++++---
Msrc/components/notifications/notifications.js28+++++++++++++++++++++-------
Msrc/components/notifications/notifications.scss49+++++++++++++++++++++++++++++++++++++------------
Msrc/components/notifications/notifications.vue11++++++++++-
Msrc/i18n/messages.js8++++++--
Msrc/main.js3++-
Msrc/modules/api.js3+++
Msrc/modules/statuses.js145++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Msrc/modules/users.js2++
Msrc/services/api/api.service.js5+++++
Msrc/services/backend_interactor_service/backend_interactor_service.js11+++++++++++
Asrc/services/notifications_fetcher/notifications_fetcher.service.js46++++++++++++++++++++++++++++++++++++++++++++++
Msrc/services/timeline_fetcher/timeline_fetcher.service.js4++--
Mtest/unit/specs/modules/statuses.spec.js141+++++++++++++++----------------------------------------------------------------
14 files changed, 276 insertions(+), 191 deletions(-)

diff --git a/src/components/notification/notification.vue b/src/components/notification/notification.vue @@ -12,7 +12,7 @@ <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-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> <small>{{$t('notifications.favorited_you')}}</small> </span> @@ -25,12 +25,17 @@ <small>{{$t('notifications.followed_you')}}</small> </span> </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> <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> </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> </template> diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js @@ -1,16 +1,21 @@ 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 = { - data () { - return { - visibleNotificationCount: 20 - } + created () { + const store = this.$store + const credentials = store.state.users.currentUser.credentials + + notificationsFetcher.startFetching({ store, credentials }) }, computed: { notifications () { - return this.$store.state.statuses.notifications + return this.$store.state.statuses.notifications.data + }, + error () { + return this.$store.state.statuses.notifications.error }, unseenNotifications () { return filter(this.notifications, ({seen}) => !seen) @@ -19,7 +24,7 @@ const Notifications = { // Don't know why, but sortBy([seen, -action.id]) doesn't work. let sortedNotifications = sortBy(this.notifications, ({action}) => -action.id) sortedNotifications = sortBy(sortedNotifications, 'seen') - return take(sortedNotifications, this.visibleNotificationCount) + return sortedNotifications }, unseenCount () { return this.unseenNotifications.length @@ -40,6 +45,15 @@ const Notifications = { methods: { markAsSeen () { this.$store.commit('markNotificationsAsSeen', this.visibleNotifications) + }, + fetchOlderNotifications () { + const store = this.$store + const credentials = store.state.users.currentUser.credentials + notificationsFetcher.fetchAndUpdate({ + store, + credentials, + older: true + }) } } } diff --git a/src/components/notifications/notifications.scss b/src/components/notifications/notifications.scss @@ -4,6 +4,10 @@ // a bit of a hack to allow scrolling below notifications padding-bottom: 15em; + .title { + display: inline-block; + } + .panel { background: $fallback--bg; background: var(--bg, $fallback--bg) @@ -22,6 +26,8 @@ background: var(--btn, $fallback--btn); color: $fallback--fg; color: var(--fg, $fallback--fg); + display: flex; + align-items: baseline; .read-button { position: absolute; right: 0.7em; @@ -44,6 +50,19 @@ 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 { box-shadow: inset 4px 0 0 var(--cRed, $fallback--cRed); padding-left: 0; @@ -56,6 +75,16 @@ border-bottom: 1px solid; 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 { width: 32px; height: 32px; @@ -69,7 +98,7 @@ } } - &:hover .animated.avatar { + &:hover .animated.avatar-compact { canvas { display: none; } @@ -145,6 +174,13 @@ max-width: 100%; text-overflow: ellipsis; white-space: nowrap; + + img { + width: 14px; + height: 14px; + vertical-align: middle; + object-fit: contain + } } .timeago { float: right; @@ -194,15 +230,4 @@ 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); - } - } } diff --git a/src/components/notifications/notifications.vue b/src/components/notifications/notifications.vue @@ -3,7 +3,10 @@ <div class="panel panel-default"> <div class="panel-heading"> <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> </div> <div class="panel-body"> @@ -11,6 +14,12 @@ <notification :notification="notification"></notification> </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> </template> diff --git a/src/i18n/messages.js b/src/i18n/messages.js @@ -357,7 +357,9 @@ const en = { read: 'Read!', followed_you: 'followed you', 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: 'Log in', @@ -1694,7 +1696,9 @@ const ru = { read: 'Прочесть', followed_you: 'начал(а) читать вас', favorited_you: 'нравится ваш статус', - repeated_you: 'повторил(а) ваш статус' + repeated_you: 'повторил(а) ваш статус', + broken_favorite: 'Неизвестный статус, ищем...', + load_older: 'Загрузить старые уведомления' }, login: { login: 'Войти', diff --git a/src/main.js b/src/main.js @@ -60,7 +60,8 @@ const persistedStateOptions = { 'config.loopVideoSilentOnly', 'config.pauseOnUnfocused', 'config.stopGifs', - 'users.lastLoginName' + 'users.lastLoginName', + 'statuses.notifications.maxSavedId' ] } diff --git a/src/modules/api.js b/src/modules/api.js @@ -46,6 +46,9 @@ const api = { store.commit('addFetcher', {timeline, fetcher}) } }, + fetchOldPost (store, { postId }) { + store.state.backendInteractor.fetchOldPost({ store, postId }) + }, stopFetching (store, timeline) { const fetcher = store.state.fetchers[timeline] window.clearInterval(fetcher) diff --git a/src/modules/statuses.js b/src/modules/statuses.js @@ -1,4 +1,5 @@ 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 parse from '../services/status_parser/status_parser.js' @@ -22,13 +23,22 @@ export const defaultState = { allStatuses: [], allStatusesObject: {}, maxId: 0, - notifications: [], + notifications: { + desktopNotificationSilence: true, + maxId: 0, + maxSavedId: 0, + minId: Number.POSITIVE_INFINITY, + data: [], + error: false, + brokenFavorites: {} + }, favorites: new Set(), error: false, timelines: { mentions: emptyTl(), public: emptyTl(), user: emptyTl(), + own: emptyTl(), publicAndExternal: emptyTl(), friends: emptyTl(), tag: emptyTl() @@ -134,11 +144,13 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us const result = mergeOrAdd(allStatuses, allStatusesObject, status) status = result.item - if (result.new) { - if (statusType(status) === 'retweet' && status.retweeted_status.user.id === user.id) { - addNotification({ type: 'repeat', status: status, action: status }) - } + const brokenFavorites = state.notifications.brokenFavorites[status.id] || [] + brokenFavorites.forEach((fav) => { + fav.status = status + }) + delete state.notifications.brokenFavorites[status.id] + if (result.new) { // We are mentioned in a post if (statusType(status) === 'status' && find(status.attentions, { id: user.id })) { const mentions = state.timelines.mentions @@ -150,10 +162,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us 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 } - const addNotification = ({type, status, action}) => { - // 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 favoriteStatus = (favorite, counter) => { const status = find(allStatuses, { id: toInteger(favorite.in_reply_to_status_id) }) if (status) { status.fave_num += 1 @@ -211,11 +193,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us if (favorite.user.id === user.id) { 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 } @@ -253,13 +230,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us 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) => { const uri = deletion.uri @@ -269,7 +239,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us return } - remove(state.notifications, ({action: {id}}) => id === status.id) + remove(state.notifications.data, ({action: {id}}) => id === status.id) remove(allStatuses, { uri }) 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 = { addNewStatuses, + addNewNotifications, showNewStatuses (state, { timeline }) { const oldTimeline = (state.timelines[timeline]) @@ -334,6 +365,12 @@ export const mutations = { setError (state, { value }) { state.error = value }, + setNotificationsError (state, { value }) { + state.notifications.error = value + }, + setNotificationsSilence (state, { value }) { + state.notifications.desktopNotificationSilence = value + }, setProfileView (state, { v }) { // load followers / friends only when needed state.timelines['user'].viewing = v @@ -345,6 +382,7 @@ export const mutations = { state.timelines['user'].followers = followers }, markNotificationsAsSeen (state, notifications) { + set(state.notifications, 'maxSavedId', state.notifications.maxId) each(notifications, (notification) => { notification.seen = true }) @@ -360,9 +398,18 @@ const statuses = { addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false }) { 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 }) { commit('setError', { value }) }, + setNotificationsError ({ rootState, commit }, { value }) { + commit('setNotificationsError', { value }) + }, + setNotificationsSilence ({ rootState, commit }, { value }) { + commit('setNotificationsSilence', { value }) + }, addFriends ({ rootState, commit }, { friends }) { commit('addFriends', { friends }) }, diff --git a/src/modules/users.js b/src/modules/users.js @@ -107,6 +107,8 @@ const users = { // Start getting fresh tweets. 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 store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => { diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js @@ -27,6 +27,7 @@ const BANNER_UPDATE_URL = '/api/account/update_profile_banner.json' const PROFILE_UPDATE_URL = '/api/account/update_profile.json' const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.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 UNBLOCKING_URL = '/api/blocks/destroy.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, friends: FRIENDS_TIMELINE_URL, mentions: MENTIONS_URL, + notifications: QVITTER_USER_NOTIFICATIONS_URL, 'publicAndExternal': PUBLIC_AND_EXTERNAL_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 } diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js @@ -54,6 +54,16 @@ const backendInteractorService = (credentials) => { 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}) => { return apiService.setUserMute({id, muted, credentials}) } @@ -86,6 +96,7 @@ const backendInteractorService = (credentials) => { fetchAllFollowing, verifyCredentials: apiService.verifyCredentials, startFetching, + fetchOldPost, setUserMute, fetchMutes, register, diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -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 diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -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 rootState = store.rootState || store.state const timelineData = rootState.statuses.timelines[camelCase(timeline)] if (older) { - args['until'] = timelineData.minVisibleId + args['until'] = until || timelineData.minVisibleId } else { args['since'] = timelineData.maxId } diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js @@ -286,40 +286,6 @@ describe('The Statuses module', () => { }) 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', () => { const user = { id: 1 } const state = cloneDeep(defaultState) @@ -335,92 +301,39 @@ describe('The Statuses module', () => { deletion.uri = 'xxx' mutations.addNewStatuses(state, { statuses: [status, otherStatus], user }) - - expect(state.notifications.length).to.eql(1) + mutations.addNewNotifications( + state, + { + notifications: [{ + ntype: 'mention', + status: otherStatus, + notice: otherStatus, + is_seen: false + }] + }) + + 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 }) expect(state.allStatuses.length).to.eql(3) - expect(state.notifications.length).to.eql(2) - expect(state.notifications[1].status).to.eql(mentionedStatus) - expect(state.notifications[1].action).to.eql(mentionedStatus) - expect(state.notifications[1].type).to.eql('mention') + expect(state.notifications.data.length).to.eql(2) + expect(state.notifications.data[1].status).to.eql(mentionedStatus) + expect(state.notifications.data[1].action).to.eql(mentionedStatus) + expect(state.notifications.data[1].type).to.eql('mention') mutations.addNewStatuses(state, { statuses: [deletion], user }) expect(state.allStatuses.length).to.eql(2) - expect(state.notifications.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) + expect(state.notifications.data.length).to.eql(1) }) }) })