Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-poll-rendering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

Restore polls in room timelines.
25 changes: 25 additions & 0 deletions src/app/components/RenderMessageContent.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { render, screen } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { MsgType } from '$types/matrix-sdk';
import { M_POLL_START } from 'matrix-js-sdk';
import { ClientConfigProvider } from '$hooks/useClientConfig';
import { MatrixClientProvider } from '$hooks/useMatrixClient';
import { RenderMessageContent } from './RenderMessageContent';
Expand All @@ -24,6 +25,10 @@ vi.mock('./url-preview', () => ({
youtubeUrl: () => false,
}));

vi.mock('./message/PollEvent', () => ({
PollEvent: () => <div data-testid="poll-event" />,
}));

function renderMessage(body: string) {
return render(
<ClientConfigProvider value={{}}>
Expand Down Expand Up @@ -132,4 +137,24 @@ describe('RenderMessageContent', () => {

expect(screen.getByTestId('uploaded-sable-css')).toHaveTextContent('amethyst.sable.css');
});

it('renders current poll events', () => {
render(
<ClientConfigProvider value={{}}>
<RenderMessageContent
displayName="Alice"
msgType=""
ts={0}
getContent={() => ({ [M_POLL_START.name]: {} })}
htmlReactParserOptions={{}}
linkifyOpts={{}}
mEvent={{} as never}
mx={{} as never}
room={{} as never}
/>
</ClientConfigProvider>
);

expect(screen.getByTestId('poll-event')).toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions src/app/components/RenderMessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { TextViewer } from './text-viewer';
import { ClientSideHoverFreeze } from './ClientSideHoverFreeze';
import { CuteEventType, MCuteEvent } from './message/MCuteEvent';
import { PollEvent } from './message/PollEvent';
import { M_TEXT } from 'matrix-js-sdk';
import { M_POLL_START, M_TEXT } from 'matrix-js-sdk';
import type { IImageInfo, IGalleryContent } from '$types/matrix/common';
import { GALLERY_MSGTYPE } from '$types/matrix/common';

Expand Down Expand Up @@ -511,7 +511,7 @@ function RenderMessageContentInternal({
}
/>
);
if (content['org.matrix.msc3381.poll.start']) {
if (content[M_POLL_START.name]) {
if (mEvent && mx && room)
return <PollEvent content={content} mEvent={mEvent} mx={mx} room={room} />;
else return <UnsupportedContent />;
Expand Down
16 changes: 16 additions & 0 deletions src/app/hooks/timeline/useProcessedTimeline.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getProcessedRowIndexForRawTimelineIndex,
useProcessedTimeline,
} from './useProcessedTimeline';
import { M_POLL_START } from 'matrix-js-sdk';

const MY_USER = '@alice:test';
const OTHER_USER = '@bob:test';
Expand Down Expand Up @@ -139,6 +140,21 @@ const dividerIds = (processed: ProcessedEvent[]) =>
processed.filter((e) => e.willRenderNewDivider).map((e) => e.id);

describe('useProcessedTimeline new-messages divider', () => {
it('keeps poll start events with default hidden-event settings', () => {
const processed = processTimeline(
[
createEvent({
id: '$poll',
type: M_POLL_START.name,
content: { 'm.poll.start': {} },
}),
],
undefined
);

expect(renderedIds(processed)).toEqual(['$poll']);
});

it('processes append-only messages without rebuilding existing rows', () => {
const events = [
createEvent({ id: '$a', ts: 1_000_000 }),
Expand Down
2 changes: 2 additions & 0 deletions src/app/hooks/timeline/useProcessedTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '$utils/room/relations';
import { inSameDay, minuteDifference } from '$utils/time';
import type { ResolvedHiddenEventSettings } from '$state/hooks/settings';
import { M_POLL_START } from 'matrix-js-sdk';

export interface UseProcessedTimelineOptions {
items: number[];
Expand Down Expand Up @@ -79,6 +80,7 @@ export const STANDARD_RENDERED_EVENT_TYPES = new Set([
'm.room.message',
'm.room.message.encrypted',
'm.sticker',
M_POLL_START.name,
'm.room.member',
'm.room.name',
'm.room.topic',
Expand Down
29 changes: 28 additions & 1 deletion src/app/hooks/timeline/useTimelineEventRenderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ vi.mock('$features/room/message', async (importActual) => {
{children}
</div>
),
EncryptedContent: () => <div data-testid="encrypted-content" />,
EncryptedContent: ({ mEvent, children }: any) =>
mEvent.getType() === M_POLL_START.name ? (
<>{children()}</>
) : (
<div data-testid="encrypted-content" />
),
Reactions: ({ mEventId: targetId, canSendReaction: canReact }: any) => (
<div data-testid="reactions" data-target-id={targetId} data-can-react={String(!!canReact)} />
),
Expand Down Expand Up @@ -725,6 +730,28 @@ describe('useTimelineEventRenderer', () => {
});
});

it('renders a decrypted poll through RenderMessageContent', () => {
const evt = createEvent({
id: '$encrypted-poll:example.com',
type: EventType.RoomMessageEncrypted,
content: {
'm.poll.start': {
question: { 'm.text': [{ body: 'Yes or No?' }] },
},
msgtype: 'm.text',
},
});
evt.getType = vi
.fn<() => string>()
.mockReturnValueOnce(EventType.RoomMessageEncrypted)
.mockReturnValue(M_POLL_START.name);

const { container } = renderEvent(evt, false);

expect(container.querySelector('[data-testid="render-message-content"]')).not.toBeNull();
expect(container.querySelector('[data-testid="message-not-decrypted"]')).toBeNull();
});

// ── Additional coverage ───────────────────────────────────────────────────

describe('activeReplyId === mEventId (marked logic)', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/app/hooks/timeline/useTimelineEventRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ export function useTimelineEventRenderer({
)}
/>
);
if (type === (EventType.RoomMessage as string)) {
if (type === (EventType.RoomMessage as string) || type === M_POLL_START.name) {
const editedEvent = getEditedEvent(mEventId, mEvent, timelineSet);
let editedNewContent: unknown;
if (editedEvent) {
Expand Down Expand Up @@ -903,6 +903,7 @@ export function useTimelineEventRenderer({
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
outlineAttachment={messageLayout === MessageLayout.Bubble}
mEvent={mEvent}
mx={mx}
room={room}
/>
Expand Down