From 677a6aae2afe13417d26f4dc47b3f7078b4cfc52 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 12 Sep 2021 22:47:03 +0900 Subject: [PATCH] note --- src/misc/check-hit-antenna.ts | 4 ++-- src/models/repositories/note.ts | 8 +++----- src/server/api/stream/channels/channel.ts | 4 ++-- src/server/api/stream/channels/global-timeline.ts | 4 ++-- src/server/api/stream/channels/hashtag.ts | 4 ++-- src/server/api/stream/channels/home-timeline.ts | 4 ++-- src/server/api/stream/channels/hybrid-timeline.ts | 4 ++-- src/server/api/stream/channels/local-timeline.ts | 4 ++-- src/server/api/stream/channels/user-list.ts | 4 ++-- src/server/api/stream/index.ts | 8 ++++---- src/services/note/read.ts | 14 +++++++------- 11 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/misc/check-hit-antenna.ts b/src/misc/check-hit-antenna.ts index 38965f4b0d..3789054b26 100644 --- a/src/misc/check-hit-antenna.ts +++ b/src/misc/check-hit-antenna.ts @@ -3,13 +3,13 @@ import { Note } from '@/models/entities/note'; import { User } from '@/models/entities/user'; import { UserListJoinings, UserGroupJoinings } from '@/models/index'; import { getFullApAccount } from './convert-host'; -import { PackedNote } from '../models/repositories/note'; import { parseAcct } from '@/misc/acct'; +import { Packed } from './schema'; /** * noteUserFollowers / antennaUserFollowing はどちらか一方が指定されていればよい */ -export async function checkHitAntenna(antenna: Antenna, note: (Note | PackedNote), noteUser: { username: string; host: string | null; }, noteUserFollowers?: User['id'][], antennaUserFollowing?: User['id'][]): Promise { +export async function checkHitAntenna(antenna: Antenna, note: (Note | Packed<'Note'>), noteUser: { username: string; host: string | null; }, noteUserFollowers?: User['id'][], antennaUserFollowing?: User['id'][]): Promise { if (note.visibility === 'specified') return false; if (note.visibility === 'followers') { diff --git a/src/models/repositories/note.ts b/src/models/repositories/note.ts index 376a09d0c6..c0ac22b2db 100644 --- a/src/models/repositories/note.ts +++ b/src/models/repositories/note.ts @@ -3,15 +3,13 @@ import * as mfm from 'mfm-js'; import { Note } from '@/models/entities/note'; import { User } from '@/models/entities/user'; import { Users, PollVotes, DriveFiles, NoteReactions, Followings, Polls, Channels } from '../index'; -import { SchemaType } from '@/misc/schema'; +import { Packed } from '@/misc/schema'; import { nyaize } from '@/misc/nyaize'; import { awaitAll } from '@/prelude/await-all'; import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '@/misc/reaction-lib'; import { NoteReaction } from '@/models/entities/note-reaction'; import { aggregateNoteEmojis, populateEmojis, prefetchEmojis } from '@/misc/populate-emojis'; -export type PackedNote = SchemaType; - @EntityRepository(Note) export class NoteRepository extends Repository { public validateCw(x: string) { @@ -67,7 +65,7 @@ export class NoteRepository extends Repository { return true; } - private async hideNote(packedNote: PackedNote, meId: User['id'] | null) { + private async hideNote(packedNote: Packed<'Note'>, meId: User['id'] | null) { // TODO: isVisibleForMe を使うようにしても良さそう(型違うけど) let hide = false; @@ -137,7 +135,7 @@ export class NoteRepository extends Repository { myReactions: Map; }; } - ): Promise { + ): Promise> { const opts = Object.assign({ detail: true, skipHide: false diff --git a/src/server/api/stream/channels/channel.ts b/src/server/api/stream/channels/channel.ts index e6a9a6c696..72ddbf93b4 100644 --- a/src/server/api/stream/channels/channel.ts +++ b/src/server/api/stream/channels/channel.ts @@ -3,8 +3,8 @@ import Channel from '../channel'; import { Notes, Users } from '@/models/index'; import { isMutedUserRelated } from '@/misc/is-muted-user-related'; import { isBlockerUserRelated } from '@/misc/is-blocker-user-related'; -import { PackedNote } from '@/models/repositories/note'; import { User } from '@/models/entities/user'; +import { Packed } from '@/misc/schema'; export default class extends Channel { public readonly chName = 'channel'; @@ -25,7 +25,7 @@ export default class extends Channel { } @autobind - private async onNote(note: PackedNote) { + private async onNote(note: Packed<'Note'>) { if (note.channelId !== this.channelId) return; // リプライなら再pack diff --git a/src/server/api/stream/channels/global-timeline.ts b/src/server/api/stream/channels/global-timeline.ts index 384ed61409..f5983ab472 100644 --- a/src/server/api/stream/channels/global-timeline.ts +++ b/src/server/api/stream/channels/global-timeline.ts @@ -3,9 +3,9 @@ import { isMutedUserRelated } from '@/misc/is-muted-user-related'; import Channel from '../channel'; import { fetchMeta } from '@/misc/fetch-meta'; import { Notes } from '@/models/index'; -import { PackedNote } from '@/models/repositories/note'; import { checkWordMute } from '@/misc/check-word-mute'; import { isBlockerUserRelated } from '@/misc/is-blocker-user-related'; +import { Packed } from '@/misc/schema'; export default class extends Channel { public readonly chName = 'globalTimeline'; @@ -24,7 +24,7 @@ export default class extends Channel { } @autobind - private async onNote(note: PackedNote) { + private async onNote(note: Packed<'Note'>) { if (note.visibility !== 'public') return; if (note.channelId != null) return; diff --git a/src/server/api/stream/channels/hashtag.ts b/src/server/api/stream/channels/hashtag.ts index 997ab75f6d..281be4f2eb 100644 --- a/src/server/api/stream/channels/hashtag.ts +++ b/src/server/api/stream/channels/hashtag.ts @@ -2,9 +2,9 @@ import autobind from 'autobind-decorator'; import { isMutedUserRelated } from '@/misc/is-muted-user-related'; import Channel from '../channel'; import { Notes } from '@/models/index'; -import { PackedNote } from '@/models/repositories/note'; import { normalizeForSearch } from '@/misc/normalize-for-search'; import { isBlockerUserRelated } from '@/misc/is-blocker-user-related'; +import { Packed } from '@/misc/schema'; export default class extends Channel { public readonly chName = 'hashtag'; @@ -23,7 +23,7 @@ export default class extends Channel { } @autobind - private async onNote(note: PackedNote) { + private async onNote(note: Packed<'Note'>) { const noteTags = note.tags ? note.tags.map((t: string) => t.toLowerCase()) : []; const matched = this.q.some(tags => tags.every(tag => noteTags.includes(normalizeForSearch(tag)))); if (!matched) return; diff --git a/src/server/api/stream/channels/home-timeline.ts b/src/server/api/stream/channels/home-timeline.ts index 0e21ab552e..52e9aec250 100644 --- a/src/server/api/stream/channels/home-timeline.ts +++ b/src/server/api/stream/channels/home-timeline.ts @@ -2,9 +2,9 @@ import autobind from 'autobind-decorator'; import { isMutedUserRelated } from '@/misc/is-muted-user-related'; import Channel from '../channel'; import { Notes } from '@/models/index'; -import { PackedNote } from '@/models/repositories/note'; import { checkWordMute } from '@/misc/check-word-mute'; import { isBlockerUserRelated } from '@/misc/is-blocker-user-related'; +import { Packed } from '@/misc/schema'; export default class extends Channel { public readonly chName = 'homeTimeline'; @@ -18,7 +18,7 @@ export default class extends Channel { } @autobind - private async onNote(note: PackedNote) { + private async onNote(note: Packed<'Note'>) { if (note.channelId) { if (!this.followingChannels.has(note.channelId)) return; } else { diff --git a/src/server/api/stream/channels/hybrid-timeline.ts b/src/server/api/stream/channels/hybrid-timeline.ts index 0b28ff616b..51f95fc0cd 100644 --- a/src/server/api/stream/channels/hybrid-timeline.ts +++ b/src/server/api/stream/channels/hybrid-timeline.ts @@ -3,9 +3,9 @@ import { isMutedUserRelated } from '@/misc/is-muted-user-related'; import Channel from '../channel'; import { fetchMeta } from '@/misc/fetch-meta'; import { Notes } from '@/models/index'; -import { PackedNote } from '@/models/repositories/note'; import { checkWordMute } from '@/misc/check-word-mute'; import { isBlockerUserRelated } from '@/misc/is-blocker-user-related'; +import { Packed } from '@/misc/schema'; export default class extends Channel { public readonly chName = 'hybridTimeline'; @@ -22,7 +22,7 @@ export default class extends Channel { } @autobind - private async onNote(note: PackedNote) { + private async onNote(note: Packed<'Note'>) { // チャンネルの投稿ではなく、自分自身の投稿 または // チャンネルの投稿ではなく、その投稿のユーザーをフォローしている または // チャンネルの投稿ではなく、全体公開のローカルの投稿 または diff --git a/src/server/api/stream/channels/local-timeline.ts b/src/server/api/stream/channels/local-timeline.ts index 20061410c4..a6166c2be2 100644 --- a/src/server/api/stream/channels/local-timeline.ts +++ b/src/server/api/stream/channels/local-timeline.ts @@ -3,9 +3,9 @@ import { isMutedUserRelated } from '@/misc/is-muted-user-related'; import Channel from '../channel'; import { fetchMeta } from '@/misc/fetch-meta'; import { Notes } from '@/models/index'; -import { PackedNote } from '@/models/repositories/note'; import { checkWordMute } from '@/misc/check-word-mute'; import { isBlockerUserRelated } from '@/misc/is-blocker-user-related'; +import { Packed } from '@/misc/schema'; export default class extends Channel { public readonly chName = 'localTimeline'; @@ -24,7 +24,7 @@ export default class extends Channel { } @autobind - private async onNote(note: PackedNote) { + private async onNote(note: Packed<'Note'>) { if (note.user.host !== null) return; if (note.visibility !== 'public') return; if (note.channelId != null && !this.followingChannels.has(note.channelId)) return; diff --git a/src/server/api/stream/channels/user-list.ts b/src/server/api/stream/channels/user-list.ts index 0ca83cd658..63b254605b 100644 --- a/src/server/api/stream/channels/user-list.ts +++ b/src/server/api/stream/channels/user-list.ts @@ -3,8 +3,8 @@ import Channel from '../channel'; import { Notes, UserListJoinings, UserLists } from '@/models/index'; import { isMutedUserRelated } from '@/misc/is-muted-user-related'; import { User } from '@/models/entities/user'; -import { PackedNote } from '@/models/repositories/note'; import { isBlockerUserRelated } from '@/misc/is-blocker-user-related'; +import { Packed } from '@/misc/schema'; export default class extends Channel { public readonly chName = 'userList'; @@ -47,7 +47,7 @@ export default class extends Channel { } @autobind - private async onNote(note: PackedNote) { + private async onNote(note: Packed<'Note'>) { if (!this.listUsers.includes(note.userId)) return; if (['followers', 'specified'].includes(note.visibility)) { diff --git a/src/server/api/stream/index.ts b/src/server/api/stream/index.ts index f83bc9331e..ccd555e149 100644 --- a/src/server/api/stream/index.ts +++ b/src/server/api/stream/index.ts @@ -14,7 +14,7 @@ import { AccessToken } from '@/models/entities/access-token'; import { UserProfile } from '@/models/entities/user-profile'; import { publishChannelStream, publishGroupMessagingStream, publishMessagingStream } from '@/services/stream'; import { UserGroup } from '@/models/entities/user-group'; -import { PackedNote } from '@/models/repositories/note'; +import { Packed } from '@/misc/schema'; /** * Main stream connection @@ -31,7 +31,7 @@ export default class Connection { public subscriber: EventEmitter; private channels: Channel[] = []; private subscribingNotes: any = {}; - private cachedNotes: PackedNote[] = []; + private cachedNotes: Packed<'Note'>[] = []; constructor( wsConnection: websocket.connection, @@ -150,8 +150,8 @@ export default class Connection { } @autobind - public cacheNote(note: PackedNote) { - const add = (note: PackedNote) => { + public cacheNote(note: Packed<'Note'>) { + const add = (note: Packed<'Note'>) => { const existIndex = this.cachedNotes.findIndex(n => n.id === note.id); if (existIndex > -1) { this.cachedNotes[existIndex] = note; diff --git a/src/services/note/read.ts b/src/services/note/read.ts index 2e221d553a..f25f86da9c 100644 --- a/src/services/note/read.ts +++ b/src/services/note/read.ts @@ -6,15 +6,15 @@ import { Not, IsNull, In } from 'typeorm'; import { Channel } from '@/models/entities/channel'; import { checkHitAntenna } from '@/misc/check-hit-antenna'; import { getAntennas } from '@/misc/antenna-cache'; -import { PackedNote } from '@/models/repositories/note'; import { readNotificationByQuery } from '@/server/api/common/read-notification'; +import { Packed } from '@/misc/schema'; /** * Mark notes as read */ export default async function( userId: User['id'], - notes: (Note | PackedNote)[], + notes: (Note | Packed<'Note'>)[], info?: { following: Set; followingChannels: Set; @@ -34,10 +34,10 @@ export default async function( })).map(x => x.followeeId)); const myAntennas = (await getAntennas()).filter(a => a.userId === userId); - const readMentions: (Note | PackedNote)[] = []; - const readSpecifiedNotes: (Note | PackedNote)[] = []; - const readChannelNotes: (Note | PackedNote)[] = []; - const readAntennaNotes: (Note | PackedNote)[] = []; + const readMentions: (Note | Packed<'Note'>)[] = []; + const readSpecifiedNotes: (Note | Packed<'Note'>)[] = []; + const readChannelNotes: (Note | Packed<'Note'>)[] = []; + const readAntennaNotes: (Note | Packed<'Note'>)[] = []; for (const note of notes) { if (note.mentions && note.mentions.includes(userId)) { @@ -52,7 +52,7 @@ export default async function( if (note.user != null) { // たぶんnullになることは無いはずだけど一応 for (const antenna of myAntennas) { - if (checkHitAntenna(antenna, note, note.user as any, undefined, Array.from(following))) { + if (await checkHitAntenna(antenna, note, note.user as any, undefined, Array.from(following))) { readAntennaNotes.push(note); } }