add header
This commit is contained in:
parent
c1f397dcf7
commit
fd74a946e0
3 changed files with 10 additions and 151 deletions
|
@ -137,7 +137,11 @@ const PinnedMessagesCard = ({ room, onClose }: IProps) => {
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <BaseCard className="mx_NotificationPanel" onClose={onClose} withoutScrollContainer>
|
return <BaseCard
|
||||||
|
header={<h2>{ _t("Pinned") }</h2>}
|
||||||
|
className="mx_NotificationPanel"
|
||||||
|
onClose={onClose}
|
||||||
|
>
|
||||||
{ content }
|
{ content }
|
||||||
</BaseCard>;
|
</BaseCard>;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,145 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright 2017 Travis Ralston
|
|
||||||
Copyright 2019 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 from "react";
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
|
||||||
import AccessibleButton from "../elements/AccessibleButton";
|
|
||||||
import PinnedEventTile from "./PinnedEventTile";
|
|
||||||
import { _t } from '../../../languageHandler';
|
|
||||||
import PinningUtils from "../../../utils/PinningUtils";
|
|
||||||
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
|
||||||
|
|
||||||
@replaceableComponent("views.rooms.PinnedEventsPanel")
|
|
||||||
export default class PinnedEventsPanel extends React.Component {
|
|
||||||
static propTypes = {
|
|
||||||
// The Room from the js-sdk we're going to show pinned events for
|
|
||||||
room: PropTypes.object.isRequired,
|
|
||||||
|
|
||||||
onCancelClick: PropTypes.func,
|
|
||||||
};
|
|
||||||
|
|
||||||
state = {
|
|
||||||
loading: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this._updatePinnedMessages();
|
|
||||||
MatrixClientPeg.get().on("RoomState.events", this._onStateEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
if (MatrixClientPeg.get()) {
|
|
||||||
MatrixClientPeg.get().removeListener("RoomState.events", this._onStateEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_onStateEvent = ev => {
|
|
||||||
if (ev.getRoomId() === this.props.room.roomId && ev.getType() === "m.room.pinned_events") {
|
|
||||||
this._updatePinnedMessages();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
_updatePinnedMessages = () => {
|
|
||||||
const pinnedEvents = this.props.room.currentState.getStateEvents("m.room.pinned_events", "");
|
|
||||||
if (!pinnedEvents || !pinnedEvents.getContent().pinned) {
|
|
||||||
this.setState({ loading: false, pinned: [] });
|
|
||||||
} else {
|
|
||||||
const promises = [];
|
|
||||||
const cli = MatrixClientPeg.get();
|
|
||||||
|
|
||||||
pinnedEvents.getContent().pinned.map((eventId) => {
|
|
||||||
promises.push(cli.getEventTimeline(this.props.room.getUnfilteredTimelineSet(), eventId, 0).then(
|
|
||||||
(timeline) => {
|
|
||||||
const event = timeline.getEvents().find((e) => e.getId() === eventId);
|
|
||||||
return {eventId, timeline, event};
|
|
||||||
}).catch((err) => {
|
|
||||||
console.error("Error looking up pinned event " + eventId + " in room " + this.props.room.roomId);
|
|
||||||
console.error(err);
|
|
||||||
return null; // return lack of context to avoid unhandled errors
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
Promise.all(promises).then((contexts) => {
|
|
||||||
// Filter out the messages before we try to render them
|
|
||||||
const pinned = contexts.filter((context) => PinningUtils.isPinnable(context.event));
|
|
||||||
|
|
||||||
this.setState({ loading: false, pinned });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this._updateReadState();
|
|
||||||
};
|
|
||||||
|
|
||||||
_updateReadState() {
|
|
||||||
const pinnedEvents = this.props.room.currentState.getStateEvents("m.room.pinned_events", "");
|
|
||||||
if (!pinnedEvents) return; // nothing to read
|
|
||||||
|
|
||||||
let readStateEvents = [];
|
|
||||||
const readPinsEvent = this.props.room.getAccountData("im.vector.room.read_pins");
|
|
||||||
if (readPinsEvent && readPinsEvent.getContent()) {
|
|
||||||
readStateEvents = readPinsEvent.getContent().event_ids || [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!readStateEvents.includes(pinnedEvents.getId())) {
|
|
||||||
readStateEvents.push(pinnedEvents.getId());
|
|
||||||
|
|
||||||
// Only keep the last 10 event IDs to avoid infinite growth
|
|
||||||
readStateEvents = readStateEvents.reverse().splice(0, 10).reverse();
|
|
||||||
|
|
||||||
MatrixClientPeg.get().setRoomAccountData(this.props.room.roomId, "im.vector.room.read_pins", {
|
|
||||||
event_ids: readStateEvents,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_getPinnedTiles() {
|
|
||||||
if (this.state.pinned.length === 0) {
|
|
||||||
return (<div>{ _t("No pinned messages.") }</div>);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.state.pinned.map((context) => {
|
|
||||||
return (
|
|
||||||
<PinnedEventTile
|
|
||||||
key={context.event.getId()}
|
|
||||||
mxRoom={this.props.room}
|
|
||||||
mxEvent={context.event}
|
|
||||||
onUnpinned={this._updatePinnedMessages}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
let tiles = <div>{ _t("Loading...") }</div>;
|
|
||||||
if (this.state && !this.state.loading) {
|
|
||||||
tiles = this._getPinnedTiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="mx_PinnedEventsPanel">
|
|
||||||
<div className="mx_PinnedEventsPanel_body">
|
|
||||||
<AccessibleButton className="mx_PinnedEventsPanel_cancel" onClick={this.props.onCancelClick}>
|
|
||||||
<img className="mx_filterFlipColor" src={require("../../../../res/img/cancel.svg")} width="18" height="18" />
|
|
||||||
</AccessibleButton>
|
|
||||||
<h3 className="mx_PinnedEventsPanel_header">{ _t("Pinned Messages") }</h3>
|
|
||||||
{ tiles }
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1508,9 +1508,6 @@
|
||||||
"Invite to just this room": "Invite to just this room",
|
"Invite to just this room": "Invite to just this room",
|
||||||
"Add a photo, so people can easily spot your room.": "Add a photo, so people can easily spot your room.",
|
"Add a photo, so people can easily spot your room.": "Add a photo, so people can easily spot your room.",
|
||||||
"This is the start of <roomName/>.": "This is the start of <roomName/>.",
|
"This is the start of <roomName/>.": "This is the start of <roomName/>.",
|
||||||
"No pinned messages.": "No pinned messages.",
|
|
||||||
"Loading...": "Loading...",
|
|
||||||
"Pinned Messages": "Pinned Messages",
|
|
||||||
"Unpin Message": "Unpin Message",
|
"Unpin Message": "Unpin Message",
|
||||||
"Jump to message": "Jump to message",
|
"Jump to message": "Jump to message",
|
||||||
"%(duration)ss": "%(duration)ss",
|
"%(duration)ss": "%(duration)ss",
|
||||||
|
@ -1718,6 +1715,10 @@
|
||||||
"The homeserver the user you’re verifying is connected to": "The homeserver the user you’re verifying is connected to",
|
"The homeserver the user you’re verifying is connected to": "The homeserver the user you’re verifying is connected to",
|
||||||
"Yours, or the other users’ internet connection": "Yours, or the other users’ internet connection",
|
"Yours, or the other users’ internet connection": "Yours, or the other users’ internet connection",
|
||||||
"Yours, or the other users’ session": "Yours, or the other users’ session",
|
"Yours, or the other users’ session": "Yours, or the other users’ session",
|
||||||
|
"You’re all caught up": "You’re all caught up",
|
||||||
|
"You have no visible notifications.": "You have no visible notifications.",
|
||||||
|
"Pinned": "Pinned",
|
||||||
|
"Pinned Messages": "Pinned Messages",
|
||||||
"Room Info": "Room Info",
|
"Room Info": "Room Info",
|
||||||
"You can only pin up to %(count)s widgets|other": "You can only pin up to %(count)s widgets",
|
"You can only pin up to %(count)s widgets|other": "You can only pin up to %(count)s widgets",
|
||||||
"Unpin": "Unpin",
|
"Unpin": "Unpin",
|
||||||
|
@ -1896,6 +1897,7 @@
|
||||||
"Add rooms to this community": "Add rooms to this community",
|
"Add rooms to this community": "Add rooms to this community",
|
||||||
"Filter community rooms": "Filter community rooms",
|
"Filter community rooms": "Filter community rooms",
|
||||||
"Something went wrong when trying to get your communities.": "Something went wrong when trying to get your communities.",
|
"Something went wrong when trying to get your communities.": "Something went wrong when trying to get your communities.",
|
||||||
|
"Loading...": "Loading...",
|
||||||
"Display your community flair in rooms configured to show it.": "Display your community flair in rooms configured to show it.",
|
"Display your community flair in rooms configured to show it.": "Display your community flair in rooms configured to show it.",
|
||||||
"You're not currently a member of any communities.": "You're not currently a member of any communities.",
|
"You're not currently a member of any communities.": "You're not currently a member of any communities.",
|
||||||
"Frequently Used": "Frequently Used",
|
"Frequently Used": "Frequently Used",
|
||||||
|
@ -2626,8 +2628,6 @@
|
||||||
"Create a new community": "Create a new community",
|
"Create a new community": "Create a new community",
|
||||||
"Create a community to group together users and rooms! Build a custom homepage to mark out your space in the Matrix universe.": "Create a community to group together users and rooms! Build a custom homepage to mark out your space in the Matrix universe.",
|
"Create a community to group together users and rooms! Build a custom homepage to mark out your space in the Matrix universe.": "Create a community to group together users and rooms! Build a custom homepage to mark out your space in the Matrix universe.",
|
||||||
"Communities are changing to Spaces": "Communities are changing to Spaces",
|
"Communities are changing to Spaces": "Communities are changing to Spaces",
|
||||||
"You’re all caught up": "You’re all caught up",
|
|
||||||
"You have no visible notifications.": "You have no visible notifications.",
|
|
||||||
"%(brand)s failed to get the protocol list from the homeserver. The homeserver may be too old to support third party networks.": "%(brand)s failed to get the protocol list from the homeserver. The homeserver may be too old to support third party networks.",
|
"%(brand)s failed to get the protocol list from the homeserver. The homeserver may be too old to support third party networks.": "%(brand)s failed to get the protocol list from the homeserver. The homeserver may be too old to support third party networks.",
|
||||||
"%(brand)s failed to get the public room list.": "%(brand)s failed to get the public room list.",
|
"%(brand)s failed to get the public room list.": "%(brand)s failed to get the public room list.",
|
||||||
"The homeserver may be unavailable or overloaded.": "The homeserver may be unavailable or overloaded.",
|
"The homeserver may be unavailable or overloaded.": "The homeserver may be unavailable or overloaded.",
|
||||||
|
|
Loading…
Reference in a new issue