mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-25 21:23:09 +02:00
Merge branch 'develop' of https://github.com/syuilo/misskey into develop
This commit is contained in:
commit
51ba738c4b
5 changed files with 41 additions and 25 deletions
|
@ -15,6 +15,9 @@ import { TextElementSearch } from './elements/search';
|
||||||
import { TextElementTitle } from './elements/title';
|
import { TextElementTitle } from './elements/title';
|
||||||
import { TextElementUrl } from './elements/url';
|
import { TextElementUrl } from './elements/url';
|
||||||
import { TextElementMotion } from './elements/motion';
|
import { TextElementMotion } from './elements/motion';
|
||||||
|
import { groupOn } from '../../prelude/array';
|
||||||
|
import * as A from '../../prelude/array';
|
||||||
|
import * as S from '../../prelude/string';
|
||||||
|
|
||||||
const elements = [
|
const elements = [
|
||||||
require('./elements/big'),
|
require('./elements/big'),
|
||||||
|
@ -89,16 +92,10 @@ export default (source: string): TextElement[] => {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// テキストを纏める
|
const combineText = (es: TextElement[]): TextElement =>
|
||||||
return tokens.reduce((a, b) => {
|
({ type: 'text', content: S.concat(es.map(e => e.content)) });
|
||||||
if (a.length && a[a.length - 1].type == 'text' && b.type == 'text') {
|
|
||||||
const tail = a.pop();
|
return A.concat(groupOn(x => x.type, tokens).map(es =>
|
||||||
return a.concat({
|
es[0].type === 'text' ? [combineText(es)] : es
|
||||||
type: 'text',
|
));
|
||||||
content: tail.content + b.content
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return a.concat(b);
|
|
||||||
}
|
|
||||||
}, [] as TextElement[]);
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,10 @@ export function erase<T>(x: T, xs: T[]): T[] {
|
||||||
return xs.filter(y => x !== y);
|
return xs.filter(y => x !== y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setDifference<T>(xs: T[], ys: T[]): T[] {
|
||||||
|
return xs.filter(x => !ys.includes(x));
|
||||||
|
}
|
||||||
|
|
||||||
export function unique<T>(xs: T[]): T[] {
|
export function unique<T>(xs: T[]): T[] {
|
||||||
return [...new Set(xs)];
|
return [...new Set(xs)];
|
||||||
}
|
}
|
||||||
|
@ -25,3 +29,19 @@ export function unique<T>(xs: T[]): T[] {
|
||||||
export function sum(xs: number[]): number {
|
export function sum(xs: number[]): number {
|
||||||
return xs.reduce((a, b) => a + b, 0);
|
return xs.reduce((a, b) => a + b, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function groupBy<T>(f: (x: T, y: T) => boolean, xs: T[]): T[][] {
|
||||||
|
const groups = [] as T[][];
|
||||||
|
for (const x of xs) {
|
||||||
|
if (groups.length !== 0 && f(groups[groups.length - 1][0], x)) {
|
||||||
|
groups[groups.length - 1].push(x);
|
||||||
|
} else {
|
||||||
|
groups.push([x]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function groupOn<T, S>(f: (x: T) => S, xs: T[]): T[][] {
|
||||||
|
return groupBy((a, b) => f(a) === f(b), xs);
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
export function concat(xs: string[]): string {
|
||||||
|
return xs.reduce((a, b) => a + b, "");
|
||||||
|
}
|
||||||
|
|
||||||
export function capitalize(s: string): string {
|
export function capitalize(s: string): string {
|
||||||
return toUpperCase(s.charAt(0)) + toLowerCase(s.slice(1));
|
return toUpperCase(s.charAt(0)) + toLowerCase(s.slice(1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import htmlToMFM from '../../../mfm/html-to-mfm';
|
||||||
import Emoji from '../../../models/emoji';
|
import Emoji from '../../../models/emoji';
|
||||||
import { ITag } from './tag';
|
import { ITag } from './tag';
|
||||||
import { toUnicode } from 'punycode';
|
import { toUnicode } from 'punycode';
|
||||||
import { unique } from '../../../prelude/array';
|
import { unique, concat, setDifference } from '../../../prelude/array';
|
||||||
|
|
||||||
const log = debug('misskey:activitypub');
|
const log = debug('misskey:activitypub');
|
||||||
|
|
||||||
|
@ -180,14 +180,8 @@ async function extractEmojis(tags: ITag[], host_: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function extractMentionedUsers(actor: IRemoteUser, to: string[], cc: string[], resolver: Resolver) {
|
async function extractMentionedUsers(actor: IRemoteUser, to: string[], cc: string[], resolver: Resolver) {
|
||||||
let uris = [] as string[];
|
const ignoreUris = ['https://www.w3.org/ns/activitystreams#Public', `${actor.uri}/followers`];
|
||||||
|
const uris = setDifference(unique(concat([to || [], cc || []])), ignoreUris);
|
||||||
if (to) uris.concat(to);
|
|
||||||
if (cc) uris.concat(cc);
|
|
||||||
|
|
||||||
uris = uris.filter(x => x !== 'https://www.w3.org/ns/activitystreams#Public');
|
|
||||||
uris = uris.filter(x => x !== `${actor.uri}/followers`);
|
|
||||||
uris = unique(uris);
|
|
||||||
|
|
||||||
const users = await Promise.all(
|
const users = await Promise.all(
|
||||||
uris.map(async uri => await resolvePerson(uri, null, resolver).catch(() => null))
|
uris.map(async uri => await resolvePerson(uri, null, resolver).catch(() => null))
|
||||||
|
|
|
@ -19,6 +19,7 @@ import webFinger from './webfinger';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import networkChart from '../chart/network';
|
import networkChart from '../chart/network';
|
||||||
import apiServer from './api';
|
import apiServer from './api';
|
||||||
|
import { sum } from '../prelude/array';
|
||||||
|
|
||||||
// Init app
|
// Init app
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
|
@ -99,9 +100,9 @@ export default () => new Promise(resolve => {
|
||||||
if (queue.length == 0) return;
|
if (queue.length == 0) return;
|
||||||
|
|
||||||
const requests = queue.length;
|
const requests = queue.length;
|
||||||
const time = queue.reduce((a, b) => a + b.time, 0);
|
const time = sum(queue.map(x => x.time));
|
||||||
const incomingBytes = queue.reduce((a, b) => a + b.req.bytes, 0);
|
const incomingBytes = sum(queue.map(x => x.req.byets));
|
||||||
const outgoingBytes = queue.reduce((a, b) => a + b.res.bytes, 0);
|
const outgoingBytes = sum(queue.map(x => x.res.byets));
|
||||||
queue = [];
|
queue = [];
|
||||||
|
|
||||||
networkChart.update(requests, time, incomingBytes, outgoingBytes);
|
networkChart.update(requests, time, incomingBytes, outgoingBytes);
|
||||||
|
|
Loading…
Reference in a new issue