Compare commits
No commits in common. "b05f2bb834fda0a115c3686b8d3a4addf215acf7" and "796b4ebc0ffd5adc240192c3f65e15f7ae47da2c" have entirely different histories.
b05f2bb834
...
796b4ebc0f
|
@ -238,16 +238,7 @@ const translation = ref<any>(null);
|
||||||
const translating = ref(false);
|
const translating = ref(false);
|
||||||
const showTicker = (defaultStore.state.instanceTicker === 'always') || (defaultStore.state.instanceTicker === 'remote' && !!appearNote?.user.instance);
|
const showTicker = (defaultStore.state.instanceTicker === 'always') || (defaultStore.state.instanceTicker === 'remote' && !!appearNote?.user.instance);
|
||||||
const canRenote = computed(() => (!!appearNote && !!$i) && (['public', 'home'].includes(appearNote.visibility) || appearNote.userId === $i.id));
|
const canRenote = computed(() => (!!appearNote && !!$i) && (['public', 'home'].includes(appearNote.visibility) || appearNote.userId === $i.id));
|
||||||
let renoteCollapsed = $ref(
|
let renoteCollapsed = $ref(note && appearNote && defaultStore.state.collapseRenotes && isRenote && (($i && ($i.id === note.userId || $i.id === appearNote.userId)) || (appearNote.myReaction != null)));
|
||||||
note &&
|
|
||||||
appearNote &&
|
|
||||||
defaultStore.state.collapseRenotes &&
|
|
||||||
isRenote.value &&
|
|
||||||
(
|
|
||||||
($i && ($i.id === note.userId || $i.id === appearNote.userId)) ||
|
|
||||||
(appearNote.myReaction != null)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const keymap = {
|
const keymap = {
|
||||||
'r': () => reply(true),
|
'r': () => reply(true),
|
||||||
|
@ -527,14 +518,12 @@ onActivated(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
onDeactivated(() => {
|
onDeactivated(() => {
|
||||||
// 不要なキャッシュ消去や通信を防止するため遅延させる
|
if (unuse.value) {
|
||||||
setTimeout(() => {
|
unuse.value();
|
||||||
if (unuse.value) {
|
unuse.value = undefined;
|
||||||
unuse.value();
|
}
|
||||||
unuse.value = undefined;
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" module>
|
<style lang="scss" module>
|
||||||
|
|
|
@ -87,11 +87,6 @@ export type Paging<E extends keyof misskey.Endpoints = keyof misskey.Endpoints>
|
||||||
offsetMode?: boolean;
|
offsetMode?: boolean;
|
||||||
|
|
||||||
pageEl?: HTMLElement;
|
pageEl?: HTMLElement;
|
||||||
|
|
||||||
/**
|
|
||||||
* 変換関数
|
|
||||||
*/
|
|
||||||
transform?: (source: Omit<MisskeyEntity, '_shouldInsertAd_'>[]) => MisskeyEntity[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type MisskeyEntityMap = Map<string, MisskeyEntity>;
|
type MisskeyEntityMap = Map<string, MisskeyEntity>;
|
||||||
|
@ -174,11 +169,6 @@ const visibility = useDocumentVisibility();
|
||||||
const isPausingUpdateByExecutingQueue = ref(false);
|
const isPausingUpdateByExecutingQueue = ref(false);
|
||||||
const denyMoveTransition = ref(false);
|
const denyMoveTransition = ref(false);
|
||||||
|
|
||||||
/**
|
|
||||||
* 変換関数
|
|
||||||
*/
|
|
||||||
const transform = computed(() => props.pagination.transform ?? ((source: MisskeyEntity[]) => source));
|
|
||||||
|
|
||||||
//#region scrolling
|
//#region scrolling
|
||||||
const checkFn = props.pagination.reversed ? isBottomVisible : isTopVisible;
|
const checkFn = props.pagination.reversed ? isBottomVisible : isTopVisible;
|
||||||
const checkTop = (tolerance?: number) => {
|
const checkTop = (tolerance?: number) => {
|
||||||
|
@ -308,9 +298,7 @@ async function init(): Promise<void> {
|
||||||
await os.api(props.pagination.endpoint, {
|
await os.api(props.pagination.endpoint, {
|
||||||
...params,
|
...params,
|
||||||
limit: props.pagination.limit ?? 10,
|
limit: props.pagination.limit ?? 10,
|
||||||
}).then(_res => {
|
}).then(res => {
|
||||||
const res = transform.value(_res);
|
|
||||||
|
|
||||||
for (let i = 0; i < res.length; i++) {
|
for (let i = 0; i < res.length; i++) {
|
||||||
const item = res[i];
|
const item = res[i];
|
||||||
if (i === 3) item._shouldInsertAd_ = true;
|
if (i === 3) item._shouldInsertAd_ = true;
|
||||||
|
@ -390,9 +378,7 @@ const fetchMore = async (): Promise<void> => {
|
||||||
} : {
|
} : {
|
||||||
untilId: Array.from(items.value.keys()).at(-1),
|
untilId: Array.from(items.value.keys()).at(-1),
|
||||||
}),
|
}),
|
||||||
}).then(_res => {
|
}).then(res => {
|
||||||
const res = transform.value(_res);
|
|
||||||
|
|
||||||
for (let i = 0; i < res.length; i++) {
|
for (let i = 0; i < res.length; i++) {
|
||||||
const item = res[i];
|
const item = res[i];
|
||||||
if (i === 10) item._shouldInsertAd_ = true;
|
if (i === 10) item._shouldInsertAd_ = true;
|
||||||
|
@ -439,15 +425,15 @@ const fetchMoreAhead = async (): Promise<void> => {
|
||||||
} : {
|
} : {
|
||||||
sinceId: Array.from(items.value.keys()).at(-1),
|
sinceId: Array.from(items.value.keys()).at(-1),
|
||||||
}),
|
}),
|
||||||
}).then(_res => {
|
}).then(res => {
|
||||||
if (_res.length === 0) {
|
if (res.length === 0) {
|
||||||
|
items.value = concatMapWithArray(items.value, res);
|
||||||
more.value = false;
|
more.value = false;
|
||||||
} else {
|
} else {
|
||||||
const res = transform.value(_res);
|
|
||||||
items.value = concatMapWithArray(items.value, res);
|
items.value = concatMapWithArray(items.value, res);
|
||||||
more.value = true;
|
more.value = true;
|
||||||
}
|
}
|
||||||
offset.value += _res.length;
|
offset.value += res.length;
|
||||||
moreFetching.value = false;
|
moreFetching.value = false;
|
||||||
}, err => {
|
}, err => {
|
||||||
moreFetching.value = false;
|
moreFetching.value = false;
|
||||||
|
@ -498,12 +484,9 @@ watch([active, visibility], () => {
|
||||||
/**
|
/**
|
||||||
* 最新のものとして1つだけアイテムを追加する
|
* 最新のものとして1つだけアイテムを追加する
|
||||||
* ストリーミングから降ってきたアイテムはこれで追加する
|
* ストリーミングから降ってきたアイテムはこれで追加する
|
||||||
* @param item アイテム(transform前)
|
* @param item アイテム
|
||||||
*/
|
*/
|
||||||
const prepend = (_item: MisskeyEntity): void => {
|
const prepend = (item: MisskeyEntity): void => {
|
||||||
const item = transform.value([_item])[0];
|
|
||||||
if (!item) return;
|
|
||||||
|
|
||||||
if (items.value.size === 0) {
|
if (items.value.size === 0) {
|
||||||
items.value.set(item.id, item);
|
items.value.set(item.id, item);
|
||||||
fetching.value = false;
|
fetching.value = false;
|
||||||
|
@ -557,10 +540,7 @@ function concatItems(oldItems: MisskeyEntity[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function executeQueue() {
|
async function executeQueue() {
|
||||||
// キューが空の場合でもタイムライン表示数を制限する役割がある
|
if (queue.value.size === 0) return;
|
||||||
// ため続行する!
|
|
||||||
// if (queue.value.size === 0) return;
|
|
||||||
|
|
||||||
if (isPausingUpdateByExecutingQueue.value) return;
|
if (isPausingUpdateByExecutingQueue.value) return;
|
||||||
if (timelineBackTopBehavior.value === 'newest') {
|
if (timelineBackTopBehavior.value === 'newest') {
|
||||||
// Safariは最新のアイテムにするだけ
|
// Safariは最新のアイテムにするだけ
|
||||||
|
@ -590,12 +570,8 @@ function prependQueue(newItem: MisskeyEntity) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* アイテムを末尾に追加する(使うの?)
|
* アイテムを末尾に追加する(使うの?)
|
||||||
* @param item アイテム(transform前)
|
|
||||||
*/
|
*/
|
||||||
const appendItem = (_item: MisskeyEntity): void => {
|
const appendItem = (item: MisskeyEntity): void => {
|
||||||
const item = transform.value([_item])[0];
|
|
||||||
if (!item) return;
|
|
||||||
|
|
||||||
items.value.set(item.id, item);
|
items.value.set(item.id, item);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,6 @@ import { $i } from '@/account';
|
||||||
import { defaultStore } from '@/store';
|
import { defaultStore } from '@/store';
|
||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
import { instance } from '@/instance';
|
import { instance } from '@/instance';
|
||||||
import { noteManager } from '@/scripts/entity-manager';
|
|
||||||
import { Note } from 'misskey-js/built/entities';
|
|
||||||
import { MisskeyEntity } from '@/types/date-separated-list';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
src: string;
|
src: string;
|
||||||
|
@ -65,16 +62,6 @@ const prepend = note => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const transform = (notes: Note[]): MisskeyEntity[] => {
|
|
||||||
return notes.map(note => {
|
|
||||||
noteManager.set(note);
|
|
||||||
return {
|
|
||||||
id: note.id,
|
|
||||||
createdAt: note.createdAt,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
let endpoint;
|
let endpoint;
|
||||||
let query;
|
let query;
|
||||||
let connection;
|
let connection;
|
||||||
|
@ -178,7 +165,6 @@ const pagination = {
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
params: query,
|
params: query,
|
||||||
transform: transform,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Note, UserLite, DriveFile } from "misskey-js/built/entities";
|
import { Note, UserLite } from "misskey-js/built/entities";
|
||||||
import { Ref, ref, ComputedRef, computed } from "vue";
|
import { Ref, ref, ComputedRef, computed } from "vue";
|
||||||
import { api } from "./api";
|
import { api } from "./api";
|
||||||
import { useStream } from '@/stream';
|
import { useStream } from '@/stream';
|
||||||
|
@ -13,9 +13,7 @@ import { $i } from "@/account";
|
||||||
export class EntitiyManager<T extends { id: string }> {
|
export class EntitiyManager<T extends { id: string }> {
|
||||||
private entities: Map<T['id'], Ref<T>>;
|
private entities: Map<T['id'], Ref<T>>;
|
||||||
|
|
||||||
constructor(
|
constructor() {
|
||||||
public key: string,
|
|
||||||
) {
|
|
||||||
this.entities = new Map();
|
this.entities = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +32,7 @@ export class EntitiyManager<T extends { id: string }> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const userLiteManager = new EntitiyManager<UserLite>('userLite');
|
export const userLiteManager = new EntitiyManager<UserLite>();
|
||||||
export const driveFileManager = new EntitiyManager<DriveFile>('driveFile');
|
|
||||||
|
|
||||||
type OmittedNote = Omit<Note, 'user' | 'renote' | 'reply'>;
|
type OmittedNote = Omit<Note, 'user' | 'renote' | 'reply'>;
|
||||||
type CachedNoteSource = Ref<OmittedNote | null>;
|
type CachedNoteSource = Ref<OmittedNote | null>;
|
||||||
|
@ -56,9 +53,8 @@ export class NoteManager {
|
||||||
private notesSource: Map<Note['id'], CachedNoteSource>;
|
private notesSource: Map<Note['id'], CachedNoteSource>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ソースからuser, renote, replyを取得したComputedRefのキャッシュを保持しておく
|
* ソースからuser, renote, replyを取得したComputedRef
|
||||||
* nullは削除済みであることを表す
|
* nullは削除済みであることを表す
|
||||||
* キャプチャが0になったら削除される
|
|
||||||
*/
|
*/
|
||||||
private notesComputed: Map<Note['id'], CachedNote>;
|
private notesComputed: Map<Note['id'], CachedNote>;
|
||||||
private updatedAt: Map<Note['id'], number>;
|
private updatedAt: Map<Note['id'], number>;
|
||||||
|
@ -71,7 +67,7 @@ export class NoteManager {
|
||||||
this.updatedAt = new Map();
|
this.updatedAt = new Map();
|
||||||
this.captureing = new Map();
|
this.captureing = new Map();
|
||||||
this.connection = $i ? useStream() : null;
|
this.connection = $i ? useStream() : null;
|
||||||
this.connection?.on('noteUpdated', noteData => this.onStreamNoteUpdated(noteData));
|
this.connection?.on('noteUpdated', this.onStreamNoteUpdated);
|
||||||
this.connection?.on('_connected_', () => {
|
this.connection?.on('_connected_', () => {
|
||||||
// 再接続時に再キャプチャ
|
// 再接続時に再キャプチャ
|
||||||
for (const [id, captureingNumber] of Array.from(this.captureing)) {
|
for (const [id, captureingNumber] of Array.from(this.captureing)) {
|
||||||
|
@ -85,29 +81,16 @@ export class NoteManager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public set(_note: Note): void {
|
public set(_note: Note): CachedNote {
|
||||||
const note: Note = { ..._note };
|
const note: Note = { ..._note };
|
||||||
|
|
||||||
userLiteManager.set(note.user);
|
userLiteManager.set(note.user);
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
delete note.user;
|
delete note.user;
|
||||||
|
|
||||||
if (note.fileIds.length > 0) {
|
|
||||||
for (const file of note.files) {
|
|
||||||
driveFileManager.set(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
//@ts-ignore
|
|
||||||
delete note.files;
|
|
||||||
|
|
||||||
if (note.renote) this.set(note.renote);
|
if (note.renote) this.set(note.renote);
|
||||||
delete note.renote;
|
delete note.renote;
|
||||||
|
|
||||||
if (note.reply) this.set(note.reply);
|
if (note.reply) this.set(note.reply);
|
||||||
delete note.reply;
|
delete note.reply;
|
||||||
|
|
||||||
const cached = this.notesSource.get(note.id);
|
const cached = this.notesSource.get(note.id);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
cached.value = note;
|
cached.value = note;
|
||||||
|
@ -115,6 +98,7 @@ export class NoteManager {
|
||||||
this.notesSource.set(note.id, ref(note));
|
this.notesSource.set(note.id, ref(note));
|
||||||
}
|
}
|
||||||
this.updatedAt.set(note.id, Date.now());
|
this.updatedAt.set(note.id, Date.now());
|
||||||
|
return this.get(note.id)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get(id: string): CachedNote {
|
public get(id: string): CachedNote {
|
||||||
|
@ -133,14 +117,11 @@ export class NoteManager {
|
||||||
const reply = note.value.replyId ? this.get(note.value.replyId) : undefined;
|
const reply = note.value.replyId ? this.get(note.value.replyId) : undefined;
|
||||||
if (reply && !reply.value) return null;
|
if (reply && !reply.value) return null;
|
||||||
|
|
||||||
const files = note.value.fileIds.map(id => driveFileManager.get(id)?.value);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...note.value,
|
...note.value,
|
||||||
user: user.value,
|
user: user.value,
|
||||||
renote: renote?.value ?? undefined,
|
renote: renote?.value ?? undefined,
|
||||||
reply: reply?.value ?? undefined,
|
reply: reply?.value ?? undefined,
|
||||||
files: files.filter(file => file) as DriveFile[],
|
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -150,8 +131,7 @@ export class NoteManager {
|
||||||
public async fetch(id: string, force = false): Promise<CachedNote> {
|
public async fetch(id: string, force = false): Promise<CachedNote> {
|
||||||
if (!force) {
|
if (!force) {
|
||||||
const updatedAt = this.updatedAt.get(id);
|
const updatedAt = this.updatedAt.get(id);
|
||||||
// 2分以上経過していない場合はキャッシュを返す
|
if (updatedAt && Date.now() - updatedAt < 1000 * 30) {
|
||||||
if (updatedAt && Date.now() - updatedAt < 1000 * 120) {
|
|
||||||
const cachedNote = this.get(id);
|
const cachedNote = this.get(id);
|
||||||
if (cachedNote) {
|
if (cachedNote) {
|
||||||
return cachedNote;
|
return cachedNote;
|
||||||
|
@ -159,10 +139,7 @@ export class NoteManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return api('notes/show', { noteId: id })
|
return api('notes/show', { noteId: id })
|
||||||
.then(fetchedNote => {
|
.then(fetchedNote => this.set(fetchedNote))
|
||||||
this.set(fetchedNote);
|
|
||||||
return this.get(id)!;
|
|
||||||
})
|
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// エラーが発生した場合はとりあえず削除されたものとして扱う
|
// エラーが発生した場合はとりあえず削除されたものとして扱う
|
||||||
const cached = this.notesSource.get(id);
|
const cached = this.notesSource.get(id);
|
||||||
|
@ -184,8 +161,6 @@ export class NoteManager {
|
||||||
if (!note || !note.value) {
|
if (!note || !note.value) {
|
||||||
this.connection?.send('un', { id });
|
this.connection?.send('un', { id });
|
||||||
this.captureing.delete(id);
|
this.captureing.delete(id);
|
||||||
this.notesComputed.delete(id);
|
|
||||||
this.updatedAt.delete(id);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,8 +219,6 @@ export class NoteManager {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updatedAt.set(id, Date.now());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private capture(id: string, markRead = true): void {
|
private capture(id: string, markRead = true): void {
|
||||||
|
@ -279,9 +252,6 @@ export class NoteManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.captureing.delete(id);
|
this.captureing.delete(id);
|
||||||
|
|
||||||
// キャプチャが終わったらcomputedキャッシュも消してしまう
|
|
||||||
this.notesComputed.delete(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -317,11 +287,3 @@ export class NoteManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const noteManager = new NoteManager();
|
export const noteManager = new NoteManager();
|
||||||
|
|
||||||
if (_DEV_) {
|
|
||||||
console.log('entity manager initialized', {
|
|
||||||
noteManager,
|
|
||||||
userLiteManager,
|
|
||||||
driveFileManager,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue