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) => { window.sendGroupInvitations = (serverInfo, pubkeys) => {
pubkeys.forEach(async pubkey => { pubkeys.forEach(async pubkeyStr => {
const convo = await ConversationController.getOrCreateAndWait( const convo = await ConversationController.getOrCreateAndWait(
pubkey, pubkeyStr,
'private' 'private'
); );

@ -1324,59 +1324,86 @@
options.publicSendData = await this.getPublicSendData(); options.publicSendData = await this.getPublicSendData();
} }
options.groupInvitation = groupInvitation;
options.sessionRestoration = sessionRestoration; 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(); return null;
}
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 textsecure.messaging.sendMessageToGroup( const groupInvitMessage = new libsession.Messages.Outgoing.GroupInvitationMessage(
dest, {
numbers, serverName: groupInvitation.name,
messageBody, channelId: groupInvitation.channelId,
finalAttachments, serverAddress: groupInvitation.address,
quote,
preview,
now,
expireTimer,
profileKey,
{}
);
} }
default: );
throw new TypeError(
`Invalid conversation type: '${conversationType}'`
);
}
})();
// Add the message sending on another queue so that our UI doesn't get blocked return libsession
this.queueMessageSend(async () => { .getMessageQueue()
message.send(this.wrapSend(promise)); .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; return true;
}); });
}, },

@ -14,7 +14,6 @@ const {
map, map,
set, set,
omit, omit,
isArrayBuffer,
} = require('lodash'); } = require('lodash');
const _ = require('lodash'); const _ = require('lodash');
@ -603,11 +602,10 @@ async function removeAllContactSignedPreKeys() {
function signatureToBase64(signature) { function signatureToBase64(signature) {
if (typeof signature === 'string') { if (typeof signature === 'string') {
return signature; 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) { async function createOrUpdatePairingAuthorisation(data) {

@ -11,6 +11,6 @@ interface DeviceMappingAnnotation {
} }
interface LokiFileServerInstance { interface LokiFileServerInstance {
getUserDeviceMapping(pubKey: string): Promise<DeviceMappingAnnotation>; getUserDeviceMapping(pubKey: string): Promise<DeviceMappingAnnotation | null>;
clearOurDeviceMappingAnnotations(): Promise<void>; 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 */ /* 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 message = new Message(attrs);
const silent = false; const silent = false;
const publicServer = const publicServer =
options.publicSendData && options.publicSendData.serverAPI; options.publicSendData && options.publicSendData.serverAPI;
return Promise.all([ await Promise.all([
this.uploadAttachments(message, publicServer), this.uploadAttachments(message, publicServer),
this.uploadThumbnails(message, publicServer), this.uploadThumbnails(message, publicServer),
this.uploadLinkPreviews(message, publicServer), this.uploadLinkPreviews(message, publicServer),
]).then( ]);
() =>
new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.sendMessageProto( this.sendMessageProto(
message.timestamp, message.timestamp,
message.recipients, message.recipients,
message.toProto(), message.toProto(),
res => { res => {
res.dataMessage = message.toArrayBuffer(); res.dataMessage = message.toArrayBuffer();
if (res.errors.length > 0) { if (res.errors.length > 0) {
reject(res); reject(res);
} else { } else {
resolve(res); resolve(res);
} }
}, },
silent, silent,
options options
); );
}) });
);
}, },
sendMessageProto( sendMessageProto(
timestamp, timestamp,

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

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

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

Loading…
Cancel
Save