remove non used function in session from sendMessage.js

pull/1194/head
Audric Ackermann 5 years ago
parent c768b2c350
commit aee7428282
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -10,7 +10,8 @@
Signal, Signal,
textsecure, textsecure,
Whisper, Whisper,
clipboard clipboard,
libsession
*/ */
/* eslint-disable more/no-then */ /* eslint-disable more/no-then */
@ -1447,39 +1448,40 @@
}, },
sendSyncMessage() { sendSyncMessage() {
const ourNumber = textsecure.storage.user.getNumber();
const { wrap, sendOptions } = ConversationController.prepareForSend(
ourNumber,
{
syncMessage: true,
}
);
this.syncPromise = this.syncPromise || Promise.resolve(); this.syncPromise = this.syncPromise || Promise.resolve();
const next = () => { const next = () => {
const dataMessage = this.get('dataMessage'); const encodedDataMessage = this.get('dataMessage');
if (this.get('synced') || !dataMessage) { if (this.get('synced') || !encodedDataMessage) {
return Promise.resolve(); return Promise.resolve();
} }
return wrap( const dataMessage = textsecure.protobuf.DataMessage.decode(
textsecure.messaging.sendSyncMessage( encodedDataMessage
dataMessage, );
this.get('sent_at'), // Sync the group message to our other devices
this.get('destination'), const sentSyncMessageParams = {
this.get('expirationStartTimestamp'), timestamp: this.get('sent_at'),
this.get('sent_to'), dataMessage,
this.get('unidentifiedDeliveries'), destination: this.get('destination'),
sendOptions expirationStartTimestamp: this.get('expirationStartTimestamp'),
) sent_to: this.get('sent_to'),
).then(result => { unidentifiedDeliveries: this.get('unidentifiedDeliveries'),
this.set({ };
synced: true, const sentSyncMessage = new libsession.Messages.Outgoing.SentSyncMessage(
dataMessage: null, sentSyncMessageParams
);
return libsession
.getMessageQueue()
.sendSyncMessage(sentSyncMessage)
.then(result => {
this.set({
synced: true,
dataMessage: null,
});
return window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message,
}).then(() => result);
}); });
return window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message,
}).then(() => result);
});
}; };
this.syncPromise = this.syncPromise.then(next, next); this.syncPromise = this.syncPromise.then(next, next);

@ -1,4 +1,4 @@
/* global textsecure, WebAPI, libsignal, window, OutgoingMessage, libloki */ /* global textsecure, WebAPI, libsignal, window, OutgoingMessage, libloki, libsession */
/* eslint-disable more/no-then, no-bitwise */ /* eslint-disable more/no-then, no-bitwise */
@ -440,76 +440,6 @@ MessageSender.prototype = {
return syncMessage; return syncMessage;
}, },
async sendSyncMessage(
encodedDataMessage,
timestamp,
destination,
expirationStartTimestamp,
sentTo = [],
unidentifiedDeliveries = [],
options
) {
const primaryDeviceKey =
window.storage.get('primaryDevicePubKey') ||
textsecure.storage.user.getNumber();
const allOurDevices = (
await window.libsession.Protocols.MultiDeviceProtocol.getAllDevices(
primaryDeviceKey
)
)
// Don't send to ourselves
.filter(pubKey => pubKey.key !== textsecure.storage.user.getNumber());
if (allOurDevices.length === 0) {
return null;
}
const dataMessage = textsecure.protobuf.DataMessage.decode(
encodedDataMessage
);
const sentMessage = new textsecure.protobuf.SyncMessage.Sent();
sentMessage.timestamp = timestamp;
sentMessage.message = dataMessage;
if (destination) {
sentMessage.destination = destination;
}
if (expirationStartTimestamp) {
sentMessage.expirationStartTimestamp = expirationStartTimestamp;
}
const unidentifiedLookup = unidentifiedDeliveries.reduce(
(accumulator, item) => {
// eslint-disable-next-line no-param-reassign
accumulator[item] = true;
return accumulator;
},
Object.create(null)
);
// Though this field has 'unidenified' in the name, it should have entries for each
// number we sent to.
if (sentTo && sentTo.length) {
sentMessage.unidentifiedStatus = sentTo.map(number => {
const status = new textsecure.protobuf.SyncMessage.Sent.UnidentifiedDeliveryStatus();
status.destination = number;
status.unidentified = Boolean(unidentifiedLookup[number]);
return status;
});
}
const syncMessage = this.createSyncMessage();
syncMessage.sent = sentMessage;
const contentMessage = new textsecure.protobuf.Content();
contentMessage.syncMessage = syncMessage;
const silent = true;
return this.sendIndividualProto(
primaryDeviceKey,
contentMessage,
Date.now(),
silent,
options
);
},
uploadAvatar(attachment) { uploadAvatar(attachment) {
// isRaw is true since the data is already encrypted // isRaw is true since the data is already encrypted
// and doesn't need to be encrypted again // and doesn't need to be encrypted again
@ -818,8 +748,15 @@ MessageSender.prototype = {
const result = await sendPromise; const result = await sendPromise;
// Sync the group message to our other devices // Sync the group message to our other devices
const encoded = textsecure.protobuf.DataMessage.encode(proto); const sentSyncMessageParams = {
this.sendSyncMessage(encoded, timestamp, null, null, [], [], options); timestamp,
dataMessage: proto,
};
const sentSyncMessage = new libsession.Messages.Outgoing.SentSyncMessage(
sentSyncMessageParams
);
await libsession.getMessageQueue().sendSyncMessage(sentSyncMessage);
return result; return result;
}, },
@ -978,71 +915,6 @@ MessageSender.prototype = {
return true; return true;
}, },
async sendGroupUpdate(
groupId,
name,
avatar,
members,
admins,
recipients,
options
) {
const proto = new textsecure.protobuf.DataMessage();
proto.group = new textsecure.protobuf.GroupContext();
proto.group.id = stringToArrayBuffer(groupId);
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
proto.group.name = name;
proto.group.members = members;
const primaryDeviceKey =
window.storage.get('primaryDevicePubKey') ||
textsecure.storage.user.getNumber();
proto.group.admins = [primaryDeviceKey];
const attachment = await this.makeAttachmentPointer(avatar);
proto.group.avatar = attachment;
// TODO: re-enable this once we have attachments
proto.group.avatar = null;
await this.sendGroupProto(recipients, proto, Date.now(), options);
return proto.group.id;
},
addNumberToGroup(groupId, newNumbers, options) {
const proto = new textsecure.protobuf.DataMessage();
proto.group = new textsecure.protobuf.GroupContext();
proto.group.id = stringToArrayBuffer(groupId);
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
proto.group.members = newNumbers;
return this.sendGroupProto(newNumbers, proto, Date.now(), options);
},
setGroupName(groupId, name, groupNumbers, options) {
const proto = new textsecure.protobuf.DataMessage();
proto.group = new textsecure.protobuf.GroupContext();
proto.group.id = stringToArrayBuffer(groupId);
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
proto.group.name = name;
proto.group.members = groupNumbers;
return this.sendGroupProto(groupNumbers, proto, Date.now(), options);
},
setGroupAvatar(groupId, avatar, groupNumbers, options) {
const proto = new textsecure.protobuf.DataMessage();
proto.group = new textsecure.protobuf.GroupContext();
proto.group.id = stringToArrayBuffer(groupId);
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
proto.group.members = groupNumbers;
return this.makeAttachmentPointer(avatar).then(attachment => {
proto.group.avatar = attachment;
return this.sendGroupProto(groupNumbers, proto, Date.now(), options);
});
},
requestSenderKeys(sender, groupId) { requestSenderKeys(sender, groupId) {
const proto = new textsecure.protobuf.DataMessage(); const proto = new textsecure.protobuf.DataMessage();
const update = new textsecure.protobuf.MediumGroupUpdate(); const update = new textsecure.protobuf.MediumGroupUpdate();
@ -1073,9 +945,6 @@ textsecure.MessageSender = function MessageSenderWrapper(username, password) {
this.sendMessage = sender.sendMessage.bind(sender); this.sendMessage = sender.sendMessage.bind(sender);
this.sendMessageToGroup = sender.sendMessageToGroup.bind(sender); this.sendMessageToGroup = sender.sendMessageToGroup.bind(sender);
this.updateMediumGroup = sender.updateMediumGroup.bind(sender); this.updateMediumGroup = sender.updateMediumGroup.bind(sender);
this.addNumberToGroup = sender.addNumberToGroup.bind(sender);
this.setGroupName = sender.setGroupName.bind(sender);
this.setGroupAvatar = sender.setGroupAvatar.bind(sender);
this.requestSenderKeys = sender.requestSenderKeys.bind(sender); this.requestSenderKeys = sender.requestSenderKeys.bind(sender);
this.sendSyncMessage = sender.sendSyncMessage.bind(sender); this.sendSyncMessage = sender.sendSyncMessage.bind(sender);
this.uploadAvatar = sender.uploadAvatar.bind(sender); this.uploadAvatar = sender.uploadAvatar.bind(sender);

@ -0,0 +1,70 @@
import { SyncMessage } from './SyncMessage';
import { SignalService } from '../../../../../protobuf';
import { MessageParams } from '../../Message';
import { PubKey } from '../../../../types';
interface SentSyncMessageParams extends MessageParams {
// const dataMessage = textsecure.protobuf.DataMessage.decode(
// encodedDataMessage
// );
dataMessage: SignalService.DataMessage;
expirationStartTimestamp?: number;
sentTo?: [PubKey];
unidentifiedDeliveries?: [PubKey];
destination?: PubKey;
}
export abstract class SentSyncMessage extends SyncMessage {
public readonly dataMessage: SignalService.DataMessage;
public readonly expirationStartTimestamp?: number;
public readonly sentTo?: [PubKey];
public readonly unidentifiedDeliveries?: [PubKey];
public readonly destination?: PubKey;
constructor(params: SentSyncMessageParams) {
super({ timestamp: params.timestamp, identifier: params.identifier });
this.dataMessage = params.dataMessage;
this.expirationStartTimestamp = params.expirationStartTimestamp;
this.sentTo = params.sentTo;
this.unidentifiedDeliveries = params.unidentifiedDeliveries;
this.destination = params.destination;
}
protected syncProto(): SignalService.SyncMessage {
const syncMessage = super.syncProto();
syncMessage.sent = new SignalService.SyncMessage.Sent();
syncMessage.sent.timestamp = this.timestamp;
syncMessage.sent.message = this.dataMessage;
if (this.destination) {
syncMessage.sent.destination = this.destination.key;
}
if (this.expirationStartTimestamp) {
syncMessage.sent.expirationStartTimestamp = this.expirationStartTimestamp;
}
if (this.unidentifiedDeliveries) {
const unidentifiedLookup = this.unidentifiedDeliveries.reduce(
(accumulator, item) => {
// eslint-disable-next-line no-param-reassign
accumulator[item.key] = true;
return accumulator;
},
Object.create(null)
);
// Though this field has 'unidenified' in the name, it should have entries for each
// number we sent to.
if (this.sentTo && this.sentTo.length) {
syncMessage.sent.unidentifiedStatus = this.sentTo.map(number => {
const status = new SignalService.SyncMessage.Sent.UnidentifiedDeliveryStatus();
status.destination = number.key;
status.unidentified = Boolean(unidentifiedLookup[number.key]);
return status;
});
}
}
return syncMessage;
}
}
Loading…
Cancel
Save