Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

897 improvement proposal spaces high level functions #898

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .husky/post-checkout

This file was deleted.

3 changes: 0 additions & 3 deletions .husky/post-commit

This file was deleted.

3 changes: 0 additions & 3 deletions .husky/post-merge

This file was deleted.

2 changes: 1 addition & 1 deletion packages/restapi/src/lib/chat/createGroupV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ChatCreateGroupTypeV2 extends EnvOptionsType {
groupImage: string | null;
rules: Rules | null;
isPublic: boolean;
groupType: 'default' | 'space';
groupType: 'default' | 'spaces';
config: {
meta: string | null;
scheduleAt: Date | null;
Expand Down
53 changes: 53 additions & 0 deletions packages/restapi/src/lib/chat/helpers/payloadHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SpaceAccess,
GroupInfoDTO,
ChatMemberProfile,
SpaceInfoDTO,
} from '../../types';
import { ENV } from '../../constants';
import { IPGPHelper, PGPHelper, pgpDecrypt } from './pgp';
Expand All @@ -19,6 +20,7 @@ import { MessageObj } from '../../types/messageTypes';

import * as CryptoJS from 'crypto-js';
import { getAllGroupMembers } from '../getAllGroupMembers';
import { ChatListType, SpaceListType } from '../../pushapi/pushAPITypes';
export interface ISendMessagePayload {
fromDID: string;
toDID: string;
Expand Down Expand Up @@ -332,6 +334,57 @@ export const groupDtoToSpaceDtoV2 = async (
return spaceDto;
};

export const groupInfoDtoToSpaceInfoDto = (
groupInfoDto: GroupInfoDTO
): SpaceInfoDTO => {
const spaceInfoDto: SpaceInfoDTO = {
spaceName: groupInfoDto.groupName,
spaceImage: groupInfoDto.groupImage,
spaceDescription: groupInfoDto.groupDescription,
isPublic: groupInfoDto.isPublic,
spaceCreator: groupInfoDto.groupCreator,
spaceId: groupInfoDto.chatId,
scheduleAt: groupInfoDto.scheduleAt,
scheduleEnd: groupInfoDto.scheduleEnd,
status: groupInfoDto.status ?? null,
rules: groupInfoDto.rules ?? null,
meta: groupInfoDto.meta ?? null,
sessionKey: groupInfoDto.sessionKey ?? null,
encryptedSecret: groupInfoDto.encryptedSecret ?? null,
};
return spaceInfoDto;
};

export const spaceDtoToSpaceInfoDto = (spaceDto: SpaceDTO): SpaceInfoDTO => {
return {
spaceName: spaceDto.spaceName,
spaceImage: spaceDto.spaceImage,
spaceDescription: spaceDto.spaceDescription,
isPublic: spaceDto.isPublic,
spaceCreator: spaceDto.spaceCreator,
spaceId: spaceDto.spaceId,
scheduleAt: spaceDto.scheduleAt,
scheduleEnd: spaceDto.scheduleEnd,
status: spaceDto.status,
rules: spaceDto.rules,
meta: spaceDto.meta,
sessionKey: null,
encryptedSecret: null,
inviteeDetails: spaceDto.inviteeDetails,
};
};

export const mapSpaceListTypeToChatListType = (type: SpaceListType): ChatListType => {
switch (type) {
case SpaceListType.SPACES:
return ChatListType.CHATS;
case SpaceListType.REQUESTS:
return ChatListType.REQUESTS;
default:
throw new Error(`Unsupported SpaceListType: ${type}`);
}
}

export const convertSpaceRulesToRules = (spaceRules: SpaceRules): Rules => {
return {
entry: spaceRules.entry,
Expand Down
12 changes: 11 additions & 1 deletion packages/restapi/src/lib/pushapi/PushAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
STREAM,
} from '../pushstream/pushStreamTypes';
import { ALPHA_FEATURE_CONFIG } from '../config';
import { Space } from './space';

export class PushAPI {
private signer?: SignerType;
Expand All @@ -27,7 +28,9 @@ export class PushAPI {
private env: ENV;
private progressHook?: (progress: ProgressHookType) => void;

public chat: Chat; // Public instances to be accessed from outside the class
public chat: Chat;
public space: Space;

public profile: Profile;
public encryption: Encryption;
private user: User;
Expand Down Expand Up @@ -66,6 +69,13 @@ export class PushAPI {
this.signer,
this.progressHook
);
this.space = new Space(
this.account,
this.env,
this.decryptedPgpPvtKey,
this.signer,
this.progressHook
);
this.profile = new Profile(
this.account,
this.env,
Expand Down
19 changes: 12 additions & 7 deletions packages/restapi/src/lib/pushapi/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,17 @@ export class Chat {
chatId: string,
options?: GetGroupParticipantsOptions
): Promise<{ members: ChatMemberProfile[] }> => {
const { page = 1, limit = 20,filter={pending:undefined,role:undefined} } = options ?? {};
const {
page = 1,
limit = 20,
filter = { pending: undefined, role: undefined },
} = options ?? {};
const getGroupMembersOptions: PUSH_CHAT.FetchChatGroupInfoType = {
chatId,
page,
limit,
pending:filter.pending,
role:filter.role,
pending: filter.pending,
role: filter.role,
env: this.env,
};

Expand All @@ -344,10 +348,10 @@ export class Chat {
chatId,
env: this.env,
});
return {
participants: count.overallCount - count.pendingCount,
pending: count.pendingCount,
};
return {
participants: count.overallCount - count.pendingCount,
pending: count.pendingCount,
};
},

status: async (
Expand Down Expand Up @@ -388,6 +392,7 @@ export class Chat {
env: this.env,
});
},

update: async (
chatId: string,
options: GroupUpdateOptions
Expand Down
53 changes: 52 additions & 1 deletion packages/restapi/src/lib/pushapi/pushAPITypes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import Constants, { ENV } from '../constants';
import { ChatMemberCounts, ChatMemberProfile, ChatStatus, ProgressHookType, Rules } from '../types';
import { ChatStatus, ProgressHookType, Rules, SpaceRules } from '../types';

export enum ChatListType {
CHATS = 'CHATS',
REQUESTS = 'REQUESTS',
}


export enum SpaceListType {
SPACES = 'SPACES',
REQUESTS = 'REQUESTS',
}
export interface PushAPIInitializeProps {
env?: ENV;
progressHook?: (progress: ProgressHookType) => void;
Expand Down Expand Up @@ -32,6 +38,15 @@ export interface ManageGroupOptions {
accounts: string[];
}

export interface ManageSpaceOptions {
role: 'SPEAKER' | 'LISTENER';
accounts: string[];
}

export interface RemoveFromSpaceOptions {
accounts: string[];
}

export interface RemoveFromGroupOptions {
role?: 'ADMIN' | 'MEMBER';
accounts: string[];
Expand All @@ -57,13 +72,49 @@ export interface GroupUpdateOptions {
rules?: Rules | null;
}

export interface SpaceUpdateOptions {
name?: string;
description?: string;
image?: string;
scheduleAt?: Date | null;
scheduleEnd?: Date | null;
status?: ChatStatus | null;
meta?: string | null;
rules?: SpaceRules | null;
}

export interface InfoOptions {
overrideAccount?: string;
}

export interface SpaceCreationOptions {
description: string;
image: string;
participants: {
speakers: string[];
listeners: string[];
};
schedule: {
start: Date;
end?: Date;
};
rules?: SpaceRules;
private: boolean;
}

export interface SpaceQueryOptions {
page: number;
limit: number;
}

export interface ParticipantStatus {
pending: boolean;
role: 'ADMIN' | 'MEMBER';
participant: boolean;
}

export interface SpaceParticipantStatus {
pending: boolean;
role: 'SPEAKER' | 'LISTENER';
participant: boolean;
}
Loading
Loading