1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-11-27 22:38:30 +09:00

Add erase function (#2641)

This commit is contained in:
Aya Morisawa 2018-09-07 00:02:55 +09:00 committed by syuilo
parent 3cace734c7
commit 00d79487cd
11 changed files with 31 additions and 19 deletions

View File

@ -1,6 +1,7 @@
import { EventEmitter } from 'eventemitter3';
import * as uuid from 'uuid';
import Connection from './stream';
import { erase } from '../../../../../prelude/array';
/**
*
@ -89,7 +90,7 @@ export default abstract class StreamManager<T extends Connection> extends EventE
* @param userId use ID
*/
public dispose(userId) {
this.users = this.users.filter(id => id != userId);
this.users = erase(userId, this.users);
this._connection.user = `Managed (${ this.users.length })`;

View File

@ -20,6 +20,7 @@
<script lang="ts">
import Vue from 'vue';
import { erase } from '../../../../../prelude/array';
export default Vue.extend({
data() {
return {
@ -53,7 +54,7 @@ export default Vue.extend({
get() {
return {
choices: this.choices.filter(choice => choice != '')
choices: erase('', this.choices)
}
},

View File

@ -62,6 +62,7 @@ import getFace from '../../../common/scripts/get-face';
import MkVisibilityChooser from '../../../common/views/components/visibility-chooser.vue';
import parse from '../../../../../mfm/parse';
import { host } from '../../../config';
import { erase } from '../../../../../prelude/array';
export default Vue.extend({
components: {
@ -346,7 +347,7 @@ export default Vue.extend({
},
removeVisibleUser(user) {
this.visibleUsers = this.visibleUsers.filter(u => u != user);
this.visibleUsers = erase(user, this.visibleUsers);
},
post() {

View File

@ -17,6 +17,7 @@ import Err from './common/views/components/connect-failed.vue';
import { LocalTimelineStreamManager } from './common/scripts/streaming/local-timeline';
import { HybridTimelineStreamManager } from './common/scripts/streaming/hybrid-timeline';
import { GlobalTimelineStreamManager } from './common/scripts/streaming/global-timeline';
import { erase } from '../../prelude/array';
//#region api requests
let spinner = null;
@ -537,7 +538,7 @@ export default class MiOS extends EventEmitter {
}
public unregisterStreamConnection(connection: Connection) {
this.connections = this.connections.filter(c => c != connection);
this.connections = erase(connection, this.connections);
}
}

View File

@ -59,6 +59,7 @@ import MkVisibilityChooser from '../../../common/views/components/visibility-cho
import getFace from '../../../common/scripts/get-face';
import parse from '../../../../../mfm/parse';
import { host } from '../../../config';
import { erase } from '../../../../../prelude/array';
export default Vue.extend({
components: {
@ -262,7 +263,7 @@ export default Vue.extend({
},
removeVisibleUser(user) {
this.visibleUsers = this.visibleUsers.filter(u => u != user);
this.visibleUsers = erase(user, this.visibleUsers);
},
clear() {

View File

@ -4,6 +4,7 @@ import * as nestedProperty from 'nested-property';
import MiOS from './mios';
import { hostname } from './config';
import { erase } from '../../prelude/array';
const defaultSettings = {
home: null,
@ -195,7 +196,7 @@ export default (os: MiOS) => new Vuex.Store({
removeDeckColumn(state, id) {
state.deck.columns = state.deck.columns.filter(c => c.id != id);
state.deck.layout = state.deck.layout.map(ids => ids.filter(x => x != id));
state.deck.layout = state.deck.layout.map(ids => erase(id, ids));
state.deck.layout = state.deck.layout.filter(ids => ids.length > 0);
},
@ -266,7 +267,7 @@ export default (os: MiOS) => new Vuex.Store({
stackLeftDeckColumn(state, id) {
const i = state.deck.layout.findIndex(ids => ids.indexOf(id) != -1);
state.deck.layout = state.deck.layout.map(ids => ids.filter(x => x != id));
state.deck.layout = state.deck.layout.map(ids => erase(id, ids));
const left = state.deck.layout[i - 1];
if (left) state.deck.layout[i - 1].push(id);
state.deck.layout = state.deck.layout.filter(ids => ids.length > 0);
@ -274,7 +275,7 @@ export default (os: MiOS) => new Vuex.Store({
popRightDeckColumn(state, id) {
const i = state.deck.layout.findIndex(ids => ids.indexOf(id) != -1);
state.deck.layout = state.deck.layout.map(ids => ids.filter(x => x != id));
state.deck.layout = state.deck.layout.map(ids => erase(id, ids));
state.deck.layout.splice(i + 1, 0, [id]);
state.deck.layout = state.deck.layout.filter(ids => ids.length > 0);
},

View File

@ -3,6 +3,7 @@
*/
import composeNotification from './common/scripts/compose-notification';
import { erase } from '../../prelude/array';
// キャッシュするリソース
const cachee = [
@ -24,8 +25,7 @@ self.addEventListener('activate', ev => {
// Clean up old caches
ev.waitUntil(
caches.keys().then(keys => Promise.all(
keys
.filter(key => key != _VERSION_)
erase(_VERSION_, keys)
.map(key => caches.delete(key))
))
);

View File

@ -13,3 +13,7 @@ export function concat<T>(xss: T[][]): T[] {
export function intersperse<T>(sep: T, xs: T[]): T[] {
return concat(xs.map(x => [sep, x])).slice(1);
}
export function erase<T>(x: T, xs: T[]): T[] {
return xs.filter(y => x !== y);
}

View File

@ -1,4 +1,5 @@
import Note from '../../../../models/note';
import { erase } from '../../../../prelude/array';
/*
a分間のユニーク投稿数が今からa分前b分前の間のユニーク投稿数のn倍以上5
@ -85,8 +86,7 @@ export default () => new Promise(async (res, rej) => {
//#endregion
// タグを人気順に並べ替え
let hots = (await Promise.all(hotsPromises))
.filter(x => x != null)
let hots = erase(null, await Promise.all(hotsPromises))
.sort((a, b) => b.count - a.count)
.map(tag => tag.name)
.slice(0, max);

View File

@ -5,6 +5,7 @@ import Mute from '../../../../models/mute';
import { getFriendIds } from '../../common/get-friends';
import { pack } from '../../../../models/note';
import getParams from '../../get-params';
import { erase } from '../../../../prelude/array';
export const meta = {
desc: {
@ -103,23 +104,23 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
if (psErr) throw psErr;
if (ps.includeUserUsernames != null) {
const ids = (await Promise.all(ps.includeUserUsernames.map(async (username) => {
const ids = erase(null, await Promise.all(ps.includeUserUsernames.map(async (username) => {
const _user = await User.findOne({
usernameLower: username.toLowerCase()
});
return _user ? _user._id : null;
}))).filter(id => id != null);
})));
ids.forEach(id => ps.includeUserIds.push(id));
}
if (ps.excludeUserUsernames != null) {
const ids = (await Promise.all(ps.excludeUserUsernames.map(async (username) => {
const ids = erase(null, await Promise.all(ps.excludeUserUsernames.map(async (username) => {
const _user = await User.findOne({
usernameLower: username.toLowerCase()
});
return _user ? _user._id : null;
}))).filter(id => id != null);
})));
ids.forEach(id => ps.excludeUserIds.push(id));
}

View File

@ -24,6 +24,7 @@ import isQuote from '../../misc/is-quote';
import { TextElementMention } from '../../mfm/parse/elements/mention';
import { TextElementHashtag } from '../../mfm/parse/elements/hashtag';
import { updateNoteStats } from '../update-chart';
import { erase } from '../../prelude/array';
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention';
@ -103,7 +104,7 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
if (data.viaMobile == null) data.viaMobile = false;
if (data.visibleUsers) {
data.visibleUsers = data.visibleUsers.filter(x => x != null);
data.visibleUsers = erase(null, data.visibleUsers);
}
if (data.reply && data.reply.deletedAt != null) {
@ -547,13 +548,13 @@ async function extractMentionedUsers(tokens: ReturnType<typeof parse>): Promise<
)];
const mentionedUsers = [...new Set(
(await Promise.all(mentionTokens.map(async m => {
erase(null, await Promise.all(mentionTokens.map(async m => {
try {
return await resolveUser(m.username, m.host);
} catch (e) {
return null;
}
}))).filter(x => x != null)
})))
)];
return mentionedUsers;