This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 832
Bridge info settings tab #3693
Merged
Merged
Bridge info settings tab #3693
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0d537ec
Add bridge info tab
Half-Shot 7c35b16
Add bridge tab button
Half-Shot 626ab17
Styling
Half-Shot 2bc6e2e
Add the one string I bothered to i18n
Half-Shot 9f2ccdf
Add support for displaying avatars and links in bridge info
Half-Shot ce21ce8
Lint
Half-Shot d994375
Remove `status` as it's no longer part of the MSC
Half-Shot 7ee5f7b
Add feature flag
Half-Shot 6225e40
i18n'ed all over the plaace
Half-Shot b1c2887
line length
Half-Shot 0a8cc41
Merge branch 'develop' into hs/bridge-info
Half-Shot fb94be4
No trailing space
Half-Shot fa9fd97
missing }
Half-Shot 668479d
Tweak as per git review
Half-Shot 831053d
Make bridge info cards more obvious
Half-Shot 50e19ba
User may not be a bot, therefore do not imply it.
Half-Shot 2ccc8ca
Fix indent
Half-Shot 7f0ed05
Update BridgeSettingsTab.js
Half-Shot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
src/components/views/settings/tabs/room/BridgeSettingsTab.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/* | ||
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 {_t} from "../../../../../languageHandler"; | ||
import MatrixClientPeg from "../../../../../MatrixClientPeg"; | ||
import Pill from "../../../elements/Pill"; | ||
import {makeUserPermalink} from "../../../../../utils/permalinks/Permalinks"; | ||
import BaseAvatar from "../../../avatars/BaseAvatar"; | ||
import { ContentRepo } from "matrix-js-sdk"; | ||
|
||
const BRIDGE_EVENT_TYPES = [ | ||
"uk.half-shot.bridge", | ||
// m.bridge | ||
]; | ||
|
||
export default class BridgeSettingsTab extends React.Component { | ||
static propTypes = { | ||
roomId: PropTypes.string.isRequired, | ||
}; | ||
|
||
_renderBridgeCard(event, room) { | ||
const content = event.getContent(); | ||
if (!content || !content.channel || !content.protocol) { | ||
return null; | ||
} | ||
const { channel, network } = content; | ||
const protocolName = content.protocol.displayname || content.protocol.id; | ||
const channelName = channel.displayname || channel.id; | ||
const networkName = network ? network.displayname || network.id : protocolName; | ||
|
||
let creator = null; | ||
if (content.creator) { | ||
creator = <p> { _t("This bridge was provisioned by <user />", {}, { | ||
user: <Pill | ||
type={Pill.TYPE_USER_MENTION} | ||
room={room} | ||
url={makeUserPermalink(content.creator)} | ||
shouldShowPillAvatar={true} | ||
/>, | ||
})}</p>; | ||
} | ||
|
||
const bot = (<p> {_t("This bridge is managed by <user />.", {}, { | ||
user: <Pill | ||
type={Pill.TYPE_USER_MENTION} | ||
room={room} | ||
url={makeUserPermalink(event.getSender())} | ||
shouldShowPillAvatar={true} | ||
/>, | ||
})} </p>); | ||
let channelLink = channelName; | ||
if (channel.external_url) { | ||
channelLink = <a target="_blank" href={channel.external_url} rel="noopener">{channelName}</a>; | ||
} | ||
|
||
let networkLink = networkName; | ||
if (network && network.external_url) { | ||
networkLink = <a target="_blank" href={network.external_url} rel="noopener">{networkName}</a>; | ||
} | ||
|
||
const chanAndNetworkInfo = ( | ||
_t("Bridged into <channelLink /> <networkLink />, on <protocolName />", {}, { | ||
channelLink, | ||
networkLink, | ||
protocolName, | ||
}) | ||
); | ||
|
||
let networkIcon = null; | ||
if (networkName && network.avatar) { | ||
const avatarUrl = ContentRepo.getHttpUriForMxc( | ||
MatrixClientPeg.get().getHomeserverUrl(), | ||
network.avatar, 32, 32, "crop", | ||
); | ||
networkIcon = <BaseAvatar | ||
width={32} | ||
height={32} | ||
resizeMethod='crop' | ||
name={ networkName } | ||
idName={ networkName } | ||
url={ avatarUrl } | ||
/>; | ||
} | ||
|
||
let channelIcon = null; | ||
if (channel.avatar) { | ||
const avatarUrl = ContentRepo.getHttpUriForMxc( | ||
MatrixClientPeg.get().getHomeserverUrl(), | ||
channel.avatar, 32, 32, "crop", | ||
); | ||
channelIcon = <BaseAvatar | ||
width={32} | ||
height={32} | ||
resizeMethod='crop' | ||
name={ networkName } | ||
idName={ networkName } | ||
url={ avatarUrl } | ||
/>; | ||
} | ||
|
||
const heading = _t("Connected to <channelIcon /> <channelName /> on <networkIcon /> <networkName />", { }, { | ||
channelIcon, | ||
channelName, | ||
networkName, | ||
networkIcon, | ||
}); | ||
|
||
return (<li key={event.stateKey}> | ||
<div> | ||
<h3>{heading}</h3> | ||
<p>{_t("Connected via %(protocolName)s", { protocolName })}</p> | ||
<details> | ||
{creator} | ||
{bot} | ||
<p>{chanAndNetworkInfo}</p> | ||
</details> | ||
</div> | ||
</li>); | ||
} | ||
|
||
static getBridgeStateEvents(roomId) { | ||
const client = MatrixClientPeg.get(); | ||
const roomState = (client.getRoom(roomId)).currentState; | ||
|
||
const bridgeEvents = Array.concat(...BRIDGE_EVENT_TYPES.map((typeName) => | ||
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); | ||
|
||
return ( | ||
<div className="mx_SettingsTab"> | ||
<div className="mx_SettingsTab_heading">{_t("Bridge Info")}</div> | ||
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'> | ||
<p>{ _t("Below is a list of bridges connected to this room.") }</p> | ||
<ul className="mx_RoomSettingsDialog_BridgeList"> | ||
{ bridgeEvents.map((event) => this._renderBridgeCard(event, room)) } | ||
</ul> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should just be "Bridges", or "Connected Bridges", or "Integrations"