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

Commit

Permalink
Wip pinned separator
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Aug 19, 2024
1 parent c37cb9f commit f4df9e1
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions res/css/_components.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
@import "./views/messages/_MessageActionBar.pcss";
@import "./views/messages/_MessageTimestamp.pcss";
@import "./views/messages/_MjolnirBody.pcss";
@import "./views/messages/_PinnedSeparator.pcss";
@import "./views/messages/_ReactionsRow.pcss";
@import "./views/messages/_ReactionsRowButton.pcss";
@import "./views/messages/_RedactedBody.pcss";
Expand Down
24 changes: 24 additions & 0 deletions res/css/views/messages/_PinnedSeparator.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

.mx_PinnedSeparator {
text-align: end;
border-bottom: 1px solid var(--cpd-color-icon-accent-primary);
font: var(--cpd-font-body-sm-semibold);
color: var(--cpd-color-text-action-accent);
text-transform: uppercase;
margin-bottom: var(--cpd-space-1x);
}
11 changes: 11 additions & 0 deletions src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import { MainGrouper } from "./grouper/MainGrouper";
import { CreationGrouper } from "./grouper/CreationGrouper";
import { _t } from "../../languageHandler";
import { getLateEventInfo } from "./grouper/LateEventGrouper";
import PinningUtils from "../../utils/PinningUtils";
import { PinnedSeparator } from "../views/messages/PinnedSeparator";

const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000; // 5 minutes
const continuedTypes = [EventType.Sticker, EventType.RoomMessage];
Expand Down Expand Up @@ -767,6 +769,15 @@ export default class MessagePanel extends React.Component<IProps, IState> {
}

const cli = MatrixClientPeg.safeGet();

if (SettingsStore.getValue<boolean>("feature_pinning") && PinningUtils.isPinned(cli, mxEv)) {
ret.push(
<li key={`${ts1}-pinned`}>
<PinnedSeparator />
</li>,
);
}

let lastInSection = true;
if (nextEventWithTile) {
const nextEv = nextEventWithTile;
Expand Down
30 changes: 30 additions & 0 deletions src/components/views/messages/PinnedSeparator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import React, { JSX } from "react";

import { _t } from "../../../languageHandler";

/**
* A separator to be displayed between pinned messages and the rest of the timeline.
*/
export function PinnedSeparator(): JSX.Element {
return (
<div className="mx_PinnedSeparator" role="separator" aria-label={_t("timeline|pinned_separator_description")}>
{_t("timeline|pinned_separator")}
</div>
);
}
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -3523,6 +3523,8 @@
"no_permission_messages_before_join": "You don't have permission to view messages from before you joined.",
"pending_moderation": "Message pending moderation",
"pending_moderation_reason": "Message pending moderation: %(reason)s",
"pinned_separator": "pinned",
"pinned_separator_description": "The following message is pinned.",
"reactions": {
"add_reaction_prompt": "Add reaction",
"custom_reaction_fallback_label": "Custom reaction",
Expand Down
20 changes: 19 additions & 1 deletion src/utils/PinningUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { MatrixEvent, EventType, M_POLL_START } from "matrix-js-sdk/src/matrix";
import { MatrixEvent, EventType, M_POLL_START, MatrixClient, EventTimeline } from "matrix-js-sdk/src/matrix";

export default class PinningUtils {
/**
Expand All @@ -38,4 +38,22 @@ export default class PinningUtils {

return true;
}

/**
* Determines if the given event is pinned.
* @param matrixClient
* @param mxEvent
*/
public static isPinned(matrixClient: MatrixClient, mxEvent: MatrixEvent): boolean {
const room = matrixClient.getRoom(mxEvent.getRoomId());
if (!room) return false;

const pinnedEvent = room
.getLiveTimeline()
.getState(EventTimeline.FORWARDS)
?.getStateEvents(EventType.RoomPinnedEvents, "");
if (!pinnedEvent) return false;
const content = pinnedEvent.getContent();
return content.pinned && Array.isArray(content.pinned) && content.pinned.includes(mxEvent.getId());
}
}

0 comments on commit f4df9e1

Please sign in to comment.