diff --git a/background.html b/background.html index 8af81e984..4e2c58282 100644 --- a/background.html +++ b/background.html @@ -129,16 +129,16 @@
- - + +
- +
{{ android-length-warning }}
- +
diff --git a/js/models/conversations.js b/js/models/conversations.js index afd7e73ee..9f2ee7562 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -77,6 +77,7 @@ unreadCount: 0, verified: textsecure.storage.protocol.VerifiedStatus.DEFAULT, keyExchangeCompleted: false, + friendRequestStatus: { allowSending: true, unlockTimestamp: null } }; }, @@ -141,6 +142,10 @@ this.on('read', this.updateAndMerge); this.on('expiration-change', this.updateAndMerge); this.on('expired', this.onExpired); + + setTimeout(() => { + this.setFriendRequestTimer(); + }, 0); }, isMe() { @@ -420,6 +425,50 @@ this.set({ keyExchangeCompleted: completed }); }, + getFriendRequestStatus() { + return this.get('friendRequestStatus'); + }, + shouldDisableInputs() { + const status = this.getFriendRequestStatus(); + if (!status) { + return false; + } + return !status.allowSending; + }, + setFriendRequestTimer() { + const friendRequestStatus = this.getFriendRequestStatus(); + if (friendRequestStatus) { + if (!friendRequestStatus.allowSending) { + const delay = Math.max(friendRequestStatus.unlockTimestamp - Date.now(), 0); + setTimeout(() => { + this.friendRequestTimedOut(); + }, delay); + } + } + }, + friendRequestTimedOut() { + let friendRequestStatus = this.getFriendRequestStatus(); + friendRequestStatus.allowSending = true; + this.save({ friendRequestStatus }) + this.trigger('disable:input', false); + }, + friendRequestSent() { + const friendRequestLockDuration = 72; // hours + + let friendRequestStatus = this.getFriendRequestStatus(); + if (!friendRequestStatus) { + friendRequestStatus = {}; + } + + friendRequestStatus.allowSending = false; + const delayMs = 100 * 1000 ;//(60 * 60 * 1000 * friendRequestLockDuration); + friendRequestStatus.unlockTimestamp = Date.now() + delayMs; + this.trigger('disable:input', true); + + setTimeout(() => { this.friendRequestTimedOut() }, delayMs); + + this.save({ friendRequestStatus }) + }, isUnverified() { if (this.isPrivate()) { const verified = this.get('verified'); diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index b26a6bbc6..b7fcc3d14 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -70,6 +70,7 @@ template: $('#conversation').html(), render_attributes() { return { + 'disable-inputs': this.model.shouldDisableInputs(), 'send-message': i18n('sendMessage'), 'android-length-warning': i18n('androidMessageLengthWarning'), }; @@ -80,6 +81,7 @@ this.listenTo(this.model, 'newmessage', this.addMessage); this.listenTo(this.model, 'opened', this.onOpened); this.listenTo(this.model, 'prune', this.onPrune); + this.listenTo(this.model, 'disable:input', this.onDisableInput); this.listenTo( this.model.messageCollection, 'show-identity', @@ -277,6 +279,10 @@ } }, + onDisableInput(disable) { + this.$('button.emoji, button.microphone, button.paperclip, .send-message').attr('disabled', disable); + }, + unload(reason) { window.log.info( 'unloading conversation', diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 665975f1b..0be0a2a77 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -368,15 +368,16 @@ OutgoingMessage.prototype = { return this.getStaleDeviceIdsForNumber(number).then(updateDevices => this.getKeysForNumber(number, updateDevices) .then(async (keysFound) => { + const conversation = ConversationController.get(number); let attachPrekeys = false; if (!keysFound) { log.info("Fallback encryption enabled"); + conversation.friendRequestSent(); this.fallBackEncryption = true; attachPrekeys = true; } else { try { - const conversation = ConversationController.get(number); attachPrekeys = !conversation.isKeyExchangeCompleted(); } catch(e) { // do nothing diff --git a/stylesheets/_conversation.scss b/stylesheets/_conversation.scss index 74094937a..7ffdcfd45 100644 --- a/stylesheets/_conversation.scss +++ b/stylesheets/_conversation.scss @@ -283,7 +283,7 @@ font-family: inherit; &[disabled='disabled'] { - background: transparent; + background: $color-light-35; } } .capture-audio {