Refactor to use fewer else's

This commit is contained in:
Robin Townsend 2022-07-15 16:08:26 -04:00
parent daeecc9b68
commit 996c5f86c1

View file

@ -67,9 +67,9 @@ export const useLoadGroupCall = (
const room = await fetchOrCreateRoom(); const room = await fetchOrCreateRoom();
const groupCall = client.getGroupCallForRoom(room.roomId); const groupCall = client.getGroupCallForRoom(room.roomId);
if (groupCall) { if (groupCall) return groupCall;
return groupCall;
} else if ( if (
room.currentState.mayClientSendStateEvent( room.currentState.mayClientSendStateEvent(
EventType.GroupCallPrefix, EventType.GroupCallPrefix,
client client
@ -83,7 +83,8 @@ export const useLoadGroupCall = (
createPtt, createPtt,
GroupCallIntent.Room GroupCallIntent.Room
); );
} else { }
// We don't have permission to create the call, so all we can do is wait // We don't have permission to create the call, so all we can do is wait
// for one to come in // for one to come in
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -100,14 +101,10 @@ export const useLoadGroupCall = (
client.on(GroupCallEventHandlerEvent.Incoming, onGroupCallIncoming); client.on(GroupCallEventHandlerEvent.Incoming, onGroupCallIncoming);
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
client.off( client.off(GroupCallEventHandlerEvent.Incoming, onGroupCallIncoming);
GroupCallEventHandlerEvent.Incoming,
onGroupCallIncoming
);
reject(new Error("Fetching group call timed out.")); reject(new Error("Fetching group call timed out."));
}, 30000); }, 30000);
}); });
}
}; };
fetchOrCreateGroupCall() fetchOrCreateGroupCall()