Skip to content

Commit

Permalink
fix: stream review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Nov 14, 2023
1 parent fc9aa28 commit cdf4370
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 122 deletions.
4 changes: 4 additions & 0 deletions packages/restapi/src/lib/constantsV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { ConditionType, GROUP_INVITER_ROLE, GROUP_RULES_CATEGORY, GROUP_RULES_PE



// TODO: Change this do . type
// TODO: Add Notif type.
// TODO: Add Notif settings, boolean and slider
// TODO: Notification alias chain
const CONSTANTS = {
ENV: ENV,
STREAM: STREAM,
Expand Down
10 changes: 5 additions & 5 deletions packages/restapi/src/lib/pushapi/PushAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class PushAPI {
public profile: Profile;
public encryption: Encryption;
private user: User;
public _stream!: PushStream;
public stream!: PushStream;
// Notification
public channel!: Channel;
public notification!: Notification;
Expand Down Expand Up @@ -163,15 +163,15 @@ export class PushAPI {
}
}

async stream(
async initStream(
listen: STREAM[],
options?: PushStreamInitializeProps
): Promise<PushStream> {
if (this._stream) {
if (this.stream) {
throw new Error('Stream is already initialized.');
}

this._stream = await PushStream.initialize(
this.stream = await PushStream.initialize(
this.account,
this.decryptedPgpPvtKey,
this.signer,
Expand All @@ -181,7 +181,7 @@ export class PushAPI {
options
);

return this._stream;
return this.stream;
}

async info() {
Expand Down
64 changes: 55 additions & 9 deletions packages/restapi/src/lib/pushstream/DataModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
NotificationEventType,
NotificationType,
NOTIFICATION,
ProposedEventNames,
} from './pushStreamTypes';

export class DataModifier {
Expand Down Expand Up @@ -317,16 +318,15 @@ export class DataModifier {
(key) => NOTIFICATION.TYPE[key] === data.payload.data.type
) || 'BROADCAST'; // Assuming 'BROADCAST' as the default

let recipients: string[];

let recipients: string[];

if (Array.isArray(data.payload.recipients)) {
recipients = data.payload.recipients;
} else if (typeof data.payload.recipients === 'string') {
recipients = [data.payload.recipients];
} else {
recipients = Object.keys(data.payload.recipients);
}
if (Array.isArray(data.payload.recipients)) {
recipients = data.payload.recipients;
} else if (typeof data.payload.recipients === 'string') {
recipients = [data.payload.recipients];
} else {
recipients = Object.keys(data.payload.recipients);
}

const notificationEvent: NotificationEvent = {
event: notificationEventType,
Expand Down Expand Up @@ -376,4 +376,50 @@ export class DataModifier {

return notificationEvent;
}

public static convertToProposedName(
currentEventName: string
): ProposedEventNames {
switch (currentEventName) {
case 'message':
return ProposedEventNames.Message;
case 'request':
return ProposedEventNames.Request;
case 'accept':
return ProposedEventNames.Accept;
case 'reject':
return ProposedEventNames.Reject;
case 'leaveGroup':
return ProposedEventNames.LeaveGroup;
case 'joinGroup':
return ProposedEventNames.JoinGroup;
case 'createGroup':
return ProposedEventNames.CreateGroup;
case 'updateGroup':
return ProposedEventNames.UpdateGroup;
case 'remove':
return ProposedEventNames.Remove;
default:
throw new Error(`Unknown current event name: ${currentEventName}`);
}
}

public static handleToField(data: any): void {
switch (data.event) {
case ProposedEventNames.LeaveGroup:
case ProposedEventNames.JoinGroup:
data.to = null;
break;

case ProposedEventNames.Accept:
case ProposedEventNames.Reject:
if (data.meta?.group) {
data.to = null;
}
break;

default:
break;
}
}
}
Loading

0 comments on commit cdf4370

Please sign in to comment.