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";
|
|
|
|
|
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';
|
|
|
|
|
import { RightPanelPhases } from "../../../stores/RightPanelStorePhases";
|
|
|
|
|
import { Action } from "../../../dispatcher/actions";
|
|
|
|
|
import { ActionPayload } from "../../../dispatcher/payloads";
|
2020-09-08 16:27:09 +01:00
|
|
|
import RightPanelStore from "../../../stores/RightPanelStore";
|
2021-06-03 08:41:22 +01:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
|
|
|
|
import { useSettingValue } from "../../../hooks/useSettings";
|
2021-05-25 16:10:44 +01:00
|
|
|
import { useReadPinnedEvents, usePinnedEvents } from './PinnedMessagesCard';
|
2021-10-14 15:27:35 +02:00
|
|
|
import { dispatchShowThreadsPanelEvent } from "../../../dispatcher/dispatch-actions/threads";
|
|
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
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-05-25 16:10:44 +01:00
|
|
|
const PinnedMessagesHeaderButton = ({ room, isHighlighted, onClick }) => {
|
|
|
|
|
const pinningEnabled = useSettingValue("feature_pinning");
|
|
|
|
|
const pinnedEvents = usePinnedEvents(pinningEnabled && room);
|
|
|
|
|
const readPinnedEvents = useReadPinnedEvents(pinningEnabled && room);
|
|
|
|
|
if (!pinningEnabled) return null;
|
|
|
|
|
|
|
|
|
|
let unreadIndicator;
|
|
|
|
|
if (pinnedEvents.some(id => !readPinnedEvents.has(id))) {
|
|
|
|
|
unreadIndicator = <div className="mx_RightPanel_pinnedMessagesButton_unreadIndicator" />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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}
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
analytics={["Right Panel", "Pinned Messages Button", "click"]}
|
|
|
|
|
>
|
|
|
|
|
{ unreadIndicator }
|
|
|
|
|
</HeaderButton>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
|
room?: Room;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 20:12:00 -07:00
|
|
|
@replaceableComponent("views.right_panel.RoomHeaderButtons")
|
2021-05-25 16:10:44 +01:00
|
|
|
export default class RoomHeaderButtons extends HeaderButtons<IProps> {
|
|
|
|
|
constructor(props: IProps) {
|
2020-07-18 16:38:20 +05:30
|
|
|
super(props, HeaderKind.Room);
|
2018-10-30 17:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
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) {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setPhase(RightPanelPhases.RoomMemberInfo, { 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) {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setPhase(RightPanelPhases.Room3pidMemberInfo, { event: 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
|
|
|
|
|
const lastPhase = RightPanelStore.getSharedInstance().roomPanelPhase;
|
|
|
|
|
if (ROOM_INFO_PHASES.includes(lastPhase)) {
|
|
|
|
|
if (this.state.phase === lastPhase) {
|
|
|
|
|
this.setPhase(lastPhase);
|
|
|
|
|
} else {
|
|
|
|
|
this.setPhase(lastPhase, RightPanelStore.getSharedInstance().roomPanelPhaseParams);
|
|
|
|
|
}
|
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);
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-30 15:58:07 +05:30
|
|
|
public renderButtons() {
|
2021-05-25 13:17:14 +01:00
|
|
|
return <>
|
2021-05-25 16:10:44 +01:00
|
|
|
<PinnedMessagesHeaderButton
|
|
|
|
|
room={this.props.room}
|
|
|
|
|
isHighlighted={this.isPhase(RightPanelPhases.PinnedMessages)}
|
|
|
|
|
onClick={this.onPinnedMessagesClicked}
|
|
|
|
|
/>
|
2021-10-14 15:27:35 +02:00
|
|
|
{ SettingsStore.getValue("feature_thread") && <HeaderButton
|
|
|
|
|
name="threadsButton"
|
|
|
|
|
title={_t("Threads")}
|
|
|
|
|
onClick={dispatchShowThreadsPanelEvent}
|
2021-11-02 13:18:51 +00:00
|
|
|
isHighlighted={this.isPhase([
|
|
|
|
|
RightPanelPhases.ThreadPanel,
|
|
|
|
|
RightPanelPhases.ThreadView,
|
|
|
|
|
])}
|
2021-10-14 15:27:35 +02:00
|
|
|
analytics={['Right Panel', 'Threads List Button', 'click']}
|
|
|
|
|
/> }
|
2020-09-08 08:48:03 +01:00
|
|
|
<HeaderButton
|
|
|
|
|
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}
|
2018-10-30 17:15:19 +01:00
|
|
|
analytics={['Right Panel', 'Notification List Button', 'click']}
|
2021-05-25 13:17:14 +01:00
|
|
|
/>
|
2020-09-09 11:06:15 +01:00
|
|
|
<HeaderButton
|
|
|
|
|
name="roomSummaryButton"
|
|
|
|
|
title={_t('Room Info')}
|
|
|
|
|
isHighlighted={this.isPhase(ROOM_INFO_PHASES)}
|
|
|
|
|
onClick={this.onRoomSummaryClicked}
|
|
|
|
|
analytics={['Right Panel', 'Room Summary Button', 'click']}
|
2021-05-25 13:17:14 +01:00
|
|
|
/>
|
|
|
|
|
</>;
|
2018-10-30 17:15:19 +01:00
|
|
|
}
|
|
|
|
|
}
|