#436 - apply patch and clean up

This commit is contained in:
dave 2019-03-31 21:59:18 -04:00
parent b909796683
commit 21ea5adc8b
5 changed files with 44 additions and 29 deletions

View file

@ -25,11 +25,11 @@ const Notification = {
}, },
computed: { computed: {
userClass () { userClass () {
return highlightClass(this.notification.action.user) return highlightClass(this.notification.from_profile)
}, },
userStyle () { userStyle () {
const highlight = this.$store.state.config.highlight 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]) return highlightStyle(highlight[user.screen_name])
} }
} }

View file

@ -59,6 +59,11 @@ const persistedStateOptions = {
const persistedState = await createPersistedState(persistedStateOptions) const persistedState = await createPersistedState(persistedStateOptions)
const store = new Vuex.Store({ const store = new Vuex.Store({
modules: { modules: {
i18n: {
getters: {
i18n: () => i18n
}
},
interface: interfaceModule, interface: interfaceModule,
instance: instanceModule, instance: instanceModule,
statuses: statusesModule, statuses: statusesModule,

View file

@ -25,7 +25,7 @@ export const defaultState = () => ({
allStatusesObject: {}, allStatusesObject: {},
maxId: 0, maxId: 0,
notifications: { notifications: {
desktopNotificationSilence: true, desktopNotificationSilence: false,
maxId: 0, maxId: 0,
minId: Number.POSITIVE_INFINITY, minId: Number.POSITIVE_INFINITY,
data: [], 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 allStatuses = state.allStatuses
const allStatusesObject = state.allStatusesObject const allStatusesObject = state.allStatusesObject
each(notifications, (notification) => { each(notifications, (notification) => {
notification.action = mergeOrAdd(allStatuses, allStatusesObject, notification.action).item if (notification.type !== 'follow') {
notification.status = notification.status && mergeOrAdd(allStatuses, allStatusesObject, notification.status).item 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 // Only add a new notification if we don't have one for the same action
if (!state.notifications.idStore.hasOwnProperty(notification.id)) { 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') { if ('Notification' in window && window.Notification.permission === 'granted') {
const notifObj = {} const notifObj = {}
const action = notification.action const status = notification.status
const title = action.user.name_html const title = notification.from_profile.name
notifObj.icon = action.user.profile_image_url notifObj.icon = notification.from_profile.profile_image_url
notifObj.body = action.text // there's a problem that it doesn't put a space before links tho 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... // Shows first attached non-nsfw image, if any. Should add configuration for this somehow...
if (action.attachments && action.attachments.length > 0 && !action.nsfw && if (status && status.attachments && status.attachments.length > 0 && !status.nsfw &&
action.attachments[0].mimetype.startsWith('image/')) { status.attachments[0].mimetype.startsWith('image/')) {
notifObj.image = action.attachments[0].url notifObj.image = status.attachments[0].url
} }
if (!notification.seen && !state.notifications.desktopNotificationSilence && visibleNotificationTypes.includes(notification.type)) { 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 }) { addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false, userId }) {
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser, userId }) commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser, userId })
}, },
addNewNotifications ({ rootState, commit, dispatch }, { notifications, older }) { addNewNotifications ({ rootState, commit, dispatch, rootGetters }, { notifications, older }) {
commit('addNewNotifications', { visibleNotificationTypes: visibleNotificationTypes(rootState), dispatch, notifications, older }) commit('addNewNotifications', { visibleNotificationTypes: visibleNotificationTypes(rootState), dispatch, notifications, older, rootGetters })
}, },
setError ({ rootState, commit }, { value }) { setError ({ rootState, commit }, { value }) {
commit('setError', { value }) commit('setError', { value })

View file

@ -122,7 +122,9 @@ export const mutations = {
status.user = state.usersObject[status.user.id] status.user = state.usersObject[status.user.id]
}, },
setUserForNotification (state, notification) { 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] notification.from_profile = state.usersObject[notification.from_profile.id]
}, },
setColor (state, { user: { id }, highlighted }) { setColor (state, { user: { id }, highlighted }) {

View file

@ -39,7 +39,7 @@ export const parseUser = (data) => {
return output return output
} }
// output.name = ??? missing output.name = data.display_name
output.name_html = addEmojis(data.display_name, data.emojis) output.name_html = addEmojis(data.display_name, data.emojis)
// output.description = ??? missing // output.description = ??? missing
@ -260,17 +260,6 @@ export const parseStatus = (data) => {
return output 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) => { export const parseNotification = (data) => {
const mastoDict = { const mastoDict = {
'favourite': 'like', 'favourite': 'like',
@ -283,7 +272,7 @@ export const parseNotification = (data) => {
output.type = mastoDict[data.type] || data.type output.type = mastoDict[data.type] || data.type
output.seen = data.pleroma.is_seen output.seen = data.pleroma.is_seen
output.status = output.type === 'follow' output.status = output.type === 'follow'
? parseFollow(data) ? null
: parseStatus(data.status) : parseStatus(data.status)
output.action = output.status // TODO: Refactor, this is unneeded output.action = output.status // TODO: Refactor, this is unneeded
output.from_profile = parseUser(data.account) output.from_profile = parseUser(data.account)