mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-29 05:12:47 -08:00
fix: restore poll rendering
This commit is contained in:
7 files changed
+80
-4
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Restore polls in room timelines.
|
||||
@@ -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';
|
||||
@@ -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={{}}>
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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';
|
||||
|
||||
@@ -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 />;
|
||||
|
||||
@@ -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';
|
||||
@@ -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 }),
|
||||
|
||||
@@ -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[];
|
||||
@@ -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',
|
||||
|
||||
@@ -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)} />
|
||||
),
|
||||
@@ -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)', () => {
|
||||
|
||||
@@ -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) {
|
||||
@@ -903,6 +903,7 @@ export function useTimelineEventRenderer({
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
outlineAttachment={messageLayout === MessageLayout.Bubble}
|
||||
mEvent={mEvent}
|
||||
mx={mx}
|
||||
room={room}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user