This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 805
Introduce room knocks bar #11475
Merged
weeman1337
merged 2 commits into
matrix-org:develop
from
nordeck:charlynguyen/introduce-room-knocks-bar
Aug 31, 2023
Merged
Introduce room knocks bar #11475
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,50 @@ | ||
| /* | ||
| Copyright 2023 Nordeck IT + Consulting GmbH | ||
|
|
||
| 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. | ||
| */ | ||
|
|
||
| .mx_RoomKnocksBar { | ||
| background-color: var(--cpd-color-bg-subtle-secondary); | ||
| display: flex; | ||
| padding: var(--cpd-space-2x) var(--cpd-space-4x); | ||
| } | ||
|
|
||
| .mx_RoomKnocksBar_content { | ||
| flex-grow: 1; | ||
| margin: 0 var(--cpd-space-3x); | ||
| } | ||
|
|
||
| .mx_RoomKnocksBar_paragraph { | ||
| color: $secondary-content; | ||
| font-size: var(--cpd-font-size-body-sm); | ||
| margin: 0; | ||
| } | ||
|
|
||
| .mx_RoomKnocksBar_link { | ||
| margin-left: var(--cpd-space-3x); | ||
| } | ||
|
|
||
| .mx_RoomKnocksBar_action, | ||
| .mx_RoomKnocksBar_avatar { | ||
| align-self: center; | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .mx_RoomKnocksBar_action + .mx_RoomKnocksBar_action { | ||
| margin-left: var(--cpd-space-3x); | ||
| } | ||
|
|
||
| .mx_RoomKnocksBar_avatar + .mx_RoomKnocksBar_avatar { | ||
| margin-left: calc(var(--cpd-space-4x) * -1); | ||
| } |
This file contains hidden or 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 hidden or 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,159 @@ | ||
| /* | ||
| Copyright 2023 Nordeck IT + Consulting GmbH | ||
|
|
||
| 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 { EventTimeline, JoinRule, MatrixError, Room, RoomStateEvent } from "matrix-js-sdk/src/matrix"; | ||
| import React, { ReactElement, ReactNode, useCallback, useState, VFC } from "react"; | ||
|
|
||
| import { Icon as CheckIcon } from "../../../../res/img/feather-customised/check.svg"; | ||
| import { Icon as XIcon } from "../../../../res/img/feather-customised/x.svg"; | ||
| import dis from "../../../dispatcher/dispatcher"; | ||
| import { useTypedEventEmitterState } from "../../../hooks/useEventEmitter"; | ||
| import { _t } from "../../../languageHandler"; | ||
| import Modal from "../../../Modal"; | ||
| import MemberAvatar from "../avatars/MemberAvatar"; | ||
| import ErrorDialog from "../dialogs/ErrorDialog"; | ||
| import { RoomSettingsTab } from "../dialogs/RoomSettingsDialog"; | ||
| import AccessibleButton from "../elements/AccessibleButton"; | ||
| import Heading from "../typography/Heading"; | ||
|
|
||
| export const RoomKnocksBar: VFC<{ room: Room }> = ({ room }) => { | ||
| const [disabled, setDisabled] = useState(false); | ||
| const knockMembers = useTypedEventEmitterState( | ||
| room, | ||
| RoomStateEvent.Members, | ||
| useCallback(() => room.getMembersWithMembership("knock"), [room]), | ||
| ); | ||
| const knockMembersCount = knockMembers.length; | ||
|
|
||
| if (room.getJoinRule() !== JoinRule.Knock || knockMembersCount === 0) return null; | ||
|
|
||
| const client = room.client; | ||
| const userId = client.getUserId() || ""; | ||
| const canInvite = room.canInvite(userId); | ||
| const member = room.getMember(userId); | ||
| const state = room.getLiveTimeline().getState(EventTimeline.FORWARDS); | ||
| const canKick = member && state ? state.hasSufficientPowerLevelFor("kick", member.powerLevel) : false; | ||
|
|
||
| if (!canInvite && !canKick) return null; | ||
|
|
||
| const onError = (error: MatrixError): void => { | ||
| Modal.createDialog(ErrorDialog, { title: error.name, description: error.message }); | ||
| }; | ||
|
|
||
| const handleApprove = (userId: string): void => { | ||
| setDisabled(true); | ||
| client | ||
| .invite(room.roomId, userId) | ||
| .catch(onError) | ||
| .finally(() => setDisabled(false)); | ||
| }; | ||
|
|
||
| const handleDeny = (userId: string): void => { | ||
| setDisabled(true); | ||
| client | ||
| .kick(room.roomId, userId) | ||
| .catch(onError) | ||
| .finally(() => setDisabled(false)); | ||
| }; | ||
|
|
||
| const handleOpenRoomSettings = (): void => | ||
| dis.dispatch({ action: "open_room_settings", room_id: room.roomId, initial_tab_id: RoomSettingsTab.People }); | ||
|
|
||
| let buttons: ReactElement = ( | ||
| <AccessibleButton | ||
| className="mx_RoomKnocksBar_action" | ||
| kind="primary" | ||
| onClick={handleOpenRoomSettings} | ||
| title={_t("action|view")} | ||
| > | ||
| {_t("action|view")} | ||
| </AccessibleButton> | ||
| ); | ||
| let names: string = knockMembers | ||
| .slice(0, 2) | ||
| .map((knockMember) => knockMember.name) | ||
| .join(", "); | ||
| let link: ReactNode = null; | ||
| switch (knockMembersCount) { | ||
| case 1: { | ||
| buttons = ( | ||
| <> | ||
| <AccessibleButton | ||
| className="mx_RoomKnocksBar_action" | ||
| disabled={!canKick || disabled} | ||
| kind="icon_primary_outline" | ||
| onClick={() => handleDeny(knockMembers[0].userId)} | ||
| title={_t("action|deny")} | ||
| > | ||
| <XIcon width={18} height={18} /> | ||
| </AccessibleButton> | ||
| <AccessibleButton | ||
| className="mx_RoomKnocksBar_action" | ||
| disabled={!canInvite || disabled} | ||
| kind="icon_primary" | ||
| onClick={() => handleApprove(knockMembers[0].userId)} | ||
| title={_t("action|approve")} | ||
| > | ||
| <CheckIcon width={18} height={18} /> | ||
| </AccessibleButton> | ||
| </> | ||
| ); | ||
| names = `${knockMembers[0].name} (${knockMembers[0].userId})`; | ||
| link = ( | ||
| <AccessibleButton | ||
| className="mx_RoomKnocksBar_link" | ||
| element="a" | ||
| kind="link_inline" | ||
| onClick={handleOpenRoomSettings} | ||
| > | ||
| {_t("action|view_message")} | ||
| </AccessibleButton> | ||
| ); | ||
| break; | ||
| } | ||
| case 2: { | ||
| names = _t("%(names)s and %(name)s", { names: knockMembers[0].name, name: knockMembers[1].name }); | ||
| break; | ||
| } | ||
| case 3: { | ||
| names = _t("%(names)s and %(name)s", { names, name: knockMembers[2].name }); | ||
| break; | ||
| } | ||
| default: | ||
| names = _t("%(names)s and %(count)s others", { names, count: knockMembersCount - 2 }); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="mx_RoomKnocksBar"> | ||
| {knockMembers.slice(0, 2).map((knockMember) => ( | ||
| <MemberAvatar | ||
| className="mx_RoomKnocksBar_avatar" | ||
| key={knockMember.userId} | ||
| member={knockMember} | ||
| size="32px" | ||
| /> | ||
| ))} | ||
| <div className="mx_RoomKnocksBar_content"> | ||
| <Heading size="4">{_t("%(count)s people asking to join", { count: knockMembersCount })}</Heading> | ||
| <p className="mx_RoomKnocksBar_paragraph"> | ||
| {names} | ||
| {link} | ||
| </p> | ||
| </div> | ||
| {buttons} | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.