merge: upstream

This commit is contained in:
Marie 2023-12-23 02:09:23 +01:00
commit 5db583a3eb
701 changed files with 50809 additions and 13660 deletions

View file

@ -34,7 +34,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
import { computed, watch, provide } from 'vue';
import { computed, watch, provide, shallowRef, ref } from 'vue';
import type { Tab } from '@/components/global/MkPageHeader.tabs.vue';
import MkTimeline from '@/components/MkTimeline.vue';
import MkInfo from '@/components/MkInfo.vue';
@ -46,9 +46,10 @@ import { i18n } from '@/i18n.js';
import { instance } from '@/instance.js';
import { $i } from '@/account.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { miLocalStorage } from '@/local-storage.js';
import { antennasCache, userListsCache } from '@/cache.js';
import { deviceKind } from '@/scripts/device-kind.js';
import { MenuItem } from '@/types/menu.js';
import { miLocalStorage } from '@/local-storage.js';
provide('shouldOmitHeaderTitle', true);
@ -59,49 +60,67 @@ const keymap = {
't': focus,
};
const tlComponent = $shallowRef<InstanceType<typeof MkTimeline>>();
const rootEl = $shallowRef<HTMLElement>();
const tlComponent = shallowRef<InstanceType<typeof MkTimeline>>();
const rootEl = shallowRef<HTMLElement>();
let queue = $ref(0);
let srcWhenNotSignin = $ref(isLocalTimelineAvailable ? 'local' : 'global');
const src = $computed({ get: () => ($i ? defaultStore.reactiveState.tl.value.src : srcWhenNotSignin), set: (x) => saveSrc(x) });
const withRenotes = $ref(true);
const withReplies = $ref($i ? defaultStore.state.tlWithReplies : false);
const withBots = $ref($i ? defaultStore.state.tlWithBots : true);
const onlyFiles = $ref(false);
const queue = ref(0);
const srcWhenNotSignin = ref(isLocalTimelineAvailable ? 'local' : 'global');
const src = computed({ get: () => ($i ? defaultStore.reactiveState.tl.value.src : srcWhenNotSignin.value), set: (x) => saveSrc(x) });
const withRenotes = ref(true);
const withReplies = ref($i ? defaultStore.state.tlWithReplies : false);
const withBots = ref($i ? defaultStore.state.tlWithBots : true);
const onlyFiles = ref(false);
watch($$(src), () => queue = 0);
watch(src, () => queue.value = 0);
watch($$(withReplies), (x) => {
watch(withReplies, (x) => {
if ($i) defaultStore.set('tlWithReplies', x);
});
function queueUpdated(q: number): void {
queue = q;
queue.value = q;
}
function top(): void {
if (rootEl) scroll(rootEl, { top: 0 });
if (rootEl.value) scroll(rootEl.value, { top: 0 });
}
async function chooseList(ev: MouseEvent): Promise<void> {
const lists = await userListsCache.fetch();
const items = lists.map(list => ({
type: 'link' as const,
text: list.name,
to: `/timeline/list/${list.id}`,
}));
const items: MenuItem[] = [
...lists.map(list => ({
type: 'link' as const,
text: list.name,
to: `/timeline/list/${list.id}`,
})),
(lists.length === 0 ? undefined : { type: 'divider' }),
{
type: 'link' as const,
icon: 'ti ti-plus',
text: i18n.ts.createNew,
to: '/my/lists',
},
];
os.popupMenu(items, ev.currentTarget ?? ev.target);
}
async function chooseAntenna(ev: MouseEvent): Promise<void> {
const antennas = await antennasCache.fetch();
const items = antennas.map(antenna => ({
type: 'link' as const,
text: antenna.name,
indicate: antenna.hasUnreadNote,
to: `/timeline/antenna/${antenna.id}`,
}));
const items: MenuItem[] = [
...antennas.map(antenna => ({
type: 'link' as const,
text: antenna.name,
indicate: antenna.hasUnreadNote,
to: `/timeline/antenna/${antenna.id}`,
})),
(antennas.length === 0 ? undefined : { type: 'divider' }),
{
type: 'link' as const,
icon: 'ti ti-plus',
text: i18n.ts.createNew,
to: '/my/antennas',
},
];
os.popupMenu(items, ev.currentTarget ?? ev.target);
}
@ -109,16 +128,30 @@ async function chooseChannel(ev: MouseEvent): Promise<void> {
const channels = await os.api('channels/my-favorites', {
limit: 100,
});
const items = channels.map(channel => ({
type: 'link' as const,
text: channel.name,
indicate: channel.hasUnreadNote,
to: `/channels/${channel.id}`,
}));
const items: MenuItem[] = [
...channels.map(channel => {
const lastReadedAt = miLocalStorage.getItemAsJson(`channelLastReadedAt:${channel.id}`) ?? null;
const hasUnreadNote = (lastReadedAt && channel.lastNotedAt) ? Date.parse(channel.lastNotedAt) > lastReadedAt : !!(!lastReadedAt && channel.lastNotedAt);
return {
type: 'link' as const,
text: channel.name,
indicate: hasUnreadNote,
to: `/channels/${channel.id}`,
};
}),
(channels.length === 0 ? undefined : { type: 'divider' }),
{
type: 'link' as const,
icon: 'ti ti-plus',
text: i18n.ts.createNew,
to: '/channels',
},
];
os.popupMenu(items, ev.currentTarget ?? ev.target);
}
function saveSrc(newSrc: 'home' | 'local' | 'social' | 'global' | `list:${string}`): void {
function saveSrc(newSrc: 'home' | 'local' | 'social' | 'global' | 'bubble' | `list:${string}`): void {
let userList = null;
if (newSrc.startsWith('userList:')) {
const id = newSrc.substring('userList:'.length);
@ -128,7 +161,7 @@ function saveSrc(newSrc: 'home' | 'local' | 'social' | 'global' | `list:${string
src: newSrc,
userList,
});
srcWhenNotSignin = newSrc;
srcWhenNotSignin.value = newSrc;
}
async function timetravel(): Promise<void> {
@ -137,21 +170,21 @@ async function timetravel(): Promise<void> {
});
if (canceled) return;
tlComponent.timetravel(date);
tlComponent.value.timetravel(date);
}
function focus(): void {
tlComponent.focus();
tlComponent.value.focus();
}
function closeTutorial(): void {
if (!['home', 'local', 'social', 'global'].includes(src)) return;
if (!['home', 'local', 'social', 'global'].includes(src.value)) return;
const before = defaultStore.state.timelineTutorials;
before[src] = true;
before[src.value] = true;
defaultStore.set('timelineTutorials', before);
}
const headerActions = $computed(() => {
const headerActions = computed(() => {
const tmp = [
{
icon: 'ph-dots-three ph-bold ph-lg',
@ -160,17 +193,17 @@ const headerActions = $computed(() => {
os.popupMenu([{
type: 'switch',
text: i18n.ts.showRenotes,
icon: 'ph-rocket-launch ph-bold ph-lg',
ref: $$(withRenotes),
}, src === 'local' || src === 'social' ? {
ref: withRenotes,
}, src.value === 'local' || src.value === 'social' ? {
type: 'switch',
text: i18n.ts.showRepliesToOthersInTimeline,
ref: $$(withReplies),
ref: withReplies,
disabled: onlyFiles,
} : undefined, {
type: 'switch',
text: i18n.ts.fileAttachedOnly,
icon: 'ph-image ph-bold ph-lg',
ref: $$(onlyFiles),
ref: onlyFiles,
disabled: src.value === 'local' || src.value === 'social' ? withReplies : false,
}], ev.currentTarget ?? ev.target);
},
},
@ -181,14 +214,14 @@ const headerActions = $computed(() => {
text: i18n.ts.reload,
handler: (ev: Event) => {
console.log('called');
tlComponent.reloadTimeline();
tlComponent.value.reloadTimeline();
},
});
}
return tmp;
});
const headerTabs = $computed(() => [...(defaultStore.reactiveState.pinnedUserLists.value.map(l => ({
const headerTabs = computed(() => [...(defaultStore.reactiveState.pinnedUserLists.value.map(l => ({
key: 'list:' + l.id,
title: l.name,
icon: 'ph-star ph-bold ph-lg',
@ -235,7 +268,7 @@ const headerTabs = $computed(() => [...(defaultStore.reactiveState.pinnedUserLis
onClick: chooseChannel,
}] as Tab[]);
const headerTabsWhenNotLogin = $computed(() => [
const headerTabsWhenNotLogin = computed(() => [
...(isLocalTimelineAvailable ? [{
key: 'local',
title: i18n.ts._timelines.local,
@ -252,7 +285,7 @@ const headerTabsWhenNotLogin = $computed(() => [
definePageMetadata(computed(() => ({
title: i18n.ts.timeline,
icon: src === 'local' ? 'ph-planet ph-bold ph-lg' : src === 'social' ? 'ph-rocket-launch ph-bold ph-lg' : src === 'global' ? 'ph-globe-hemisphere-west ph-bold ph-lg' : 'ph-house ph-bold ph-lg',
icon: src.value === 'local' ? 'ph-planet ph-bold ph-lg' : src.value === 'social' ? 'ph-rocket-launch ph-bold ph-lg' : src.value === 'global' ? 'ph-globe-hemisphere-west ph-bold ph-lg' : src.value === 'bubble' ? 'ph-drop ph-bold ph-lg' : 'ph-house ph-bold ph-lg',
})));
</script>