From 21ea5adc8b4f8eb16026cdefd60a60c8952ae162 Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 31 Mar 2019 21:59:18 -0400 Subject: [PATCH] #436 - apply patch and clean up --- src/components/notification/notification.js | 4 +- src/main.js | 5 +++ src/modules/statuses.js | 45 +++++++++++++------ src/modules/users.js | 4 +- .../entity_normalizer.service.js | 15 +------ 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/components/notification/notification.js b/src/components/notification/notification.js index fe5b7018..4e6f46a6 100644 --- a/src/components/notification/notification.js +++ b/src/components/notification/notification.js @@ -25,11 +25,11 @@ const Notification = { }, computed: { userClass () { - return highlightClass(this.notification.action.user) + return highlightClass(this.notification.from_profile) }, userStyle () { const highlight = this.$store.state.config.highlight - const user = this.notification.action.user + const user = this.notification.from_profile return highlightStyle(highlight[user.screen_name]) } } diff --git a/src/main.js b/src/main.js index 9ffc3727..c80aea36 100644 --- a/src/main.js +++ b/src/main.js @@ -59,6 +59,11 @@ const persistedStateOptions = { const persistedState = await createPersistedState(persistedStateOptions) const store = new Vuex.Store({ modules: { + i18n: { + getters: { + i18n: () => i18n + } + }, interface: interfaceModule, instance: instanceModule, statuses: statusesModule, diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 6e356be0..63af7ce2 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -25,7 +25,7 @@ export const defaultState = () => ({ allStatusesObject: {}, maxId: 0, notifications: { - desktopNotificationSilence: true, + desktopNotificationSilence: false, maxId: 0, minId: Number.POSITIVE_INFINITY, data: [], @@ -271,12 +271,14 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us } } -const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes }) => { +const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes, rootGetters }) => { const allStatuses = state.allStatuses const allStatusesObject = state.allStatusesObject each(notifications, (notification) => { - notification.action = mergeOrAdd(allStatuses, allStatusesObject, notification.action).item - notification.status = notification.status && mergeOrAdd(allStatuses, allStatusesObject, notification.status).item + if (notification.type !== 'follow') { + notification.action = mergeOrAdd(allStatuses, allStatusesObject, notification.action).item + notification.status = notification.status && mergeOrAdd(allStatuses, allStatusesObject, notification.status).item + } // Only add a new notification if we don't have one for the same action if (!state.notifications.idStore.hasOwnProperty(notification.id)) { @@ -292,15 +294,32 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot if ('Notification' in window && window.Notification.permission === 'granted') { const notifObj = {} - const action = notification.action - const title = action.user.name_html - notifObj.icon = action.user.profile_image_url - notifObj.body = action.text // there's a problem that it doesn't put a space before links tho + const status = notification.status + const title = notification.from_profile.name + notifObj.icon = notification.from_profile.profile_image_url + let i18nString + switch (notification.type) { + case 'like': + i18nString = 'favorited_you' + break + case 'repeat': + i18nString = 'repeated_you' + break + case 'follow': + i18nString = 'followed_you' + break + } + + if (i18nString) { + notifObj.body = rootGetters.i18n.t('notifications.' + i18nString) + } else { + notifObj.body = notification.status.text + } // 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/')) { - notifObj.image = action.attachments[0].url + if (status && status.attachments && status.attachments.length > 0 && !status.nsfw && + status.attachments[0].mimetype.startsWith('image/')) { + notifObj.image = status.attachments[0].url } if (!notification.seen && !state.notifications.desktopNotificationSilence && visibleNotificationTypes.includes(notification.type)) { @@ -413,8 +432,8 @@ const statuses = { addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false, userId }) { commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser, userId }) }, - addNewNotifications ({ rootState, commit, dispatch }, { notifications, older }) { - commit('addNewNotifications', { visibleNotificationTypes: visibleNotificationTypes(rootState), dispatch, notifications, older }) + addNewNotifications ({ rootState, commit, dispatch, rootGetters }, { notifications, older }) { + commit('addNewNotifications', { visibleNotificationTypes: visibleNotificationTypes(rootState), dispatch, notifications, older, rootGetters }) }, setError ({ rootState, commit }, { value }) { commit('setError', { value }) diff --git a/src/modules/users.js b/src/modules/users.js index 2c525526..1482de43 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -122,7 +122,9 @@ export const mutations = { status.user = state.usersObject[status.user.id] }, setUserForNotification (state, notification) { - notification.action.user = state.usersObject[notification.action.user.id] + if (notification.type !== 'follow') { + notification.action.user = state.usersObject[notification.action.user.id] + } notification.from_profile = state.usersObject[notification.from_profile.id] }, setColor (state, { user: { id }, highlighted }) { diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 8e3cb066..923a7caf 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -39,7 +39,7 @@ export const parseUser = (data) => { return output } - // output.name = ??? missing + output.name = data.display_name output.name_html = addEmojis(data.display_name, data.emojis) // output.description = ??? missing @@ -260,17 +260,6 @@ export const parseStatus = (data) => { return output } -// This is for masto API only. -export const parseFollow = (data) => { - const output = {} - output.id = String(data.id) - output.visibility = true - output.created_at = new Date(data.created_at) - output.user = parseUser(data.account) - - return output -} - export const parseNotification = (data) => { const mastoDict = { 'favourite': 'like', @@ -283,7 +272,7 @@ export const parseNotification = (data) => { output.type = mastoDict[data.type] || data.type output.seen = data.pleroma.is_seen output.status = output.type === 'follow' - ? parseFollow(data) + ? null : parseStatus(data.status) output.action = output.status // TODO: Refactor, this is unneeded output.from_profile = parseUser(data.account)