add rendering for all options

Signed-off-by: Shea <[email protected]>
This commit is contained in:
Shea committed 2026-06-01 06:28:35 +03:00
1 parent 16d67f19d3
commit 1d265ba222
11 files changed
+114 -24

No files matched your search

+5 -2
View File
@@ -448,8 +448,11 @@ function RenderMessageContentInternal({
}
/>
);
if (content['org.matrix.msc3381.poll.start'] && mEvent && mx && room)
return <PollEvent content={content} mEvent={mEvent} mx={mx} room={room} />;
if (content['org.matrix.msc3381.poll.start']) {
if (mEvent && mx && room)
return <PollEvent content={content} mEvent={mEvent} mx={mx} room={room} />;
else return <UnsupportedContent body="abba" />;
}
return (
<UnsupportedContent
body={
+3 -3
View File
@@ -154,11 +154,11 @@ export function PollEvent({ content, mEvent, mx, room }: PollEventProps) {
// The choice of making it not the same size and style as an Attachment is deliberate as Polls tipically are Way more wordy and this feels more spacious
return (
<Box direction="Column" className={css.PollEvent} grow="Yes" gap="100">
<Box className={css.PollHeader}>
<Box className={css.PollHeader} shrink="No">
<Text>{questionBody} </Text>
</Box>
<Line direction="Horizontal" variant="SurfaceVariant" className={css.PollEventSeparator} />
<Box direction="Column" grow="Yes" gap="300" className={css.PollAnswersBody}>
<Box direction="Column" grow="Yes" shrink="No" gap="300" className={css.PollAnswersBody}>
{answers.map((item) => {
const optionBody = item['org.matrix.msc1767.text'];
const voteCount = votes[item.id];
@@ -210,7 +210,7 @@ export function PollEvent({ content, mEvent, mx, room }: PollEventProps) {
</Box>
);
})}
<Box gap="200" grow="Yes" justifyContent="SpaceBetween" alignItems="Center">
<Box gap="200" grow="Yes" shrink="No" justifyContent="SpaceBetween" alignItems="Center">
<Text size="T200">
{isDisclosed || isEnded
? `${totalVotes} vote${totalVotes !== 1 ? 's' : ''} ${totalVotes !== voters.size ? `by ${voters.size} voter${voters.size !== 1 ? 's' : ''}` : ''}`
+19 -3
View File
@@ -44,6 +44,7 @@ import {
} from './content';
import * as css from './Reply.css';
import { LinePlaceholder } from './placeholder';
import { M_POLL_START } from 'matrix-js-sdk';
const ROOM_REPLY_TIMELINE_EVENT_TYPES = new Set<string>([
EventType.RoomMessage as string,
@@ -203,6 +204,11 @@ export const Reply = as<'div', ReplyProps>(
const mx = useMatrixClient();
const { body, formatted_body: formattedBody, format } = replyEvent?.getContent() ?? {};
const extensibleContent = replyEvent?.getContent()['org.matrix.msc1767.text'] as
| string
| { body: string }
| undefined;
const extensibleBody = (extensibleContent as { body: string })?.body ?? extensibleContent;
const sender = replyEvent?.getSender();
const eventType = replyEvent?.getType();
@@ -233,7 +239,7 @@ export const Reply = as<'div', ReplyProps>(
const isFormattedReply =
format === 'org.matrix.custom.html' && typeof formattedBody === 'string';
const hasPlainTextReply = typeof body === 'string' && body !== '';
const hasExtensibleBody = typeof extensibleBody === 'string' && extensibleBody !== '';
// An encrypted event that hasn't been decrypted yet (keys pending) has an
// empty result from getClearContent(). Treat it as still-loading rather
// than a failure so the UI shows a placeholder instead of MessageFailedContent
@@ -267,8 +273,12 @@ export const Reply = as<'div', ReplyProps>(
}),
[mx, room.roomId, mentionClickHandler, nicknames, settingsLinkBaseUrl]
);
if (isFormattedReply && formattedBody !== '') {
if(eventType === M_POLL_START.name){
const question = (replyEvent?.getContent()[M_POLL_START.name] as {question: {'org.matrix.msc1767.text'?: string, body?: string}})?.question;
image = Icons.UnorderList;
bodyJSX = `'s poll asking ${question['org.matrix.msc1767.text'] ?? question.body ?? ''}`
}
else if (isFormattedReply && formattedBody !== '') {
const sanitizedHtml = sanitizeReplyFormattedPreview(formattedBody);
if (shouldParseReplyFormattedPreview(sanitizedHtml)) {
const parserOpts = getReactCustomHtmlParser(mx, room.roomId, {
@@ -284,10 +294,16 @@ export const Reply = as<'div', ReplyProps>(
} else if (hasPlainTextReply) {
const strippedBody = trimReplyFromBody(body).replaceAll(/(?:\r\n|\r|\n)/g, ' ');
bodyJSX = scaleSystemEmoji(strippedBody);
} else if (hasExtensibleBody) {
const strippedBody = trimReplyFromBody(extensibleBody).replaceAll(/(?:\r\n|\r|\n)/g, ' ');
bodyJSX = scaleSystemEmoji(strippedBody);
}
} else if (hasPlainTextReply) {
const strippedBody = trimReplyFromBody(body).replaceAll(/(?:\r\n|\r|\n)/g, ' ');
bodyJSX = scaleSystemEmoji(strippedBody);
} else if (hasExtensibleBody) {
const strippedBody = trimReplyFromBody(extensibleBody).replaceAll(/(?:\r\n|\r|\n)/g, ' ');
bodyJSX = scaleSystemEmoji(strippedBody);
} else if (eventType === EventType.RoomMember && !!replyEvent) {
const parsedMemberEvent = parseMemberEvent(replyEvent);
image = parsedMemberEvent.icon;
@@ -171,6 +171,8 @@ export function SearchResultGroup({
linkifyOpts={linkifyOpts}
highlightRegex={highlightRegex}
outlineAttachment
mx={mx}
room={room}
/>
);
},
+12 -3
View File
@@ -163,7 +163,7 @@ import { PollDialog } from './add-poll';
// Returns the event ID of the most recent non-reaction/non-edit event in a thread,
// falling back to the thread root if no replies exist yet.
const getLatestThreadEventId = (room: Room, threadRootId: string): string => {
export const getLatestThreadEventId = (room: Room, threadRootId: string): string => {
const thread = room.getThread(threadRootId);
const threadEvents: MatrixEvent[] = thread?.events ?? [];
const filtered = threadEvents.filter(
@@ -192,7 +192,10 @@ const getLatestThreadEventId = (room: Room, threadRootId: string): string => {
return threadRootId;
};
const getReplyContent = (replyDraft: IReplyDraft | undefined, room?: Room): IEventRelation => {
export const getReplyContent = (
replyDraft: IReplyDraft | undefined,
room?: Room
): IEventRelation => {
if (!replyDraft) return {};
const relatesTo: IEventRelation = {};
@@ -1817,7 +1820,13 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
/>
)}
{showPollPicker && (
<PollDialog onCancel={() => setShowPollPicker(false)} mx={mx} roomId={roomId} />
<PollDialog
onCancel={() => setShowPollPicker(false)}
mx={mx}
room={room}
replyDraft={replyDraft}
clearReplyDraft={() => setReplyDraft(undefined)}
/>
)}
</div>
);
+3
View File
@@ -247,6 +247,9 @@ function ThreadPreview({ room, thread, onClick, onJump }: ThreadPreviewProps) {
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
outlineAttachment
mEvent={rootEvent}
mx={mx}
room={room}
/>
);
}}
@@ -21,11 +21,12 @@ export const PollDialogAnswerBody = style({
export const PollDialogAnswerInput = style({ width: '100%' });
export const PollDialogMaxSelectionNumber = style({ width: toRem(80) });
export const PollDialogMaxSelectionSlider = style({
width: '100%',
cursor: 'pointer',
appearance: 'none',
height: toRem(6),
borderRadius: config.radii.Pill,
backgroundColor: color.Background.ContainerLine,
accentColor: color.Primary.Main,});
export const PollDialogMaxSelectionSlider = style({
width: '100%',
cursor: 'pointer',
appearance: 'none',
height: toRem(6),
borderRadius: config.radii.Pill,
backgroundColor: color.Background.ContainerLine,
accentColor: color.Primary.Main,
});
+13 -4
View File
@@ -23,18 +23,23 @@ import { randomStr } from '$utils/common';
import { SettingTile } from '$components/setting-tile';
import { SequenceCard } from '$components/sequence-card';
import { SequenceCardStyle } from '$features/settings/styles.css';
import type { IContent, MatrixClient, TimelineEvents } from 'matrix-js-sdk';
import type { IContent, MatrixClient, Room, TimelineEvents } from 'matrix-js-sdk';
import { M_POLL_KIND_DISCLOSED, M_POLL_KIND_UNDISCLOSED, M_POLL_START } from 'matrix-js-sdk';
import { isKeyHotkey } from 'is-hotkey';
import * as css from './PollDialog.css';
import type { IReplyDraft } from '$state/room/roomInputDrafts';
import { getReplyContent } from '../RoomInput';
type PollDialogProps = {
onCancel: () => void;
mx: MatrixClient;
roomId: string;
room: Room;
replyDraft?: IReplyDraft;
clearReplyDraft?: () => void;
};
export function PollDialog({ onCancel, mx, roomId }: PollDialogProps) {
export function PollDialog({ onCancel, mx, room, replyDraft, clearReplyDraft }: PollDialogProps) {
const roomId = room.roomId;
const [isDisclosed, setIsDisclosed] = useState(true);
const [maxSelections, setMaxSelections] = useState(1);
const [inputValue, setInputValue] = useState(1);
@@ -75,6 +80,10 @@ export function PollDialog({ onCancel, mx, roomId }: PollDialogProps) {
},
'org.matrix.msc1767.text': `New poll\n Question: ${title.current}\nAnswers:\n ${answers.map((item) => item['org.matrix.msc1767.text']).join('\n')}`,
};
if (replyDraft && clearReplyDraft) {
pollContent['m.relates_to'] = getReplyContent(replyDraft, room);
clearReplyDraft();
}
mx.sendEvent(
roomId,
@@ -113,7 +122,7 @@ export function PollDialog({ onCancel, mx, roomId }: PollDialogProps) {
<Header className={css.PollDialogHeader} variant="Surface" size="500">
<Box grow="Yes" gap="200">
<Icon src={Icons.UnorderList} />
<Text size="H4">New Poll </Text>
<Text size="H4">{`New Poll ${replyDraft ? '(reply / thread)' : ''}`} </Text>
</Box>
<IconButton
size="300"
@@ -96,6 +96,7 @@ import type { PinReadMarker } from '$features/room/RoomViewHeader';
import * as css from './RoomPinMenu.css';
import { CustomAccountDataEvent } from '$types/matrix/accountData';
import { EventType } from '$types/matrix-sdk';
import { M_POLL_START } from 'matrix-js-sdk';
const log = createLogger('RoomPinMenu');
@@ -195,7 +196,9 @@ function PinnedMessageActiveContent(
onClick={handleOpenClick}
/>
)}
<Box onClick={handleOpenClick}>
{renderContent(pinnedEvent.getType(), false, pinnedEvent, displayName, getContent)}
</Box>
</ModernLayout>
);
}
@@ -410,6 +413,9 @@ export const RoomPinMenu = forwardRef<HTMLDivElement, RoomPinMenuProps>(
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
outlineAttachment
mEvent={event}
mx={mx}
room={room}
/>
);
},
@@ -474,6 +480,9 @@ export const RoomPinMenu = forwardRef<HTMLDivElement, RoomPinMenuProps>(
urlPreview={urlPreview}
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
mx={mx}
room={room}
mEvent={event}
/>
);
}
@@ -515,6 +524,33 @@ export const RoomPinMenu = forwardRef<HTMLDivElement, RoomPinMenuProps>(
/>
);
},
[M_POLL_START.name]: (event, displayName, getContent) => {
if (event.isRedacted()) {
const unsigned = event.getUnsigned();
const redactionContent = unsigned.redacted_because?.content as
| { reason?: string }
| undefined;
return <RedactedContent reason={redactionContent?.reason} />;
}
return (
<RenderMessageContent
displayName={displayName}
msgType={event.getContent().msgtype ?? ''}
ts={event.getTs()}
getContent={getContent}
edited={!!event.replacingEvent()}
mediaAutoLoad={mediaAutoLoad}
urlPreview={urlPreview}
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
outlineAttachment
mEvent={event}
mx={mx}
room={room}
/>
);
},
},
undefined,
(event) => {
@@ -514,6 +514,8 @@ export function useTimelineEventRenderer({
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
outlineAttachment={messageLayout === MessageLayout.Bubble}
mx={mx}
room={room}
/>
)}
</Message>
@@ -682,6 +684,8 @@ export function useTimelineEventRenderer({
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
outlineAttachment={messageLayout === MessageLayout.Bubble}
mx={mx}
room={room}
/>
);
}
+8 -1
View File
@@ -286,7 +286,8 @@ function RoomNotificationsGroupComp({
if (event.unsigned?.redacted_because) {
return <RedactedContent reason={event.unsigned?.redacted_because.content.reason} />;
}
const evtTimeline = room.getTimelineForEvent(event.event_id);
const mEvent = evtTimeline?.getEvents().find((e) => e.getId() === event.event_id);
return (
<RenderMessageContent
displayName={displayName}
@@ -298,6 +299,9 @@ function RoomNotificationsGroupComp({
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
outlineAttachment
mx={mx}
room={room}
mEvent={mEvent}
/>
);
},
@@ -356,6 +360,9 @@ function RoomNotificationsGroupComp({
urlPreview={urlPreview}
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
mx={mx}
room={room}
mEvent={mEvent}
/>
);
}