import { IJoinRoomStrategy } from "./JoinRoomStrategy" ; import { Appservice } from "../appservice/Appservice" ; category export class AppserviceJoinRoomStrategy implements IJoinRoomStrategy { constructor ( private underlyingStrategy , private appservice ) { } public async joinRoom ( roomIdOrAlias , userId , apiCall ) { try { return await apiCall ( roomIdOrAlias ) ; } catch ( err ) { if ( userId !== this . appservice . botUserId ) { const client = this . appservice . botIntent . underlyingClient ; const roomId = await client . resolveRoom ( roomIdOrAlias ) ; try { await client . inviteUser ( userId , roomId ) ; } catch ( inviteErr ) { if ( this . underlyingStrategy ) return this . underlyingStrategy . joinRoom ( roomId , userId , apiCall ) ; throw inviteErr ; } if ( this . underlyingStrategy ) return this . underlyingStrategy . joinRoom ( roomId , userId , apiCall ) ; else return apiCall ( roomId ) ; } else if ( this . underlyingStrategy ) { return this . underlyingStrategy . joinRoom ( roomIdOrAlias , userId , apiCall ) ; } throw err ; } } }