@@ -17,23 +17,16 @@ import { Icon as ExternalLinkIcon } from "@vector-im/compound-design-tokens/icon
17
17
import { Button , IconButton , Tooltip } from "@vector-im/compound-web" ;
18
18
import React , { useCallback , useMemo } from "react" ;
19
19
import { logger } from "matrix-js-sdk/src/logger" ;
20
- import {
21
- EventTimeline ,
22
- EventType ,
23
- IJoinRuleEventContent ,
24
- JoinRule ,
25
- Room ,
26
- RoomStateEvent ,
27
- } from "matrix-js-sdk/src/matrix" ;
20
+ import { EventType , IJoinRuleEventContent , JoinRule , Room } from "matrix-js-sdk/src/matrix" ;
28
21
29
22
import Modal from "../../../../Modal" ;
30
23
import ShareDialog from "../../dialogs/ShareDialog" ;
31
24
import { _t } from "../../../../languageHandler" ;
32
25
import SettingsStore from "../../../../settings/SettingsStore" ;
33
26
import SdkConfig from "../../../../SdkConfig" ;
34
27
import { calculateRoomVia } from "../../../../utils/permalinks/Permalinks" ;
35
- import { useEventEmitterState } from "../../../../hooks/useEventEmitter" ;
36
28
import BaseDialog from "../../dialogs/BaseDialog" ;
29
+ import { useGuestAccessInformation } from "../../../../hooks/room/useGuestAccessInformation" ;
37
30
38
31
/**
39
32
* Display a button to open a dialog to share a link to the call using a element call guest spa url (`element_call:guest_spa_url` in the EW config).
@@ -45,23 +38,7 @@ export const CallGuestLinkButton: React.FC<{ room: Room }> = ({ room }) => {
45
38
return SdkConfig . get ( "element_call" ) . guest_spa_url ;
46
39
} , [ ] ) ;
47
40
48
- // We use the direct function only in functions triggered by user interaction to avoid computation on every render.
49
- const isRoomJoinable = useCallback (
50
- ( ) => room . getJoinRule ( ) === JoinRule . Public || room . getJoinRule ( ) === JoinRule . Knock ,
51
- [ room ] ,
52
- ) ;
53
-
54
- const isRoomJoinableState = useEventEmitterState ( room , RoomStateEvent . Events , isRoomJoinable ) ;
55
-
56
- const canChangeJoinRule = useEventEmitterState (
57
- room ,
58
- RoomStateEvent . Events ,
59
- ( ) =>
60
- room
61
- . getLiveTimeline ( )
62
- ?. getState ( EventTimeline . FORWARDS )
63
- ?. maySendStateEvent ( EventType . RoomJoinRules , room . myUserId ) ?? false ,
64
- ) ;
41
+ const { canChangeJoinRule, roomIsJoinableState, isRoomJoinable, canInvite } = useGuestAccessInformation ( room ) ;
65
42
66
43
const generateCallLink = useCallback ( ( ) => {
67
44
if ( ! isRoomJoinable ( ) ) throw new Error ( "Cannot create link for room that users can not join without invite." ) ;
@@ -104,16 +81,17 @@ export const CallGuestLinkButton: React.FC<{ room: Room }> = ({ room }) => {
104
81
// the room needs to be set to public or knock to generate a link
105
82
Modal . createDialog ( JoinRuleDialog , {
106
83
room,
84
+ canInvite,
107
85
} ) . finished . then ( ( ) => {
108
86
// we need to use the function here because the callback got called before the state was updated.
109
87
if ( isRoomJoinable ( ) ) showLinkModal ( ) ;
110
88
} ) ;
111
89
}
112
- } , [ showLinkModal , room , isRoomJoinable ] ) ;
90
+ } , [ isRoomJoinable , showLinkModal , room , canInvite ] ) ;
113
91
114
92
return (
115
93
< >
116
- { ( canChangeJoinRule || isRoomJoinableState ) && guestSpaUrl && (
94
+ { ( canChangeJoinRule || roomIsJoinableState ) && guestSpaUrl && (
117
95
< Tooltip label = { _t ( "voip|get_call_link" ) } >
118
96
< IconButton onClick = { shareClick } aria-label = { _t ( "voip|get_call_link" ) } >
119
97
< ExternalLinkIcon />
@@ -132,7 +110,8 @@ export const CallGuestLinkButton: React.FC<{ room: Room }> = ({ room }) => {
132
110
export const JoinRuleDialog : React . FC < {
133
111
onFinished ( ) : void ;
134
112
room : Room ;
135
- } > = ( { room, onFinished } ) => {
113
+ canInvite : boolean ;
114
+ } > = ( { onFinished, room, canInvite } ) => {
136
115
const askToJoinEnabled = SettingsStore . getValue ( "feature_ask_to_join" ) ;
137
116
const [ isUpdating , setIsUpdating ] = React . useState < undefined | JoinRule > ( undefined ) ;
138
117
const changeJoinRule = useCallback (
@@ -156,7 +135,7 @@ export const JoinRuleDialog: React.FC<{
156
135
< BaseDialog title = { _t ( "update_room_access_modal|title" ) } onFinished = { onFinished } className = "mx_JoinRuleDialog" >
157
136
< p > { _t ( "update_room_access_modal|description" ) } </ p >
158
137
< div className = "mx_JoinRuleDialogButtons" >
159
- { askToJoinEnabled && (
138
+ { askToJoinEnabled && canInvite && (
160
139
< Button
161
140
kind = "secondary"
162
141
className = "mx_Dialog_nonDialogButton"
0 commit comments