feat(userbot,api,frontend): backfill stories and unbreak all-stories list
This commit is contained in:
@@ -315,7 +315,7 @@ export function getMessageAt(chatId: number, date: string): Promise<MessageAt> {
|
||||
}
|
||||
|
||||
export function getStories(
|
||||
peerId: number,
|
||||
peerId: number | null,
|
||||
page: Page = {}
|
||||
): Promise<StoryView[]> {
|
||||
return request<StoryView[]>("/stories", {
|
||||
@@ -367,6 +367,15 @@ export function enqueueBackfill(
|
||||
});
|
||||
}
|
||||
|
||||
export function enqueueStoriesBackfill(
|
||||
peerId: number
|
||||
): Promise<{ job_id: number }> {
|
||||
return request<{ job_id: number }>("/stories/backfill", {
|
||||
method: "POST",
|
||||
body: { account_id: accounts.selectedId, peer_id: peerId },
|
||||
});
|
||||
}
|
||||
|
||||
export function discoverPeers(
|
||||
query: string,
|
||||
remote = false
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
const KIND_LABELS: Record<string, string> = {
|
||||
backfill: "Бэкфилл",
|
||||
backfill_stories: "Бэкфилл сторис",
|
||||
fetch_media: "Докачка медиа",
|
||||
fetch_avatar: "Аватар",
|
||||
fetch_custom_emoji: "Кастом-эмодзи",
|
||||
@@ -88,12 +89,12 @@
|
||||
}
|
||||
|
||||
function processed(job: JobView): number | null {
|
||||
const value = job.progress.processed;
|
||||
const value = job.progress.processed ?? job.progress.saved;
|
||||
return typeof value === "number" ? value : null;
|
||||
}
|
||||
|
||||
function chatId(job: JobView): number | null {
|
||||
const value = job.params.chat_id;
|
||||
const value = job.params.chat_id ?? job.params.peer_id;
|
||||
return typeof value === "number" ? value : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,19 +6,21 @@
|
||||
import ProfileInfo from "$lib/components/profile/ProfileInfo.svelte";
|
||||
import SharedLinks from "$lib/components/profile/SharedLinks.svelte";
|
||||
import SharedMedia from "$lib/components/profile/SharedMedia.svelte";
|
||||
import StoriesArchive from "$lib/components/stories/StoriesArchive.svelte";
|
||||
import Avatar from "$lib/components/ui/Avatar.svelte";
|
||||
import EmptyState from "$lib/components/ui/EmptyState.svelte";
|
||||
import Icon from "$lib/components/ui/Icon.svelte";
|
||||
import { peerName } from "$lib/format/peer";
|
||||
import { chats } from "$lib/stores/chats.svelte";
|
||||
|
||||
type Tab = "info" | "media" | "files" | "links" | "calendar";
|
||||
type Tab = "info" | "media" | "files" | "links" | "stories" | "calendar";
|
||||
|
||||
const TABS: { id: Tab; icon: string; label: string }[] = [
|
||||
{ id: "info", icon: "info", label: "Инфо" },
|
||||
{ id: "media", icon: "photo", label: "Медиа" },
|
||||
{ id: "files", icon: "document", label: "Файлы" },
|
||||
{ id: "links", icon: "link", label: "Ссылки" },
|
||||
{ id: "stories", icon: "play-story", label: "Сторис" },
|
||||
{ id: "calendar", icon: "calendar", label: "Календарь" },
|
||||
];
|
||||
|
||||
@@ -114,6 +116,8 @@
|
||||
<SharedMedia {chatId} kinds={FILE_KINDS} layout="list" />
|
||||
{:else if tab === "links"}
|
||||
<SharedLinks {chatId} />
|
||||
{:else if tab === "stories"}
|
||||
<StoriesArchive {chatId} />
|
||||
{:else if tab === "calendar"}
|
||||
<ChatCalendar {chatId} />
|
||||
{/if}
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from "svelte";
|
||||
import { getChat, getPeers, getStories } from "$lib/api/endpoints";
|
||||
import {
|
||||
enqueueStoriesBackfill,
|
||||
getChat,
|
||||
getPeers,
|
||||
getStories,
|
||||
} from "$lib/api/endpoints";
|
||||
import { loadStoryMedia } from "$lib/api/stories";
|
||||
import type { StoryView } from "$lib/api/types";
|
||||
import StoryViewer from "$lib/components/stories/StoryViewer.svelte";
|
||||
import Avatar from "$lib/components/ui/Avatar.svelte";
|
||||
import Button from "$lib/components/ui/Button.svelte";
|
||||
import EmptyState from "$lib/components/ui/EmptyState.svelte";
|
||||
import Icon from "$lib/components/ui/Icon.svelte";
|
||||
import Spinner from "$lib/components/ui/Spinner.svelte";
|
||||
import { peerName } from "$lib/format/peer";
|
||||
import { poster } from "$lib/media/poster";
|
||||
import { accounts } from "$lib/stores/accounts.svelte";
|
||||
import { toasts } from "$lib/stores/toasts.svelte";
|
||||
|
||||
interface Group {
|
||||
hasAvatar: boolean;
|
||||
@@ -31,12 +38,13 @@
|
||||
let viewerIndex = $state(0);
|
||||
let viewerItems = $state<StoryView[]>([]);
|
||||
let viewerPeerId = $state(0);
|
||||
let backfilling = $state<number | null>(null);
|
||||
|
||||
async function load() {
|
||||
const current = token;
|
||||
loading = true;
|
||||
try {
|
||||
const stories = await getStories(0, { limit: FETCH_LIMIT });
|
||||
const stories = await getStories(null, { limit: FETCH_LIMIT });
|
||||
if (current !== token) {
|
||||
return;
|
||||
}
|
||||
@@ -127,6 +135,21 @@
|
||||
};
|
||||
});
|
||||
|
||||
async function backfill(peerId: number) {
|
||||
if (backfilling !== null) {
|
||||
return;
|
||||
}
|
||||
backfilling = peerId;
|
||||
try {
|
||||
await enqueueStoriesBackfill(peerId);
|
||||
toasts.success("Загружаем старые сторис");
|
||||
} catch {
|
||||
toasts.error("Не удалось запустить загрузку сторис");
|
||||
} finally {
|
||||
backfilling = null;
|
||||
}
|
||||
}
|
||||
|
||||
function openViewer(group: Group, index: number) {
|
||||
viewerItems = group.stories;
|
||||
viewerPeerId = group.peerId;
|
||||
@@ -154,6 +177,16 @@
|
||||
/>
|
||||
<span class="group-name">{group.name}</span>
|
||||
<span class="group-count">{group.stories.length}</span>
|
||||
<Button
|
||||
variant="translucent"
|
||||
round
|
||||
smaller
|
||||
loading={backfilling === group.peerId}
|
||||
onclick={() => backfill(group.peerId)}
|
||||
aria-label="Загрузить старые сторис"
|
||||
>
|
||||
<Icon name="cloud-download" />
|
||||
</Button>
|
||||
</header>
|
||||
<div class="grid">
|
||||
{#each group.stories as item, index (item.story_id)}
|
||||
|
||||
@@ -1,22 +1,32 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from "svelte";
|
||||
import { page } from "$app/state";
|
||||
import { getStories } from "$lib/api/endpoints";
|
||||
import { enqueueStoriesBackfill, getStories } from "$lib/api/endpoints";
|
||||
import { loadStoryMedia } from "$lib/api/stories";
|
||||
import type { StoryView } from "$lib/api/types";
|
||||
import StoryViewer from "$lib/components/stories/StoryViewer.svelte";
|
||||
import Button from "$lib/components/ui/Button.svelte";
|
||||
import EmptyState from "$lib/components/ui/EmptyState.svelte";
|
||||
import Icon from "$lib/components/ui/Icon.svelte";
|
||||
import Spinner from "$lib/components/ui/Spinner.svelte";
|
||||
import { poster } from "$lib/media/poster";
|
||||
import { accounts } from "$lib/stores/accounts.svelte";
|
||||
import { toasts } from "$lib/stores/toasts.svelte";
|
||||
|
||||
interface Props {
|
||||
chatId?: number | null;
|
||||
}
|
||||
|
||||
let { chatId = null }: Props = $props();
|
||||
|
||||
const PAGE = 60;
|
||||
|
||||
const peerId = $derived(
|
||||
page.params.chatId ? Number(page.params.chatId) : null
|
||||
chatId ?? (page.params.chatId ? Number(page.params.chatId) : null)
|
||||
);
|
||||
|
||||
let backfilling = $state(false);
|
||||
|
||||
let items = $state<StoryView[]>([]);
|
||||
let loading = $state(false);
|
||||
let done = $state(false);
|
||||
@@ -90,67 +100,114 @@
|
||||
viewerIndex = index;
|
||||
viewerOpen = true;
|
||||
}
|
||||
|
||||
async function backfill(id: number) {
|
||||
if (backfilling) {
|
||||
return;
|
||||
}
|
||||
backfilling = true;
|
||||
try {
|
||||
await enqueueStoriesBackfill(id);
|
||||
toasts.success("Загружаем старые сторис");
|
||||
} catch {
|
||||
toasts.error("Не удалось запустить загрузку сторис");
|
||||
} finally {
|
||||
backfilling = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function reload(id: number) {
|
||||
token++;
|
||||
items = [];
|
||||
done = false;
|
||||
loading = false;
|
||||
await loadMore(id);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if peerId === null}
|
||||
<EmptyState title="Сторис" description="Откройте чат" />
|
||||
{:else if items.length === 0}
|
||||
{#if loading}
|
||||
<div class="center"><Spinner /></div>
|
||||
{:else}
|
||||
<EmptyState title="Нет сторис" />
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="grid">
|
||||
{#each items as item, index (item.story_id)}
|
||||
<button
|
||||
type="button"
|
||||
class="tile"
|
||||
class:expired={item.deleted}
|
||||
onclick={() => openViewer(index)}
|
||||
>
|
||||
{#if previews[item.story_id]}
|
||||
{#if item.media_kind === "video"}
|
||||
<video
|
||||
src={previews[item.story_id]}
|
||||
muted
|
||||
playsinline
|
||||
preload="metadata"
|
||||
use:poster
|
||||
></video>
|
||||
<span class="play"><Icon name="play" size="1.5rem" /></span>
|
||||
{:else}
|
||||
<img src={previews[item.story_id]} alt="">
|
||||
{/if}
|
||||
{:else}
|
||||
<span class="ph"><Icon name="play-story" /></span>
|
||||
{/if}
|
||||
{#if item.pinned}
|
||||
<span class="badge pin"
|
||||
><Icon name="story-priority" size="0.875rem" /></span
|
||||
>
|
||||
{/if}
|
||||
{#if item.views}
|
||||
<span class="badge views">
|
||||
<Icon name="eye" size="0.875rem" />{item.views}
|
||||
</span>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
<div class="toolbar">
|
||||
<Button
|
||||
variant="secondary"
|
||||
pill
|
||||
smaller
|
||||
loading={backfilling}
|
||||
onclick={() => peerId !== null && backfill(peerId)}
|
||||
>
|
||||
<Icon name="cloud-download" />Загрузить старые
|
||||
</Button>
|
||||
<Button
|
||||
variant="translucent"
|
||||
round
|
||||
smaller
|
||||
onclick={() => peerId !== null && reload(peerId).catch(() => undefined)}
|
||||
aria-label="Обновить"
|
||||
>
|
||||
<Icon name="reload" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{#if !done}
|
||||
<button
|
||||
type="button"
|
||||
class="more"
|
||||
onclick={() => peerId !== null && loadMore(peerId)}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? "Загрузка…" : "Показать ещё"}
|
||||
</button>
|
||||
{/if}
|
||||
{#if items.length === 0}
|
||||
{#if loading}
|
||||
<div class="center"><Spinner /></div>
|
||||
{:else}
|
||||
<EmptyState
|
||||
title="Нет сторис"
|
||||
description="Нажмите «Загрузить старые», чтобы забрать архив"
|
||||
/>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="grid">
|
||||
{#each items as item, index (item.story_id)}
|
||||
<button
|
||||
type="button"
|
||||
class="tile"
|
||||
class:expired={item.deleted}
|
||||
onclick={() => openViewer(index)}
|
||||
>
|
||||
{#if previews[item.story_id]}
|
||||
{#if item.media_kind === "video"}
|
||||
<video
|
||||
src={previews[item.story_id]}
|
||||
muted
|
||||
playsinline
|
||||
preload="metadata"
|
||||
use:poster
|
||||
></video>
|
||||
<span class="play"><Icon name="play" size="1.5rem" /></span>
|
||||
{:else}
|
||||
<img src={previews[item.story_id]} alt="">
|
||||
{/if}
|
||||
{:else}
|
||||
<span class="ph"><Icon name="play-story" /></span>
|
||||
{/if}
|
||||
{#if item.pinned}
|
||||
<span class="badge pin"
|
||||
><Icon name="story-priority" size="0.875rem" /></span
|
||||
>
|
||||
{/if}
|
||||
{#if item.views}
|
||||
<span class="badge views">
|
||||
<Icon name="eye" size="0.875rem" />{item.views}
|
||||
</span>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
{#if !done}
|
||||
<button
|
||||
type="button"
|
||||
class="more"
|
||||
onclick={() => peerId !== null && loadMore(peerId)}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? "Загрузка…" : "Показать ещё"}
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
{#if peerId !== null}
|
||||
<StoryViewer
|
||||
{peerId}
|
||||
{items}
|
||||
@@ -167,6 +224,14 @@
|
||||
padding: 2rem 0;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
border-bottom: 1px solid var(--color-borders);
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
|
||||
Reference in New Issue
Block a user