Remove unused code from WebAPI
This commit is contained in:
parent
cd710bb8d2
commit
eec669f284
2 changed files with 16 additions and 91 deletions
|
@ -21,7 +21,7 @@ import {
|
|||
UnidentifiedSenderMessageContent,
|
||||
} from '@signalapp/signal-client';
|
||||
|
||||
import type { WebAPIType } from './WebAPI';
|
||||
import type { WebAPIType, MessageType } from './WebAPI';
|
||||
import { SendMetadataType, SendOptionsType } from './SendMessage';
|
||||
import {
|
||||
OutgoingIdentityKeyError,
|
||||
|
@ -52,13 +52,6 @@ export type SendLogCallbackType = (options: {
|
|||
deviceIds: Array<number>;
|
||||
}) => Promise<void>;
|
||||
|
||||
type SendMetadata = {
|
||||
type: number;
|
||||
destinationDeviceId: number;
|
||||
destinationRegistrationId: number;
|
||||
content: string;
|
||||
};
|
||||
|
||||
export const serializedCertificateSchema = z
|
||||
.object({
|
||||
expires: z.number().optional(),
|
||||
|
@ -289,7 +282,7 @@ export default class OutgoingMessage {
|
|||
|
||||
async transmitMessage(
|
||||
identifier: string,
|
||||
jsonData: Array<unknown>,
|
||||
jsonData: ReadonlyArray<MessageType>,
|
||||
timestamp: number,
|
||||
{ accessKey }: { accessKey?: string } = {}
|
||||
): Promise<void> {
|
||||
|
@ -419,7 +412,7 @@ export default class OutgoingMessage {
|
|||
new Address(theirUuid, destinationDeviceId)
|
||||
);
|
||||
|
||||
return window.textsecure.storage.protocol.enqueueSessionJob<SendMetadata>(
|
||||
return window.textsecure.storage.protocol.enqueueSessionJob<MessageType>(
|
||||
address,
|
||||
async () => {
|
||||
const protocolAddress = ProtocolAddress.new(
|
||||
|
@ -494,7 +487,7 @@ export default class OutgoingMessage {
|
|||
);
|
||||
})
|
||||
)
|
||||
.then(async (jsonData: Array<SendMetadata>) => {
|
||||
.then(async (jsonData: Array<MessageType>) => {
|
||||
if (sealedSender) {
|
||||
return this.transmitMessage(identifier, jsonData, this.timestamp, {
|
||||
accessKey,
|
||||
|
|
|
@ -28,7 +28,7 @@ import { v4 as getGuid } from 'uuid';
|
|||
import { z } from 'zod';
|
||||
import Long from 'long';
|
||||
|
||||
import { assert, strictAssert } from '../util/assert';
|
||||
import { assert } from '../util/assert';
|
||||
import * as durations from '../util/durations';
|
||||
import { getUserAgent } from '../util/getUserAgent';
|
||||
import { toWebSafeBase64 } from '../util/webSafeBase64';
|
||||
|
@ -103,69 +103,6 @@ function getSgxConstants() {
|
|||
return sgxConstantCache;
|
||||
}
|
||||
|
||||
const _call = (object: any) => Object.prototype.toString.call(object);
|
||||
|
||||
// TODO: DESKTOP-2424
|
||||
const ArrayBufferToString = _call(new ArrayBuffer(0));
|
||||
const Uint8ArrayToString = _call(new Uint8Array());
|
||||
|
||||
function _getString(thing: any): string {
|
||||
if (typeof thing !== 'string') {
|
||||
if (_call(thing) === Uint8ArrayToString) {
|
||||
return String.fromCharCode.apply(null, thing);
|
||||
}
|
||||
if (_call(thing) === ArrayBufferToString) {
|
||||
return _getString(new Uint8Array(thing));
|
||||
}
|
||||
}
|
||||
|
||||
return thing;
|
||||
}
|
||||
|
||||
function _getStringable(thing: any) {
|
||||
return (
|
||||
typeof thing === 'string' ||
|
||||
typeof thing === 'number' ||
|
||||
typeof thing === 'boolean' ||
|
||||
(thing === Object(thing) &&
|
||||
(_call(thing) === ArrayBufferToString ||
|
||||
_call(thing) === Uint8ArrayToString))
|
||||
);
|
||||
}
|
||||
|
||||
function _ensureStringed(thing: any): any {
|
||||
if (_getStringable(thing)) {
|
||||
return _getString(thing);
|
||||
}
|
||||
if (thing instanceof Array) {
|
||||
const res = [];
|
||||
for (let i = 0; i < thing.length; i += 1) {
|
||||
res[i] = _ensureStringed(thing[i]);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
if (thing === Object(thing)) {
|
||||
const res: any = {};
|
||||
for (const key in thing) {
|
||||
res[key] = _ensureStringed(thing[key]);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
if (thing === null) {
|
||||
return null;
|
||||
}
|
||||
if (thing === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
throw new Error(`unsure of how to jsonify object of type ${typeof thing}`);
|
||||
}
|
||||
|
||||
function _jsonThing(thing: any): string {
|
||||
return JSON.stringify(_ensureStringed(thing));
|
||||
}
|
||||
|
||||
function _createRedactor(
|
||||
...toReplace: ReadonlyArray<string | undefined>
|
||||
): RedactUrl {
|
||||
|
@ -639,7 +576,12 @@ type InitializeOptionsType = {
|
|||
version: string;
|
||||
};
|
||||
|
||||
type MessageType = unknown;
|
||||
export type MessageType = Readonly<{
|
||||
type: number;
|
||||
destinationDeviceId: number;
|
||||
destinationRegistrationId: number;
|
||||
content: string;
|
||||
}>;
|
||||
|
||||
type AjaxOptionsType = {
|
||||
accessKey?: string;
|
||||
|
@ -882,13 +824,13 @@ export type WebAPIType = {
|
|||
requestVerificationVoice: (number: string) => Promise<void>;
|
||||
sendMessages: (
|
||||
destination: string,
|
||||
messageArray: Array<MessageType>,
|
||||
messageArray: ReadonlyArray<MessageType>,
|
||||
timestamp: number,
|
||||
online?: boolean
|
||||
) => Promise<void>;
|
||||
sendMessagesUnauth: (
|
||||
destination: string,
|
||||
messageArray: Array<MessageType>,
|
||||
messageArray: ReadonlyArray<MessageType>,
|
||||
timestamp: number,
|
||||
online?: boolean,
|
||||
options?: { accessKey?: string }
|
||||
|
@ -1143,7 +1085,7 @@ export function initialize({
|
|||
contentType: param.contentType || 'application/json; charset=utf-8',
|
||||
data:
|
||||
param.data ||
|
||||
(param.jsonData ? _jsonThing(param.jsonData) : undefined),
|
||||
(param.jsonData ? JSON.stringify(param.jsonData) : undefined),
|
||||
headers: param.headers,
|
||||
host: param.host || url,
|
||||
password: param.password || password,
|
||||
|
@ -1722,15 +1664,9 @@ export function initialize({
|
|||
return handleKeys(keys);
|
||||
}
|
||||
|
||||
function validateMessages(messages: Array<unknown>): void {
|
||||
for (const message of messages) {
|
||||
strictAssert(message !== null, 'Attempting to send `null` message');
|
||||
}
|
||||
}
|
||||
|
||||
async function sendMessagesUnauth(
|
||||
destination: string,
|
||||
messages: Array<MessageType>,
|
||||
messages: ReadonlyArray<MessageType>,
|
||||
timestamp: number,
|
||||
online?: boolean,
|
||||
{ accessKey }: { accessKey?: string } = {}
|
||||
|
@ -1742,8 +1678,6 @@ export function initialize({
|
|||
jsonData = { messages, timestamp };
|
||||
}
|
||||
|
||||
validateMessages(messages);
|
||||
|
||||
await _ajax({
|
||||
call: 'messages',
|
||||
httpType: 'PUT',
|
||||
|
@ -1757,7 +1691,7 @@ export function initialize({
|
|||
|
||||
async function sendMessages(
|
||||
destination: string,
|
||||
messages: Array<MessageType>,
|
||||
messages: ReadonlyArray<MessageType>,
|
||||
timestamp: number,
|
||||
online?: boolean
|
||||
) {
|
||||
|
@ -1768,8 +1702,6 @@ export function initialize({
|
|||
jsonData = { messages, timestamp };
|
||||
}
|
||||
|
||||
validateMessages(messages);
|
||||
|
||||
await _ajax({
|
||||
call: 'messages',
|
||||
httpType: 'PUT',
|
||||
|
|
Loading…
Reference in a new issue