You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
5 years ago
|
import { SyncMessage } from './SyncMessage';
|
||
|
import { SignalService } from '../../../../../protobuf';
|
||
|
import { MessageParams } from '../../Message';
|
||
|
import { StringUtils } from '../../../../utils';
|
||
|
|
||
|
interface BlockedListSyncMessageParams extends MessageParams {
|
||
|
groups: Array<string>;
|
||
|
numbers: Array<string>;
|
||
|
}
|
||
|
|
||
|
export abstract class BlockedListSyncMessage extends SyncMessage {
|
||
|
public readonly groups: Array<Uint8Array>;
|
||
|
public readonly numbers: Array<string>;
|
||
|
|
||
|
constructor(params: BlockedListSyncMessageParams) {
|
||
|
super({ timestamp: params.timestamp, identifier: params.identifier });
|
||
|
this.groups = params.groups.map(g => {
|
||
|
if (typeof g !== 'string') {
|
||
|
throw new TypeError(
|
||
|
`invalid group id (expected string) found:${typeof g}`
|
||
|
);
|
||
|
}
|
||
|
return new Uint8Array(StringUtils.encode(g, 'utf8'));
|
||
|
});
|
||
|
if (params.numbers.length && typeof params.numbers[0] !== 'string') {
|
||
|
throw new TypeError(
|
||
|
`invalid number (expected string) found:${typeof params.numbers[0]}`
|
||
|
);
|
||
|
}
|
||
|
this.numbers = params.numbers;
|
||
|
}
|
||
|
|
||
|
protected syncProto(): SignalService.SyncMessage {
|
||
|
const syncMessage = super.syncProto();
|
||
|
syncMessage.blocked = new SignalService.SyncMessage.Blocked({
|
||
|
groupIds: this.groups,
|
||
|
numbers: this.numbers,
|
||
|
});
|
||
|
|
||
|
return syncMessage;
|
||
|
}
|
||
|
}
|