summaryrefslogtreecommitdiff
path: root/src/services/note/create.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2020-08-18 22:44:21 +0900
committerGitHub <noreply@github.com>2020-08-18 22:44:21 +0900
commit9855405b8989713b81709fc1700e2ead97423467 (patch)
tree54254d2159378d1903e962f0fb37c799bb0f4464 /src/services/note/create.ts
parentSign (request-target) Fix #6652 (#6656) (diff)
downloadmisskey-9855405b8989713b81709fc1700e2ead97423467.tar.gz
misskey-9855405b8989713b81709fc1700e2ead97423467.tar.bz2
misskey-9855405b8989713b81709fc1700e2ead97423467.zip
Channel (#6621)
* wip * wip * wip * wip * wip * wip * wip * wip * wop * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * add notes * wip * wip * wip * wip * sound * wip * add kick_gaba2 * wip
Diffstat (limited to 'src/services/note/create.ts')
-rw-r--r--src/services/note/create.ts75
1 files changed, 69 insertions, 6 deletions
diff --git a/src/services/note/create.ts b/src/services/note/create.ts
index 44ec5fda6f..a530b86f55 100644
--- a/src/services/note/create.ts
+++ b/src/services/note/create.ts
@@ -17,7 +17,7 @@ import extractMentions from '../../misc/extract-mentions';
import extractEmojis from '../../misc/extract-emojis';
import extractHashtags from '../../misc/extract-hashtags';
import { Note, IMentionedRemoteUsers } from '../../models/entities/note';
-import { Mutings, Users, NoteWatchings, Notes, Instances, UserProfiles, Antennas, Followings, MutedNotes } from '../../models';
+import { Mutings, Users, NoteWatchings, Notes, Instances, UserProfiles, Antennas, Followings, MutedNotes, Channels, ChannelFollowings } from '../../models';
import { DriveFile } from '../../models/entities/drive-file';
import { App } from '../../models/entities/app';
import { Not, getConnection, In } from 'typeorm';
@@ -33,6 +33,7 @@ import { checkWordMute } from '../../misc/check-word-mute';
import { addNoteToAntenna } from '../add-note-to-antenna';
import { countSameRenotes } from '../../misc/count-same-renotes';
import { deliverToRelays } from '../relay';
+import { Channel } from '../../models/entities/channel';
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention';
@@ -102,6 +103,7 @@ type Option = {
cw?: string | null;
visibility?: string;
visibleUsers?: User[] | null;
+ channel?: Channel | null;
apMentions?: User[] | null;
apHashtags?: string[] | null;
apEmojis?: string[] | null;
@@ -111,13 +113,31 @@ type Option = {
};
export default async (user: User, data: Option, silent = false) => new Promise<Note>(async (res, rej) => {
+ // チャンネル外にリプライしたら対象のスコープに合わせる
+ // (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
+ if (data.reply && data.channel && data.reply.channelId !== data.channel.id) {
+ if (data.reply.channelId) {
+ data.channel = await Channels.findOne(data.reply.channelId);
+ } else {
+ data.channel = null;
+ }
+ }
+
+ // チャンネル内にリプライしたら対象のスコープに合わせる
+ // (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
+ if (data.reply && (data.channel == null) && data.reply.channelId) {
+ data.channel = await Channels.findOne(data.reply.channelId);
+ }
+
if (data.createdAt == null) data.createdAt = new Date();
if (data.visibility == null) data.visibility = 'public';
if (data.viaMobile == null) data.viaMobile = false;
if (data.localOnly == null) data.localOnly = false;
+ if (data.channel != null) data.visibility = 'public';
+ if (data.channel != null) data.visibleUsers = [];
// サイレンス
- if (user.isSilenced && data.visibility === 'public') {
+ if (user.isSilenced && data.visibility === 'public' && data.channel == null) {
data.visibility = 'home';
}
@@ -142,12 +162,12 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
}
// ローカルのみをRenoteしたらローカルのみにする
- if (data.renote && data.renote.localOnly) {
+ if (data.renote && data.renote.localOnly && data.channel == null) {
data.localOnly = true;
}
// ローカルのみにリプライしたらローカルのみにする
- if (data.reply && data.reply.localOnly) {
+ if (data.reply && data.reply.localOnly && data.channel == null) {
data.localOnly = true;
}
@@ -255,6 +275,18 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
}
});
+ // Channel
+ if (note.channelId) {
+ ChannelFollowings.find({ followeeId: note.channelId }).then(followings => {
+ for (const following of followings) {
+ insertNoteUnread(following.followerId, note, {
+ isSpecified: false,
+ isMentioned: false,
+ });
+ }
+ });
+ }
+
if (data.reply) {
saveReply(data.reply, note);
}
@@ -273,11 +305,23 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
if (data.visibleUsers == null) throw new Error('invalid param');
for (const u of data.visibleUsers) {
- insertNoteUnread(u, note, true);
+ // ローカルユーザーのみ
+ if (!Users.isLocalUser(u)) continue;
+
+ insertNoteUnread(u.id, note, {
+ isSpecified: true,
+ isMentioned: false,
+ });
}
} else {
for (const u of mentionedUsers) {
- insertNoteUnread(u, note, false);
+ // ローカルユーザーのみ
+ if (!Users.isLocalUser(u)) continue;
+
+ insertNoteUnread(u.id, note, {
+ isSpecified: false,
+ isMentioned: true,
+ });
}
}
@@ -379,6 +423,24 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
//#endregion
}
+ if (data.channel) {
+ Channels.increment({ id: data.channel.id }, 'notesCount', 1);
+ Channels.update(data.channel.id, {
+ lastNotedAt: new Date(),
+ });
+
+ Notes.count({
+ userId: user.id,
+ channelId: data.channel.id,
+ }).then(count => {
+ // この処理が行われるのはノート作成後なので、ノートが一つしかなかったら最初の投稿だと判断できる
+ // TODO: とはいえノートを削除して何回も投稿すればその分だけインクリメントされる雑さもあるのでどうにかしたい
+ if (count === 1) {
+ Channels.increment({ id: data.channel.id }, 'usersCount', 1);
+ }
+ });
+ }
+
// Register to search database
index(note);
});
@@ -405,6 +467,7 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri
fileIds: data.files ? data.files.map(file => file.id) : [],
replyId: data.reply ? data.reply.id : null,
renoteId: data.renote ? data.renote.id : null,
+ channelId: data.channel ? data.channel.id : null,
name: data.name,
text: data.text,
hasPoll: data.poll != null,