Block input if a friend request is pending

This commit is contained in:
Niels Andriesse 2019-07-19 13:15:17 +10:00
parent b123948230
commit 8c054a060e
5 changed files with 30 additions and 6 deletions

View File

@ -54,7 +54,7 @@ public class InputPanel extends LinearLayout
private QuoteView quoteView; private QuoteView quoteView;
private LinkPreviewView linkPreview; private LinkPreviewView linkPreview;
private EmojiToggle emojiToggle; private EmojiToggle emojiToggle;
private ComposeText composeText; public ComposeText composeText;
private View quickCameraToggle; private View quickCameraToggle;
private View quickAudioToggle; private View quickAudioToggle;
private View buttonToggle; private View buttonToggle;

View File

@ -38,6 +38,7 @@ import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Browser; import android.provider.Browser;
import android.provider.ContactsContract; import android.provider.ContactsContract;
@ -66,6 +67,7 @@ import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener; import android.view.View.OnKeyListener;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.TextView; import android.widget.TextView;
@ -152,6 +154,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel; import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.FriendRequestViewDelegate; import org.thoughtcrime.securesms.loki.FriendRequestViewDelegate;
import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestDatabaseDelegate;
import org.thoughtcrime.securesms.mediasend.Media; import org.thoughtcrime.securesms.mediasend.Media;
import org.thoughtcrime.securesms.mediasend.MediaSendActivity; import org.thoughtcrime.securesms.mediasend.MediaSendActivity;
import org.thoughtcrime.securesms.mms.AttachmentManager; import org.thoughtcrime.securesms.mms.AttachmentManager;
@ -249,6 +252,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
InputPanel.MediaListener, InputPanel.MediaListener,
ComposeText.CursorPositionChangedListener, ComposeText.CursorPositionChangedListener,
ConversationSearchBottomBar.EventListener, ConversationSearchBottomBar.EventListener,
LokiThreadFriendRequestDatabaseDelegate,
FriendRequestViewDelegate FriendRequestViewDelegate
{ {
private static final String TAG = ConversationActivity.class.getSimpleName(); private static final String TAG = ConversationActivity.class.getSimpleName();
@ -435,6 +439,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
MessageNotifier.setVisibleThread(threadId); MessageNotifier.setVisibleThread(threadId);
markThreadAsRead(); markThreadAsRead();
DatabaseFactory.getLokiThreadFriendRequestDatabase(this).setDelegate(this);
updateInputPanel(); updateInputPanel();
Log.i(TAG, "onResume() Finished: " + (System.currentTimeMillis() - getIntent().getLongExtra(TIMING_EXTRA, 0))); Log.i(TAG, "onResume() Finished: " + (System.currentTimeMillis() - getIntent().getLongExtra(TIMING_EXTRA, 0)));
@ -451,6 +456,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
markLastSeen(); markLastSeen();
AudioSlidePlayer.stopAll(); AudioSlidePlayer.stopAll();
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
DatabaseFactory.getLokiThreadFriendRequestDatabase(this).setDelegate(null);
} }
@Override @Override
@ -1588,7 +1595,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
recipient.addListener(this); recipient.addListener(this);
} }
private void initializeLinkPreviewObserver() { private void initializeLinkPreviewObserver() {
linkPreviewViewModel = ViewModelProviders.of(this, new LinkPreviewViewModel.Factory(new LinkPreviewRepository())).get(LinkPreviewViewModel.class); linkPreviewViewModel = ViewModelProviders.of(this, new LinkPreviewViewModel.Factory(new LinkPreviewRepository())).get(LinkPreviewViewModel.class);
@ -2013,8 +2019,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
attachmentManager.cleanup(); attachmentManager.cleanup();
updateLinkPreviewState(); updateLinkPreviewState();
}
updateInputPanel(); @Override
public void handleThreadFriendRequestStatusChanged(long threadID) {
if (threadID != this.threadId) { return; }
new Handler(getMainLooper()).post(this::updateInputPanel);
} }
private void updateInputPanel() { private void updateInputPanel() {
@ -2022,6 +2032,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
inputPanel.setEnabled(!hasPendingFriendRequest); inputPanel.setEnabled(!hasPendingFriendRequest);
int hintID = hasPendingFriendRequest ? R.string.activity_conversation_pending_friend_request_hint : R.string.activity_conversation_default_hint; int hintID = hasPendingFriendRequest ? R.string.activity_conversation_pending_friend_request_hint : R.string.activity_conversation_default_hint;
inputPanel.setHint(getResources().getString(hintID)); inputPanel.setHint(getResources().getString(hintID));
if (!hasPendingFriendRequest) {
inputPanel.composeText.requestFocus();
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(inputPanel.composeText, 0);
}
} }
private void sendMessage() { private void sendMessage() {

View File

@ -9,6 +9,7 @@ import org.whispersystems.signalservice.loki.messaging.LokiThreadDatabaseProtoco
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus
class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiThreadDatabaseProtocol { class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiThreadDatabaseProtocol {
var delegate: LokiThreadFriendRequestDatabaseDelegate? = null
companion object { companion object {
private val tableName = "loki_thread_friend_request_database" private val tableName = "loki_thread_friend_request_database"
@ -40,6 +41,8 @@ class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHel
contentValues.put(Companion.friendRequestStatus, friendRequestStatus.rawValue) contentValues.put(Companion.friendRequestStatus, friendRequestStatus.rawValue)
database.insertOrUpdate(tableName, contentValues, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) database.insertOrUpdate(tableName, contentValues, "${Companion.threadID} = ?", arrayOf( threadID.toString() ))
notifyConversationListListeners() notifyConversationListListeners()
notifyConversationListeners(threadID)
delegate?.handleThreadFriendRequestStatusChanged(threadID)
} }
fun hasPendingFriendRequest(threadID: Long): Boolean { fun hasPendingFriendRequest(threadID: Long): Boolean {

View File

@ -0,0 +1,6 @@
package org.thoughtcrime.securesms.loki
interface LokiThreadFriendRequestDatabaseDelegate {
fun handleThreadFriendRequestStatusChanged(threadID: Long)
}