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

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

@ -419,53 +419,16 @@ MessageSender.prototype = {
// If however we want to use the results from forEach then // If however we want to use the results from forEach then
// we would need to convert this to a Promise.all(numbers.map(...)) // we would need to convert this to a Promise.all(numbers.map(...))
numbers.forEach(async number => { numbers.forEach(async number => {
// Note: if we are sending a private group message, we do our best to const outgoing = new OutgoingMessage(
// ensure we have signal protocol sessions with every member, but if we this.server,
// fail, let's at least send messages to those members with which we do: timestamp,
const haveSession = _.some( numbers,
textsecure.storage.protocol.sessions, message,
s => s.number === number silent,
callback,
options
); );
this.queueJobForNumber(number, () => outgoing.sendToNumber(number));
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);
}
}
}); });
}, },

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

Loading…
Cancel
Save