diff --git a/src/api/user.js b/src/api/user.js index b4b6fafa9..a94c10241 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -1,4 +1,4 @@ -import { concat, last } from 'lodash' +import { last } from 'lodash' import { paramsString, promisedRequest } from './helpers.js' import { fetchFriends, MASTODON_STATUS_URL } from './public.js' @@ -412,7 +412,7 @@ export const exportFriends = ({ id, credentials }) => { credentials, withRelationships: true, }) - friends = concat(friends, users) + friends = [...friends, ...users] if (users.length === 0) { more = false } diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 5bec225ce..ee5e50a39 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -3,14 +3,12 @@ import { find, findIndex, first, - isArray, last, maxBy, merge, minBy, omitBy, remove, - slice, } from 'lodash' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' @@ -206,7 +204,7 @@ const addNewStatuses = ( }, ) => { // Sanity check - if (!isArray(statuses)) { + if (!Array.isArray(statuses)) { return false } @@ -410,7 +408,7 @@ export const mutations = { const oldTimeline = state.timelines[timeline] oldTimeline.newStatusCount = 0 - oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50) + oldTimeline.visibleStatuses = oldTimeline.statuses.slice(0, 50) oldTimeline.minVisibleId = last(oldTimeline.visibleStatuses).id oldTimeline.minId = oldTimeline.minVisibleId oldTimeline.visibleStatusesObject = {} diff --git a/src/modules/users.js b/src/modules/users.js index 8777f18da..b58566859 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,14 +1,5 @@ import Cookies from 'js-cookie' -import { - compact, - concat, - each, - isArray, - last, - map, - mergeWith, - uniq, -} from 'lodash' +import { compact, each, last, map, mergeWith } from 'lodash' import { registerPushNotifications, @@ -76,7 +67,7 @@ export const mergeOrAdd = (arr, obj, item) => { } const mergeArrayLength = (oldValue, newValue) => { - if (isArray(oldValue) && isArray(newValue)) { + if (Array.isArray(oldValue) && Array.isArray(newValue)) { oldValue.length = newValue.length return mergeWith(oldValue, newValue, mergeArrayLength) } @@ -234,11 +225,11 @@ export const mutations = { }, saveFriendIds(state, { id, friendIds }) { const user = state.usersObject[id] - user.friendIds = uniq(concat(user.friendIds || [], friendIds)) + user.friendIds = [...new Set([...(user.friendIds || []), ...friendIds])] }, saveFollowerIds(state, { id, followerIds }) { const user = state.usersObject[id] - user.followerIds = uniq(concat(user.followerIds || [], followerIds)) + user.followerIds = [...new Set([user.followerIds || [], ...followerIds])] }, // Because frontend doesn't have a reason to keep these stuff in memory // outside of viewing someones user profile. diff --git a/src/services/poll/poll.service.js b/src/services/poll/poll.service.js index 468fc6ff9..ea52b6228 100644 --- a/src/services/poll/poll.service.js +++ b/src/services/poll/poll.service.js @@ -1,5 +1,3 @@ -import { uniq } from 'lodash' - import * as DateUtils from 'src/services/date_utils/date_utils.js' const pollFallbackValues = { @@ -19,9 +17,9 @@ export const pollFormToMasto = (poll) => { pollFallback(poll, 'expiryAmount'), ) - const options = uniq( + const options = [...new Set( pollFallback(poll, 'options').filter((option) => option !== ''), - ) + )] if (options.length < 2) { return { errorKey: 'polls.not_enough_options' } } diff --git a/src/stores/admin_settings.js b/src/stores/admin_settings.js index 5aa91c819..766da26fb 100644 --- a/src/stores/admin_settings.js +++ b/src/stores/admin_settings.js @@ -1,4 +1,4 @@ -import { cloneDeep, differenceWith, flatten, get, isEqual, set } from 'lodash' +import { cloneDeep, differenceWith, get, isEqual, set } from 'lodash' import { defineStore } from 'pinia' import { useOAuthStore } from 'src/stores/oauth.js' @@ -209,11 +209,11 @@ export const useAdminSettingsStore = defineStore('adminSettings', { } // Getting all group-keys used in config - const allGroupKeys = flatten( - Object.entries(this.config).map(([group, lv1data]) => + const allGroupKeys = Object.entries(this.config) + .map(([group, lv1data]) => Object.keys(lv1data).map((key) => ({ group, key })), - ), - ) + ) + .flat() // Only using group-keys where there are changes detected const changedGroupKeys = allGroupKeys.filter(({ group, key }) => { diff --git a/src/stores/sync_config.js b/src/stores/sync_config.js index 47c6978d5..83fbe34f7 100644 --- a/src/stores/sync_config.js +++ b/src/stores/sync_config.js @@ -4,13 +4,12 @@ import { clamp, cloneDeep, findLastIndex, - flatten, get, groupBy, isEqual, set, take, - takeRight, + last, uniqWith, unset, } from 'lodash' @@ -222,15 +221,16 @@ export const _mergeFlags = (recent, stale, allFlagKeys) => { export const _mergeJournal = (...journals) => { // Ignore invalid journal entries - const allJournals = flatten( - journals.map((j) => (Array.isArray(j) ? j : [])), - ).filter( - (entry) => - Object.hasOwn(entry, 'path') && - Object.hasOwn(entry, 'operation') && - Object.hasOwn(entry, 'args') && - Object.hasOwn(entry, 'timestamp'), - ) + const allJournals = journals + .map((j) => (Array.isArray(j) ? j : [])) + .flat() + .filter( + (entry) => + Object.hasOwn(entry, 'path') && + Object.hasOwn(entry, 'operation') && + Object.hasOwn(entry, 'args') && + Object.hasOwn(entry, 'timestamp'), + ) const grouped = groupBy(allJournals, 'path') const trimmedGrouped = Object.entries(grouped).map(([path, rawJournal]) => { const journal = rawJournal @@ -271,13 +271,14 @@ export const _mergeJournal = (...journals) => { }) } else if (path.startsWith('simple')) { // Only the last record is important - return takeRight(journal) + return [last(journal)] } else { return journal } }) - const flat = flatten(trimmedGrouped) + const flat = trimmedGrouped + .flat() .map((data, index) => ({ data, index })) .toSorted(({ data: a, index: ai }, { data: b, index: bi }) => { if (a.timestamp === b.timestamp) { diff --git a/src/stores/user_highlight.js b/src/stores/user_highlight.js index 759ebd509..0db37703d 100644 --- a/src/stores/user_highlight.js +++ b/src/stores/user_highlight.js @@ -2,10 +2,9 @@ import { merge as _merge, clone, cloneDeep, - flatten, groupBy, isEqual, - takeRight, + last, } from 'lodash' import { defineStore } from 'pinia' import { toRaw } from 'vue' @@ -117,25 +116,26 @@ export const _getRecentData = (cache, live, isTest) => { const _mergeJournal = (...journals) => { // Ignore invalid journal entries - const allJournals = flatten( - journals.map((j) => (Array.isArray(j) ? j : [])), - ).filter( - (entry) => - Object.hasOwn(entry, 'user') && - Object.hasOwn(entry, 'operation') && - Object.hasOwn(entry, 'args') && - Object.hasOwn(entry, 'timestamp'), - ) + const allJournals = journals + .map((j) => (Array.isArray(j) ? j : [])) + .flat() + .filter( + (entry) => + Object.hasOwn(entry, 'user') && + Object.hasOwn(entry, 'operation') && + Object.hasOwn(entry, 'args') && + Object.hasOwn(entry, 'timestamp'), + ) const grouped = groupBy(allJournals, 'user') const trimmedGrouped = Object.entries(grouped).map(([user, journal]) => { // side effect journal.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1)) - return takeRight(journal) + return [last(journal)] }) - return flatten(trimmedGrouped).sort((a, b) => - a.timestamp > b.timestamp ? 1 : -1, - ) + return trimmedGrouped + .flat() + .sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1)) } export const _mergeHighlights = (recent, stale) => {