diff --git a/_locales/en/messages.json b/_locales/en/messages.json index c9b9e7c2a..10e36976d 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -816,6 +816,14 @@ "message": "Send a message", "description": "Placeholder text in the message entry field" }, + "sendMessageDisabled": { + "message": "Waiting for friend request approval", + "description": "Placeholder text in the message entry field when it is disabled while we are waiting for a friend request approval" + }, + "sendMessageFriendRequest": { + "message": "Hi there! This is !", + "description": "Placeholder text in the message entry field when it is the first message sent to that contact" + }, "groupMembers": { "message": "Group members" }, diff --git a/js/models/conversations.js b/js/models/conversations.js index 9f2ee7562..33aadb89d 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -428,12 +428,12 @@ getFriendRequestStatus() { return this.get('friendRequestStatus'); }, - shouldDisableInputs() { - const status = this.getFriendRequestStatus(); - if (!status) { + waitingForFriendRequestApproval() { + const friendRequestStatus = this.getFriendRequestStatus(); + if (!friendRequestStatus) { return false; } - return !status.allowSending; + return !friendRequestStatus.allowSending; }, setFriendRequestTimer() { const friendRequestStatus = this.getFriendRequestStatus(); @@ -441,18 +441,24 @@ if (!friendRequestStatus.allowSending) { const delay = Math.max(friendRequestStatus.unlockTimestamp - Date.now(), 0); setTimeout(() => { - this.friendRequestTimedOut(); + this.onFriendRequestTimedOut(); }, delay); } } }, - friendRequestTimedOut() { + onFriendRequestAccepted() { + this.save({ friendRequestStatus: null }) + this.trigger('disable:input', false); + this.trigger('change:placeholder', 'chat'); + }, + onFriendRequestTimedOut() { let friendRequestStatus = this.getFriendRequestStatus(); friendRequestStatus.allowSending = true; this.save({ friendRequestStatus }) this.trigger('disable:input', false); + this.trigger('change:placeholder', 'friend-request'); }, - friendRequestSent() { + onFriendRequestSent() { const friendRequestLockDuration = 72; // hours let friendRequestStatus = this.getFriendRequestStatus(); @@ -464,8 +470,9 @@ const delayMs = 100 * 1000 ;//(60 * 60 * 1000 * friendRequestLockDuration); friendRequestStatus.unlockTimestamp = Date.now() + delayMs; this.trigger('disable:input', true); + this.trigger('change:placeholder', 'disabled'); - setTimeout(() => { this.friendRequestTimedOut() }, delayMs); + setTimeout(() => { this.onFriendRequestTimedOut() }, delayMs); this.save({ friendRequestStatus }) }, diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index b7fcc3d14..05d609e78 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -69,9 +69,16 @@ }, template: $('#conversation').html(), render_attributes() { + let sendMessagePlaceholder = 'sendMessageFriendRequest'; + const sendDisabled = this.model.waitingForFriendRequestApproval(); + if (sendDisabled) { + sendMessagePlaceholder = 'sendMessageDisabled'; + } else if (this.model.getFriendRequestStatus() === null) { + sendMessagePlaceholder = 'sendMessage'; + } return { - 'disable-inputs': this.model.shouldDisableInputs(), - 'send-message': i18n('sendMessage'), + 'disable-inputs': sendDisabled, + 'send-message': i18n(sendMessagePlaceholder), 'android-length-warning': i18n('androidMessageLengthWarning'), }; }, @@ -82,6 +89,7 @@ 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, 'change:placeholder', this.onChangePlaceholder); this.listenTo( this.model.messageCollection, 'show-identity', @@ -283,6 +291,22 @@ this.$('button.emoji, button.microphone, button.paperclip, .send-message').attr('disabled', disable); }, + onChangePlaceholder(type) { + let placeholder; + switch (type) { + case 'friend-request': + placeholder = i18n('sendMessageFriendRequest'); + break; + case 'disabled': + placeholder = i18n('sendMessageDisabled'); + break; + default: + placeholder = i18n('sendMessage'); + break; + } + this.$messageField.attr('placeholder', placeholder); + }, + unload(reason) { window.log.info( 'unloading conversation', diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 0be0a2a77..3303d7be2 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -373,7 +373,7 @@ OutgoingMessage.prototype = { if (!keysFound) { log.info("Fallback encryption enabled"); - conversation.friendRequestSent(); + conversation.onFriendRequestSent(); this.fallBackEncryption = true; attachPrekeys = true; } else {