Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Add prefix to poll in the pinned message banner
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Sep 3, 2024
1 parent aaecebd commit 101e542
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/views/rooms/PinnedMessageBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import React, { JSX, useEffect, useMemo, useState } from "react";
import { Icon as PinIcon } from "@vector-im/compound-design-tokens/icons/pin-solid.svg";
import { Button } from "@vector-im/compound-web";
import { MatrixEvent, MsgType, Room } from "matrix-js-sdk/src/matrix";
import { M_POLL_START, MatrixEvent, MsgType, Room } from "matrix-js-sdk/src/matrix";
import classNames from "classnames";

import { usePinnedEvents, useSortedFetchedPinnedEvents } from "../../../hooks/usePinnedEvents";
Expand Down Expand Up @@ -146,7 +146,7 @@ function EventPreview({ pinnedEvent }: EventPreviewProps): JSX.Element | null {
const preview = useEventPreview(pinnedEvent);
if (!preview) return null;

const prefix = getPreviewPrefix(pinnedEvent.getContent().msgtype as MsgType);
const prefix = getPreviewPrefix(pinnedEvent.getType(), pinnedEvent.getContent().msgtype as MsgType);
if (!prefix) return <span className="mx_PinnedMessageBanner_message">{preview}</span>;

return (
Expand Down Expand Up @@ -177,10 +177,17 @@ function useEventPreview(pinnedEvent: MatrixEvent | null): string | null {
}

/**
* Get the prefix for the preview based on the message type.
* Get the prefix for the preview based on the type and the message type.
* @param type
* @param msgType
*/
function getPreviewPrefix(msgType: MsgType): string | null {
function getPreviewPrefix(type: string, msgType: MsgType): string | null {
switch (type) {
case M_POLL_START.name:
return _t("room|pinned_message_banner|prefix|poll");
default:
}

switch (msgType) {
case MsgType.Audio:
return _t("room|pinned_message_banner|prefix|audio");
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,7 @@
"audio": "Audio",
"file": "File",
"image": "Image",
"poll": "Poll",
"video": "Video"
},
"preview": "<bold>%(prefix)s:</bold> %(preview)s",
Expand Down

0 comments on commit 101e542

Please sign in to comment.