@@ -44,7 +44,7 @@ async def put_state(
44
44
45
45
access_token , homeserver_url , _ = creds
46
46
47
- async with MatrixClient (homeserver_url , access_token ) as client :
47
+ async with MatrixClient (homeserver_url , access_token , max_timeouts = 15 ) as client :
48
48
res = await client .room_put_state (
49
49
room_id ,
50
50
state_type ,
@@ -86,7 +86,7 @@ async def create_room(
86
86
if not any ([matrix_id .split ("@" )[1 ].islower () for matrix_id in invite ]):
87
87
raise Exception ("Matrix IDs must be lowercase" )
88
88
89
- async with MatrixClient (homeserver_url , access_token ) as client :
89
+ async with MatrixClient (homeserver_url , access_token , max_timeouts = 15 ) as client :
90
90
res = await client .room_create (
91
91
name = name ,
92
92
space = space ,
@@ -117,7 +117,7 @@ async def add_subspace(
117
117
118
118
access_token , homeserver_url , _ = creds
119
119
120
- async with MatrixClient (homeserver_url , access_token ) as client :
120
+ async with MatrixClient (homeserver_url , access_token , max_timeouts = 15 ) as client :
121
121
res = await client .room_put_state (
122
122
parent_room_id ,
123
123
"m.space.child" ,
@@ -132,16 +132,26 @@ async def add_subspace(
132
132
% (child_room_id , parent_room_id )
133
133
)
134
134
135
- async def accept_invite_as_user (self , room_id : str , homeserver_url : str ):
136
- creds = AuthenticatedController .get_creds ()
137
- if not creds :
138
- raise Exception ("You must be logged in to accept an invite to a space" )
139
-
140
- access_token , homeserver_url , user_matrix_id = creds
135
+ async def accept_invite_as_user (
136
+ self , room_id : str , homeserver_url : str , matrix_creds : Optional [tuple [str , str ]] = None
137
+ ):
138
+ """
139
+ Args:
140
+ room_id (str): The room ID to accept the invite to
141
+ homeserver_url (str): The homeserver URL
142
+ matrix_creds (tuple[matrix_id, access_token], optional): The Matrix credentials to use.
143
+ Defaults to logged in user's credentials.
144
+ """
145
+ if not matrix_creds :
146
+ creds = AuthenticatedController .get_creds ()
147
+ if not creds :
148
+ raise Exception ("You must be logged in to accept an invite to a space" )
149
+ access_token , homeserver_url , user_matrix_id = creds
150
+ else :
151
+ user_matrix_id , access_token = matrix_creds
141
152
142
153
async with MatrixClient (
143
- homeserver_url = homeserver_url ,
144
- access_token = access_token ,
154
+ homeserver_url = homeserver_url , access_token = access_token , max_timeouts = 15
145
155
) as client :
146
156
logger .info ("Accepting invite for %s as %s" % (room_id , user_matrix_id ))
147
157
await client .join_room (room_id )
@@ -154,13 +164,12 @@ async def accept_invite_as_device(
154
164
async with MatrixClient (
155
165
homeserver_url = homeserver_url ,
156
166
access_token = device_creds .access_token ,
167
+ max_timeouts = 15 ,
157
168
) as client :
158
169
logger .info ("Accepting invite for %s as %s" % (room_id , device_matrix_id ))
159
170
await client .join_room (room_id )
160
171
161
172
async def invite_user (self , matrix_id : str , room_id : str ) -> None :
162
- from fractal .cli .controllers .auth import AuthenticatedController
163
-
164
173
# FIXME: Once user has accounts on many homeservers, we need to strip the
165
174
# host off of the room id and try to find credentials that match that host
166
175
creds = AuthenticatedController .get_creds ()
@@ -172,6 +181,7 @@ async def invite_user(self, matrix_id: str, room_id: str) -> None:
172
181
async with MatrixClient (
173
182
homeserver_url = homeserver_url ,
174
183
access_token = access_token ,
184
+ max_timeouts = 15 ,
175
185
) as client :
176
186
logger .info ("Inviting %s to %s" % (matrix_id , room_id ))
177
187
await client .invite (user_id = matrix_id , room_id = room_id , admin = True )
@@ -189,6 +199,7 @@ async def register_device_account(
189
199
async with MatrixClient (
190
200
homeserver_url = homeserver_url ,
191
201
access_token = access_token ,
202
+ max_timeouts = 15 ,
192
203
) as client :
193
204
registration_token = await client .generate_registration_token ()
194
205
await client .whoami ()
@@ -218,6 +229,7 @@ async def set_display_name(
218
229
async with MatrixClient (
219
230
homeserver_url = homeserver_url ,
220
231
access_token = creds .access_token ,
232
+ max_timeouts = 15 ,
221
233
) as client :
222
234
await client .set_displayname (display_name )
223
235
0 commit comments