From 10070394780ac79e9ee1e8548500586a1f78f65b Mon Sep 17 00:00:00 2001 From: Sergey Suprunenko Date: Sun, 10 May 2020 12:54:55 +0200 Subject: Autocomplete domain mutes from list of known instances --- src/modules/instance.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/modules') diff --git a/src/modules/instance.js b/src/modules/instance.js index da82eb01..ec5f4e54 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -1,6 +1,7 @@ import { set } from 'vue' import { getPreset, applyTheme } from '../services/style_setter/style_setter.js' import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js' +import apiService from '../services/api/api.service.js' import { instanceDefaultProperties } from './config.js' const defaultState = { @@ -48,6 +49,7 @@ const defaultState = { postFormats: [], restrictedNicknames: [], safeDM: true, + knownDomains: [], // Feature-set, apparently, not everything here is reported... chatAvailable: false, @@ -80,6 +82,9 @@ const instance = { if (typeof value !== 'undefined') { set(state, name, value) } + }, + setKnownDomains (state, domains) { + state.knownDomains = domains } }, getters: { @@ -182,6 +187,18 @@ const instance = { state.emojiFetched = true dispatch('getStaticEmoji') } + }, + + async getKnownDomains ({ commit, rootState }) { + try { + const result = await apiService.fetchKnownDomains({ + credentials: rootState.users.currentUser.credentials + }) + commit('setKnownDomains', result) + } catch (e) { + console.warn("Can't load known domains") + console.warn(e) + } } } } -- cgit v1.2.3-70-g09d2 From a52a393266744560c6c6b2cbd24da812d35562fb Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 11 Jun 2020 15:22:31 +0200 Subject: NotificationUtils: Extract preparation of notification object. --- src/modules/statuses.js | 41 ++------------------- .../notification_utils/notification_utils.js | 42 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 38 deletions(-) (limited to 'src/modules') diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 9a2e0df1..073b15f1 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -13,7 +13,7 @@ import { omitBy } from 'lodash' import { set } from 'vue' -import { isStatusNotification } from '../services/notification_utils/notification_utils.js' +import { isStatusNotification, prepareNotificationObject } from '../services/notification_utils/notification_utils.js' import apiService from '../services/api/api.service.js' import { muteWordHits } from '../services/status_parser/status_parser.js' @@ -344,42 +344,7 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot state.notifications.idStore[notification.id] = notification if ('Notification' in window && window.Notification.permission === 'granted') { - const notifObj = {} - 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 - case 'move': - i18nString = 'migrated_to' - break - case 'follow_request': - i18nString = 'follow_request' - break - } - - if (notification.type === 'pleroma:emoji_reaction') { - notifObj.body = rootGetters.i18n.t('notifications.reacted_with', [notification.emoji]) - } else if (i18nString) { - notifObj.body = rootGetters.i18n.t('notifications.' + i18nString) - } else if (isStatusNotification(notification.type)) { - notifObj.body = notification.status.text - } - - // Shows first attached non-nsfw image, if any. Should add configuration for this somehow... - if (status && status.attachments && status.attachments.length > 0 && !status.nsfw && - status.attachments[0].mimetype.startsWith('image/')) { - notifObj.image = status.attachments[0].url - } + const notifObj = prepareNotificationObject(notification, rootGetters.i18n) const reasonsToMuteNotif = ( notification.seen || @@ -393,7 +358,7 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot ) ) if (!reasonsToMuteNotif) { - let desktopNotification = new window.Notification(title, notifObj) + let desktopNotification = new window.Notification(notifObj.title, notifObj) // Chrome is known for not closing notifications automatically // according to MDN, anyway. setTimeout(desktopNotification.close.bind(desktopNotification), 5000) diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index eb479227..4576ea83 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -43,3 +43,45 @@ export const filteredNotificationsFromStore = (store, types) => { export const unseenNotificationsFromStore = store => filter(filteredNotificationsFromStore(store), ({ seen }) => !seen) + +export const prepareNotificationObject = (notification, i18n) => { + const notifObj = {} + const status = notification.status + const title = notification.from_profile.name + notifObj.title = title + 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 + case 'move': + i18nString = 'migrated_to' + break + case 'follow_request': + i18nString = 'follow_request' + break + } + + if (notification.type === 'pleroma:emoji_reaction') { + notifObj.body = i18n.t('notifications.reacted_with', [notification.emoji]) + } else if (i18nString) { + notifObj.body = i18n.t('notifications.' + i18nString) + } else if (isStatusNotification(notification.type)) { + notifObj.body = notification.status.text + } + + // Shows first attached non-nsfw image, if any. Should add configuration for this somehow... + if (status && status.attachments && status.attachments.length > 0 && !status.nsfw && + status.attachments[0].mimetype.startsWith('image/')) { + notifObj.image = status.attachments[0].url + } + + return notifObj +} -- cgit v1.2.3-70-g09d2 From 9c884fef11e52541ab64508c9a9e0b8694432cbb Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 18 Jun 2020 12:29:13 +0300 Subject: remove search blocker, fix debounce params --- src/components/emoji_input/suggestor.js | 8 ++++---- src/modules/users.js | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src/modules') diff --git a/src/components/emoji_input/suggestor.js b/src/components/emoji_input/suggestor.js index 15a71eff..91d5cfb9 100644 --- a/src/components/emoji_input/suggestor.js +++ b/src/components/emoji_input/suggestor.js @@ -1,4 +1,4 @@ -import { debounce } from 'lodash' +import debounce from 'lodash/debounce' /** * suggest - generates a suggestor function to be used by emoji-input * data: object providing source information for specific types of suggestions: @@ -13,7 +13,7 @@ import { debounce } from 'lodash' const debounceUserSearch = debounce((data, input) => { data.updateUsersList(input) -}, 500, { leading: true, trailing: false }) +}, 500) export default data => input => { const firstChar = input[0] @@ -97,8 +97,8 @@ export const suggestUsers = data => input => { replacement: '@' + screen_name + ' ' })) - // BE search users if there are no matches - if (newUsers.length === 0 && data.updateUsersList) { + // BE search users to get more comprehensive results + if (data.updateUsersList) { debounceUserSearch(data, noPrefix) } return newUsers diff --git a/src/modules/users.js b/src/modules/users.js index f9329f2a..a640fb3b 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -225,6 +225,12 @@ export const mutations = { signUpFailure (state, errors) { state.signUpPending = false state.signUpErrors = errors + }, + addRecentQuery (state, query) { + state.recentQueries = state.recentQueries.concat(query) + if (state.recentQueries.length > 10) { + state.recentQueries = state.recentQueries.slice(1) + } } } @@ -251,7 +257,8 @@ export const defaultState = { usersObject: {}, signUpPending: false, signUpErrors: [], - relationships: {} + relationships: {}, + recentQueries: [] } const users = { @@ -428,10 +435,15 @@ const users = { store.commit('setUserForNotification', notification) }) }, - searchUsers (store, { query }) { - return store.rootState.api.backendInteractor.searchUsers({ query }) + searchUsers ({ rootState, commit }, { query }) { + // Don't fetch if this query was already done recently + if (rootState.users.recentQueries.includes(query)) { + return [] + } + return rootState.api.backendInteractor.searchUsers({ query }) .then((users) => { - store.commit('addNewUsers', users) + commit('addRecentQuery', query) + commit('addNewUsers', users) return users }) }, -- cgit v1.2.3-70-g09d2 From fa7bcb74cecb8af095e6e22271243f2d51835f39 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 18 Jun 2020 13:00:09 +0300 Subject: return the correct promise type from action --- src/modules/users.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/users.js b/src/modules/users.js index a640fb3b..df710ac9 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -438,7 +438,7 @@ const users = { searchUsers ({ rootState, commit }, { query }) { // Don't fetch if this query was already done recently if (rootState.users.recentQueries.includes(query)) { - return [] + return Promise.resolve([]) } return rootState.api.backendInteractor.searchUsers({ query }) .then((users) => { -- cgit v1.2.3-70-g09d2 From 4e0b4427a969b2d0584a3a1c1ffd3fe3fbfc2998 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 18 Jun 2020 14:19:21 +0300 Subject: remove recentqueries thing --- src/modules/users.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'src/modules') diff --git a/src/modules/users.js b/src/modules/users.js index df710ac9..5e32bb49 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -225,12 +225,6 @@ export const mutations = { signUpFailure (state, errors) { state.signUpPending = false state.signUpErrors = errors - }, - addRecentQuery (state, query) { - state.recentQueries = state.recentQueries.concat(query) - if (state.recentQueries.length > 10) { - state.recentQueries = state.recentQueries.slice(1) - } } } @@ -257,8 +251,7 @@ export const defaultState = { usersObject: {}, signUpPending: false, signUpErrors: [], - relationships: {}, - recentQueries: [] + relationships: {} } const users = { @@ -436,13 +429,8 @@ const users = { }) }, searchUsers ({ rootState, commit }, { query }) { - // Don't fetch if this query was already done recently - if (rootState.users.recentQueries.includes(query)) { - return Promise.resolve([]) - } return rootState.api.backendInteractor.searchUsers({ query }) .then((users) => { - commit('addRecentQuery', query) commit('addNewUsers', users) return users }) -- cgit v1.2.3-70-g09d2