Closes https://github.com/vector-im/element-web/issues/18958
This commit is contained in:
parent
9c753765d5
commit
f8c516d927
8 changed files with 83 additions and 16 deletions
|
@ -27,6 +27,7 @@ import { CallHangupEvent } from "./previews/CallHangupEvent";
|
|||
import { StickerEventPreview } from "./previews/StickerEventPreview";
|
||||
import { ReactionEventPreview } from "./previews/ReactionEventPreview";
|
||||
import { UPDATE_EVENT } from "../AsyncStore";
|
||||
import { Thread } from "matrix-js-sdk/src/models/thread";
|
||||
|
||||
// Emitted event for when a room's preview has changed. First argument will the room for which
|
||||
// the change happened.
|
||||
|
@ -108,6 +109,15 @@ export class MessagePreviewStore extends AsyncStoreWithClient<IState> {
|
|||
return previews.get(inTagId);
|
||||
}
|
||||
|
||||
public generateThreadPreview(thread: Thread): string {
|
||||
const lastEvent = thread.replyToEvent;
|
||||
const previewDef = PREVIEWS[lastEvent.getType()];
|
||||
// TODO: Handle case where we don't have
|
||||
if (!previewDef) return '';
|
||||
const previewText = previewDef.previewer.getTextFor(lastEvent, null, true);
|
||||
return previewText ?? '';
|
||||
}
|
||||
|
||||
private async generatePreview(room: Room, tagId?: TagID) {
|
||||
const events = room.timeline;
|
||||
if (!events) return; // should only happen in tests
|
||||
|
|
|
@ -23,7 +23,7 @@ import ReplyThread from "../../../components/views/elements/ReplyThread";
|
|||
import { getHtmlText } from "../../../HtmlUtils";
|
||||
|
||||
export class MessageEventPreview implements IPreview {
|
||||
public getTextFor(event: MatrixEvent, tagId?: TagID): string {
|
||||
public getTextFor(event: MatrixEvent, tagId?: TagID, isThread?: boolean): string {
|
||||
let eventContent = event.getContent();
|
||||
|
||||
if (event.isRelation("m.replace")) {
|
||||
|
@ -64,7 +64,7 @@ export class MessageEventPreview implements IPreview {
|
|||
return _t("* %(senderName)s %(emote)s", { senderName: getSenderName(event), emote: body });
|
||||
}
|
||||
|
||||
if (isSelf(event) || !shouldPrefixMessagesIn(event.getRoomId(), tagId)) {
|
||||
if (isThread || isSelf(event) || !shouldPrefixMessagesIn(event.getRoomId(), tagId)) {
|
||||
return body;
|
||||
} else {
|
||||
return _t("%(senderName)s: %(message)s", { senderName: getSenderName(event), message: body });
|
||||
|
|
|
@ -23,7 +23,7 @@ import SettingsStore from "../../../settings/SettingsStore";
|
|||
import DMRoomMap from "../../../utils/DMRoomMap";
|
||||
|
||||
export class ReactionEventPreview implements IPreview {
|
||||
public getTextFor(event: MatrixEvent, tagId?: TagID): string {
|
||||
public getTextFor(event: MatrixEvent, tagId?: TagID, isThread?: boolean): string {
|
||||
const showDms = SettingsStore.getValue("feature_roomlist_preview_reactions_dms");
|
||||
const showAll = SettingsStore.getValue("feature_roomlist_preview_reactions_all");
|
||||
|
||||
|
@ -41,7 +41,7 @@ export class ReactionEventPreview implements IPreview {
|
|||
const reaction = relation.key;
|
||||
if (!reaction) return null; // invalid reaction (unknown format)
|
||||
|
||||
if (isSelf(event) || !shouldPrefixMessagesIn(event.getRoomId(), tagId)) {
|
||||
if (isThread || isSelf(event) || !shouldPrefixMessagesIn(event.getRoomId(), tagId)) {
|
||||
return reaction;
|
||||
} else {
|
||||
return _t("%(senderName)s: %(reaction)s", { senderName: getSenderName(event), reaction });
|
||||
|
|
|
@ -21,11 +21,11 @@ import { getSenderName, isSelf, shouldPrefixMessagesIn } from "./utils";
|
|||
import { _t } from "../../../languageHandler";
|
||||
|
||||
export class StickerEventPreview implements IPreview {
|
||||
public getTextFor(event: MatrixEvent, tagId?: TagID): string {
|
||||
public getTextFor(event: MatrixEvent, tagId?: TagID, isThread?: boolean): string {
|
||||
const stickerName = event.getContent()['body'];
|
||||
if (!stickerName) return null;
|
||||
|
||||
if (isSelf(event) || !shouldPrefixMessagesIn(event.getRoomId(), tagId)) {
|
||||
if (isThread || isSelf(event) || !shouldPrefixMessagesIn(event.getRoomId(), tagId)) {
|
||||
return stickerName;
|
||||
} else {
|
||||
return _t("%(senderName)s: %(stickerName)s", { senderName: getSenderName(event), stickerName });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue