2018-10-30 17:15:19 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
|
Copyright 2017 New Vector Ltd
|
|
|
|
|
Copyright 2018 New Vector Ltd
|
2020-01-28 22:06:04 +00:00
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
2018-10-30 17:15:19 +01:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-05-25 16:10:44 +01:00
|
|
|
import React from "react";
|
2021-12-13 14:05:42 +00:00
|
|
|
import classNames from "classnames";
|
2021-05-25 16:10:44 +01:00
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
|
|
2021-06-03 08:41:22 +01:00
|
|
|
import { _t } from '../../../languageHandler';
|
2018-10-30 17:15:19 +01:00
|
|
|
import HeaderButton from './HeaderButton';
|
2021-06-03 08:41:22 +01:00
|
|
|
import HeaderButtons, { HeaderKind } from './HeaderButtons';
|
2022-01-05 16:14:44 +01:00
|
|
|
import { RightPanelPhases } from '../../../stores/right-panel/RightPanelStorePhases';
|
2021-06-03 08:41:22 +01:00
|
|
|
import { Action } from "../../../dispatcher/actions";
|
|
|
|
|
import { ActionPayload } from "../../../dispatcher/payloads";
|
2022-01-05 16:14:44 +01:00
|
|
|
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
|
2021-06-03 08:41:22 +01:00
|
|
|
import { useSettingValue } from "../../../hooks/useSettings";
|
2021-05-25 16:10:44 +01:00
|
|
|
import { useReadPinnedEvents, usePinnedEvents } from './PinnedMessagesCard';
|
2022-01-05 17:25:41 +01:00
|
|
|
import { showThreadPanel } from "../../../dispatcher/dispatch-actions/threads";
|
2021-10-14 15:27:35 +02:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2022-09-08 15:53:57 +01:00
|
|
|
import {
|
|
|
|
|
RoomNotificationStateStore,
|
|
|
|
|
UPDATE_STATUS_INDICATOR,
|
|
|
|
|
} from "../../../stores/notifications/RoomNotificationStateStore";
|
2021-11-30 11:06:20 +01:00
|
|
|
import { NotificationColor } from "../../../stores/notifications/NotificationColor";
|
2021-12-13 14:05:42 +00:00
|
|
|
import { ThreadsRoomNotificationState } from "../../../stores/notifications/ThreadsRoomNotificationState";
|
2022-09-08 15:53:57 +01:00
|
|
|
import { SummarizedNotificationState } from "../../../stores/notifications/SummarizedNotificationState";
|
2021-12-13 14:05:42 +00:00
|
|
|
import { NotificationStateEvents } from "../../../stores/notifications/NotificationState";
|
2022-02-28 14:11:14 +00:00
|
|
|
import PosthogTrackers from "../../../PosthogTrackers";
|
|
|
|
|
import { ButtonEvent } from "../elements/AccessibleButton";
|
2018-10-30 17:15:19 +01:00
|
|
|
|
2020-09-08 08:48:03 +01:00
|
|
|
const ROOM_INFO_PHASES = [
|
|
|
|
|
RightPanelPhases.RoomSummary,
|
|
|
|
|
RightPanelPhases.Widget,
|
|
|
|
|
RightPanelPhases.FilePanel,
|
2020-07-18 16:38:20 +05:30
|
|
|
RightPanelPhases.RoomMemberList,
|
|
|
|
|
RightPanelPhases.RoomMemberInfo,
|
|
|
|
|
RightPanelPhases.EncryptionPanel,
|
|
|
|
|
RightPanelPhases.Room3pidMemberInfo,
|
2019-04-11 13:31:21 +02:00
|
|
|
];
|
|
|
|
|
|
2021-11-30 11:06:20 +01:00
|
|
|
interface IUnreadIndicatorProps {
|
2021-12-13 14:05:42 +00:00
|
|
|
color?: NotificationColor;
|
2021-11-30 11:06:20 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-13 14:05:42 +00:00
|
|
|
const UnreadIndicator = ({ color }: IUnreadIndicatorProps) => {
|
|
|
|
|
if (color === NotificationColor.None) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const classes = classNames({
|
2022-04-05 17:15:31 +01:00
|
|
|
"mx_Indicator": true,
|
2021-12-13 14:05:42 +00:00
|
|
|
"mx_RightPanel_headerButton_unreadIndicator": true,
|
2022-02-08 18:37:03 +01:00
|
|
|
"mx_Indicator_bold": color === NotificationColor.Bold,
|
2021-12-13 14:05:42 +00:00
|
|
|
"mx_Indicator_gray": color === NotificationColor.Grey,
|
2022-02-08 20:03:15 +01:00
|
|
|
"mx_Indicator_red": color === NotificationColor.Red,
|
2021-12-13 14:05:42 +00:00
|
|
|
});
|
|
|
|
|
return <>
|
2021-11-30 11:06:20 +01:00
|
|
|
<div className="mx_RightPanel_headerButton_unreadIndicator_bg" />
|
2021-12-13 14:05:42 +00:00
|
|
|
<div className={classes} />
|
|
|
|
|
</>;
|
2021-11-30 11:06:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface IHeaderButtonProps {
|
|
|
|
|
room: Room;
|
|
|
|
|
isHighlighted: boolean;
|
|
|
|
|
onClick: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PinnedMessagesHeaderButton = ({ room, isHighlighted, onClick }: IHeaderButtonProps) => {
|
2021-05-25 16:10:44 +01:00
|
|
|
const pinningEnabled = useSettingValue("feature_pinning");
|
|
|
|
|
const pinnedEvents = usePinnedEvents(pinningEnabled && room);
|
|
|
|
|
const readPinnedEvents = useReadPinnedEvents(pinningEnabled && room);
|
2022-02-28 09:52:16 -05:00
|
|
|
if (!pinnedEvents?.length) return null;
|
2021-05-25 16:10:44 +01:00
|
|
|
|
|
|
|
|
let unreadIndicator;
|
|
|
|
|
if (pinnedEvents.some(id => !readPinnedEvents.has(id))) {
|
2021-12-13 14:05:42 +00:00
|
|
|
unreadIndicator = <UnreadIndicator />;
|
2021-05-25 16:10:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <HeaderButton
|
|
|
|
|
name="pinnedMessagesButton"
|
2021-05-26 13:51:17 +01:00
|
|
|
title={_t("Pinned messages")}
|
2021-05-25 16:10:44 +01:00
|
|
|
isHighlighted={isHighlighted}
|
2022-04-04 12:36:54 +01:00
|
|
|
isUnread={!!unreadIndicator}
|
2021-05-25 16:10:44 +01:00
|
|
|
onClick={onClick}
|
|
|
|
|
>
|
|
|
|
|
{ unreadIndicator }
|
|
|
|
|
</HeaderButton>;
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-30 11:06:20 +01:00
|
|
|
const TimelineCardHeaderButton = ({ room, isHighlighted, onClick }: IHeaderButtonProps) => {
|
|
|
|
|
let unreadIndicator;
|
2021-12-13 14:05:42 +00:00
|
|
|
const color = RoomNotificationStateStore.instance.getRoomState(room).color;
|
|
|
|
|
switch (color) {
|
2022-02-08 18:37:03 +01:00
|
|
|
case NotificationColor.Bold:
|
2021-11-30 11:06:20 +01:00
|
|
|
case NotificationColor.Grey:
|
|
|
|
|
case NotificationColor.Red:
|
2021-12-13 14:05:42 +00:00
|
|
|
unreadIndicator = <UnreadIndicator color={color} />;
|
2021-11-30 11:06:20 +01:00
|
|
|
}
|
2021-11-29 17:06:15 +01:00
|
|
|
return <HeaderButton
|
|
|
|
|
name="timelineCardButton"
|
|
|
|
|
title={_t("Chat")}
|
|
|
|
|
isHighlighted={isHighlighted}
|
|
|
|
|
onClick={onClick}
|
2021-11-30 11:06:20 +01:00
|
|
|
>
|
|
|
|
|
{ unreadIndicator }
|
|
|
|
|
</HeaderButton>;
|
2021-11-29 17:06:15 +01:00
|
|
|
};
|
|
|
|
|
|
2021-05-25 16:10:44 +01:00
|
|
|
interface IProps {
|
|
|
|
|
room?: Room;
|
2021-11-29 19:01:47 +01:00
|
|
|
excludedRightPanelPhaseButtons?: Array<RightPanelPhases>;
|
2021-05-25 16:10:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default class RoomHeaderButtons extends HeaderButtons<IProps> {
|
2021-11-11 11:00:18 +00:00
|
|
|
private static readonly THREAD_PHASES = [
|
|
|
|
|
RightPanelPhases.ThreadPanel,
|
|
|
|
|
RightPanelPhases.ThreadView,
|
|
|
|
|
];
|
2021-12-13 14:05:42 +00:00
|
|
|
private threadNotificationState: ThreadsRoomNotificationState;
|
2022-09-08 15:53:57 +01:00
|
|
|
private globalNotificationState: SummarizedNotificationState;
|
2021-11-11 11:00:18 +00:00
|
|
|
|
2021-05-25 16:10:44 +01:00
|
|
|
constructor(props: IProps) {
|
2020-07-18 16:38:20 +05:30
|
|
|
super(props, HeaderKind.Room);
|
2021-12-13 14:05:42 +00:00
|
|
|
|
|
|
|
|
this.threadNotificationState = RoomNotificationStateStore.instance.getThreadsRoomState(this.props.room);
|
2022-09-08 15:53:57 +01:00
|
|
|
this.globalNotificationState = RoomNotificationStateStore.instance.globalState;
|
2018-10-30 17:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-13 14:05:42 +00:00
|
|
|
public componentDidMount(): void {
|
|
|
|
|
super.componentDidMount();
|
|
|
|
|
this.threadNotificationState.on(NotificationStateEvents.Update, this.onThreadNotification);
|
2022-09-08 15:53:57 +01:00
|
|
|
RoomNotificationStateStore.instance.on(UPDATE_STATUS_INDICATOR, this.onUpdateStatus);
|
2021-12-13 14:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public componentWillUnmount(): void {
|
|
|
|
|
super.componentWillUnmount();
|
|
|
|
|
this.threadNotificationState.off(NotificationStateEvents.Update, this.onThreadNotification);
|
2022-09-08 15:53:57 +01:00
|
|
|
RoomNotificationStateStore.instance.off(UPDATE_STATUS_INDICATOR, this.onUpdateStatus);
|
2021-12-13 14:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private onThreadNotification = (): void => {
|
2022-09-08 15:53:57 +01:00
|
|
|
// XXX: why don't we read from this.state.threadNotificationColor in the render methods?
|
2021-12-13 14:05:42 +00:00
|
|
|
this.setState({
|
|
|
|
|
threadNotificationColor: this.threadNotificationState.color,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-08 15:53:57 +01:00
|
|
|
private onUpdateStatus = (notificationState: SummarizedNotificationState): void => {
|
|
|
|
|
// XXX: why don't we read from this.state.globalNotificationCount in the render methods?
|
|
|
|
|
this.globalNotificationState = notificationState;
|
|
|
|
|
this.setState({
|
|
|
|
|
globalNotificationColor: notificationState.color,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-30 16:13:13 +05:30
|
|
|
protected onAction(payload: ActionPayload) {
|
2020-05-13 21:03:12 -06:00
|
|
|
if (payload.action === Action.ViewUser) {
|
2018-10-30 17:15:19 +01:00
|
|
|
if (payload.member) {
|
2022-01-05 17:25:41 +01:00
|
|
|
if (payload.push) {
|
|
|
|
|
RightPanelStore.instance.pushCard(
|
|
|
|
|
{ phase: RightPanelPhases.RoomMemberInfo, state: { member: payload.member } },
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
RightPanelStore.instance.setCards([
|
|
|
|
|
{ phase: RightPanelPhases.RoomSummary },
|
|
|
|
|
{ phase: RightPanelPhases.RoomMemberList },
|
|
|
|
|
{ phase: RightPanelPhases.RoomMemberInfo, state: { member: payload.member } },
|
|
|
|
|
]);
|
|
|
|
|
}
|
2018-10-30 17:15:19 +01:00
|
|
|
} else {
|
2020-07-18 16:38:20 +05:30
|
|
|
this.setPhase(RightPanelPhases.RoomMemberList);
|
2018-10-30 17:15:19 +01:00
|
|
|
}
|
2019-03-28 20:38:15 -06:00
|
|
|
} else if (payload.action === "view_3pid_invite") {
|
|
|
|
|
if (payload.event) {
|
2022-01-05 16:14:44 +01:00
|
|
|
this.setPhase(RightPanelPhases.Room3pidMemberInfo, { memberInfoEvent: payload.event });
|
2019-03-28 20:38:15 -06:00
|
|
|
} else {
|
2020-07-18 16:38:20 +05:30
|
|
|
this.setPhase(RightPanelPhases.RoomMemberList);
|
2019-03-28 20:38:15 -06:00
|
|
|
}
|
2018-10-30 17:15:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-08 08:48:03 +01:00
|
|
|
private onRoomSummaryClicked = () => {
|
2020-09-08 16:27:09 +01:00
|
|
|
// use roomPanelPhase rather than this.state.phase as it remembers the latest one if we close
|
2022-01-05 16:14:44 +01:00
|
|
|
const currentPhase = RightPanelStore.instance.currentCard.phase;
|
|
|
|
|
if (ROOM_INFO_PHASES.includes(currentPhase)) {
|
|
|
|
|
if (this.state.phase === currentPhase) {
|
|
|
|
|
this.setPhase(currentPhase);
|
2020-09-08 16:27:09 +01:00
|
|
|
} else {
|
2022-01-05 16:14:44 +01:00
|
|
|
this.setPhase(currentPhase, RightPanelStore.instance.currentCard.state);
|
2020-09-08 16:27:09 +01:00
|
|
|
}
|
2020-09-08 15:39:58 +01:00
|
|
|
} else {
|
|
|
|
|
// This toggles for us, if needed
|
|
|
|
|
this.setPhase(RightPanelPhases.RoomSummary);
|
|
|
|
|
}
|
2020-09-04 12:14:43 +01:00
|
|
|
};
|
2019-04-11 13:22:47 +02:00
|
|
|
|
2020-09-04 12:14:43 +01:00
|
|
|
private onNotificationsClicked = () => {
|
2019-12-05 23:28:06 -07:00
|
|
|
// This toggles for us, if needed
|
2020-07-18 16:38:20 +05:30
|
|
|
this.setPhase(RightPanelPhases.NotificationPanel);
|
2020-09-04 12:14:43 +01:00
|
|
|
};
|
2019-04-11 13:22:47 +02:00
|
|
|
|
2021-05-25 16:10:44 +01:00
|
|
|
private onPinnedMessagesClicked = () => {
|
|
|
|
|
// This toggles for us, if needed
|
|
|
|
|
this.setPhase(RightPanelPhases.PinnedMessages);
|
|
|
|
|
};
|
2021-11-29 17:06:15 +01:00
|
|
|
private onTimelineCardClicked = () => {
|
|
|
|
|
this.setPhase(RightPanelPhases.Timeline);
|
|
|
|
|
};
|
2021-05-25 16:10:44 +01:00
|
|
|
|
2022-02-28 14:11:14 +00:00
|
|
|
private onThreadsPanelClicked = (ev: ButtonEvent) => {
|
2021-11-11 11:00:18 +00:00
|
|
|
if (RoomHeaderButtons.THREAD_PHASES.includes(this.state.phase)) {
|
2022-06-17 16:57:40 -04:00
|
|
|
RightPanelStore.instance.togglePanel(this.props.room?.roomId);
|
2021-11-11 11:00:18 +00:00
|
|
|
} else {
|
2022-01-05 17:25:41 +01:00
|
|
|
showThreadPanel();
|
2022-02-28 14:11:14 +00:00
|
|
|
PosthogTrackers.trackInteraction("WebRoomHeaderButtonsThreadsButton", ev);
|
2021-11-11 11:00:18 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-30 15:58:07 +05:30
|
|
|
public renderButtons() {
|
2021-11-29 19:01:47 +01:00
|
|
|
const rightPanelPhaseButtons: Map<RightPanelPhases, any> = new Map();
|
|
|
|
|
|
|
|
|
|
rightPanelPhaseButtons.set(RightPanelPhases.PinnedMessages,
|
2021-05-25 16:10:44 +01:00
|
|
|
<PinnedMessagesHeaderButton
|
2021-12-13 14:05:42 +00:00
|
|
|
key="pinnedMessagesButton"
|
2021-05-25 16:10:44 +01:00
|
|
|
room={this.props.room}
|
|
|
|
|
isHighlighted={this.isPhase(RightPanelPhases.PinnedMessages)}
|
2021-11-29 19:01:47 +01:00
|
|
|
onClick={this.onPinnedMessagesClicked} />,
|
|
|
|
|
);
|
|
|
|
|
rightPanelPhaseButtons.set(RightPanelPhases.Timeline,
|
2021-11-29 17:06:15 +01:00
|
|
|
<TimelineCardHeaderButton
|
2021-12-13 14:05:42 +00:00
|
|
|
key="timelineButton"
|
2021-11-29 17:06:15 +01:00
|
|
|
room={this.props.room}
|
|
|
|
|
isHighlighted={this.isPhase(RightPanelPhases.Timeline)}
|
2021-11-29 19:01:47 +01:00
|
|
|
onClick={this.onTimelineCardClicked} />,
|
|
|
|
|
);
|
|
|
|
|
rightPanelPhaseButtons.set(RightPanelPhases.ThreadPanel,
|
|
|
|
|
SettingsStore.getValue("feature_thread")
|
|
|
|
|
? <HeaderButton
|
2022-01-05 16:14:44 +01:00
|
|
|
key={RightPanelPhases.ThreadPanel}
|
2021-11-29 19:01:47 +01:00
|
|
|
name="threadsButton"
|
|
|
|
|
title={_t("Threads")}
|
|
|
|
|
onClick={this.onThreadsPanelClicked}
|
|
|
|
|
isHighlighted={this.isPhase(RoomHeaderButtons.THREAD_PHASES)}
|
2022-04-04 12:36:54 +01:00
|
|
|
isUnread={this.threadNotificationState.color > 0}
|
2022-06-14 17:51:51 +01:00
|
|
|
>
|
2021-12-13 14:05:42 +00:00
|
|
|
<UnreadIndicator color={this.threadNotificationState.color} />
|
|
|
|
|
</HeaderButton>
|
2021-11-29 19:01:47 +01:00
|
|
|
: null,
|
|
|
|
|
);
|
|
|
|
|
rightPanelPhaseButtons.set(RightPanelPhases.NotificationPanel,
|
2020-09-08 08:48:03 +01:00
|
|
|
<HeaderButton
|
2021-12-13 14:05:42 +00:00
|
|
|
key="notifsButton"
|
2020-09-08 08:48:03 +01:00
|
|
|
name="notifsButton"
|
2019-02-12 17:31:47 +00:00
|
|
|
title={_t('Notifications')}
|
2020-07-18 16:38:20 +05:30
|
|
|
isHighlighted={this.isPhase(RightPanelPhases.NotificationPanel)}
|
2020-07-29 23:58:32 +05:30
|
|
|
onClick={this.onNotificationsClicked}
|
2022-09-08 15:53:57 +01:00
|
|
|
isUnread={this.globalNotificationState.color === NotificationColor.Red}
|
|
|
|
|
>
|
|
|
|
|
{ this.globalNotificationState.color === NotificationColor.Red ?
|
|
|
|
|
<UnreadIndicator color={this.globalNotificationState.color} /> :
|
|
|
|
|
null }
|
|
|
|
|
</HeaderButton>,
|
2021-11-29 19:01:47 +01:00
|
|
|
);
|
|
|
|
|
rightPanelPhaseButtons.set(RightPanelPhases.RoomSummary,
|
2020-09-09 11:06:15 +01:00
|
|
|
<HeaderButton
|
2021-12-13 14:05:42 +00:00
|
|
|
key="roomSummaryButton"
|
2020-09-09 11:06:15 +01:00
|
|
|
name="roomSummaryButton"
|
2022-10-06 22:27:28 -04:00
|
|
|
title={_t('Room info')}
|
2020-09-09 11:06:15 +01:00
|
|
|
isHighlighted={this.isPhase(ROOM_INFO_PHASES)}
|
|
|
|
|
onClick={this.onRoomSummaryClicked}
|
2022-06-14 17:51:51 +01:00
|
|
|
/>,
|
2021-11-29 19:01:47 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return <>
|
|
|
|
|
{
|
|
|
|
|
Array.from(rightPanelPhaseButtons.keys()).map((phase) =>
|
2022-09-08 15:53:57 +01:00
|
|
|
(this.props.excludedRightPanelPhaseButtons?.includes(phase)
|
2021-11-29 19:01:47 +01:00
|
|
|
? null
|
|
|
|
|
: rightPanelPhaseButtons.get(phase)))
|
|
|
|
|
}
|
2021-05-25 13:17:14 +01:00
|
|
|
</>;
|
2018-10-30 17:15:19 +01:00
|
|
|
}
|
|
|
|
|
}
|