This commit is contained in:
syuilo 2018-07-21 07:05:51 +09:00
parent ed48349e39
commit 91ad9e4c41
1 changed files with 25 additions and 17 deletions

View File

@ -112,6 +112,10 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
saveReply(data.reply, note);
}
if (data.renote) {
incRenoteCount(data.renote);
}
if (isQuote(note)) {
saveQuote(data.renote, note);
}
@ -119,25 +123,16 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
// Pack the note
const noteObj = await pack(note);
const noteActivity = await (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);
})();
const nm = new NotificationManager(user, note);
createMentionedEvents(mentionedUsers, noteObj, nm);
const noteActivity = await renderActivity(data, note);
if (isLocalUser(user)) {
deliverNoteToMentionedRemoteUsers(mentionedUsers, user, noteActivity);
}
if (!silent) {
publish(user, note, noteObj, data.reply, data.renote, data.visibleUsers, noteActivity);
}
// If has in reply to note
if (data.reply) {
// Fetch watchers
@ -176,19 +171,32 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
event(data.renote.userId, 'renote', noteObj);
}
}
}
// Update renoteee status
Note.update({ _id: data.renote._id }, {
$inc: {
renoteCount: 1
}
});
if (!silent) {
publish(user, note, noteObj, data.reply, data.renote, data.visibleUsers, noteActivity);
}
// Register to search database
index(note);
});
async function renderActivity(data: Option, note: INote) {
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);
}
function incRenoteCount(renote: INote) {
Note.update({ _id: renote._id }, {
$inc: {
renoteCount: 1
}
});
}
async function publish(user: IUser, note: INote, noteObj: any, reply: INote, renote: INote, visibleUsers: IUser[], noteActivity: any) {
if (isLocalUser(user)) {
// 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送