Compare commits

...

56 Commits
2.4.0 ... 2.6.2

Author SHA1 Message Date
12c624fa58 2.6.2 2018-05-14 14:16:56 +09:00
97c4758de2 Use _id instead of createdAt to improve performance 2018-05-14 13:58:44 +09:00
f20c08f0f7 Fix bug 2018-05-14 13:54:18 +09:00
1641d6bce2 Update add-file.ts 2018-05-14 12:47:33 +09:00
f5d2cb5c61 Improve performance 2018-05-14 09:24:49 +09:00
26941f62c6 2.6.1 2018-05-14 09:15:49 +09:00
06461bb9ee NoteのuserIdに対してインデックスを張るように 2018-05-14 09:15:43 +09:00
9f4624283d Disable prev/next 2018-05-14 09:01:37 +09:00
d4b696d03a Fix bug 2018-05-13 17:00:34 +09:00
219fdecc50 Fix bug 2018-05-13 16:52:47 +09:00
7af9ad9869 Better error handling 2018-05-13 16:26:11 +09:00
a858dd4453 2.6.0 2018-05-13 03:17:09 +09:00
f47377d181 ✌️ 2018-05-13 03:16:31 +09:00
bc197bc958 Add index 2018-05-13 03:13:55 +09:00
1836dd7312 Merge branch 'master' of https://github.com/syuilo/misskey 2018-05-13 03:08:33 +09:00
b844a8e9d5 Add note 2018-05-13 03:08:00 +09:00
a4ed163b62 Merge pull request #1576 from mei23/mei-preview
Fix url preview
2018-05-10 06:36:19 +09:00
f40e1ff0cc Fix cause error in case preview has data URI 2018-05-10 01:08:33 +09:00
d261fdbbc0 Fix can't preview some url 2018-05-09 20:14:34 +09:00
6b0a42af27 Merge pull request #1575 from mei23/mei-listlm
Fix list load-more is not working
2018-05-09 05:15:51 +09:00
107d9fd2c8 Fix list load-more is not working 2018-05-09 04:56:07 +09:00
4116b9eaf2 Provide originalNotesCount and originalUsersCount 2018-05-08 07:19:23 +09:00
ecd71ef5ff Fix bug 2018-05-08 07:08:02 +09:00
058602352c Fix #1574 2018-05-08 07:03:06 +09:00
59c39fab13 Update setup.ja.md 2018-05-08 04:04:18 +09:00
ab4f97ff20 2.5.0 2018-05-07 18:22:44 +09:00
79640d6861 Fix bug 2018-05-07 18:20:15 +09:00
d305c7e401 Fix 2018-05-07 17:45:21 +09:00
8afaca36d9 Better text parsing 2018-05-07 17:19:00 +09:00
9950fafff7 oops 2018-05-07 17:15:20 +09:00
0d9857db63 2.5.0-beta1 2018-05-07 17:05:17 +09:00
10c932876d Better banner redering 2018-05-07 17:05:05 +09:00
d5d7a527a0 Fix #1569 2018-05-07 16:53:56 +09:00
9eb8595130 Fix ui 2018-05-07 16:39:00 +09:00
8c46e5b3d9 投稿のレンダリングを改善 2018-05-07 16:31:33 +09:00
73bd877993 Merge branch 'master' of https://github.com/syuilo/misskey 2018-05-07 16:25:21 +09:00
de6cbf8a22 リモートアカウントの投稿に対しての返信にはメンションを付けるように 2018-05-07 16:25:06 +09:00
89f618d732 Update i18n.ts 2018-05-07 05:22:06 +09:00
4955df3911 oops 2018-05-07 04:26:45 +09:00
6785f50a1f 良い感じに 2018-05-07 04:08:39 +09:00
a549327170 Merge branch 'master' of https://github.com/syuilo/misskey 2018-05-07 03:19:27 +09:00
1f018d87f2 メンションを処理 2018-05-07 03:19:24 +09:00
769ee734fa Merge pull request #1572 from ha-dai/patch1
Fix typo.
2018-05-07 03:09:45 +09:00
6419185228 fix typo 2018-05-07 03:05:00 +09:00
b77cbeca22 #1427 2018-05-07 02:54:14 +09:00
4cce10a7d7 Fix glitch 2018-05-07 01:43:51 +09:00
1a6fd7d72e Fix ui glitch 2018-05-06 21:13:21 +09:00
97ce939a73 Fix 2018-05-06 18:19:17 +09:00
f850283147 Merge branch 'master' of github.com:syuilo/misskey 2018-05-04 02:49:46 +09:00
c512c07630 Merge branch 'master' of github.com:syuilo/misskey 2017-12-07 17:23:12 +09:00
105623e398 Merge branch 'master' of github.com:syuilo/misskey 2017-11-30 13:24:41 +09:00
6c75bc6d51 Merge branch 'master' of github.com:syuilo/misskey 2017-11-27 03:41:47 +09:00
a068741d05 Merge branch 'master' of https://github.com/syuilo/misskey 2017-11-06 13:37:48 +09:00
4e83106853 Merge branch 'master' of https://github.com/syuilo/misskey 2017-11-02 13:58:47 +09:00
0b688a909e Merge branch 'master' of https://github.com/syuilo/misskey 2017-10-26 15:05:20 +09:00
fabcad6db9 Merge branch 'master' of https://github.com/syuilo/misskey 2017-10-25 16:24:16 +09:00
34 changed files with 420 additions and 344 deletions

View File

@ -67,3 +67,15 @@ web-push generate-vapid-keys
1. `git reset --hard && git pull origin master`
2. `npm install`
3. `npm run build`
## メモリが足りなくてビルドできない場合
Misskeyの(クライアントの)ビルドには、目安として8GBくらいのメモリを必要とします。
VPSなどでビルドする時は、もしかしたらメモリが足りなくなる可能性があります。
そうなった場合、もしVPSではなくあなたのPCが十分なメモリを搭載しているなら、あなたのPC上でビルドし、生成されたファイルをVPSにFTPでアップロードする方法を採ることができます。
1. あなたのPC上にMisskeyをインストールする
2. 設定ファイルを用意する。設定ファイルは、サーバーに合わせた設定にします。
3. npm run webpack
4. built/client をサーバーにアップロードする
5. サーバー上で、npm run gulp
6. 完了

View File

@ -44,6 +44,8 @@ async function main() {
}
}
if (Object.keys(set).length === 0) return res([i, user]);
User.update({
_id: user._id
}, {

View File

@ -1,8 +1,8 @@
{
"name": "misskey",
"author": "syuilo <i@syuilo.com>",
"version": "2.4.0",
"clientVersion": "1.0.5215",
"version": "2.6.2",
"clientVersion": "1.0.5260",
"codename": "nighthike",
"main": "./built/index.js",
"private": true,
@ -69,6 +69,7 @@
"@types/ms": "0.7.30",
"@types/node": "9.6.6",
"@types/nopt": "3.0.29",
"@types/parse5": "^3.0.0",
"@types/pug": "2.0.4",
"@types/qrcode": "0.8.1",
"@types/ratelimiter": "2.1.28",
@ -166,6 +167,7 @@
"object-assign-deep": "0.4.0",
"on-build-webpack": "0.1.0",
"os-utils": "0.0.14",
"parse5": "^4.0.0",
"progress-bar-webpack-plugin": "1.11.0",
"prominence": "0.2.0",
"promise-sequential": "^1.1.1",

View File

@ -7,7 +7,7 @@ import locale from '../../locales';
export default class Replacer {
private lang: string;
public pattern = /%i18n:([a-z_\-@\.\!]+?)%/g;
public pattern = /%i18n:([a-z0-9_\-@\.\!]+?)%/g;
constructor(lang: string) {
this.lang = lang;

View File

@ -35,6 +35,7 @@ export default Vue.extend({
<style lang="stylus" scoped>
.mk-avatar
display inline-block
vertical-align bottom
background-size cover
background-position center center
transition border-radius 1s ease

View File

@ -45,7 +45,7 @@ export default Vue.extend({
} else if (url.hostname == 'youtu.be') {
this.youtubeId = url.pathname;
} else {
fetch('/url?url=' + this.url).then(res => {
fetch('/url?url=' + encodeURIComponent(this.url)).then(res => {
res.json().then(info => {
this.title = info.title;
this.description = info.description;

View File

@ -333,7 +333,7 @@ root(isDark)
> .renote
display flex
align-items baseline
align-items center
padding 16px 32px
line-height 28px
color #9dbb00

View File

@ -105,21 +105,11 @@ export default Vue.extend({
}
},
watch: {
text() {
this.saveDraft();
},
poll() {
this.saveDraft();
},
files() {
this.saveDraft();
}
},
mounted() {
if (this.reply && this.reply.user.host != null) {
this.text = `@${this.reply.user.username}@${this.reply.user.host} `;
}
this.$nextTick(() => {
// 書きかけの投稿を復元
const draft = JSON.parse(localStorage.getItem('drafts') || '{}')[this.draftId];
@ -134,10 +124,18 @@ export default Vue.extend({
}
this.$emit('change-attached-media', this.files);
}
this.$nextTick(() => this.watch());
});
},
methods: {
watch() {
this.$watch('text', () => this.saveDraft());
this.$watch('poll', () => this.saveDraft());
this.$watch('files', () => this.saveDraft());
},
focus() {
(this.$refs.text as any).focus();
},

View File

@ -62,7 +62,7 @@ export default Vue.extend({
more() {
this.moreFetching = true;
(this as any).api('notes/list-timeline', {
(this as any).api('notes/user-list-timeline', {
listId: this.list.id,
limit: fetchLimit + 1,
untilId: (this.$refs.timeline as any).tail().id,

View File

@ -1,9 +1,11 @@
<template>
<mk-ui>
<main v-if="!fetching">
<a v-if="note.next" :href="note.next">%fa:angle-up%%i18n:@next%</a>
<mk-note-detail :note="note"/>
<a v-if="note.prev" :href="note.prev">%fa:angle-down%%i18n:@prev%</a>
<footer>
<router-link v-if="note.next" :to="note.next">%fa:angle-left% %i18n:@next%</router-link>
<router-link v-if="note.prev" :to="note.prev">%i18n:@prev% %fa:angle-right%</router-link>
</footer>
</main>
</mk-ui>
</template>
@ -48,17 +50,12 @@ main
padding 16px
text-align center
> a
display inline-block
> footer
margin-top 16px
&:first-child
margin-bottom 4px
&:last-child
margin-top 4px
> [data-fa]
margin-right 4px
> a
display inline-block
margin 0 16px
> .mk-note-detail
margin 0 auto

View File

@ -2,8 +2,8 @@
<div class="header" :data-is-dark-background="user.bannerUrl != null">
<div class="is-suspended" v-if="user.isSuspended"><p>%fa:exclamation-triangle% %i18n:@is-suspended%</p></div>
<div class="is-remote" v-if="user.host != null"><p>%fa:exclamation-triangle% %i18n:@is-remote%<a :href="user.url || user.uri" target="_blank">%i18n:@view-remote%</a></p></div>
<div class="banner-container" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl})` : ''">
<div class="banner" ref="banner" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl})` : ''" @click="onBannerClick"></div>
<div class="banner-container" :style="style">
<div class="banner" ref="banner" :style="style" @click="onBannerClick"></div>
<div class="fade"></div>
</div>
<div class="container">
@ -25,6 +25,15 @@ import Vue from 'vue';
export default Vue.extend({
props: ['user'],
computed: {
style(): any {
if (this.user.bannerUrl == null) return {};
return {
backgroundColor: this.user.bannerColor ? `rgb(${ this.user.bannerColor.join(',') })` : null,
backgroundImage: `url(${ this.user.bannerUrl })`
};
}
},
mounted() {
if (this.user.bannerUrl) {
window.addEventListener('load', this.onScroll);

View File

@ -252,7 +252,7 @@ root(isDark)
> .renote
display flex
align-items baseline
align-items center
padding 8px 16px
line-height 28px
color #9dbb00

View File

@ -188,6 +188,11 @@ export default Vue.extend({
}
if ((this as any).clientSettings.fetchOnScroll !== false) {
// 親要素が display none だったら弾く
// https://github.com/syuilo/misskey/issues/1569
// http://d.hatena.ne.jp/favril/20091105/1257403319
if (this.$el.offsetHeight == 0) return;
const current = window.scrollY + window.innerHeight;
if (current > document.body.offsetHeight - 8) this.loadMore();
}

View File

@ -25,13 +25,15 @@
</div>
<mk-poll-editor v-if="poll" ref="poll" @destroyed="poll = false"/>
<mk-uploader ref="uploader" @uploaded="attachMedia" @change="onChangeUploadings"/>
<button class="upload" @click="chooseFile">%fa:upload%</button>
<button class="drive" @click="chooseFileFromDrive">%fa:cloud%</button>
<button class="kao" @click="kao">%fa:R smile%</button>
<button class="poll" @click="poll = true">%fa:chart-pie%</button>
<button class="poll" @click="useCw = !useCw">%fa:eye-slash%</button>
<button class="geo" @click="geo ? removeGeo() : setGeo()">%fa:map-marker-alt%</button>
<button class="visibility" @click="setVisibility" ref="visibilityButton">%fa:lock%</button>
<footer>
<button class="upload" @click="chooseFile">%fa:upload%</button>
<button class="drive" @click="chooseFileFromDrive">%fa:cloud%</button>
<button class="kao" @click="kao">%fa:R smile%</button>
<button class="poll" @click="poll = true">%fa:chart-pie%</button>
<button class="poll" @click="useCw = !useCw">%fa:eye-slash%</button>
<button class="geo" @click="geo ? removeGeo() : setGeo()">%fa:map-marker-alt%</button>
<button class="visibility" @click="setVisibility" ref="visibilityButton">%fa:lock%</button>
</footer>
<input ref="file" class="file" type="file" accept="image/*" multiple="multiple" @change="onChangeFile"/>
</div>
</div>
@ -67,6 +69,10 @@ export default Vue.extend({
},
mounted() {
if (this.reply && this.reply.user.host != null) {
this.text = `@${this.reply.user.username}@${this.reply.user.host} `;
}
this.$nextTick(() => {
this.focus();
});
@ -332,24 +338,25 @@ root(isDark)
> .file
display none
> .upload
> .drive
> .kao
> .poll
> .geo
> .visibility
display inline-block
padding 0
margin 0
width 48px
height 48px
font-size 20px
color #657786
background transparent
outline none
border none
border-radius 0
box-shadow none
> footer
white-space nowrap
overflow auto
-webkit-overflow-scrolling touch
overflow-scrolling touch
> *
display inline-block
padding 0
margin 0
width 48px
height 48px
font-size 20px
color #657786
background transparent
outline none
border none
border-radius 0
box-shadow none
.mk-post-form[data-darkmode]
root(true)

View File

@ -62,7 +62,7 @@ export default Vue.extend({
more() {
this.moreFetching = true;
(this as any).api('notes/list-timeline', {
(this as any).api('notes/user-list-timeline', {
listId: this.list.id,
limit: fetchLimit + 1,
untilId: (this.$refs.timeline as any).tail().id,

View File

@ -6,8 +6,8 @@
<mk-note-detail :note="note"/>
</div>
<footer>
<a v-if="note.prev" :href="note.prev">%fa:angle-left% %i18n:@prev%</a>
<a v-if="note.next" :href="note.next">%i18n:@next% %fa:angle-right%</a>
<router-link v-if="note.prev" :to="note.prev">%fa:angle-left% %i18n:@prev%</router-link>
<router-link v-if="note.next" :to="note.next">%i18n:@next% %fa:angle-right%</router-link>
</footer>
</main>
</mk-ui>

View File

@ -5,7 +5,7 @@
<div class="is-suspended" v-if="user.isSuspended"><p>%fa:exclamation-triangle% %i18n:@is-suspended%</p></div>
<div class="is-remote" v-if="user.host != null"><p>%fa:exclamation-triangle% %i18n:@is-remote%<a :href="user.url || user.uri" target="_blank">%i18n:@view-remote%</a></p></div>
<header>
<div class="banner" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl})` : ''"></div>
<div class="banner" :style="style"></div>
<div class="body">
<div class="top">
<a class="avatar">
@ -80,6 +80,13 @@ export default Vue.extend({
computed: {
age(): number {
return age(this.user.profile.birthday);
},
style(): any {
if (this.user.bannerUrl == null) return {};
return {
backgroundColor: this.user.bannerColor ? `rgb(${ this.user.bannerColor.join(',') })` : null,
backgroundImage: `url(${ this.user.bannerUrl })`
};
}
},
watch: {

View File

@ -14,13 +14,13 @@ mixin propTable(props)
if prop.kind == 'id'
if prop.entity
| (
a(href=`/${lang}/api/entities/${kebab(prop.entity)}`)= prop.entity
a(href=`/docs/${lang}/api/entities/${kebab(prop.entity)}`)= prop.entity
| ID)
else
| (ID)
else if prop.kind == 'entity'
| (
a(href=`/${lang}/api/entities/${kebab(prop.entity)}`)= prop.entity
a(href=`/docs/${lang}/api/entities/${kebab(prop.entity)}`)= prop.entity
| )
else if prop.kind == 'object'
if prop.def

View File

@ -9,6 +9,7 @@ import User from './user';
import DriveFileThumbnail, { deleteDriveFileThumbnail } from './drive-file-thumbnail';
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
DriveFile.createIndex('md5');
DriveFile.createIndex('metadata.uri', { sparse: true, unique: true });
export default DriveFile;

View File

@ -15,9 +15,8 @@ import Notification, { deleteNotification } from './notification';
import Following from './following';
const Note = db.get<INote>('notes');
Note.createIndex('uri', { sparse: true, unique: true });
Note.createIndex('userId');
export default Note;
export function isValidText(text: string): boolean {
@ -271,41 +270,10 @@ export const pack = async (
// When requested a detailed note data
if (opts.detail) {
// Get previous note info
_note.prev = (async () => {
const prev = await Note.findOne({
userId: _note.userId,
_id: {
$lt: id
}
}, {
fields: {
_id: true
},
sort: {
_id: -1
}
});
return prev ? prev._id.toHexString() : null;
})();
// Get next note info
_note.next = (async () => {
const next = await Note.findOne({
userId: _note.userId,
_id: {
$gt: id
}
}, {
fields: {
_id: true
},
sort: {
_id: 1
}
});
return next ? next._id.toHexString() : null;
})();
//#region 重いので廃止
_note.prev = null;
_note.next = null;
//#endregion
if (_note.replyId) {
// Populate reply to note

View File

@ -2,6 +2,7 @@ import { createQueue } from 'kue';
import config from '../config';
import http from './processors/http';
import { ILocalUser } from '../models/user';
const queue = createQueue({
redis: {
@ -20,7 +21,7 @@ export function createHttp(data) {
.backoff({ delay: 16384, type: 'exponential' });
}
export function deliver(user, content, to) {
export function deliver(user: ILocalUser, content, to) {
createHttp({
title: 'deliver',
type: 'deliver',

View File

@ -7,13 +7,14 @@ export default async (job: kue.Job, done): Promise<void> => {
await request(job.data.user, job.data.to, job.data.content);
done();
} catch (res) {
if (res.statusCode == null) return done();
if (res.statusCode >= 400 && res.statusCode < 500) {
// HTTPステータスコード4xxはクライアントエラーであり、それはつまり
// 何回再送しても成功することはないということなのでエラーにはしないでおく
done();
} else {
console.warn(`deliver failed: ${res.statusMessage}`);
done(new Error(res.statusMessage));
done(res);
}
}
};

View File

@ -11,7 +11,12 @@ export default function(note: INote) {
if (note.poll != null) {
const url = `${config.url}/notes/${note._id}`;
// TODO: i18n
html += `<p>【投票】<br />${url}</p>`;
html += `<p><a href="${url}">【Misskeyで投票を見る】</a></p>`;
}
if (note.renoteId != null) {
const url = `${config.url}/notes/${note.renoteId}`;
html += `<p>RE: <a href="${url}">${url}</a></p>`;
}
return html;

View File

@ -1,5 +1,5 @@
import * as mongo from 'mongodb';
import { JSDOM } from 'jsdom';
import * as parse5 from 'parse5';
import * as debug from 'debug';
import config from '../../../config';
@ -13,6 +13,76 @@ import { IRemoteUser } from '../../../models/user';
const log = debug('misskey:activitypub');
function parse(html: string): string {
const dom = parse5.parseFragment(html) as parse5.AST.Default.Document;
let text = '';
dom.childNodes.forEach(n => analyze(n));
return text.trim();
function getText(node) {
if (node.nodeName == '#text') return node.value;
if (node.childNodes) {
return node.childNodes.map(n => getText(n)).join('');
}
return '';
}
function analyze(node) {
switch (node.nodeName) {
case '#text':
text += node.value;
break;
case 'br':
text += '\n';
break;
case 'a':
const txt = getText(node);
// メンション
if (txt.startsWith('@')) {
const part = txt.split('@');
if (part.length == 2) {
//#region ホスト名部分が省略されているので復元する
const href = new URL(node.attrs.find(x => x.name == 'href').value);
const acct = txt + '@' + href.hostname;
text += acct;
break;
//#endregion
} else if (part.length == 3) {
text += txt;
break;
}
}
if (node.childNodes) {
node.childNodes.forEach(n => analyze(n));
}
break;
case 'p':
text += '\n\n';
if (node.childNodes) {
node.childNodes.forEach(n => analyze(n));
}
break;
default:
if (node.childNodes) {
node.childNodes.forEach(n => analyze(n));
}
break;
}
}
}
/**
* Noteをフェッチします。
*
@ -87,9 +157,8 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
// リプライ
const reply = note.inReplyTo ? await resolveNote(note.inReplyTo, resolver) : null;
// MastodonはHTMLを送り付けてくる
// そして改行は<br />で表現されている
const { window } = new JSDOM(note.content.replace(/<br \/>/g, '\n'));
// テキストのパース
const text = parse(note.content);
// ユーザーの情報が古かったらついでに更新しておく
if (actor.updatedAt == null || Date.now() - actor.updatedAt.getTime() > 1000 * 60 * 60 * 24) {
@ -101,7 +170,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
media,
reply,
renote: undefined,
text: window.document.body.textContent,
text: text,
viaMobile: false,
geo: undefined,
visibility,

View File

@ -15,6 +15,7 @@ export interface IObject {
icon?: any;
image?: any;
url?: string;
tag?: any[];
}
export interface IActivity extends IObject {

View File

@ -1,11 +1,16 @@
import { toUnicode, toASCII } from 'punycode';
import User from '../models/user';
import User, { IUser } from '../models/user';
import webFinger from './webfinger';
import config from '../config';
import { createPerson } from './activitypub/models/person';
export default async (username, _host, option) => {
export default async (username, _host, option?): Promise<IUser> => {
const usernameLower = username.toLowerCase();
if (_host == null) {
return await User.findOne({ usernameLower });
}
const hostAscii = toASCII(_host).toLowerCase();
const host = toUnicode(hostAscii);

View File

@ -57,6 +57,8 @@ export default (
.count({
recipientId: userId,
isRead: false
}, {
limit: 1
});
if (count == 0) {

View File

@ -43,6 +43,8 @@ export default (
.count({
notifieeId: userId,
isRead: false
}, {
limit: 1
});
if (count == 0) {

View File

@ -38,12 +38,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
if (pollErr) return rej('invalid poll param');
const query = {
createdAt: {
$gte: new Date(Date.now() - ms('1days'))
},
renoteCount: {
$gt: 0
}
_id: { $gte: new Date(Date.now() - ms('1days')) },
renoteCount: { $gt: 0 },
'_user.host': null
} as any;
if (reply != undefined) {

View File

@ -1,48 +1,26 @@
/**
* Module dependencies
*/
import Note from '../../../models/note';
import User from '../../../models/user';
/**
* @swagger
* /stats:
* note:
* summary: Show the misskey's statistics
* responses:
* 200:
* description: Success
* schema:
* type: object
* properties:
* notesCount:
* description: count of all notes of misskey
* type: number
* usersCount:
* description: count of all users of misskey
* type: number
*
* default:
* description: Failed
* schema:
* $ref: "#/definitions/Error"
*/
/**
* Show the misskey's statistics
*
* @param {any} params
* @return {Promise<any>}
* Get the misskey's statistics
*/
module.exports = params => new Promise(async (res, rej) => {
const notesCount = await Note
.count();
const notesCount = await Note.count();
const usersCount = await User
.count();
const usersCount = await User.count();
const originalNotesCount = await Note.count({
'_user.host': null
});
const originalUsersCount = await User.count({
host: null
});
res({
notesCount: notesCount,
usersCount: usersCount
notesCount,
usersCount,
originalNotesCount,
originalUsersCount
});
});

View File

@ -87,7 +87,7 @@ router.get('/url', require('./url-preview'));
//#region for crawlers
// User
router.get('/@:user', async ctx => {
router.get('/@:user', async (ctx, next) => {
const { username, host } = parseAcct(ctx.params.user);
const user = await User.findOne({
usernameLower: username.toLowerCase(),
@ -97,7 +97,8 @@ router.get('/@:user', async ctx => {
if (user != null) {
await ctx.render('user', { user });
} else {
ctx.status = 404;
// リモートユーザーなので
await next();
}
});

View File

@ -14,8 +14,8 @@ module.exports = async (ctx: Koa.Context) => {
function wrap(url: string): string {
return url != null
? url.startsWith('https://')
? url.startsWith('https://') || url.startsWith('data:')
? url
: `https://images.weserv.nl/?url=${url.replace(/^http:\/\//, '')}`
: `https://images.weserv.nl/?url=${encodeURIComponent(url.replace(/^http:\/\//, ''))}`
: null;
}

View File

@ -118,7 +118,8 @@ const addFile = async (
// Check if there is a file with the same hash
const much = await DriveFile.findOne({
md5: hash,
'metadata.userId': user._id
'metadata.userId': user._id,
'metadata.deletedAt': { $exists: false }
});
if (much !== null) {

View File

@ -1,5 +1,5 @@
import Note, { pack, INote } from '../../models/note';
import User, { isLocalUser, IUser, isRemoteUser } from '../../models/user';
import User, { isLocalUser, IUser, isRemoteUser, IRemoteUser, ILocalUser } from '../../models/user';
import stream, { publishLocalTimelineStream, publishGlobalTimelineStream, publishUserListStream } from '../../publishers/stream';
import Following from '../../models/following';
import { deliver } from '../../queue';
@ -17,6 +17,62 @@ import event from '../../publishers/stream';
import parse from '../../text/parse';
import { IApp } from '../../models/app';
import UserList from '../../models/user-list';
import resolveUser from '../../remote/resolve-user';
type Reason = 'reply' | 'quote' | 'mention';
/**
* ServiceWorkerへの通知を担当
*/
class NotificationManager {
private user: IUser;
private note: any;
private list: Array<{
user: ILocalUser['_id'],
reason: Reason;
}> = [];
constructor(user, note) {
this.user = user;
this.note = note;
}
public push(user: ILocalUser['_id'], reason: Reason) {
// 自分自身へは通知しない
if (this.user._id.equals(user)) return;
const exist = this.list.find(x => x.user.equals(user));
if (exist) {
// 「メンションされているかつ返信されている」場合は、メンションとしての通知ではなく返信としての通知にする
if (reason != 'mention') {
exist.reason = reason;
}
} else {
this.list.push({
user, reason
});
}
}
public deliver() {
this.list.forEach(async x => {
const mentionee = x.user;
// ミュート情報を取得
const mentioneeMutes = await Mute.find({
muterId: mentionee
});
const mentioneesMutedUserIds = mentioneeMutes.map(m => m.muteeId.toString());
// 通知される側のユーザーが通知する側のユーザーをミュートしていない限りは通知する
if (!mentioneesMutedUserIds.includes(this.user._id.toString())) {
pushSw(mentionee, x.reason, this.note);
}
});
}
}
export default async (user: IUser, data: {
createdAt?: Date;
@ -40,7 +96,7 @@ export default async (user: IUser, data: {
const tags = data.tags || [];
let tokens = null;
let tokens: any[] = null;
if (data.text) {
// Analyze
@ -119,152 +175,142 @@ export default async (user: IUser, data: {
// Serialize
const noteObj = await pack(note);
// タイムラインへの投稿
if (note.channelId == null) {
if (!silent) {
if (isLocalUser(user)) {
if (note.visibility == 'private' || note.visibility == 'followers' || note.visibility == 'specified') {
// Publish event to myself's stream
stream(note.userId, 'note', await pack(note, user, {
detail: true
}));
} else {
// Publish event to myself's stream
stream(note.userId, 'note', noteObj);
const nm = new NotificationManager(user, noteObj);
// Publish note to local timeline stream
if (note.visibility != 'home') {
publishLocalTimelineStream(noteObj);
}
const render = async () => {
const content = data.renote && data.text == null
? renderAnnounce(data.renote.uri ? data.renote.uri : await renderNote(data.renote))
: renderCreate(await renderNote(note));
return packAp(content);
};
if (!silent) {
if (isLocalUser(user)) {
if (note.visibility == 'private' || note.visibility == 'followers' || note.visibility == 'specified') {
// Publish event to myself's stream
stream(note.userId, 'note', await pack(note, user, {
detail: true
}));
} else {
// Publish event to myself's stream
stream(note.userId, 'note', noteObj);
// Publish note to local timeline stream
if (note.visibility != 'home') {
publishLocalTimelineStream(noteObj);
}
}
}
// Publish note to global timeline stream
publishGlobalTimelineStream(noteObj);
// Publish note to global timeline stream
publishGlobalTimelineStream(noteObj);
if (note.visibility == 'specified') {
data.visibleUsers.forEach(async u => {
stream(u._id, 'note', await pack(note, u, {
detail: true
}));
});
}
if (note.visibility == 'specified') {
data.visibleUsers.forEach(async u => {
stream(u._id, 'note', await pack(note, u, {
detail: true
}));
});
}
if (note.visibility == 'public' || note.visibility == 'home' || note.visibility == 'followers') {
// フォロワーに配信
Following.find({
followeeId: note.userId
}).then(followers => {
followers.map(async following => {
const follower = following._follower;
if (note.visibility == 'public' || note.visibility == 'home' || note.visibility == 'followers') {
// フォロワーに配信
Following.find({
followeeId: note.userId
}).then(followers => {
followers.map(async following => {
const follower = following._follower;
if (isLocalUser(follower)) {
// ストーキングしていない場合
if (!following.stalk) {
// この投稿が返信ならスキップ
if (note.replyId && !note._reply.userId.equals(following.followerId) && !note._reply.userId.equals(note.userId)) return;
}
// Publish event to followers stream
stream(following.followerId, 'note', noteObj);
} else {
//#region AP配送
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信
if (isLocalUser(user)) {
deliver(user, await render(), follower.inbox);
}
//#endergion
if (isLocalUser(follower)) {
// ストーキングしていない場合
if (!following.stalk) {
// この投稿が返信ならスキップ
if (note.replyId && !note._reply.userId.equals(following.followerId) && !note._reply.userId.equals(note.userId)) return;
}
});
});
}
// リストに配信
UserList.find({
userIds: note.userId
}).then(lists => {
lists.forEach(list => {
publishUserListStream(list._id, 'note', noteObj);
// Publish event to followers stream
stream(following.followerId, 'note', noteObj);
} else {
//#region AP配送
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信
if (isLocalUser(user)) {
deliver(user, await render(), follower.inbox);
}
//#endergion
}
});
});
}
//#region リプライとAnnounceのAP配送
const render = async () => {
const content = data.renote && data.text == null
? renderAnnounce(data.renote.uri ? data.renote.uri : await renderNote(data.renote))
: renderCreate(await renderNote(note));
return packAp(content);
};
// 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送
if (data.reply && isLocalUser(user) && isRemoteUser(data.reply._user)) {
deliver(user, await render(), data.reply._user.inbox);
}
// 投稿がRenoteかつ投稿者がローカルユーザーかつRenote元の投稿の投稿者がリモートユーザーなら配送
if (data.renote && isLocalUser(user) && isRemoteUser(data.renote._user)) {
deliver(user, await render(), data.renote._user.inbox);
}
//#endergion
// リストに配信
UserList.find({
userIds: note.userId
}).then(lists => {
lists.forEach(list => {
publishUserListStream(list._id, 'note', noteObj);
});
});
}
// チャンネルへの投稿
/* TODO
if (note.channelId) {
promises.push(
// Increment channel index(notes count)
Channel.update({ _id: note.channelId }, {
$inc: {
index: 1
//#region リプライとAnnounceのAP配送
// 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送
if (data.reply && isLocalUser(user) && isRemoteUser(data.reply._user)) {
deliver(user, await render(), data.reply._user.inbox);
}
// 投稿がRenoteかつ投稿者がローカルユーザーかつRenote元の投稿の投稿者がリモートユーザーなら配送
if (data.renote && isLocalUser(user) && isRemoteUser(data.renote._user)) {
deliver(user, await render(), data.renote._user.inbox);
}
//#endergion
//#region メンション
if (data.text) {
// TODO: Drop dupulicates
const mentions = tokens
.filter(t => t.type == 'mention');
let mentionedUsers = await Promise.all(mentions.map(async m => {
try {
return await resolveUser(m.username, m.host);
} catch (e) {
return null;
}
}));
// TODO: Drop dupulicates
mentionedUsers = mentionedUsers.filter(x => x != null);
mentionedUsers.filter(u => isLocalUser(u)).forEach(async u => {
// 既に言及されたユーザーに対する返信や引用renoteの場合も無視
if (data.reply && data.reply.userId.equals(u._id)) return;
if (data.renote && data.renote.userId.equals(u._id)) return;
// Create notification
notify(u._id, user._id, 'mention', {
noteId: note._id
});
nm.push(u._id, 'mention');
});
if (isLocalUser(user)) {
mentionedUsers.filter(u => isRemoteUser(u)).forEach(async u => {
deliver(user, await render(), (u as IRemoteUser).inbox);
});
}
// Append mentions data
if (mentionedUsers.length > 0) {
Note.update({ _id: note._id }, {
$set: {
mentions: mentionedUsers.map(u => u._id)
}
}),
// Publish event to channel
promisedNoteObj.then(noteObj => {
publishChannelStream(note.channelId, 'note', noteObj);
}),
Promise.all([
promisedNoteObj,
// Get channel watchers
ChannelWatching.find({
channelId: note.channelId,
// 削除されたドキュメントは除く
deletedAt: { $exists: false }
})
]).then(([noteObj, watches]) => {
// チャンネルの視聴者(のタイムライン)に配信
watches.forEach(w => {
stream(w.userId, 'note', noteObj);
});
})
);
}*/
const mentions = [];
async function addMention(mentionee, reason) {
// Reject if already added
if (mentions.some(x => x.equals(mentionee))) return;
// Add mention
mentions.push(mentionee);
// Publish event
if (!user._id.equals(mentionee)) {
const mentioneeMutes = await Mute.find({
muter_id: mentionee,
deleted_at: { $exists: false }
});
const mentioneesMutedUserIds = mentioneeMutes.map(m => m.muteeId.toString());
if (mentioneesMutedUserIds.indexOf(user._id.toString()) == -1) {
event(mentionee, reason, noteObj);
pushSw(mentionee, reason, noteObj);
}
}
}
//#endregion
// If has in reply to note
if (data.reply) {
@ -303,8 +349,7 @@ export default async (user: IUser, data: {
watch(user._id, data.reply);
}
// Add mention
addMention(data.reply.userId, 'reply');
nm.push(data.reply.userId, 'reply');
}
// If it is renote
@ -339,7 +384,7 @@ export default async (user: IUser, data: {
// If it is quote renote
if (data.text) {
// Add mention
addMention(data.renote.userId, 'quote');
nm.push(data.renote.userId, 'quote');
} else {
// Publish event
if (!user._id.equals(data.renote.userId)) {
@ -347,14 +392,17 @@ export default async (user: IUser, data: {
}
}
//#region TODO: これ重い
// 今までで同じ投稿をRenoteしているか
const existRenote = await Note.findOne({
userId: user._id,
renoteId: data.renote._id,
_id: {
$ne: note._id
}
});
//const existRenote = await Note.findOne({
// userId: user._id,
// renoteId: data.renote._id,
// _id: {
// $ne: note._id
// }
//});
const existRenote = null;
//#endregion
if (!existRenote) {
// Update renoteee status
@ -365,48 +413,4 @@ export default async (user: IUser, data: {
});
}
}
// If has text content
if (data.text) {
// Extract an '@' mentions
const atMentions = tokens
.filter(t => t.type == 'mention')
.map(m => m.username)
// Drop dupulicates
.filter((v, i, s) => s.indexOf(v) == i);
// Resolve all mentions
await Promise.all(atMentions.map(async mention => {
// Fetch mentioned user
// SELECT _id
const mentionee = await User
.findOne({
usernameLower: mention.toLowerCase()
}, { _id: true });
// When mentioned user not found
if (mentionee == null) return;
// 既に言及されたユーザーに対する返信や引用renoteの場合も無視
if (data.reply && data.reply.userId.equals(mentionee._id)) return;
if (data.renote && data.renote.userId.equals(mentionee._id)) return;
// Add mention
addMention(mentionee._id, 'mention');
// Create notification
notify(mentionee._id, user._id, 'mention', {
noteId: note._id
});
}));
}
// Append mentions data
if (mentions.length > 0) {
Note.update({ _id: note._id }, {
$set: {
mentions
}
});
}
});