From 3f23aecd10e570f78b4142687a9a3fa349c13018 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Tue, 23 Feb 2021 10:00:23 +0200 Subject: add sensitive by default option --- src/modules/config.js | 3 ++- src/modules/instance.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/config.js b/src/modules/config.js index f992519e..b08903d1 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -67,7 +67,8 @@ export const defaultState = { greentext: undefined, // instance default hidePostStats: undefined, // instance default hideUserStats: undefined, // instance default - virtualScrolling: undefined // instance default + virtualScrolling: undefined, // instance default + sensitiveByDefault: undefined } // caching the instance default properties diff --git a/src/modules/instance.js b/src/modules/instance.js index 411b1caa..96de73ca 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -43,6 +43,7 @@ const defaultState = { subjectLineBehavior: 'email', theme: 'pleroma-dark', virtualScrolling: true, + sensitiveByDefault: false, // Nasty stuff customEmoji: [], -- cgit v1.2.3-70-g09d2 From ecb211606cddeeec809c8a6bc39f9c96a0af95f5 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Tue, 23 Feb 2021 10:06:45 +0200 Subject: change config comment to be consistent --- src/modules/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/config.js b/src/modules/config.js index b08903d1..eca58c12 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -68,7 +68,7 @@ export const defaultState = { hidePostStats: undefined, // instance default hideUserStats: undefined, // instance default virtualScrolling: undefined, // instance default - sensitiveByDefault: undefined + sensitiveByDefault: undefined // instance default } // caching the instance default properties -- cgit v1.2.3-70-g09d2 From cd2f5ced31a3598eb8a1fcdeef47d70dabf8bb00 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Fri, 26 Feb 2021 14:27:25 +0200 Subject: add basic validation for statusless status notifications --- CHANGELOG.md | 1 + src/modules/statuses.js | 29 ++++++++++++++++------ .../notification_utils/notification_utils.js | 7 ++++++ 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src/modules') diff --git a/CHANGELOG.md b/CHANGELOG.md index 2685fd32..929292f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fixed missing highlighted border in expanded conversations again - Fixed some UI jumpiness when opening images particularly in chat view - Fixed chat unread badge looking weird +- Fixed notifications crashing on an invalid notificaiton ### Changed - Display 'people voted' instead of 'votes' for multi-choice polls diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 33c68c57..ac5d25c4 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -13,7 +13,11 @@ import { omitBy } from 'lodash' import { set } from 'vue' -import { isStatusNotification, maybeShowNotification } from '../services/notification_utils/notification_utils.js' +import { + isStatusNotification, + isValidNotification, + maybeShowNotification +} from '../services/notification_utils/notification_utils.js' import apiService from '../services/api/api.service.js' const emptyTl = (userId = 0) => ({ @@ -310,8 +314,24 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us } } +const updateNotificationsMinMaxId = (state, notification) => { + state.notifications.maxId = notification.id > state.notifications.maxId + ? notification.id + : state.notifications.maxId + state.notifications.minId = notification.id < state.notifications.minId + ? notification.id + : state.notifications.minId +} + const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes, rootGetters, newNotificationSideEffects }) => { each(notifications, (notification) => { + // If invalid notification, update ids but don't add it to store + if (!isValidNotification(notification)) { + console.error('Invalid notification:', notification) + updateNotificationsMinMaxId(state, notification) + return + } + if (isStatusNotification(notification.type)) { notification.action = addStatusToGlobalStorage(state, notification.action).item notification.status = notification.status && addStatusToGlobalStorage(state, notification.status).item @@ -323,12 +343,7 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot // Only add a new notification if we don't have one for the same action if (!state.notifications.idStore.hasOwnProperty(notification.id)) { - state.notifications.maxId = notification.id > state.notifications.maxId - ? notification.id - : state.notifications.maxId - state.notifications.minId = notification.id < state.notifications.minId - ? notification.id - : state.notifications.minId + updateNotificationsMinMaxId(state, notification) state.notifications.data.push(notification) state.notifications.idStore[notification.id] = notification diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index d912d19f..6fef1022 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -22,6 +22,13 @@ const statusNotifications = ['like', 'mention', 'repeat', 'pleroma:emoji_reactio export const isStatusNotification = (type) => includes(statusNotifications, type) +export const isValidNotification = (notification) => { + if (isStatusNotification(notification.type) && !notification.status) { + return false + } + return true +} + const sortById = (a, b) => { const seqA = Number(a.id) const seqB = Number(b.id) -- cgit v1.2.3-70-g09d2