Skip to content

Commit

Permalink
Add decryption-capable versions of modular presencemessage decode fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
SimonWoolf committed Dec 5, 2024
1 parent e2f99d9 commit 24f6cea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions modular.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* | `MessageStatic.fromEncodedArray()` | [`decodeMessages()`](../functions/modular.decodeMessages.html) |
* | `MessageStatic.fromEncodedArray()` | [`decodeEncryptedMessages()`](../functions/modular.decodeEncryptedMessages.html) |
* | `PresenceMessageStatic.fromEncoded()` | [`decodePresenceMessage()`](../functions/modular.decodePresenceMessage.html) |
* | `PresenceMessageStatic.fromEncoded()` | [`decodeEncryptedPresenceMessage()`](../functions/modular.decodeEncryptedPresenceMessage.html) |
* | `PresenceMessageStatic.fromEncodedArray()` | [`decodeEncryptedPresenceMessages()`](../functions/modular.decodeEncryptedPresenceMessages.html) |
* | `PresenceMessageStatic.fromEncodedArray()` | [`decodePresenceMessages()`](../functions/modular.decodePresenceMessages.html) |
* | `PresenceMessageStatic.fromValues()` | [`constructPresenceMessage()`](../functions/modular.constructPresenceMessage.html) |
*
Expand Down Expand Up @@ -60,6 +62,8 @@ export declare const decodeMessages: MessageStatic['fromEncodedArray'];
export declare const decodeEncryptedMessages: MessageStatic['fromEncodedArray'];
export declare const decodePresenceMessage: PresenceMessageStatic['fromEncoded'];
export declare const decodePresenceMessages: PresenceMessageStatic['fromEncodedArray'];
export declare const decodeEncryptedPresenceMessage: PresenceMessageStatic['fromEncoded'];
export declare const decodeEncryptedPresenceMessages: PresenceMessageStatic['fromEncodedArray'];
export declare const constructPresenceMessage: PresenceMessageStatic['fromValues'];

/**
Expand Down
2 changes: 2 additions & 0 deletions scripts/moduleReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const functions = [
{ name: 'decodeEncryptedMessages', transitiveImports: ['Crypto'] },
{ name: 'decodePresenceMessage', transitiveImports: [] },
{ name: 'decodePresenceMessages', transitiveImports: [] },
{ name: 'decodeEncryptedPresenceMessage', transitiveImports: ['Crypto'] },
{ name: 'decodeEncryptedPresenceMessages', transitiveImports: ['Crypto'] },
{ name: 'constructPresenceMessage', transitiveImports: [] },
];

Expand Down
14 changes: 12 additions & 2 deletions src/platform/web/modular/presencemessage.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import * as API from '../../../../ably';
import { fromEncoded, fromEncodedArray, fromValues } from '../../../common/lib/types/presencemessage';
import { Crypto } from './crypto';
import Platform from 'common/platform';

Check failure on line 4 in src/platform/web/modular/presencemessage.ts

View workflow job for this annotation

GitHub Actions / lint

'Platform' is defined but never used. Allowed unused vars must match /^_/u
import Logger from '../../../common/lib/util/logger';

// The type assertions for the functions below are due to https://github.com/ably/ably-js/issues/1421

export const decodePresenceMessage = ((obj, options) => {
return fromEncoded(Logger.defaultLogger, Platform.Crypto, obj, options);
return fromEncoded(Logger.defaultLogger, null, obj, options);
}) as API.PresenceMessageStatic['fromEncoded'];

export const decodeEncryptedPresenceMessage = ((obj, options) => {
return fromEncoded(Logger.defaultLogger, Crypto, obj, options);
}) as API.PresenceMessageStatic['fromEncoded'];

export const decodePresenceMessages = ((obj, options) => {
return fromEncodedArray(Logger.defaultLogger, Platform.Crypto, obj, options);
return fromEncodedArray(Logger.defaultLogger, null, obj, options);
}) as API.PresenceMessageStatic['fromEncodedArray'];


export const decodeEncryptedPresenceMessages = ((obj, options) => {
return fromEncodedArray(Logger.defaultLogger, Crypto, obj, options);
}) as API.PresenceMessageStatic['fromEncodedArray'];

export const constructPresenceMessage = fromValues as API.PresenceMessageStatic['fromValues'];

0 comments on commit 24f6cea

Please sign in to comment.