Fix conversation input.

This commit is contained in:
Mikunj Varsani 2019-11-13 16:05:37 +11:00
parent 9c243eed75
commit a90b0e70f5
2 changed files with 22 additions and 20 deletions

View File

@ -329,7 +329,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
protected HidingLinearLayout quickAttachmentToggle; protected HidingLinearLayout quickAttachmentToggle;
protected HidingLinearLayout inlineAttachmentToggle; protected HidingLinearLayout inlineAttachmentToggle;
private InputPanel inputPanel; private InputPanel inputPanel;
private boolean alwaysEnableInputPanel = false;
private LinkPreviewViewModel linkPreviewViewModel; private LinkPreviewViewModel linkPreviewViewModel;
private ConversationSearchViewModel searchViewModel; private ConversationSearchViewModel searchViewModel;
@ -354,6 +353,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private ArrayList<Mention> mentions = new ArrayList<>(); private ArrayList<Mention> mentions = new ArrayList<>();
private String oldText = ""; private String oldText = "";
// Multi Device
private boolean isFriendsWithAnyDevice = false;
@Override @Override
protected void onPreCreate() { protected void onPreCreate() {
@ -2204,13 +2205,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private void updateInputPanel() { private void updateInputPanel() {
/* /*
alwaysEnableInputPanel caches whether we have enabled the input once. isFriendsWithAnyDevice caches whether we are friends with any of the other users device.
This stops the case where the input panel disables and enables rapidly. This stops the case where the input panel disables and enables rapidly.
- This can occur when we are not friends with the current thread BUT multi-device tells us that we are friends with another one of their devices. - This can occur when we are not friends with the current thread BUT multi-device tells us that we are friends with another one of their devices.
*/ */
if (recipient.isGroupRecipient() || isNoteToSelf() || isFriendsWithAnyDevice) {
if (recipient.isGroupRecipient() || isNoteToSelf() || alwaysEnableInputPanel) {
setInputPanelEnabled(true); setInputPanelEnabled(true);
return; return;
} }
@ -2220,13 +2220,23 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
boolean isPending = friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENDING || friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENT || friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_RECEIVED; boolean isPending = friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENDING || friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENT || friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_RECEIVED;
setInputPanelEnabled(!isPending); setInputPanelEnabled(!isPending);
alwaysEnableInputPanel = friendRequestStatus == LokiThreadFriendRequestStatus.FRIENDS; // We should always have the input panel enabled if we are friends with the current user
isFriendsWithAnyDevice = friendRequestStatus == LokiThreadFriendRequestStatus.FRIENDS;
// This promise correctly updates the UI for multidevice // Multi-device input logic
if (friendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS) { if (!isFriendsWithAnyDevice) {
MultiDeviceUtilities.shouldEnableUserInput(this, recipient).success(shouldEnableInput -> { // We should enable the input if we don't have any pending friend requests OR we are friends with a linked device
alwaysEnableInputPanel = shouldEnableInput; MultiDeviceUtilities.hasPendingFriendRequestWithAnyLinkedDevice(this, recipient).success(hasPendingRequests -> {
setInputPanelEnabled(shouldEnableInput); if (!hasPendingRequests) {
setInputPanelEnabled(true);
} else {
MultiDeviceUtilities.isFriendsWithAnyLinkedDevice(this, recipient).success(isFriends -> {
// If we are friend with any of the other devices then we want to make sure the input panel is always enabled for the duration of this conversation
isFriendsWithAnyDevice = isFriends;
setInputPanelEnabled(isFriends);
return Unit.INSTANCE;
});
}
return Unit.INSTANCE; return Unit.INSTANCE;
}); });
} }
@ -2447,9 +2457,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
} }
private void updateToggleButtonState() { private void updateToggleButtonState() {
// Don't allow attachments if we're not friends // Don't allow attachments if we're not friends with any device
LokiThreadFriendRequestStatus friendRequestStatus = DatabaseFactory.getLokiThreadDatabase(this).getFriendRequestStatus(threadId); if (!isNoteToSelf() && !recipient.isGroupRecipient() && !isFriendsWithAnyDevice) {
if (!isNoteToSelf() && !recipient.isGroupRecipient() && friendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS) {
buttonToggle.display(sendButton); buttonToggle.display(sendButton);
quickAttachmentToggle.hide(); quickAttachmentToggle.hide();
inlineAttachmentToggle.hide(); inlineAttachmentToggle.hide();

View File

@ -185,10 +185,3 @@ fun hasPendingFriendRequestWithAnyLinkedDevice(context: Context, recipient: Reci
false false
} }
} }
fun shouldEnableUserInput(context: Context, recipient: Recipient): Promise<Boolean, Exception> {
// Input should be enabled if we don't have any pending requests OR we're friends with any linked device
return hasPendingFriendRequestWithAnyLinkedDevice(context, recipient).bind { hasPendingFriendRequest ->
if (!hasPendingFriendRequest) Promise.of(true) else isFriendsWithAnyLinkedDevice(context, recipient)
}.recover { true }
}