From af05d27260a94f5c37dfd3f9bff7a87fcc4200ef Mon Sep 17 00:00:00 2001 From: Arnab Chatterjee Date: Mon, 11 Sep 2023 17:19:00 +0530 Subject: [PATCH] refactor: rm speaker check logic --- .../helpers/getIncomingIndexFromAddress.ts | 7 --- .../lib/spaceV2/helpers/getPlainAddress.ts | 5 -- .../restapi/src/lib/spaceV2/joinAsSpeaker.ts | 50 +------------------ 3 files changed, 1 insertion(+), 61 deletions(-) delete mode 100644 packages/restapi/src/lib/spaceV2/helpers/getIncomingIndexFromAddress.ts delete mode 100644 packages/restapi/src/lib/spaceV2/helpers/getPlainAddress.ts diff --git a/packages/restapi/src/lib/spaceV2/helpers/getIncomingIndexFromAddress.ts b/packages/restapi/src/lib/spaceV2/helpers/getIncomingIndexFromAddress.ts deleted file mode 100644 index e4c61cf44..000000000 --- a/packages/restapi/src/lib/spaceV2/helpers/getIncomingIndexFromAddress.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { PeerData } from "../../types"; - -const getIncomingIndexFromAddress = (incomingPeers: PeerData[], address: string) => { - return incomingPeers.findIndex(incomingPeer => incomingPeer.address === address); -} - -export default getIncomingIndexFromAddress; diff --git a/packages/restapi/src/lib/spaceV2/helpers/getPlainAddress.ts b/packages/restapi/src/lib/spaceV2/helpers/getPlainAddress.ts deleted file mode 100644 index d24da128a..000000000 --- a/packages/restapi/src/lib/spaceV2/helpers/getPlainAddress.ts +++ /dev/null @@ -1,5 +0,0 @@ -const getPlainAddress = (prefixedAddress: string) => { - return prefixedAddress.replace('eip155:', ''); -}; - -export default getPlainAddress; diff --git a/packages/restapi/src/lib/spaceV2/joinAsSpeaker.ts b/packages/restapi/src/lib/spaceV2/joinAsSpeaker.ts index 827e83376..047ef90f7 100644 --- a/packages/restapi/src/lib/spaceV2/joinAsSpeaker.ts +++ b/packages/restapi/src/lib/spaceV2/joinAsSpeaker.ts @@ -5,60 +5,12 @@ import { get } from './get'; import { SpaceV2 } from './SpaceV2'; -import { approve } from './approve'; -import getIncomingIndexFromAddress from './helpers/getIncomingIndexFromAddress'; import sendMetaMessage from './helpers/sendMetaMessage' -import { ChatStatus, META_ACTION } from '../types'; -import getPlainAddress from '../spaceV2/helpers/getPlainAddress'; +import { META_ACTION } from '../types'; export async function joinAsSpeaker(this: SpaceV2) { try { - const space = await get({ - spaceId: this.data.spaceInfo.spaceId, - env: this.env, - }); - - if (space.status !== ChatStatus.ACTIVE) - throw new Error('Space not active yet'); - - // checking what is the current role of caller address - let isSpeaker = false; - - const localAddress = getPlainAddress(this.data.local.address); - - space.members.forEach((member) => { - if (getPlainAddress(member.wallet) === localAddress) { - if (member.isSpeaker) { - isSpeaker = true; - } - } - }); - - console.log("🚀 ~ file: joinAsSpeaker.ts:34 ~ space.members.forEach ~ isSpeaker:", isSpeaker) - - const hostAddress = getPlainAddress(space.spaceCreator); - const incomingIndex = getIncomingIndexFromAddress( - this.data.incoming, - hostAddress - ); - - // check if we arent already connected to the host - if ((isSpeaker) && incomingIndex > -1) { - return Promise.resolve(); - } - - // if speaker is pending then approve first or if listner is pending/not found then approve first - if (!isSpeaker) { - console.log('CALLING APPROVE'); - await approve({ - signer: this.signer, - pgpPrivateKey: this.pgpPrivateKey, - senderAddress: this.data.spaceInfo.spaceId, - env: this.env, - }); - } - // send meta message to host await sendMetaMessage({ pgpPrivateKey: this.pgpPrivateKey,