Compare commits

..

No commits in common. "b05f2bb834fda0a115c3686b8d3a4addf215acf7" and "796b4ebc0ffd5adc240192c3f65e15f7ae47da2c" have entirely different histories.

4 changed files with 25 additions and 112 deletions

View File

@ -238,16 +238,7 @@ const translation = ref<any>(null);
const translating = ref(false);
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));
let renoteCollapsed = $ref(
note &&
appearNote &&
defaultStore.state.collapseRenotes &&
isRenote.value &&
(
($i && ($i.id === note.userId || $i.id === appearNote.userId)) ||
(appearNote.myReaction != null)
)
);
let renoteCollapsed = $ref(note && appearNote && defaultStore.state.collapseRenotes && isRenote && (($i && ($i.id === note.userId || $i.id === appearNote.userId)) || (appearNote.myReaction != null)));
const keymap = {
'r': () => reply(true),
@ -527,14 +518,12 @@ onActivated(() => {
});
onDeactivated(() => {
//
setTimeout(() => {
if (unuse.value) {
unuse.value();
unuse.value = undefined;
}
}, 1000);
if (unuse.value) {
unuse.value();
unuse.value = undefined;
}
});
</script>
<style lang="scss" module>

View File

@ -87,11 +87,6 @@ export type Paging<E extends keyof misskey.Endpoints = keyof misskey.Endpoints>
offsetMode?: boolean;
pageEl?: HTMLElement;
/**
* 変換関数
*/
transform?: (source: Omit<MisskeyEntity, '_shouldInsertAd_'>[]) => MisskeyEntity[];
};
type MisskeyEntityMap = Map<string, MisskeyEntity>;
@ -174,11 +169,6 @@ const visibility = useDocumentVisibility();
const isPausingUpdateByExecutingQueue = ref(false);
const denyMoveTransition = ref(false);
/**
* 変換関数
*/
const transform = computed(() => props.pagination.transform ?? ((source: MisskeyEntity[]) => source));
//#region scrolling
const checkFn = props.pagination.reversed ? isBottomVisible : isTopVisible;
const checkTop = (tolerance?: number) => {
@ -308,9 +298,7 @@ async function init(): Promise<void> {
await os.api(props.pagination.endpoint, {
...params,
limit: props.pagination.limit ?? 10,
}).then(_res => {
const res = transform.value(_res);
}).then(res => {
for (let i = 0; i < res.length; i++) {
const item = res[i];
if (i === 3) item._shouldInsertAd_ = true;
@ -390,9 +378,7 @@ const fetchMore = async (): Promise<void> => {
} : {
untilId: Array.from(items.value.keys()).at(-1),
}),
}).then(_res => {
const res = transform.value(_res);
}).then(res => {
for (let i = 0; i < res.length; i++) {
const item = res[i];
if (i === 10) item._shouldInsertAd_ = true;
@ -439,15 +425,15 @@ const fetchMoreAhead = async (): Promise<void> => {
} : {
sinceId: Array.from(items.value.keys()).at(-1),
}),
}).then(_res => {
if (_res.length === 0) {
}).then(res => {
if (res.length === 0) {
items.value = concatMapWithArray(items.value, res);
more.value = false;
} else {
const res = transform.value(_res);
items.value = concatMapWithArray(items.value, res);
more.value = true;
}
offset.value += _res.length;
offset.value += res.length;
moreFetching.value = false;
}, err => {
moreFetching.value = false;
@ -498,12 +484,9 @@ watch([active, visibility], () => {
/**
* 最新のものとして1つだけアイテムを追加する
* ストリーミングから降ってきたアイテムはこれで追加する
* @param item アイテムtransform前
* @param item アイテム
*/
const prepend = (_item: MisskeyEntity): void => {
const item = transform.value([_item])[0];
if (!item) return;
const prepend = (item: MisskeyEntity): void => {
if (items.value.size === 0) {
items.value.set(item.id, item);
fetching.value = false;
@ -557,10 +540,7 @@ function concatItems(oldItems: MisskeyEntity[]) {
}
async function executeQueue() {
//
//
// if (queue.value.size === 0) return;
if (queue.value.size === 0) return;
if (isPausingUpdateByExecutingQueue.value) return;
if (timelineBackTopBehavior.value === 'newest') {
// Safari
@ -590,12 +570,8 @@ function prependQueue(newItem: MisskeyEntity) {
/*
* アイテムを末尾に追加する使うの
* @param item アイテムtransform前
*/
const appendItem = (_item: MisskeyEntity): void => {
const item = transform.value([_item])[0];
if (!item) return;
const appendItem = (item: MisskeyEntity): void => {
items.value.set(item.id, item);
};

View File

@ -26,9 +26,6 @@ import { $i } from '@/account';
import { defaultStore } from '@/store';
import { i18n } from '@/i18n';
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<{
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 query;
let connection;
@ -178,7 +165,6 @@ const pagination = {
endpoint: endpoint,
limit: 10,
params: query,
transform: transform,
};
onUnmounted(() => {

View File

@ -3,7 +3,7 @@
* 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 { api } from "./api";
import { useStream } from '@/stream';
@ -13,9 +13,7 @@ import { $i } from "@/account";
export class EntitiyManager<T extends { id: string }> {
private entities: Map<T['id'], Ref<T>>;
constructor(
public key: string,
) {
constructor() {
this.entities = new Map();
}
@ -34,8 +32,7 @@ export class EntitiyManager<T extends { id: string }> {
}
}
export const userLiteManager = new EntitiyManager<UserLite>('userLite');
export const driveFileManager = new EntitiyManager<DriveFile>('driveFile');
export const userLiteManager = new EntitiyManager<UserLite>();
type OmittedNote = Omit<Note, 'user' | 'renote' | 'reply'>;
type CachedNoteSource = Ref<OmittedNote | null>;
@ -56,9 +53,8 @@ export class NoteManager {
private notesSource: Map<Note['id'], CachedNoteSource>;
/**
* user, renote, replyを取得したComputedRefのキャッシュを保持しておく
* user, renote, replyを取得したComputedRef
* nullは削除済みであることを表す
* 0
*/
private notesComputed: Map<Note['id'], CachedNote>;
private updatedAt: Map<Note['id'], number>;
@ -71,7 +67,7 @@ export class NoteManager {
this.updatedAt = new Map();
this.captureing = new Map();
this.connection = $i ? useStream() : null;
this.connection?.on('noteUpdated', noteData => this.onStreamNoteUpdated(noteData));
this.connection?.on('noteUpdated', this.onStreamNoteUpdated);
this.connection?.on('_connected_', () => {
// 再接続時に再キャプチャ
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 };
userLiteManager.set(note.user);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
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);
delete note.renote;
if (note.reply) this.set(note.reply);
delete note.reply;
const cached = this.notesSource.get(note.id);
if (cached) {
cached.value = note;
@ -115,6 +98,7 @@ export class NoteManager {
this.notesSource.set(note.id, ref(note));
}
this.updatedAt.set(note.id, Date.now());
return this.get(note.id)!;
}
public get(id: string): CachedNote {
@ -133,14 +117,11 @@ export class NoteManager {
const reply = note.value.replyId ? this.get(note.value.replyId) : undefined;
if (reply && !reply.value) return null;
const files = note.value.fileIds.map(id => driveFileManager.get(id)?.value);
return {
...note.value,
user: user.value,
renote: renote?.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> {
if (!force) {
const updatedAt = this.updatedAt.get(id);
// 2分以上経過していない場合はキャッシュを返す
if (updatedAt && Date.now() - updatedAt < 1000 * 120) {
if (updatedAt && Date.now() - updatedAt < 1000 * 30) {
const cachedNote = this.get(id);
if (cachedNote) {
return cachedNote;
@ -159,10 +139,7 @@ export class NoteManager {
}
}
return api('notes/show', { noteId: id })
.then(fetchedNote => {
this.set(fetchedNote);
return this.get(id)!;
})
.then(fetchedNote => this.set(fetchedNote))
.catch(() => {
// エラーが発生した場合はとりあえず削除されたものとして扱う
const cached = this.notesSource.get(id);
@ -184,8 +161,6 @@ export class NoteManager {
if (!note || !note.value) {
this.connection?.send('un', { id });
this.captureing.delete(id);
this.notesComputed.delete(id);
this.updatedAt.delete(id);
return;
}
@ -244,8 +219,6 @@ export class NoteManager {
break;
}
}
this.updatedAt.set(id, Date.now());
}
private capture(id: string, markRead = true): void {
@ -279,9 +252,6 @@ export class NoteManager {
}
this.captureing.delete(id);
// キャプチャが終わったらcomputedキャッシュも消してしまう
this.notesComputed.delete(id);
}
/**
@ -317,11 +287,3 @@ export class NoteManager {
}
export const noteManager = new NoteManager();
if (_DEV_) {
console.log('entity manager initialized', {
noteManager,
userLiteManager,
driveFileManager,
});
}