fix one to one (session) chats with just the body set

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

@ -1137,9 +1137,9 @@
};
window.sendGroupInvitations = (serverInfo, pubkeys) => {
pubkeys.forEach(async pubkey => {
pubkeys.forEach(async pubkeyStr => {
const convo = await ConversationController.getOrCreateAndWait(
pubkey,
pubkeyStr,
'private'
);

@ -1324,59 +1324,86 @@
options.publicSendData = await this.getPublicSendData();
}
options.groupInvitation = groupInvitation;
options.sessionRestoration = sessionRestoration;
const destinationPubkey = new libsession.Types.PubKey(destination);
// Handle Group Invitation Message
if (groupInvitation) {
if (conversationType !== Message.PRIVATE) {
window.console.warning('Cannot send groupInvite to group chat');
const groupNumbers = this.getRecipients();
const promise = (() => {
switch (conversationType) {
case Message.PRIVATE:
return textsecure.messaging.sendMessageToNumber(
destination,
messageBody,
finalAttachments,
quote,
preview,
now,
expireTimer,
profileKey,
{}
);
case Message.GROUP: {
let dest = destination;
let numbers = groupNumbers;
if (this.isMediumGroup()) {
dest = this.id;
numbers = [destination];
options.isMediumGroup = true;
}
return null;
}
return textsecure.messaging.sendMessageToGroup(
dest,
numbers,
messageBody,
finalAttachments,
quote,
preview,
now,
expireTimer,
profileKey,
{}
);
const groupInvitMessage = new libsession.Messages.Outgoing.GroupInvitationMessage(
{
serverName: groupInvitation.name,
channelId: groupInvitation.channelId,
serverAddress: groupInvitation.address,
}
default:
throw new TypeError(
`Invalid conversation type: '${conversationType}'`
);
}
})();
);
// Add the message sending on another queue so that our UI doesn't get blocked
this.queueMessageSend(async () => {
message.send(this.wrapSend(promise));
return libsession
.getMessageQueue()
.sendUsingMultiDevice(destinationPubkey, groupInvitMessage);
}
const chatMessage = new libsession.Messages.Outgoing.ChatMessage({
body,
timestamp: Date.now(),
});
// Start handle ChatMessages (attachments/quote/preview/body)
if (conversationType === Message.PRIVATE) {
await libsession
.getMessageQueue()
.sendUsingMultiDevice(destinationPubkey, chatMessage);
// return textsecure.messaging.sendMessageToNumber(
// destination,
// messageBody,
// finalAttachments,
// quote,
// preview,
// now,
// expireTimer,
// profileKey,
// {}
// );
} else if (conversationType === Message.GROUP) {
// return textsecure.messaging.sendMessageToGroup(
// dest,
// numbers,
// messageBody,
// finalAttachments,
// quote,
// preview,
// now,
// expireTimer,
// profileKey,
// {}
// );
// let dest = destination;
// let numbers = groupNumbers;
if (this.isMediumGroup()) {
// dest = this.id;
// numbers = [destination];
// options.isMediumGroup = true;
throw new Error('To implement');
} else {
const closedGroupChatMessage = new libsession.Messages.Outgoing.ClosedGroupChatMessage(
{
chatMessage,
groupId: destination,
}
);
await libsession
.getMessageQueue()
.sendToGroup(closedGroupChatMessage);
}
} else {
throw new TypeError(
`Invalid conversation type: '${conversationType}'`
);
}
return true;
});
},

@ -14,7 +14,6 @@ const {
map,
set,
omit,
isArrayBuffer,
} = require('lodash');
const _ = require('lodash');
@ -603,11 +602,10 @@ async function removeAllContactSignedPreKeys() {
function signatureToBase64(signature) {
if (typeof signature === 'string') {
return signature;
}
// Ensure signature is ByteBuffer, ArrayBuffer or Uint8Array otherwise throw error
return dcodeIO.ByteBuffer.wrap(signature).toString('base64');
}
// Ensure signature is ByteBuffer, ArrayBuffer or Uint8Array otherwise throw error
return dcodeIO.ByteBuffer.wrap(signature).toString('base64');
}
async function createOrUpdatePairingAuthorisation(data) {

@ -11,6 +11,6 @@ interface DeviceMappingAnnotation {
}
interface LokiFileServerInstance {
getUserDeviceMapping(pubKey: string): Promise<DeviceMappingAnnotation>;
getUserDeviceMapping(pubKey: string): Promise<DeviceMappingAnnotation | null>;
clearOurDeviceMappingAnnotations(): Promise<void>;
}

@ -1,4 +1,4 @@
/* global _, textsecure, WebAPI, libsignal, OutgoingMessage, window, libloki, libsession */
/* global _, textsecure, WebAPI, libsignal, OutgoingMessage, window, libloki */
/* eslint-disable more/no-then, no-bitwise */
@ -351,36 +351,35 @@ MessageSender.prototype = {
});
},
sendMessage(attrs, options) {
async sendMessage(attrs, options) {
const message = new Message(attrs);
const silent = false;
const publicServer =
options.publicSendData && options.publicSendData.serverAPI;
return Promise.all([
await Promise.all([
this.uploadAttachments(message, publicServer),
this.uploadThumbnails(message, publicServer),
this.uploadLinkPreviews(message, publicServer),
]).then(
() =>
new Promise((resolve, reject) => {
this.sendMessageProto(
message.timestamp,
message.recipients,
message.toProto(),
res => {
res.dataMessage = message.toArrayBuffer();
if (res.errors.length > 0) {
reject(res);
} else {
resolve(res);
}
},
silent,
options
);
})
);
]);
return new Promise((resolve, reject) => {
this.sendMessageProto(
message.timestamp,
message.recipients,
message.toProto(),
res => {
res.dataMessage = message.toArrayBuffer();
if (res.errors.length > 0) {
reject(res);
} else {
resolve(res);
}
},
silent,
options
);
});
},
sendMessageProto(
timestamp,

@ -7,7 +7,6 @@
window.textsecure = window.textsecure || {};
async function SyncRequest() {
// this.receiver = receiver;
// this.oncontact = this.onContactSyncComplete.bind(this);
@ -27,7 +26,9 @@
timestamp: Date.now(),
reqestType: CONFIGURATION,
});
await libsession.getMessageQueue().send(user, requestConfigurationSyncMessage);
await libsession
.getMessageQueue()
.send(user, requestConfigurationSyncMessage);
window.log.info('SyncRequest now sending contact sync message...');
const { CONTACTS } = textsecure.protobuf.SyncMessage.Request.Type;

@ -670,7 +670,7 @@ export async function handleMessageEvent(event: any): Promise<void> {
confirm,
source,
isGroupMessage,
primarySource
primarySource.key
).ignore();
});
}

@ -84,6 +84,10 @@ export class MultiDeviceProtocol {
);
// TODO: Filter out invalid authorisations
if (!mapping || !mapping.authorisations) {
return [];
}
return mapping.authorisations.map(
({
primaryDevicePubKey,
@ -144,6 +148,11 @@ export class MultiDeviceProtocol {
): Promise<Array<PubKey>> {
const pubKey = typeof user === 'string' ? new PubKey(user) : user;
const authorisations = await this.getPairingAuthorisations(pubKey);
if (authorisations.length === 0) {
const array: Array<PubKey> = new Array();
array.push(pubKey);
return array;
}
const devices = _.flatMap(
authorisations,
({ primaryDevicePubKey, secondaryDevicePubKey }) => [

Loading…
Cancel
Save