diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index b412ba59b..95902daef 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -1,8 +1,7 @@ import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js' import { muteFilterHits } from '../status_parser/status_parser.js' -import { useSyncConfigStore } from 'src/stores/sync_config.js' -import { useAnnouncementsStore } from 'src/stores/announcements.js' +import { useAnnouncementsStore } from 'src/stores/announcements' import { useI18nStore } from 'src/stores/i18n.js' import FaviconService from 'src/services/favicon_service/favicon_service.js' @@ -101,14 +100,14 @@ export const filteredNotificationsFromStore = ( .map((_) => _) .sort(sortById) // TODO implement sorting elsewhere and make it optional - console.log(types, visibleTypes(notificationVisibility)) return sortedNotifications.filter((notification) => (types || visibleTypes(notificationVisibility)).includes(notification.type), ) } export const unseenNotificationsFromStore = (store, notificationVisibility) => { - const ignoreInactionableSeen = useSyncConfigStore().mergedConfig.ignoreInactionableSeen + const rootGetters = store.rootGetters || store.getters + const ignoreInactionableSeen = rootGetters.mergedConfig.ignoreInactionableSeen return filteredNotificationsFromStore(store, notificationVisibility).filter( ({ seen, type }) => { @@ -189,7 +188,10 @@ export const prepareNotificationObject = (notification, i18n) => { return notifObj } -export const countExtraNotifications = (mergedConfig) => { +export const countExtraNotifications = (store) => { + const rootGetters = store.rootGetters || store.getters + const mergedConfig = rootGetters.mergedConfig + if (!mergedConfig.showExtraNotifications) { return 0 } diff --git a/test/unit/specs/components/gallery.spec.js b/test/unit/specs/components/gallery.spec.js index 3e7aa0de2..941110e78 100644 --- a/test/unit/specs/components/gallery.spec.js +++ b/test/unit/specs/components/gallery.spec.js @@ -21,57 +21,57 @@ describe('Gallery', () => { it('one audio attachment', () => { local = { - attachments: [{ type: 'audio' }], + attachments: [{ mimetype: 'audio/mpeg' }], } expect(Gallery.computed.rows.call(local)).to.eql([ - { audio: true, items: [{ type: 'audio' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, ]) }) it('one image attachment', () => { local = { - attachments: [{ type: 'image' }], + attachments: [{ mimetype: 'image/png' }], } expect(Gallery.computed.rows.call(local)).to.eql([ - { items: [{ type: 'image' }] }, + { items: [{ mimetype: 'image/png' }] }, ]) }) it('one audio attachment and one image attachment', () => { local = { - attachments: [{ type: 'audio' }, { type: 'image' }], + attachments: [{ mimetype: 'audio/mpeg' }, { mimetype: 'image/png' }], } expect(Gallery.computed.rows.call(local)).to.eql([ - { audio: true, items: [{ type: 'audio' }] }, - { items: [{ type: 'image' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, + { items: [{ mimetype: 'image/png' }] }, ]) }) it('has "size" key set to "hide"', () => { let local local = { - attachments: [{ type: 'audio' }], + attachments: [{ mimetype: 'audio/mpeg' }], size: 'hide', } expect(Gallery.computed.rows.call(local)).to.eql([ - { minimal: true, items: [{ type: 'audio' }] }, + { minimal: true, items: [{ mimetype: 'audio/mpeg' }] }, ]) local = { attachments: [ - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'audio' }, - { type: 'image' }, - { type: 'audio' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, + { mimetype: 'audio/mpeg' }, + { mimetype: 'image/png' }, + { mimetype: 'audio/mpeg' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, ], size: 'hide', } @@ -79,186 +79,186 @@ describe('Gallery', () => { // When defining `size: hide`, the `items` aren't // grouped and `audio` isn't set expect(Gallery.computed.rows.call(local)).to.eql([ - { minimal: true, items: [{ type: 'image' }] }, - { minimal: true, items: [{ type: 'image' }] }, - { minimal: true, items: [{ type: 'image' }] }, - { minimal: true, items: [{ type: 'audio' }] }, - { minimal: true, items: [{ type: 'image' }] }, - { minimal: true, items: [{ type: 'audio' }] }, - { minimal: true, items: [{ type: 'image' }] }, - { minimal: true, items: [{ type: 'image' }] }, - { minimal: true, items: [{ type: 'image' }] }, + { minimal: true, items: [{ mimetype: 'image/jpg' }] }, + { minimal: true, items: [{ mimetype: 'image/png' }] }, + { minimal: true, items: [{ mimetype: 'image/jpg' }] }, + { minimal: true, items: [{ mimetype: 'audio/mpeg' }] }, + { minimal: true, items: [{ mimetype: 'image/png' }] }, + { minimal: true, items: [{ mimetype: 'audio/mpeg' }] }, + { minimal: true, items: [{ mimetype: 'image/jpg' }] }, + { minimal: true, items: [{ mimetype: 'image/png' }] }, + { minimal: true, items: [{ mimetype: 'image/jpg' }] }, ]) }) // types other than image or audio should be `minimal` - it('non-image', () => { + it('non-image/audio', () => { let local local = { - attachments: [{ type: 'plain' }], + attachments: [{ mimetype: 'plain/text' }], } expect(Gallery.computed.rows.call(local)).to.eql([ - { minimal: true, items: [{ type: 'plain' }] }, + { minimal: true, items: [{ mimetype: 'plain/text' }] }, ]) - // No grouping of non-image items + // No grouping of non-image/audio items local = { attachments: [ - { type: 'plain' }, - { type: 'plain' }, - { type: 'plain' }, + { mimetype: 'plain/text' }, + { mimetype: 'plain/text' }, + { mimetype: 'plain/text' }, ], } expect(Gallery.computed.rows.call(local)).to.eql([ - { minimal: true, items: [{ type: 'plain' }] }, - { minimal: true, items: [{ type: 'plain' }] }, - { minimal: true, items: [{ type: 'plain' }] }, + { minimal: true, items: [{ mimetype: 'plain/text' }] }, + { minimal: true, items: [{ mimetype: 'plain/text' }] }, + { minimal: true, items: [{ mimetype: 'plain/text' }] }, ]) local = { attachments: [ - { type: 'image' }, - { type: 'plain' }, - { type: 'image' }, - { type: 'audio' }, + { mimetype: 'image/png' }, + { mimetype: 'plain/text' }, + { mimetype: 'image/jpg' }, + { mimetype: 'audio/mpeg' }, ], } // NOTE / TODO: When defining `size: hide`, the `items` aren't // grouped and `audio` isn't set expect(Gallery.computed.rows.call(local)).to.eql([ - { items: [{ type: 'image' }] }, - { minimal: true, items: [{ type: 'plain' }] }, - { items: [{ type: 'image' }] }, - { audio: true, items: [{ type: 'audio' }] }, + { items: [{ mimetype: 'image/png' }] }, + { minimal: true, items: [{ mimetype: 'plain/text' }] }, + { items: [{ mimetype: 'image/jpg' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, ]) }) it('mixed attachments', () => { local = { attachments: [ - { type: 'audio' }, - { type: 'image' }, - { type: 'audio' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'audio/mpeg' }, + { mimetype: 'image/png' }, + { mimetype: 'audio/mpeg' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/jpg' }, ], } expect(Gallery.computed.rows.call(local)).to.eql([ - { audio: true, items: [{ type: 'audio' }] }, - { items: [{ type: 'image' }] }, - { audio: true, items: [{ type: 'audio' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, + { items: [{ mimetype: 'image/png' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, { items: [ - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/jpg' }, ], }, ]) local = { attachments: [ - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'audio' }, - { type: 'image' }, - { type: 'audio' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/jpg' }, + { mimetype: 'audio/mpeg' }, + { mimetype: 'image/png' }, + { mimetype: 'audio/mpeg' }, ], } expect(Gallery.computed.rows.call(local)).to.eql([ { items: [ - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, ], }, - { items: [{ type: 'image' }] }, - { audio: true, items: [{ type: 'audio' }] }, - { items: [{ type: 'image' }] }, - { audio: true, items: [{ type: 'audio' }] }, + { items: [{ mimetype: 'image/jpg' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, + { items: [{ mimetype: 'image/png' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, ]) local = { attachments: [ - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, ], } // Group by three-per-row, unless there's one dangling, then stick it on the end of the last row - // https:/.pleroma.social-fe/-_requests#note_98514 + // https://git.pleroma.social/pleroma/pleroma-fe/-/merge_requests/1785#note_98514 expect(Gallery.computed.rows.call(local)).to.eql([ { items: [ - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, ], }, { items: [ - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, ], }, ]) local = { attachments: [ - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, ], } expect(Gallery.computed.rows.call(local)).to.eql([ { items: [ - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, ], }, { items: [ - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/png' }, ], }, - { items: [{ type: 'image' }, { type: 'image' }] }, + { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }] }, ]) }) it('does not do grouping when grid is set', () => { const attachments = [ - { type: 'audio' }, - { type: 'image' }, - { type: 'audio' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, - { type: 'image' }, + { mimetype: 'audio/mpeg' }, + { mimetype: 'image/png' }, + { mimetype: 'audio/mpeg' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, + { mimetype: 'image/jpg' }, ] local = { grid: true, attachments } @@ -270,34 +270,34 @@ describe('Gallery', () => { it('limit is set', () => { const attachments = [ - { type: 'audio' }, - { type: 'image' }, - { type: 'image' }, - { type: 'audio' }, - { type: 'image' }, + { mimetype: 'audio/mpeg' }, + { mimetype: 'image/png' }, + { mimetype: 'image/jpg' }, + { mimetype: 'audio/mpeg' }, + { mimetype: 'image/jpg' }, ] let local local = { attachments, limit: 2 } expect(Gallery.computed.rows.call(local)).to.eql([ - { audio: true, items: [{ type: 'audio' }] }, - { items: [{ type: 'image' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, + { items: [{ mimetype: 'image/png' }] }, ]) local = { attachments, limit: 3 } expect(Gallery.computed.rows.call(local)).to.eql([ - { audio: true, items: [{ type: 'audio' }] }, - { items: [{ type: 'image' }, { type: 'image' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, + { items: [{ mimetype: 'image/png' }, { mimetype: 'image/jpg' }] }, ]) local = { attachments, limit: 4 } expect(Gallery.computed.rows.call(local)).to.eql([ - { audio: true, items: [{ type: 'audio' }] }, - { items: [{ type: 'image' }, { type: 'image' }] }, - { audio: true, items: [{ type: 'audio' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, + { items: [{ mimetype: 'image/png' }, { mimetype: 'image/jpg' }] }, + { audio: true, items: [{ mimetype: 'audio/mpeg' }] }, ]) }) }) diff --git a/test/unit/specs/services/notification_utils/notification_utils.spec.js b/test/unit/specs/services/notification_utils/notification_utils.spec.js index dbdd3d660..0db318e3c 100644 --- a/test/unit/specs/services/notification_utils/notification_utils.spec.js +++ b/test/unit/specs/services/notification_utils/notification_utils.spec.js @@ -53,11 +53,7 @@ describe('NotificationUtils', () => { type: 'like', }, ] - expect(NotificationUtils.filteredNotificationsFromStore(store, { - mentions: false, - likes: true, - repeats: true, - })).to.eql( + expect(NotificationUtils.filteredNotificationsFromStore(store)).to.eql( expected, ) }) @@ -81,7 +77,16 @@ describe('NotificationUtils', () => { }, ], }, - } + }, + getters: { + mergedConfig: { + notificationVisibility: { + likes: true, + repeats: true, + mentions: false, + }, + }, + }, } const expected = [ { @@ -90,11 +95,7 @@ describe('NotificationUtils', () => { seen: false, }, ] - expect(NotificationUtils.unseenNotificationsFromStore(store, { - likes: true, - repeats: true, - mentions: false, - })).to.eql( + expect(NotificationUtils.unseenNotificationsFromStore(store)).to.eql( expected, ) }) diff --git a/test/unit/specs/stores/sync_config.spec.js b/test/unit/specs/stores/sync_config.spec.js index 9aed6193b..b065bede9 100644 --- a/test/unit/specs/stores/sync_config.spec.js +++ b/test/unit/specs/stores/sync_config.spec.js @@ -493,6 +493,11 @@ describe('The SyncConfig store', () => { }) describe('_resetFlags', () => { + it('should reset all known flags to 0 when reset flag is set to > 0 and < 9000', () => { + const totalFlags = { a: 0, b: 3, reset: 1 } + + expect(_resetFlags(totalFlags)).to.eql({ a: 0, b: 0, reset: 0 }) + }) it('should trim all flags to known when reset is set to 1000', () => { const totalFlags = { a: 0, b: 3, c: 33, reset: COMMAND_TRIM_FLAGS }