element-web/src/components/views/settings/tabs/room/BridgeSettingsTab.js

102 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-12-02 20:27:12 +03:00
/*
2020-01-03 16:57:59 +03:00
Copyright 2019 The Matrix.org Foundation C.I.C.
2019-12-02 20:27:12 +03: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.
*/
import React from 'react';
import PropTypes from 'prop-types';
import {_t} from "../../../../../languageHandler";
2020-01-10 00:16:32 +03:00
import {MatrixClientPeg} from "../../../../../MatrixClientPeg";
2020-01-27 17:05:22 +03:00
import BridgeTile from "../../BridgeTile";
2019-12-02 20:27:12 +03:00
const BRIDGE_EVENT_TYPES = [
"uk.half-shot.bridge",
// m.bridge
];
export default class BridgeSettingsTab extends React.Component {
static propTypes = {
roomId: PropTypes.string.isRequired,
};
constructor() {
super();
}
2019-12-02 20:27:12 +03:00
_renderBridgeCard(event, room) {
const content = event.getContent();
if (!content || !content.channel || !content.protocol) {
return null;
}
2020-01-27 17:05:22 +03:00
return <BridgeTile room={room} ev={event}></BridgeTile>
2019-12-02 20:27:12 +03:00
}
static getBridgeStateEvents(roomId) {
const client = MatrixClientPeg.get();
const roomState = (client.getRoom(roomId)).currentState;
2020-01-17 13:04:38 +03:00
const bridgeEvents = [].concat(...BRIDGE_EVENT_TYPES.map((typeName) =>
2019-12-02 20:27:12 +03:00
Object.values(roomState.events[typeName] || {}),
));
return bridgeEvents;
}
render() {
// This settings tab will only be invoked if the following function returns more
// than 0 events, so no validation is needed at this stage.
const bridgeEvents = BridgeSettingsTab.getBridgeStateEvents(this.props.roomId);
const client = MatrixClientPeg.get();
const room = client.getRoom(this.props.roomId);
let content = null;
if (bridgeEvents.length > 0) {
content = <div>
<p>{_t(
"This room is bridging messages to the following platforms. " +
"<a>Learn more.</a>", {},
{
// TODO: We don't have this link yet: this will prevent the translators
// having to re-translate the string when we do.
a: sub => '',
},
)}</p>
<ul className="mx_RoomSettingsDialog_BridgeList">
{ bridgeEvents.map((event) => this._renderBridgeCard(event, room)) }
</ul>
</div>
} else {
content = <p>{_t(
"This room isnt bridging messages to any platforms. " +
"<a>Learn more.</a>", {},
{
// TODO: We don't have this link yet: this will prevent the translators
// having to re-translate the string when we do.
a: sub => '',
},
)}</p>
}
2019-12-02 20:27:12 +03:00
return (
<div className="mx_SettingsTab">
<div className="mx_SettingsTab_heading">{_t("Bridges")}</div>
2019-12-02 20:27:12 +03:00
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
{content}
2019-12-02 20:27:12 +03:00
</div>
</div>
);
}
}