summaryrefslogtreecommitdiff
path: root/src/services/note/create.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-06-13 05:40:12 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-06-13 05:40:12 +0900
commit7d8e70b2ac8e2073e0838eb5a5b4d428eaf24059 (patch)
tree62043fae5fcc48e563615f8154b8e47377744bf0 /src/services/note/create.ts
parent2.38.2 (diff)
downloadsharkey-7d8e70b2ac8e2073e0838eb5a5b4d428eaf24059.tar.gz
sharkey-7d8e70b2ac8e2073e0838eb5a5b4d428eaf24059.tar.bz2
sharkey-7d8e70b2ac8e2073e0838eb5a5b4d428eaf24059.zip
Fix bug
Diffstat (limited to 'src/services/note/create.ts')
-rw-r--r--src/services/note/create.ts110
1 files changed, 56 insertions, 54 deletions
diff --git a/src/services/note/create.ts b/src/services/note/create.ts
index 7eec7485be..f74d04ae62 100644
--- a/src/services/note/create.ts
+++ b/src/services/note/create.ts
@@ -204,6 +204,62 @@ export default async (user: IUser, data: {
return packAp(content);
};
+ //#region メンション
+ if (data.text) {
+ // TODO: Drop dupulicates
+ const mentionTokens = tokens
+ .filter(t => t.type == 'mention');
+
+ // TODO: Drop dupulicates
+ const mentionedUsers = (await Promise.all(mentionTokens.map(async m => {
+ try {
+ return await resolveUser(m.username, m.host);
+ } catch (e) {
+ return null;
+ }
+ }))).filter(x => x != null);
+
+ // Append mentions data
+ if (mentionedUsers.length > 0) {
+ const set = {
+ mentions: mentionedUsers.map(u => u._id),
+ mentionedRemoteUsers: mentionedUsers.filter(u => isRemoteUser(u)).map(u => ({
+ uri: (u as IRemoteUser).uri,
+ username: u.username,
+ host: u.host
+ }))
+ };
+
+ Note.update({ _id: note._id }, {
+ $set: set
+ });
+
+ Object.assign(note, set);
+ }
+
+ mentionedUsers.filter(u => isLocalUser(u)).forEach(async u => {
+ event(u, 'mention', noteObj);
+
+ // 既に言及されたユーザーに対する返信や引用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);
+ });
+ }
+ }
+ //#endregion
+
if (!silent) {
if (isLocalUser(user)) {
if (note.visibility == 'private' || note.visibility == 'followers' || note.visibility == 'specified') {
@@ -287,60 +343,6 @@ export default async (user: IUser, data: {
}
//#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 => {
- event(u, 'mention', noteObj);
-
- // 既に言及されたユーザーに対する返信や引用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),
- mentionedRemoteUsers: mentionedUsers.filter(u => isRemoteUser(u)).map(u => ({
- uri: (u as IRemoteUser).uri,
- username: u.username,
- host: u.host
- }))
- }
- });
- }
- }
- //#endregion
-
// If has in reply to note
if (data.reply) {
// Increment replies count