pass the db id to our messagesender message and clean a few files

pull/1205/head
Audric Ackermann 5 years ago
parent c419ff9cd2
commit 6a91d44e08
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1267,6 +1267,7 @@
Message: Whisper.Message, Message: Whisper.Message,
}); });
message.set({ id }); message.set({ id });
message.markPendingSend();
this.set({ this.set({
lastMessage: model.getNotificationText(), lastMessage: model.getNotificationText(),
@ -1307,6 +1308,7 @@
// FIXME audric add back profileKey // FIXME audric add back profileKey
const lokiProfile = this.getOurProfile(); const lokiProfile = this.getOurProfile();
const chatMessage = new libsession.Messages.Outgoing.ChatMessage({ const chatMessage = new libsession.Messages.Outgoing.ChatMessage({
identifier: id,
body: messageBody, body: messageBody,
timestamp: Date.now(), timestamp: Date.now(),
attachments: finalAttachments, attachments: finalAttachments,
@ -1322,10 +1324,7 @@
await message.markMessageSyncOnly(); await message.markMessageSyncOnly();
// sending is done in the 'private' case below // sending is done in the 'private' case below
} }
const options = {};
options.messageType = message.get('type');
options.isPublic = this.isPublic();
if (this.isPublic()) { if (this.isPublic()) {
// FIXME audric add back attachments, quote, preview // FIXME audric add back attachments, quote, preview
const openGroup = { const openGroup = {
@ -1334,6 +1333,7 @@
conversationId: this.id, conversationId: this.id,
}; };
const openGroupParams = { const openGroupParams = {
identifier: id,
body, body,
timestamp: Date.now(), timestamp: Date.now(),
group: openGroup, group: openGroup,
@ -1346,7 +1346,6 @@
return null; return null;
} }
options.sessionRestoration = sessionRestoration;
const destinationPubkey = new libsession.Types.PubKey(destination); const destinationPubkey = new libsession.Types.PubKey(destination);
// Handle Group Invitation Message // Handle Group Invitation Message
if (groupInvitation) { if (groupInvitation) {
@ -1358,6 +1357,8 @@
const groupInvitMessage = new libsession.Messages.Outgoing.GroupInvitationMessage( const groupInvitMessage = new libsession.Messages.Outgoing.GroupInvitationMessage(
{ {
identifier: id,
timestamp: Date.now(),
serverName: groupInvitation.name, serverName: groupInvitation.name,
channelId: groupInvitation.channelId, channelId: groupInvitation.channelId,
serverAddress: groupInvitation.address, serverAddress: groupInvitation.address,
@ -1379,6 +1380,8 @@
if (this.isMediumGroup()) { if (this.isMediumGroup()) {
const mediumGroupChatMessage = new libsession.Messages.Outgoing.MediumGroupChatMessage( const mediumGroupChatMessage = new libsession.Messages.Outgoing.MediumGroupChatMessage(
{ {
identifier: id,
timestamp: chatMessage.timestamp,
chatMessage, chatMessage,
groupId: destination, groupId: destination,
} }
@ -1395,7 +1398,9 @@
} else { } else {
const closedGroupChatMessage = new libsession.Messages.Outgoing.ClosedGroupChatMessage( const closedGroupChatMessage = new libsession.Messages.Outgoing.ClosedGroupChatMessage(
{ {
identifier: id,
chatMessage, chatMessage,
timestamp: chatMessage.timestamp,
groupId: destination, groupId: destination,
} }
); );
@ -1642,6 +1647,7 @@
} }
const expireUpdate = { const expireUpdate = {
identifier: id,
timestamp: message.get('sent_at'), timestamp: message.get('sent_at'),
expireTimer, expireTimer,
profileKey, profileKey,
@ -1822,6 +1828,7 @@
const createParams = { const createParams = {
timestamp: Date.now(), timestamp: Date.now(),
groupId: id, groupId: id,
identifier: messageId,
groupSecretKey: secretKey, groupSecretKey: secretKey,
members: members.map(pkHex => StringView.hexToArrayBuffer(pkHex)), members: members.map(pkHex => StringView.hexToArrayBuffer(pkHex)),
groupName: name, groupName: name,
@ -1833,7 +1840,7 @@
const mediumGroupCreateMessage = new libsession.Messages.Outgoing.MediumGroupCreateMessage( const mediumGroupCreateMessage = new libsession.Messages.Outgoing.MediumGroupCreateMessage(
createParams createParams
); );
message.trigger('pending'); message.markPendingSend();
members.forEach(member => { members.forEach(member => {
const memberPubKey = new libsession.Types.PubKey(member); const memberPubKey = new libsession.Types.PubKey(member);
@ -1847,6 +1854,7 @@
const updateParams = { const updateParams = {
timestamp: Date.now(), timestamp: Date.now(),
identifier: messageId,
groupId: this.id, groupId: this.id,
name: this.get('name'), name: this.get('name'),
avatar: this.get('avatar'), avatar: this.get('avatar'),
@ -1922,6 +1930,7 @@
const quitGroup = { const quitGroup = {
timestamp: Date.now(), timestamp: Date.now(),
groupId: this.id, groupId: this.id,
identifier: id,
}; };
const quitGroupMessage = new libsession.Messages.Outgoing.ClosedGroupLeaveMessage( const quitGroupMessage = new libsession.Messages.Outgoing.ClosedGroupLeaveMessage(
quitGroup quitGroup

@ -991,6 +991,10 @@
}); });
}, },
markPendingSend() {
this.trigger('pending'); // I don't this does anything
},
// One caller today: event handler for the 'Retry Send' entry in triple-dot menu // One caller today: event handler for the 'Retry Send' entry in triple-dot menu
async retrySend() { async retrySend() {
if (!textsecure.messaging) { if (!textsecure.messaging) {
@ -1039,12 +1043,13 @@
// const previewWithData = await loadPreviewData(this.get('preview')); // const previewWithData = await loadPreviewData(this.get('preview'));
const chatMessage = new libsession.Messages.Outgoing.ChatMessage({ const chatMessage = new libsession.Messages.Outgoing.ChatMessage({
body, body,
identifier: this.id,
timestamp: this.get('sent_at'), timestamp: this.get('sent_at'),
expireTimer: this.get('expireTimer'), expireTimer: this.get('expireTimer'),
}); });
// Special-case the self-send case - we send only a sync message // Special-case the self-send case - we send only a sync message
if (recipients.length === 1 && recipients[0] === this.OUR_NUMBER) { if (recipients.length === 1 && recipients[0] === this.OUR_NUMBER) {
this.trigger('pending'); this.markPendingSend();
// FIXME audric add back profileKey // FIXME audric add back profileKey
await this.markMessageSyncOnly(); await this.markMessageSyncOnly();
// sending is done in the private case below // sending is done in the private case below
@ -1053,19 +1058,20 @@
if (conversation.isPrivate()) { if (conversation.isPrivate()) {
const [number] = recipients; const [number] = recipients;
const recipientPubKey = new libsession.Types.PubKey(number); const recipientPubKey = new libsession.Types.PubKey(number);
this.trigger('pending'); this.markPendingSend();
return libsession return libsession
.getMessageQueue() .getMessageQueue()
.sendUsingMultiDevice(recipientPubKey, chatMessage); .sendUsingMultiDevice(recipientPubKey, chatMessage);
} }
this.trigger('pending'); this.markPendingSend();
// TODO should we handle open groups message here too? and mediumgroups // TODO should we handle open groups message here too? and mediumgroups
// Not sure there is the concept of retrySend for those // Not sure there is the concept of retrySend for those
const closedGroupChatMessage = new libsession.Messages.Outgoing.ClosedGroupChatMessage( const closedGroupChatMessage = new libsession.Messages.Outgoing.ClosedGroupChatMessage(
{ {
chatMessage, chatMessage,
identifier: this.id,
groupId: this.get('conversationId'), groupId: this.get('conversationId'),
} }
); );
@ -1126,7 +1132,7 @@
// Special-case the self-send case - we send only a sync message // Special-case the self-send case - we send only a sync message
if (number === this.OUR_NUMBER) { if (number === this.OUR_NUMBER) {
this.trigger('pending'); this.markPendingSend();
await this.markMessageSyncOnly(); await this.markMessageSyncOnly();
// sending is done in the private case below // sending is done in the private case below
} }
@ -1134,7 +1140,7 @@
const recipientPubKey = new libsession.Types.PubKey(number); const recipientPubKey = new libsession.Types.PubKey(number);
if (conversation.isPrivate()) { if (conversation.isPrivate()) {
this.trigger('pending'); this.markPendingSend();
return libsession return libsession
.getMessageQueue() .getMessageQueue()
.sendUsingMultiDevice(recipientPubKey, chatMessage); .sendUsingMultiDevice(recipientPubKey, chatMessage);
@ -1147,7 +1153,7 @@
} }
); );
// resend tries to send the message to that specific user only in the context of a closed group // resend tries to send the message to that specific user only in the context of a closed group
this.trigger('pending'); this.markPendingSend();
return libsession return libsession
.getMessageQueue() .getMessageQueue()
.sendUsingMultiDevice(recipientPubKey, closedGroupChatMessage); .sendUsingMultiDevice(recipientPubKey, closedGroupChatMessage);
@ -1286,92 +1292,7 @@
Message: Whisper.Message, Message: Whisper.Message,
}); });
}, },
send(promise) {
this.trigger('pending');
return promise
.then(async result => {
this.trigger('done');
// This is used by sendSyncMessage, then set to null
if (!this.get('synced') && result.dataMessage) {
this.set({ dataMessage: result.dataMessage });
}
const sentTo = this.get('sent_to') || [];
this.set({
sent_to: _.union(sentTo, result.successfulNumbers),
sent: true,
expirationStartTimestamp: Date.now(),
unidentifiedDeliveries: result.unidentifiedDeliveries,
});
await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message,
});
this.trigger('sent', this);
})
.catch(result => {
this.trigger('done');
if (result.dataMessage) {
this.set({ dataMessage: result.dataMessage });
}
let promises = [];
if (result instanceof Error) {
this.saveErrors(result);
if (result.name === 'SignedPreKeyRotationError') {
promises.push(getAccountManager().rotateSignedPreKey());
} else if (result.name === 'OutgoingIdentityKeyError') {
const c = ConversationController.get(result.number);
promises.push(c.getProfiles());
}
} else {
if (result.successfulNumbers.length > 0) {
const sentTo = this.get('sent_to') || [];
// In groups, we don't treat unregistered users as a user-visible
// error. The message will look successful, but the details
// screen will show that we didn't send to these unregistered users.
const filteredErrors = _.reject(
result.errors,
error => error.name === 'UnregisteredUserError'
);
// We don't start the expiration timer if there are real errors
// left after filtering out all of the unregistered user errors.
const expirationStartTimestamp = filteredErrors.length
? null
: Date.now();
this.saveErrors(filteredErrors);
this.set({
sent_to: _.union(sentTo, result.successfulNumbers),
sent: true,
expirationStartTimestamp,
unidentifiedDeliveries: result.unidentifiedDeliveries,
});
} else {
this.saveErrors(result.errors);
}
promises = promises.concat(
_.map(result.errors, error => {
if (error.name === 'OutgoingIdentityKeyError') {
const c = ConversationController.get(error.number);
promises.push(c.getProfiles());
}
})
);
}
this.trigger('send-error', this.get('errors'));
return Promise.all(promises);
});
},
someRecipientsFailed() { someRecipientsFailed() {
const c = this.getConversation(); const c = this.getConversation();

@ -9,7 +9,8 @@
i18n, i18n,
Whisper, Whisper,
textsecure, textsecure,
Signal Signal,
_
*/ */
// eslint-disable-next-line func-names // eslint-disable-next-line func-names

@ -108,25 +108,6 @@
} }
inherit(ReplayableError, MessageError); inherit(ReplayableError, MessageError);
function UnregisteredUserError(number, httpError) {
this.message = httpError.message;
this.name = 'UnregisteredUserError';
Error.call(this, this.message);
// Maintains proper stack trace, where our error was thrown (only available on V8)
// via https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
if (Error.captureStackTrace) {
Error.captureStackTrace(this);
}
this.number = number;
this.code = httpError.code;
appendStack(this, httpError);
}
inherit(Error, UnregisteredUserError);
function EmptySwarmError(number, message) { function EmptySwarmError(number, message) {
// eslint-disable-next-line prefer-destructuring // eslint-disable-next-line prefer-destructuring
this.number = number.split('.')[0]; this.number = number.split('.')[0];
@ -276,7 +257,6 @@
} }
} }
window.textsecure.UnregisteredUserError = UnregisteredUserError;
window.textsecure.SendMessageNetworkError = SendMessageNetworkError; window.textsecure.SendMessageNetworkError = SendMessageNetworkError;
window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError; window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError;
window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError; window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError;

@ -281,14 +281,7 @@ OutgoingMessage.prototype = {
}).then(results => results.every(value => value === true)); }).then(results => results.every(value => value === true));
}) })
.catch(e => { .catch(e => {
if (e.name === 'HTTPError' && e.code === 404) { throw e;
if (device !== 1) {
return this.removeDeviceIdsForNumber(number, [device]);
}
throw new textsecure.UnregisteredUserError(number, e);
} else {
throw e;
}
}) })
); );
}); });
@ -312,12 +305,7 @@ OutgoingMessage.prototype = {
await lokiMessageAPI.sendMessage(pubKey, data, timestamp, ttl, options); await lokiMessageAPI.sendMessage(pubKey, data, timestamp, ttl, options);
} catch (e) { } catch (e) {
if (e.name === 'HTTPError' && e.code !== 409 && e.code !== 410) { if (e.name === 'HTTPError' && e.code !== 409 && e.code !== 410) {
// 409 and 410 should bubble and be handled by doSendMessage
// 404 should throw UnregisteredUserError
// all other network errors can be retried later.
if (e.code === 404) {
throw new textsecure.UnregisteredUserError(number, e);
}
throw new textsecure.SendMessageNetworkError(number, '', e, timestamp); throw new textsecure.SendMessageNetworkError(number, '', e, timestamp);
} else if (e.name === 'TimedOutError') { } else if (e.name === 'TimedOutError') {
throw new textsecure.PoWError(number, e); throw new textsecure.PoWError(number, e);

Loading…
Cancel
Save