Skip to content

Commit

Permalink
refactor: rm speaker check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
arn4b committed Sep 11, 2023
1 parent 0cba72e commit af05d27
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 61 deletions.

This file was deleted.

5 changes: 0 additions & 5 deletions packages/restapi/src/lib/spaceV2/helpers/getPlainAddress.ts

This file was deleted.

50 changes: 1 addition & 49 deletions packages/restapi/src/lib/spaceV2/joinAsSpeaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit af05d27

Please sign in to comment.