* Make EventTileViewModel usage coherent * Extract render helpers * Extracted small render views * Reduce Render Branch Duplication * Clean Up Dead or Legacy Inline Code * Add/Update documentation * Updated snapshot * Fix Sonar issue * Updated snapshots after merge error * Fix prettier issue
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { EventType, type MatrixClient, type MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { TimelineRenderingType } from "../../../../contexts/RoomContext";
|
||||
|
||||
/** Inputs for deriving EventTile highlight display state. */
|
||||
export interface EventTileHighlightStateInput {
|
||||
/** Matrix client used to resolve push actions and the current user. */
|
||||
cli: MatrixClient;
|
||||
/** Matrix event rendered by the tile. */
|
||||
mxEvent: MatrixEvent;
|
||||
/** Current timeline rendering mode. */
|
||||
timelineRenderingType: TimelineRenderingType;
|
||||
/** Whether the tile is rendering for export. */
|
||||
forExport?: boolean;
|
||||
/** Whether the event is considered redacted by the tile. */
|
||||
isRedacted?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether an event should be highlighted.
|
||||
* For edited events, if a previous version of the event was highlighted, the event should remain highlighted as the
|
||||
* user may have been notified.
|
||||
*/
|
||||
export function shouldHighlightEventTile({
|
||||
cli,
|
||||
mxEvent,
|
||||
timelineRenderingType,
|
||||
forExport,
|
||||
isRedacted,
|
||||
}: EventTileHighlightStateInput): boolean {
|
||||
if (forExport) return false;
|
||||
if (timelineRenderingType === TimelineRenderingType.Notification) return false;
|
||||
if (timelineRenderingType === TimelineRenderingType.ThreadsList) return false;
|
||||
if (isRedacted) return false;
|
||||
|
||||
// This event is a room mention but we don't want the call tile to have a highlight.
|
||||
if (mxEvent.getType() === EventType.RTCNotification) return false;
|
||||
|
||||
const actions = cli.getPushActionsForEvent(mxEvent.replacingEvent() || mxEvent);
|
||||
const previousActions = mxEvent.replacingEvent() ? cli.getPushActionsForEvent(mxEvent) : undefined;
|
||||
if (!actions?.tweaks && !previousActions?.tweaks) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't show self-highlights from another of our clients.
|
||||
if (mxEvent.getSender() === cli.credentials.userId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !!(actions?.tweaks.highlight || previousActions?.tweaks.highlight);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { CallErrorCode } from "matrix-js-sdk/src/webrtc/call";
|
||||
|
||||
/** Call event state used to decide whether EventTile should suppress rendering. */
|
||||
export interface EventTileCallEventState {
|
||||
/** Legacy call hangup reason, when available. */
|
||||
hangupReason?: string | null;
|
||||
}
|
||||
|
||||
/** Inputs for deriving EventTile hidden display state. */
|
||||
export interface EventTileVisibilityStateInput {
|
||||
/** Legacy call event grouping state for this tile. */
|
||||
callEventGrouper?: EventTileCallEventState;
|
||||
}
|
||||
|
||||
/**
|
||||
* In some cases EventTile cannot rely on the event's own visibility because replacement call events are rendered by
|
||||
* the replacing call tile instead.
|
||||
*/
|
||||
export function shouldHideEventTile({ callEventGrouper }: EventTileVisibilityStateInput): boolean {
|
||||
return callEventGrouper?.hangupReason === CallErrorCode.Replaced;
|
||||
}
|
||||
Reference in New Issue
Block a user