fix session requests

pull/1183/head
Audric Ackermann 5 years ago
parent 0a2af13cb1
commit 12bb6673ea
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1141,7 +1141,7 @@ MessageReceiver.prototype.extend({
const device = {
identityKey,
deviceId,
preKey: {...preKey, keyId: preKeyId},
preKey: preKeyObject,
signedPreKey,
registrationId: 0,
};
@ -1172,8 +1172,11 @@ MessageReceiver.prototype.extend({
if (envelope.type === SESSION_REQUEST) {
await this.handleSessionRequestMessage(envelope, content);
} else {
const device = new libsession.Types.PubKey(envelope.source);
await libsession.Protocols.SessionProtocol.onSessionEstablished(
envelope.source
device
);
// TODO process sending queue for this device now that we have a session
}

@ -215,8 +215,7 @@ OutgoingMessage.prototype = {
}
return (
libloki.storage
.getAllDevicePubKeysForPrimaryPubKey(primaryPubKey)
window.libsession.Protocols.MultiDeviceProtocol.getAllDevices(primaryPubKey)
// Don't send to ourselves
.then(devicesPubKeys =>
devicesPubKeys.filter(pubKey => pubKey !== ourNumber)

@ -419,53 +419,16 @@ MessageSender.prototype = {
// If however we want to use the results from forEach then
// we would need to convert this to a Promise.all(numbers.map(...))
numbers.forEach(async number => {
// Note: if we are sending a private group message, we do our best to
// ensure we have signal protocol sessions with every member, but if we
// fail, let's at least send messages to those members with which we do:
const haveSession = _.some(
textsecure.storage.protocol.sessions,
s => s.number === number
const outgoing = new OutgoingMessage(
this.server,
timestamp,
numbers,
message,
silent,
callback,
options
);
let keysFound = false;
// If we don't have a session but we already have prekeys to
// start communication then we should use them
if (!haveSession && !options.isPublic && !options.isMediumGroup) {
keysFound = await hasKeys(number);
}
if (
number === ourNumber ||
haveSession ||
keysFound ||
options.isPublic ||
options.isMediumGroup
) {
const outgoing = new OutgoingMessage(
this.server,
timestamp,
numbers,
message,
silent,
callback,
options
);
this.queueJobForNumber(number, () => outgoing.sendToNumber(number));
} else {
window.log.error(`No session for number: ${number}`);
const isGroupMessage = !!(
message &&
message.dataMessage &&
message.dataMessage.group
);
// If it was a message to a group then we need to send a session request
if (isGroupMessage || options.autoSession) {
const sessionRequestMessage = textsecure.OutgoingMessage.buildSessionRequestMessage(
number
);
sessionRequestMessage.sendToNumber(number);
}
}
this.queueJobForNumber(number, () => outgoing.sendToNumber(number));
});
},

@ -46,6 +46,8 @@ export class MessageQueue implements MessageQueueInterface {
devices: Array<PubKey>,
message: ContentMessage
) {
await this.pendingMessageCache.isReady;
let currentDevices = [...devices];
// Sync to our devices if syncable
@ -82,6 +84,7 @@ export class MessageQueue implements MessageQueueInterface {
) {
return false;
}
await this.pendingMessageCache.isReady;
// Closed groups
if (message instanceof ClosedGroupMessage) {
@ -115,6 +118,7 @@ export class MessageQueue implements MessageQueueInterface {
}
public async sendSyncMessage(message: ContentMessage, sendTo: Array<PubKey>) {
await this.pendingMessageCache.isReady;
// Sync with our devices
const promises = sendTo.map(async device => {
const syncMessage = SyncMessageUtils.from(message);
@ -126,6 +130,7 @@ export class MessageQueue implements MessageQueueInterface {
}
public async processPending(device: PubKey) {
await this.pendingMessageCache.isReady;
const messages = this.pendingMessageCache.getForDevice(device);
const isMediumGroup = GroupUtils.isMediumGroup(device);
@ -156,7 +161,6 @@ export class MessageQueue implements MessageQueueInterface {
}
private async processAllPending() {
await this.pendingMessageCache.isReady;
const devices = this.pendingMessageCache.getDevices();
const promises = devices.map(async device => this.processPending(device));

Loading…
Cancel
Save