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

Commit 464bb72

Browse files
authored
Update and expand ways to access pinned messages (#7906)
* Hide pinned messages header button when nothing is pinned Signed-off-by: Robin Townsend <[email protected]> * Add pinned messages option to room info panel Signed-off-by: Robin Townsend <[email protected]> * Add pinned messages option to room header menu Signed-off-by: Robin Townsend <[email protected]> * Make condition more concise Signed-off-by: Robin Townsend <[email protected]>
1 parent 3365794 commit 464bb72

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

res/css/views/right_panel/_RoomSummaryCard.scss

+4
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ limitations under the License.
251251
mask-image: url('$(res)/img/element-icons/room/files.svg');
252252
}
253253

254+
.mx_RoomSummaryCard_icon_pins::before {
255+
mask-image: url('$(res)/img/element-icons/room/pin-upright.svg');
256+
}
257+
254258
.mx_RoomSummaryCard_icon_threads::before {
255259
mask-image: url('$(res)/img/element-icons/message/thread.svg');
256260
}

res/css/views/rooms/_RoomTile.scss

+4
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ limitations under the License.
213213
mask-image: url('$(res)/img/element-icons/room/files.svg');
214214
}
215215

216+
.mx_RoomTile_iconPins::before {
217+
mask-image: url('$(res)/img/element-icons/room/pin-upright.svg');
218+
}
219+
216220
.mx_RoomTile_iconWidgets::before {
217221
mask-image: url('$(res)/img/element-icons/room/apps.svg');
218222
}

src/components/views/context_menus/RoomContextMenu.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import { EchoChamber } from "../../../stores/local-echo/EchoChamber";
3636
import { RoomNotifState } from "../../../RoomNotifs";
3737
import Modal from "../../../Modal";
3838
import ExportDialog from "../dialogs/ExportDialog";
39+
import { useSettingValue } from "../../../hooks/useSettings";
40+
import { usePinnedEvents } from "../right_panel/PinnedMessagesCard";
3941
import RoomViewStore from "../../../stores/RoomViewStore";
4042
import { RightPanelPhases } from '../../../stores/right-panel/RightPanelStorePhases';
4143
import { ROOM_NOTIFICATIONS_TAB } from "../dialogs/RoomSettingsDialog";
@@ -228,6 +230,29 @@ const RoomContextMenu = ({ room, onFinished, ...props }: IProps) => {
228230
/>;
229231
}
230232

233+
const pinningEnabled = useSettingValue("feature_pinning");
234+
const pinCount = usePinnedEvents(pinningEnabled && room)?.length;
235+
236+
let pinsOption: JSX.Element;
237+
if (pinningEnabled) {
238+
pinsOption = <IconizedContextMenuOption
239+
onClick={(ev: ButtonEvent) => {
240+
ev.preventDefault();
241+
ev.stopPropagation();
242+
243+
ensureViewingRoom(ev);
244+
RightPanelStore.instance.pushCard({ phase: RightPanelPhases.PinnedMessages }, false);
245+
onFinished();
246+
}}
247+
label={_t("Pinned")}
248+
iconClassName="mx_RoomTile_iconPins"
249+
>
250+
{ pinCount > 0 && <span className="mx_IconizedContextMenu_sublabel">
251+
{ pinCount }
252+
</span> }
253+
</IconizedContextMenuOption>;
254+
}
255+
231256
const onTagRoom = (ev: ButtonEvent, tagId: TagID) => {
232257
ev.preventDefault();
233258
ev.stopPropagation();
@@ -278,6 +303,8 @@ const RoomContextMenu = ({ room, onFinished, ...props }: IProps) => {
278303
iconClassName="mx_RoomTile_iconFiles"
279304
/>
280305

306+
{ pinsOption }
307+
281308
<IconizedContextMenuOption
282309
onClick={(ev: ButtonEvent) => {
283310
ev.preventDefault();

src/components/views/right_panel/RoomHeaderButtons.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const PinnedMessagesHeaderButton = ({ room, isHighlighted, onClick }: IHeaderBut
8282
const pinningEnabled = useSettingValue("feature_pinning");
8383
const pinnedEvents = usePinnedEvents(pinningEnabled && room);
8484
const readPinnedEvents = useReadPinnedEvents(pinningEnabled && room);
85-
if (!pinningEnabled) return null;
85+
if (!pinnedEvents?.length) return null;
8686

8787
let unreadIndicator;
8888
if (pinnedEvents.some(id => !readPinnedEvents.has(id))) {

src/components/views/right_panel/RoomSummaryCard.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import { UIFeature } from "../../../settings/UIFeature";
4242
import { ChevronFace, ContextMenuTooltipButton, useContextMenu } from "../../structures/ContextMenu";
4343
import WidgetContextMenu from "../context_menus/WidgetContextMenu";
4444
import { useRoomMemberCount } from "../../../hooks/useRoomMembers";
45+
import { useSettingValue } from "../../../hooks/useSettings";
46+
import { usePinnedEvents } from "./PinnedMessagesCard";
4547
import { Container, MAX_PINNED, WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore";
4648
import RoomName from "../elements/RoomName";
4749
import UIStore from "../../../stores/UIStore";
@@ -239,6 +241,10 @@ const onRoomFilesClick = () => {
239241
RightPanelStore.instance.pushCard({ phase: RightPanelPhases.FilePanel }, true);
240242
};
241243

244+
const onRoomPinsClick = () => {
245+
RightPanelStore.instance.pushCard({ phase: RightPanelPhases.PinnedMessages }, true);
246+
};
247+
242248
const onRoomSettingsClick = (ev: ButtonEvent) => {
243249
defaultDispatcher.dispatch({ action: "open_room_settings" });
244250
PosthogTrackers.trackInteraction("WebRightPanelRoomInfoSettingsButton", ev);
@@ -290,6 +296,8 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, onClose }) => {
290296
</React.Fragment>;
291297

292298
const memberCount = useRoomMemberCount(room);
299+
const pinningEnabled = useSettingValue("feature_pinning");
300+
const pinCount = usePinnedEvents(pinningEnabled && room)?.length;
293301

294302
return <BaseCard header={header} className="mx_RoomSummaryCard" onClose={onClose}>
295303
<Group title={_t("About")} className="mx_RoomSummaryCard_aboutGroup">
@@ -302,6 +310,12 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, onClose }) => {
302310
<Button className="mx_RoomSummaryCard_icon_files" onClick={onRoomFilesClick}>
303311
{ _t("Files") }
304312
</Button>
313+
{ pinningEnabled && <Button className="mx_RoomSummaryCard_icon_pins" onClick={onRoomPinsClick}>
314+
{ _t("Pinned") }
315+
{ pinCount > 0 && <span className="mx_BaseCard_Button_sublabel">
316+
{ pinCount }
317+
</span> }
318+
</Button> }
305319
<Button className="mx_RoomSummaryCard_icon_export" onClick={onRoomExportClick}>
306320
{ _t("Export chat") }
307321
</Button>

src/i18n/strings/en_EN.json

+1
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,7 @@
19611961
"Not encrypted": "Not encrypted",
19621962
"About": "About",
19631963
"Files": "Files",
1964+
"Pinned": "Pinned",
19641965
"Export chat": "Export chat",
19651966
"Share room": "Share room",
19661967
"Room settings": "Room settings",

0 commit comments

Comments
 (0)