fix(frontend): channel posts show no sender id, a post sent as a chat shows its title and avatar
This commit is contained in:
1 parent
98dda99c5c
commit
309614c979
2 files changed
+63
-26
No files matched your search
@@ -18,11 +18,14 @@
|
||||
import Icon from "#lib/components/ui/Icon.svelte";
|
||||
import WebPage from "#lib/components/WebPage.svelte";
|
||||
import { accountName, peerColorIndex, peerName } from "#lib/format/peer.js";
|
||||
import { t } from "#lib/i18n/locale.svelte.js";
|
||||
import { accounts } from "#lib/stores/accounts.svelte.js";
|
||||
import { chats } from "#lib/stores/chats.svelte.js";
|
||||
import { peers } from "#lib/stores/peers.svelte.js";
|
||||
import { toasts } from "#lib/stores/toasts.svelte.js";
|
||||
import { ui } from "#lib/stores/ui.svelte.js";
|
||||
import { appear } from "#lib/transitions/appear.js";
|
||||
import { goto } from "$app/navigation";
|
||||
|
||||
interface Props {
|
||||
animate: boolean;
|
||||
@@ -59,27 +62,47 @@
|
||||
);
|
||||
|
||||
const ownId = $derived(accounts.selected?.tg_user_id ?? null);
|
||||
const senderChat = $derived(
|
||||
message.sender_id !== null && message.sender_id < 0
|
||||
? message.sender_id
|
||||
: null
|
||||
);
|
||||
const sender = $derived(
|
||||
message.sender_id === null ? undefined : peers.get(message.sender_id)
|
||||
message.sender_id === null || senderChat !== null
|
||||
? undefined
|
||||
: peers.get(message.sender_id)
|
||||
);
|
||||
const senderName = $derived.by(() => {
|
||||
if (own) {
|
||||
return accounts.selected ? accountName(accounts.selected) : "You";
|
||||
return accounts.selected ? accountName(accounts.selected) : t("chat.you");
|
||||
}
|
||||
if (senderChat !== null) {
|
||||
return chats.byId(senderChat)?.title ?? "";
|
||||
}
|
||||
if (sender) {
|
||||
return peerName(sender);
|
||||
}
|
||||
return message.sender_id === null ? "" : String(message.sender_id);
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (senderChat !== null) {
|
||||
chats.ensure(senderChat);
|
||||
}
|
||||
});
|
||||
const colorIndex = $derived(peerColorIndex(message.sender_id ?? 0));
|
||||
const showName = $derived(isGroupChat && !own && firstInGroup);
|
||||
|
||||
const avatarId = $derived(own ? ownId : message.sender_id);
|
||||
const avatarHas = $derived(
|
||||
own
|
||||
? ownId !== null && peers.get(ownId)?.has_avatar
|
||||
: (sender?.has_avatar ?? false)
|
||||
);
|
||||
const avatarHas = $derived.by(() => {
|
||||
if (own) {
|
||||
return ownId !== null && Boolean(peers.get(ownId)?.has_avatar);
|
||||
}
|
||||
if (senderChat !== null) {
|
||||
return chats.byId(senderChat)?.has_avatar ?? false;
|
||||
}
|
||||
return sender?.has_avatar ?? false;
|
||||
});
|
||||
|
||||
const hasCallbacks = $derived(
|
||||
message.inline_buttons.some((row) =>
|
||||
@@ -116,14 +139,18 @@
|
||||
}
|
||||
async function copyText() {
|
||||
await navigator.clipboard.writeText(message.text ?? "");
|
||||
toasts.success("Текст скопирован");
|
||||
toasts.success(t("thread.copiedText"));
|
||||
}
|
||||
async function copyId() {
|
||||
await navigator.clipboard.writeText(String(message.message_id));
|
||||
toasts.success("ID скопирован");
|
||||
toasts.success(t("thread.copiedId"));
|
||||
}
|
||||
function openSenderProfile() {
|
||||
if (message.sender_id !== null) {
|
||||
if (senderChat === message.chat_id) {
|
||||
ui.openPanel("profile");
|
||||
} else if (senderChat !== null) {
|
||||
goto(`/app/${senderChat}`);
|
||||
} else if (message.sender_id !== null) {
|
||||
ui.openPerson(message.chat_id, message.sender_id);
|
||||
}
|
||||
}
|
||||
@@ -155,7 +182,10 @@
|
||||
type="button"
|
||||
>
|
||||
<Avatar
|
||||
avatar={{ id: avatarId, kind: "peer" }}
|
||||
avatar={{
|
||||
id: avatarId,
|
||||
kind: senderChat === null ? "peer" : "chat",
|
||||
}}
|
||||
colorKey={avatarId}
|
||||
hasAvatar={avatarHas}
|
||||
name={senderName}
|
||||
@@ -185,7 +215,7 @@
|
||||
{#if deleted}
|
||||
<span class="deleted-tag">
|
||||
<Icon name="delete" size="0.875rem" />
|
||||
deleted
|
||||
{t("thread.deleted")}
|
||||
</span>
|
||||
{/if}
|
||||
{#if message.poll}
|
||||
@@ -218,7 +248,7 @@
|
||||
/>
|
||||
</div>
|
||||
{:else if !(message.has_media || deleted || special)}
|
||||
<div class="text empty">(no text)</div>
|
||||
<div class="text empty">{t("feed.noText")}</div>
|
||||
{/if}
|
||||
{#if message.web_page}
|
||||
<WebPage {message} {onmedia} {own} />
|
||||
@@ -233,8 +263,7 @@
|
||||
{#if linkCount > 0}
|
||||
<button class="detail-chip" onclick={openLinks} type="button">
|
||||
<Icon name="link" size="0.875rem" />
|
||||
{linkCount}
|
||||
{linkCount === 1 ? "ссылка" : "ссылки"}
|
||||
{t("thread.links", { count: linkCount })}
|
||||
</button>
|
||||
{/if}
|
||||
<MessageMeta {message} {onversions} {own} />
|
||||
@@ -244,7 +273,7 @@
|
||||
{#if hasCallbacks}
|
||||
<button class="detail-chip" onclick={openCallbacks} type="button">
|
||||
<Icon name="bot-command" size="0.875rem" />
|
||||
Callback-данные
|
||||
{t("panel.callbacks")}
|
||||
</button>
|
||||
{/if}
|
||||
{#if lastInGroup}
|
||||
@@ -263,42 +292,44 @@
|
||||
<MessageReadItem {message} />
|
||||
{/if}
|
||||
<ContextMenuItem icon="note" onselect={openAnnotations}
|
||||
>Заметки</ContextMenuItem
|
||||
>{t("panel.annotations")}</ContextMenuItem
|
||||
>
|
||||
{#if message.reactions.length}
|
||||
<ContextMenuItem icon="heart" onselect={openReactions}
|
||||
>Реакции</ContextMenuItem
|
||||
>{t("panel.reactions")}</ContextMenuItem
|
||||
>
|
||||
{/if}
|
||||
{#if linkCount > 0}
|
||||
<ContextMenuItem icon="link" onselect={openLinks}>Ссылки</ContextMenuItem>
|
||||
<ContextMenuItem icon="link" onselect={openLinks}
|
||||
>{t("panel.links")}</ContextMenuItem
|
||||
>
|
||||
{/if}
|
||||
{#if hasCallbacks}
|
||||
<ContextMenuItem icon="bot-command" onselect={openCallbacks}
|
||||
>Callback-данные</ContextMenuItem
|
||||
>{t("panel.callbacks")}</ContextMenuItem
|
||||
>
|
||||
{/if}
|
||||
{#if message.edited_at}
|
||||
<ContextMenuItem icon="edit" onselect={onversions}
|
||||
>Версии</ContextMenuItem
|
||||
>{t("panel.versions")}</ContextMenuItem
|
||||
>
|
||||
{/if}
|
||||
{#if (message.reply?.message_id ?? null) !== null}
|
||||
<ContextMenuItem icon="reply" onselect={jumpToReply}
|
||||
>Перейти к ответу</ContextMenuItem
|
||||
>{t("thread.toReply")}</ContextMenuItem
|
||||
>
|
||||
{/if}
|
||||
{#if hasText}
|
||||
<ContextMenuItem icon="copy" onselect={copyText}
|
||||
>Копировать текст</ContextMenuItem
|
||||
>{t("thread.copyText")}</ContextMenuItem
|
||||
>
|
||||
{/if}
|
||||
<ContextMenuItem icon="hashtag" onselect={copyId}
|
||||
>Копировать ID</ContextMenuItem
|
||||
>{t("thread.copyId")}</ContextMenuItem
|
||||
>
|
||||
{#if isGroupChat && !own && message.sender_id !== null}
|
||||
<ContextMenuItem icon="info" onselect={openSenderProfile}
|
||||
>Профиль автора</ContextMenuItem
|
||||
>{t("thread.senderProfile")}</ContextMenuItem
|
||||
>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
import { formatDay } from "#lib/format/datetime.js";
|
||||
import { t } from "#lib/i18n/locale.svelte.js";
|
||||
import { accounts } from "#lib/stores/accounts.svelte.js";
|
||||
import { chats } from "#lib/stores/chats.svelte.js";
|
||||
import { discover } from "#lib/stores/discover.svelte.js";
|
||||
import { events } from "#lib/stores/events.svelte.js";
|
||||
import { peers } from "#lib/stores/peers.svelte.js";
|
||||
import { toasts } from "#lib/stores/toasts.svelte.js";
|
||||
@@ -54,7 +56,11 @@
|
||||
let highlightTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const ownId = $derived(accounts.selected?.tg_user_id ?? null);
|
||||
const isGroupChat = $derived(chatId < 0);
|
||||
const isChannel = $derived(
|
||||
Boolean(chats.byId(chatId)?.is_broadcast) ||
|
||||
discover.get(chatId)?.kind === "channel"
|
||||
);
|
||||
const isGroupChat = $derived(chatId < 0 && !isChannel);
|
||||
|
||||
interface Row {
|
||||
dayKey: string;
|
||||
|
||||
Reference in new issue
Block a user