partialかどうかの判定に新規のプロパティを利用するように

This commit is contained in:
kakkokari-gtyih 2024-12-28 17:48:22 +09:00
parent ba685850df
commit 3ae17b7217
12 changed files with 190 additions and 80 deletions

View File

@ -325,6 +325,17 @@ export class NoteEntityService implements OnModuleInit {
return true; return true;
} }
/** CDNなどにキャッシュしても問題ないートかどうか */
@bindThis
public canCache(note: MiNote | Packed<'Note'>): boolean {
return (
(note.visibility === 'public' || note.visibility === 'home') &&
note.user?.makeNotesFollowersOnlyBefore == null &&
note.user?.makeNotesHiddenBefore == null &&
(note.user?.requireSigninToViewContents == false || note.user?.requireSigninToViewContents == null)
);
}
@bindThis @bindThis
public async packAttachedFiles(fileIds: MiNote['fileIds'], packedFiles: Map<MiNote['fileIds'][number], Packed<'DriveFile'> | null>): Promise<Packed<'DriveFile'>[]> { public async packAttachedFiles(fileIds: MiNote['fileIds'], packedFiles: Map<MiNote['fileIds'][number], Packed<'DriveFile'> | null>): Promise<Packed<'DriveFile'>[]> {
const missingIds = []; const missingIds = [];

View File

@ -29,7 +29,7 @@ class AntennaChannel extends Channel {
} }
@bindThis @bindThis
public async init(params: any) { public async init(params: JsonObject) {
if (typeof params.antennaId !== 'string') return; if (typeof params.antennaId !== 'string') return;
this.antennaId = params.antennaId as string; this.antennaId = params.antennaId as string;
this.minimize = !!(params.minimize ?? false); this.minimize = !!(params.minimize ?? false);
@ -45,13 +45,21 @@ class AntennaChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return; if (this.isNoteMutedOrBlocked(note)) return;
if (this.minimize && ['public', 'home'].includes(note.visibility)) { if (this.minimize) {
this.send('note', { if (this.noteEntityService.canCache(note)) {
id: note.id, myReaction: note.myReaction, this.send('note', {
poll: note.poll?.choices ? { choices: note.poll.choices } : undefined, id: note.id, myReaction: note.myReaction,
reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined, poll: note.poll?.choices ? { choices: note.poll.choices } : undefined,
renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined,
}); renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined,
_allowCached_: true,
});
} else {
this.send('note', {
id: note.id,
_allowCached_: false,
});
}
} else { } else {
this.connection.cacheNote(note); this.connection.cacheNote(note);
this.send('note', note); this.send('note', note);

View File

@ -29,7 +29,7 @@ class ChannelChannel extends Channel {
} }
@bindThis @bindThis
public async init(params: any) { public async init(params: JsonObject) {
if (typeof params.channelId !== 'string') return; if (typeof params.channelId !== 'string') return;
this.channelId = params.channelId as string; this.channelId = params.channelId as string;
this.minimize = !!(params.minimize ?? false); this.minimize = !!(params.minimize ?? false);
@ -51,13 +51,21 @@ class ChannelChannel extends Channel {
} }
} }
if (this.minimize && ['public', 'home'].includes(note.visibility)) { if (this.minimize) {
this.send('note', { if (this.noteEntityService.canCache(note)) {
id: note.id, myReaction: note.myReaction, this.send('note', {
poll: note.poll?.choices ? { choices: note.poll.choices } : undefined, id: note.id, myReaction: note.myReaction,
reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined, poll: note.poll?.choices ? { choices: note.poll.choices } : undefined,
renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined,
}); renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined,
_allowCached_: true,
});
} else {
this.send('note', {
id: note.id,
_allowCached_: false,
});
}
} else { } else {
this.connection.cacheNote(note); this.connection.cacheNote(note);
this.send('note', note); this.send('note', note);

View File

@ -64,13 +64,21 @@ class GlobalTimelineChannel extends Channel {
} }
} }
if (this.minimize && ['public', 'home'].includes(note.visibility)) { if (this.minimize) {
this.send('note', { if (this.noteEntityService.canCache(note)) {
id: note.id, myReaction: note.myReaction, this.send('note', {
poll: note.poll?.choices ? { choices: note.poll.choices } : undefined, id: note.id, myReaction: note.myReaction,
reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined, poll: note.poll?.choices ? { choices: note.poll.choices } : undefined,
renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined,
}); renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined,
_allowCached_: true,
});
} else {
this.send('note', {
id: note.id,
_allowCached_: false,
});
}
} else { } else {
this.connection.cacheNote(note); this.connection.cacheNote(note);
this.send('note', note); this.send('note', note);

View File

@ -88,13 +88,21 @@ class HomeTimelineChannel extends Channel {
} }
} }
if (this.minimize && ['public', 'home'].includes(note.visibility)) { if (this.minimize) {
this.send('note', { if (this.noteEntityService.canCache(note)) {
id: note.id, myReaction: note.myReaction, this.send('note', {
poll: note.poll?.choices ? { choices: note.poll.choices } : undefined, id: note.id, myReaction: note.myReaction,
reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined, poll: note.poll?.choices ? { choices: note.poll.choices } : undefined,
renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined,
}); renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined,
_allowCached_: true,
});
} else {
this.send('note', {
id: note.id,
_allowCached_: false,
});
}
} else { } else {
this.connection.cacheNote(note); this.connection.cacheNote(note);
this.send('note', note); this.send('note', note);

View File

@ -103,13 +103,21 @@ class HybridTimelineChannel extends Channel {
} }
} }
if (this.minimize && ['public', 'home'].includes(note.visibility)) { if (this.minimize) {
this.send('note', { if (this.noteEntityService.canCache(note)) {
id: note.id, myReaction: note.myReaction, this.send('note', {
poll: note.poll?.choices ? { choices: note.poll.choices } : undefined, id: note.id, myReaction: note.myReaction,
reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined, poll: note.poll?.choices ? { choices: note.poll.choices } : undefined,
renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined,
}); renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined,
_allowCached_: true,
});
} else {
this.send('note', {
id: note.id,
_allowCached_: false,
});
}
} else { } else {
this.connection.cacheNote(note); this.connection.cacheNote(note);
this.send('note', note); this.send('note', note);

View File

@ -74,13 +74,21 @@ class LocalTimelineChannel extends Channel {
} }
} }
if (this.minimize && ['public', 'home'].includes(note.visibility)) { if (this.minimize) {
this.send('note', { if (this.noteEntityService.canCache(note)) {
id: note.id, myReaction: note.myReaction, this.send('note', {
poll: note.poll?.choices ? { choices: note.poll.choices } : undefined, id: note.id, myReaction: note.myReaction,
reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined, poll: note.poll?.choices ? { choices: note.poll.choices } : undefined,
renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined,
}); renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined,
_allowCached_: true,
});
} else {
this.send('note', {
id: note.id,
_allowCached_: false,
});
}
} else { } else {
this.connection.cacheNote(note); this.connection.cacheNote(note);
this.send('note', note); this.send('note', note);

View File

@ -50,14 +50,23 @@ class RoleTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return; if (this.isNoteMutedOrBlocked(note)) return;
if (this.minimize && ['public', 'home'].includes(note.visibility)) { if (this.minimize) {
this.send('note', { if (this.noteEntityService.canCache(note)) {
id: note.id, myReaction: note.myReaction, this.send('note', {
poll: note.poll?.choices ? { choices: note.poll.choices } : undefined, id: note.id, myReaction: note.myReaction,
reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined, poll: note.poll?.choices ? { choices: note.poll.choices } : undefined,
renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined, reply: note.reply?.myReaction ? { myReaction: note.reply.myReaction } : undefined,
}); renote: note.renote?.myReaction ? { myReaction: note.renote.myReaction } : undefined,
_allowCached_: true,
});
} else {
this.send('note', {
id: note.id,
_allowCached_: false,
});
}
} else { } else {
this.connection.cacheNote(note);
this.send('note', note); this.send('note', note);
} }
} else { } else {

View File

@ -29,6 +29,8 @@ import { $i, iAmModerator } from '@/account.js';
import { instance } from '@/instance.js'; import { instance } from '@/instance.js';
import { defaultStore } from '@/store.js'; import { defaultStore } from '@/store.js';
import { Paging } from '@/components/MkPagination.vue'; import { Paging } from '@/components/MkPagination.vue';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { MisskeyEntity } from '@/types/date-separated-list.js';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
src: BasicTimelineType | 'mentions' | 'directs' | 'list' | 'antenna' | 'channel' | 'role'; src: BasicTimelineType | 'mentions' | 'directs' | 'list' | 'antenna' | 'channel' | 'role';
@ -73,20 +75,33 @@ const tlComponent = shallowRef<InstanceType<typeof MkNotes>>();
let tlNotesCount = 0; let tlNotesCount = 0;
async function prepend(data) { async function prepend(data: Misskey.entities.Note | Misskey.entities.StreamNote) {
if (tlComponent.value == null) return; if (tlComponent.value == null) return;
let note = data; let note: Misskey.entities.Note & MisskeyEntity;
// if ('_allowCached_' in data) {
// minimizeid let fullNote: Misskey.entities.Note | null = null;
if (!data.visibility) {
const res = await window.fetch(`/notes/${data.id}.json`, { const { _allowCached_, ..._data } = data;
method: 'GET',
credentials: 'omit', if (_allowCached_) {
}); const res = await window.fetch(`/notes/${data.id}.json`, {
if (!res.ok) return; method: 'GET',
note = deepMerge(data, await res.json()); credentials: 'omit',
});
if (!res.ok) return;
fullNote = await res.json();
} else {
fullNote = await misskeyApi('notes/show', {
noteId: data.id,
});
}
if (fullNote == null) return;
note = deepMerge(_data, fullNote);
} else {
note = data;
} }
tlNotesCount++; tlNotesCount++;

View File

@ -635,7 +635,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -647,7 +647,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -659,7 +659,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -670,7 +670,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -682,7 +682,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -701,7 +701,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -711,7 +711,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -721,7 +721,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -1222,6 +1222,7 @@ declare namespace entities {
EmojiUpdated, EmojiUpdated,
EmojiDeleted, EmojiDeleted,
AnnouncementCreated, AnnouncementCreated,
StreamNote,
SignupRequest, SignupRequest,
SignupResponse, SignupResponse,
SignupPendingRequest, SignupPendingRequest,
@ -3192,6 +3193,19 @@ export type StreamEvents = {
_disconnected_: void; _disconnected_: void;
} & BroadcastEvents; } & BroadcastEvents;
// @public (undocumented)
type StreamNote = ({
id: Note['id'];
poll?: Pick<NonNullable<Note['poll']>, 'choices'>;
reply?: Pick<NonNullable<Note['reply']>, 'myReaction'>;
renote?: Pick<NonNullable<Note['renote']>, 'myReaction'>;
} & {
_allowCached_: true;
}) | {
id: Note['id'];
_allowCached_: false;
};
// Warning: (ae-forgotten-export) The symbol "SwitchCase" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "SwitchCase" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "IsCaseMatched" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "IsCaseMatched" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "GetCaseResult" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "GetCaseResult" needs to be exported by the entry point index.d.ts
@ -3421,8 +3435,8 @@ type UsersUpdateMemoRequest = operations['users___update-memo']['requestBody']['
// Warnings were encountered during analysis: // Warnings were encountered during analysis:
// //
// src/entities.ts:50:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts // src/entities.ts:50:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts
// src/streaming.types.ts:228:4 - (ae-forgotten-export) The symbol "ReversiUpdateKey" needs to be exported by the entry point index.d.ts // src/streaming.types.ts:229:4 - (ae-forgotten-export) The symbol "ReversiUpdateKey" needs to be exported by the entry point index.d.ts
// src/streaming.types.ts:238:4 - (ae-forgotten-export) The symbol "ReversiUpdateSettings" needs to be exported by the entry point index.d.ts // src/streaming.types.ts:239:4 - (ae-forgotten-export) The symbol "ReversiUpdateSettings" needs to be exported by the entry point index.d.ts
// (No @packageDocumentation comment for this package) // (No @packageDocumentation comment for this package)

View File

@ -248,6 +248,18 @@ export type AnnouncementCreated = {
announcement: Announcement; announcement: Announcement;
}; };
export type StreamNote = ({
id: Note['id'];
poll?: Pick<NonNullable<Note['poll']>, 'choices'>;
reply?: Pick<NonNullable<Note['reply']>, 'myReaction'>;
renote?: Pick<NonNullable<Note['renote']>, 'myReaction'>;
} & {
_allowCached_: true;
}) | {
id: Note['id'];
_allowCached_: false;
};
export type SignupRequest = { export type SignupRequest = {
username: string; username: string;
password: string; password: string;

View File

@ -19,6 +19,7 @@ import {
QueueStatsLog, QueueStatsLog,
ServerStats, ServerStats,
ServerStatsLog, ServerStatsLog,
StreamNote,
ReversiGameDetailed, ReversiGameDetailed,
} from './entities.js'; } from './entities.js';
import { import {
@ -76,7 +77,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -88,7 +89,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -100,7 +101,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -111,7 +112,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -123,7 +124,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -142,7 +143,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -152,7 +153,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };
@ -162,7 +163,7 @@ export type Channels = {
minimize?: boolean; minimize?: boolean;
}; };
events: { events: {
note: (payload: Note) => void; note: (payload: Note | StreamNote) => void;
}; };
receives: null; receives: null;
}; };