From cddc7fa30669b3334bbc421152389d8c16eedc15 Mon Sep 17 00:00:00 2001 From: Arnab Chatterjee <60937304+arn4b@users.noreply.github.com> Date: Mon, 11 Sep 2023 17:31:18 +0530 Subject: [PATCH] feat: add join as speaker (#705) * feat: add join as speaker * refactor: add file level comment * refactor: eOF * refactor: rm speaker check logic * fix: getPlain added * fix: rm updation --- .../lib/spaceV2/helpers/sendMetaMessage.ts | 44 +++++++++++++++++++ .../restapi/src/lib/spaceV2/joinAsSpeaker.ts | 28 ++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 packages/restapi/src/lib/spaceV2/helpers/sendMetaMessage.ts create mode 100644 packages/restapi/src/lib/spaceV2/joinAsSpeaker.ts diff --git a/packages/restapi/src/lib/spaceV2/helpers/sendMetaMessage.ts b/packages/restapi/src/lib/spaceV2/helpers/sendMetaMessage.ts new file mode 100644 index 000000000..776b113b2 --- /dev/null +++ b/packages/restapi/src/lib/spaceV2/helpers/sendMetaMessage.ts @@ -0,0 +1,44 @@ +/** + * @file sendMetaMessage helper function + * This module provides a function for sending metadata-related messages within a live space. + */ + +import { send } from '../../chat'; +import { MessageType } from '../../constants'; +import { EnvOptionsType, LiveSpaceData, SignerType } from '../../types'; +import { META_ACTION } from '../../types/messageTypes'; + +interface ISendMetaMessage extends EnvOptionsType { + liveSpaceData?: LiveSpaceData; + action: META_ACTION; + spaceId: string; + pgpPrivateKey: string; + signer: SignerType; +} + +const sendMetaMessage = async ({ + liveSpaceData, + action, + spaceId, + pgpPrivateKey, + signer, + env, +}: ISendMetaMessage) => { + await send({ + receiverAddress: spaceId, + pgpPrivateKey, + env, + signer, + messageType: MessageType.META, + messageObj: { + content: 'PUSH SPACE V2 META MESSAGE', + action, + info: { + affected: [], + arbitrary: liveSpaceData, + }, + }, + }); +}; + +export default sendMetaMessage; diff --git a/packages/restapi/src/lib/spaceV2/joinAsSpeaker.ts b/packages/restapi/src/lib/spaceV2/joinAsSpeaker.ts new file mode 100644 index 000000000..c6f4852bd --- /dev/null +++ b/packages/restapi/src/lib/spaceV2/joinAsSpeaker.ts @@ -0,0 +1,28 @@ +/** + * @file joinAsSpeaker + * defines a function that allows a user to join a space as a speaker in the SpaceV2 implmentation + */ + +import { SpaceV2 } from './SpaceV2'; +import sendMetaMessage from './helpers/sendMetaMessage' + +import { META_ACTION } from '../types'; + +export async function joinAsSpeaker(this: SpaceV2) { + try { + // send meta message to host + await sendMetaMessage({ + pgpPrivateKey: this.pgpPrivateKey, + env: this.env, + spaceId: this.data.spaceInfo.spaceId, + signer: this.signer, + // TODO: add relevant meta message later + action: META_ACTION.ADD_MEMBER, + }); + + /* rest logic to be implemented here after host has called the approve/reject call */ + } catch (err) { + console.error(`[Push SDK] - API - Error - API ${joinAsSpeaker.name} -: `, err); + throw Error(`[Push SDK] - API - Error - API ${joinAsSpeaker.name} -: ${err}`); + } +};