Lock text input while waiting for friend request reply

pull/14/head
sachaaaaa 7 years ago
parent 886f47b8e7
commit d4d0d05adf

@ -129,16 +129,16 @@
<form class='send clearfix'> <form class='send clearfix'>
<div class='attachment-previews'></div> <div class='attachment-previews'></div>
<div class='flex'> <div class='flex'>
<button class='emoji'></button> <button class='emoji' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></button>
<textarea class='send-message' placeholder='{{ send-message }}' rows='1' dir='auto'></textarea> <textarea class='send-message' placeholder='{{ send-message }}' rows='1' dir='auto' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></textarea>
<div class='capture-audio'> <div class='capture-audio'>
<button class='microphone'></button> <button class='microphone' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></button>
</div> </div>
<div class='android-length-warning'> <div class='android-length-warning'>
{{ android-length-warning }} {{ android-length-warning }}
</div> </div>
<div class='choose-file'> <div class='choose-file'>
<button class='paperclip thumbnail'></button> <button class='paperclip thumbnail' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></button>
<input type='file' class='file-input'> <input type='file' class='file-input'>
</div> </div>
</div> </div>

@ -77,6 +77,7 @@
unreadCount: 0, unreadCount: 0,
verified: textsecure.storage.protocol.VerifiedStatus.DEFAULT, verified: textsecure.storage.protocol.VerifiedStatus.DEFAULT,
keyExchangeCompleted: false, keyExchangeCompleted: false,
friendRequestStatus: { allowSending: true, unlockTimestamp: null }
}; };
}, },
@ -141,6 +142,10 @@
this.on('read', this.updateAndMerge); this.on('read', this.updateAndMerge);
this.on('expiration-change', this.updateAndMerge); this.on('expiration-change', this.updateAndMerge);
this.on('expired', this.onExpired); this.on('expired', this.onExpired);
setTimeout(() => {
this.setFriendRequestTimer();
}, 0);
}, },
isMe() { isMe() {
@ -420,6 +425,50 @@
this.set({ keyExchangeCompleted: completed }); 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() { isUnverified() {
if (this.isPrivate()) { if (this.isPrivate()) {
const verified = this.get('verified'); const verified = this.get('verified');

@ -70,6 +70,7 @@
template: $('#conversation').html(), template: $('#conversation').html(),
render_attributes() { render_attributes() {
return { return {
'disable-inputs': this.model.shouldDisableInputs(),
'send-message': i18n('sendMessage'), 'send-message': i18n('sendMessage'),
'android-length-warning': i18n('androidMessageLengthWarning'), 'android-length-warning': i18n('androidMessageLengthWarning'),
}; };
@ -80,6 +81,7 @@
this.listenTo(this.model, 'newmessage', this.addMessage); this.listenTo(this.model, 'newmessage', this.addMessage);
this.listenTo(this.model, 'opened', this.onOpened); this.listenTo(this.model, 'opened', this.onOpened);
this.listenTo(this.model, 'prune', this.onPrune); this.listenTo(this.model, 'prune', this.onPrune);
this.listenTo(this.model, 'disable:input', this.onDisableInput);
this.listenTo( this.listenTo(
this.model.messageCollection, this.model.messageCollection,
'show-identity', 'show-identity',
@ -277,6 +279,10 @@
} }
}, },
onDisableInput(disable) {
this.$('button.emoji, button.microphone, button.paperclip, .send-message').attr('disabled', disable);
},
unload(reason) { unload(reason) {
window.log.info( window.log.info(
'unloading conversation', 'unloading conversation',

@ -368,15 +368,16 @@ OutgoingMessage.prototype = {
return this.getStaleDeviceIdsForNumber(number).then(updateDevices => return this.getStaleDeviceIdsForNumber(number).then(updateDevices =>
this.getKeysForNumber(number, updateDevices) this.getKeysForNumber(number, updateDevices)
.then(async (keysFound) => { .then(async (keysFound) => {
const conversation = ConversationController.get(number);
let attachPrekeys = false; let attachPrekeys = false;
if (!keysFound) if (!keysFound)
{ {
log.info("Fallback encryption enabled"); log.info("Fallback encryption enabled");
conversation.friendRequestSent();
this.fallBackEncryption = true; this.fallBackEncryption = true;
attachPrekeys = true; attachPrekeys = true;
} else { } else {
try { try {
const conversation = ConversationController.get(number);
attachPrekeys = !conversation.isKeyExchangeCompleted(); attachPrekeys = !conversation.isKeyExchangeCompleted();
} catch(e) { } catch(e) {
// do nothing // do nothing

@ -283,7 +283,7 @@
font-family: inherit; font-family: inherit;
&[disabled='disabled'] { &[disabled='disabled'] {
background: transparent; background: $color-light-35;
} }
} }
.capture-audio { .capture-audio {

Loading…
Cancel
Save