Skip to content

Commit

Permalink
Merge v1.23.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	background.html
#	package.json
#	yarn.lock
  • Loading branch information
Mikunj committed Apr 18, 2019
2 parents 5d91674 + dd13e16 commit 3a81110
Show file tree
Hide file tree
Showing 27 changed files with 967 additions and 579 deletions.
13 changes: 6 additions & 7 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
"Shown in menu for conversation, and moves conversation out of main conversation list"
},
"moveConversationToInbox": {
"message": "Move Converstion to Inbox",
"message": "Move Conversation to Inbox",
"description":
"Undoes Archive Conversation action, and moves archived conversation back to the main conversation list"
},
Expand Down Expand Up @@ -817,6 +817,11 @@
"description":
"When rendering an address, used to provide context to a post office box"
},
"downloading": {
"message": "Downloading",
"description":
"Shown in the message bubble while a long message attachment is being downloaded"
},
"downloadAttachment": {
"message": "Download Attachment",
"description":
Expand Down Expand Up @@ -1316,12 +1321,6 @@
"description":
"Warning notification that this version of the app has expired"
},
"androidMessageLengthWarning": {
"message":
"Android clients will only receive the first 2000 characters of this message.",
"description":
"Warning that long messages could not get received completely by Android clients."
},
"upgrade": {
"message": "Upgrade",
"description":
Expand Down
3 changes: 0 additions & 3 deletions background.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ <h3>{{ welcomeToSignal }}</h3>
<div class='capture-audio hide'>
<button class='microphone' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></button>
</div>
<div class='android-length-warning'>
{{ android-length-warning }}
</div>
<div class='choose-file hide'>
<button class='paperclip thumbnail' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></button>
<input type='file' class='file-input' multiple='multiple'>
Expand Down
26 changes: 19 additions & 7 deletions js/models/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -1293,12 +1293,21 @@
messageWithSchema.attachments.map(loadAttachmentData)
);

const {
body: messageBody,
attachments: finalAttachments,
} = Whisper.Message.getLongMessageAttachment({
body,
attachments: attachmentsWithData,
now,
});

// Special-case the self-send case - we send only a sync message
if (this.isMe()) {
const dataMessage = await textsecure.messaging.getMessageProto(
destination,
body,
attachmentsWithData,
messageBody,
finalAttachments,
quote,
preview,
now,
Expand All @@ -1320,8 +1329,8 @@
case Message.PRIVATE:
return textsecure.messaging.sendMessageToNumber(
destination,
body,
attachmentsWithData,
messageBody,
finalAttachments,
quote,
preview,
now,
Expand All @@ -1333,8 +1342,8 @@
return textsecure.messaging.sendMessageToGroup(
destination,
groupNumbers,
body,
attachmentsWithData,
messageBody,
finalAttachments,
quote,
preview,
now,
Expand Down Expand Up @@ -1649,6 +1658,8 @@
let promise;

if (this.isMe()) {
const flags =
textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE;
const dataMessage = await textsecure.messaging.getMessageProto(
this.get('id'),
null,
Expand All @@ -1657,7 +1668,8 @@
[],
message.get('sent_at'),
expireTimer,
profileKey
profileKey,
flags
);
return message.sendSyncMessageOnly(dataMessage);
}
Expand Down
105 changes: 90 additions & 15 deletions js/models/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
writeAttachment,
upgradeMessageSchema,
} = window.Signal.Migrations;
const { bytesFromString } = window.Signal.Crypto;

window.AccountCache = Object.create(null);
window.AccountJobs = Object.create(null);
Expand Down Expand Up @@ -366,9 +367,12 @@
this.hasExpired = true;
},
getPropsForTimerNotification() {
const { expireTimer, fromSync, source } = this.get(
'expirationTimerUpdate'
);
const timerUpdate = this.get('expirationTimerUpdate');
if (!timerUpdate) {
return null;
}

const { expireTimer, fromSync, source } = timerUpdate;
const timespan = Whisper.ExpirationTimerOptions.getName(expireTimer || 0);
const disabled = !expireTimer;

Expand Down Expand Up @@ -641,6 +645,7 @@

return {
text: this.createNonBreakingLastSeparator(this.get('body')),
textPending: this.get('bodyPending'),
id: this.id,
direction: this.isIncoming() ? 'incoming' : 'outgoing',
timestamp: this.get('sent_at'),
Expand Down Expand Up @@ -1008,6 +1013,12 @@
const attachmentsWithData = await Promise.all(
(this.get('attachments') || []).map(loadAttachmentData)
);
const { body, attachments } = Whisper.Message.getLongMessageAttachment({
body: this.get('body'),
attachments: attachmentsWithData,
now: this.get('sent_at'),
});

const quoteWithData = await loadQuoteData(this.get('quote'));
const previewWithData = await loadPreviewData(this.get('preview'));

Expand All @@ -1016,8 +1027,8 @@
const [number] = numbers;
const dataMessage = await textsecure.messaging.getMessageProto(
number,
this.get('body'),
attachmentsWithData,
body,
attachments,
quoteWithData,
previewWithData,
this.get('sent_at'),
Expand All @@ -1035,8 +1046,8 @@
const [number] = numbers;
promise = textsecure.messaging.sendMessageToNumber(
number,
this.get('body'),
attachmentsWithData,
body,
attachments,
quoteWithData,
previewWithData,
this.get('sent_at'),
Expand All @@ -1051,9 +1062,9 @@
promise = textsecure.messaging.sendMessage(
{
recipients: numbers,
body: this.get('body'),
body,
timestamp: this.get('sent_at'),
attachments: attachmentsWithData,
attachments,
quote: quoteWithData,
preview: previewWithData,
needsSync: !this.get('synced'),
Expand Down Expand Up @@ -1096,15 +1107,21 @@
const attachmentsWithData = await Promise.all(
(this.get('attachments') || []).map(loadAttachmentData)
);
const { body, attachments } = Whisper.Message.getLongMessageAttachment({
body: this.get('body'),
attachments: attachmentsWithData,
now: this.get('sent_at'),
});

const quoteWithData = await loadQuoteData(this.get('quote'));
const previewWithData = await loadPreviewData(this.get('preview'));

// Special-case the self-send case - we send only a sync message
if (number === this.OUR_NUMBER) {
const dataMessage = await textsecure.messaging.getMessageProto(
number,
this.get('body'),
attachmentsWithData,
body,
attachments,
quoteWithData,
previewWithData,
this.get('sent_at'),
Expand All @@ -1119,8 +1136,8 @@
);
const promise = textsecure.messaging.sendMessageToNumber(
number,
this.get('body'),
attachmentsWithData,
body,
attachments,
quoteWithData,
previewWithData,
this.get('sent_at'),
Expand Down Expand Up @@ -1471,9 +1488,34 @@
async queueAttachmentDownloads() {
const messageId = this.id;
let count = 0;
let bodyPending;

const [longMessageAttachments, normalAttachments] = _.partition(
this.get('attachments') || [],
attachment =>
attachment.contentType === Whisper.Message.LONG_MESSAGE_CONTENT_TYPE
);

if (longMessageAttachments.length > 1) {
window.log.error(
`Received more than one long message attachment in message ${this.idForLogging()}`
);
}
if (longMessageAttachments.length > 0) {
count += 1;
bodyPending = true;
await window.Signal.AttachmentDownloads.addJob(
longMessageAttachments[0],
{
messageId,
type: 'long-message',
index: 0,
}
);
}

const attachments = await Promise.all(
(this.get('attachments') || []).map((attachment, index) => {
normalAttachments.map((attachment, index) => {
count += 1;
return window.Signal.AttachmentDownloads.addJob(attachment, {
messageId,
Expand Down Expand Up @@ -1567,7 +1609,7 @@
}

if (count > 0) {
this.set({ attachments, preview, contact, quote, group });
this.set({ bodyPending, attachments, preview, contact, quote, group });

await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message,
Expand Down Expand Up @@ -2081,6 +2123,39 @@
},
});

// Receive will be enabled before we enable send
Whisper.Message.LONG_MESSAGE_SEND_DISABLED = true;
Whisper.Message.LONG_MESSAGE_CONTENT_TYPE = 'text/x-signal-plain';

Whisper.Message.getLongMessageAttachment = ({ body, attachments, now }) => {
if (Whisper.Message.LONG_MESSAGE_SEND_DISABLED) {
return {
body,
attachments,
};
}

if (body.length <= 2048) {
return {
body,
attachments,
};
}

const data = bytesFromString(body);
const attachment = {
contentType: Whisper.Message.LONG_MESSAGE_CONTENT_TYPE,
fileName: `long-message-${now}.txt`,
data,
size: data.byteLength,
};

return {
body: body.slice(0, 2048),
attachments: [attachment, ...attachments],
};
};

Whisper.Message.refreshExpirationTimer = () =>
Whisper.ExpiringMessagesListener.update();

Expand Down
14 changes: 14 additions & 0 deletions js/modules/attachment_downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
saveMessage,
setAttachmentDownloadJobPending,
} = require('./data');
const { stringFromBytes } = require('./crypto');

module.exports = {
start,
Expand Down Expand Up @@ -312,6 +313,19 @@ async function _addAttachmentToMessage(message, attachment, { type, index }) {

const logPrefix = `${message.idForLogging()} (type: ${type}, index: ${index})`;

if (type === 'long-message') {
try {
const { data } = await Signal.Migrations.loadAttachmentData(attachment);
message.set({
body: attachment.isError ? message.get('body') : stringFromBytes(data),
bodyPending: false,
});
} finally {
Signal.Migrations.deleteAttachmentData(attachment.path);
}
return;
}

if (type === 'attachment') {
const attachments = message.get('attachments');
if (!attachments || attachments.length <= index) {
Expand Down
17 changes: 12 additions & 5 deletions js/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
MESSAGE: 'message',
};

function filter(text) {
return (text || '')
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}

Whisper.Notifications = new (Backbone.Collection.extend({
initialize() {
this.isEnabled = false;
Expand Down Expand Up @@ -151,15 +160,13 @@

drawAttention();

const notification = new Notification(title, {
body: message,
this.lastNotification = new Notification(title, {
body: window.platform === 'linux' ? filter(message) : message,
icon: iconUrl,
tag: isNotificationGroupingSupported ? 'signal' : undefined,
silent: !status.shouldPlayNotificationSound,
});
notification.onclick = () =>
this.lastNotification.onclick = () =>
this.trigger('click', last.conversationId, last.id);
this.lastNotification = notification;

// We continue to build up more and more messages for our notifications
// until the user comes back to our app or closes the app. Then we’ll
Expand Down
Loading

0 comments on commit 3a81110

Please sign in to comment.