Disable input bar if a friend request is pending

This commit is contained in:
Niels Andriesse 2019-06-25 11:48:39 +10:00
parent b27dfdf6ce
commit 047a98ad63
5 changed files with 28 additions and 4 deletions

View File

@ -1550,5 +1550,8 @@
<string name="view_friend_request_outgoing_pending_message">You\'ve sent %1$s a friend request</string> <string name="view_friend_request_outgoing_pending_message">You\'ve sent %1$s a friend request</string>
<string name="view_friend_request_outgoing_accepted_message">%1$s accepted your friend request</string> <string name="view_friend_request_outgoing_accepted_message">%1$s accepted your friend request</string>
<string name="view_friend_request_outgoing_expired_message">Your friend request to %1$s has expired</string> <string name="view_friend_request_outgoing_expired_message">Your friend request to %1$s has expired</string>
<!-- Conversation activity -->
<string name="activity_conversation_pending_friend_request_hint">Pending Friend Request…</string>
<string name="activity_conversation_default_hint">New Message</string>
</resources> </resources>

View File

@ -11,7 +11,6 @@ import android.support.v13.view.inputmethod.EditorInfoCompat;
import android.support.v13.view.inputmethod.InputConnectionCompat; import android.support.v13.view.inputmethod.InputConnectionCompat;
import android.support.v13.view.inputmethod.InputContentInfoCompat; import android.support.v13.view.inputmethod.InputContentInfoCompat;
import android.support.v4.os.BuildCompat; import android.support.v4.os.BuildCompat;
import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
@ -20,13 +19,12 @@ import android.text.TextUtils;
import android.text.TextUtils.TruncateAt; import android.text.TextUtils.TruncateAt;
import android.text.style.RelativeSizeSpan; import android.text.style.RelativeSizeSpan;
import android.util.AttributeSet; import android.util.AttributeSet;
import org.thoughtcrime.securesms.logging.Log;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.TransportOption; import org.thoughtcrime.securesms.TransportOption;
import org.thoughtcrime.securesms.components.emoji.EmojiEditText; import org.thoughtcrime.securesms.components.emoji.EmojiEditText;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
public class ComposeText extends EmojiEditText { public class ComposeText extends EmojiEditText {
@ -139,10 +137,12 @@ public class ComposeText extends EmojiEditText {
setInputType(inputType); setInputType(inputType);
setImeOptions(imeOptions); setImeOptions(imeOptions);
/*
setHint(transport.getComposeHint(), setHint(transport.getComposeHint(),
transport.getSimName().isPresent() transport.getSimName().isPresent()
? getContext().getString(R.string.conversation_activity__from_sim_name, transport.getSimName().get()) ? getContext().getString(R.string.conversation_activity__from_sim_name, transport.getSimName().get())
: null); : null);
*/
} }
@Override @Override

View File

@ -255,6 +255,10 @@ public class InputPanel extends LinearLayout
quickCameraToggle.setEnabled(enabled); quickCameraToggle.setEnabled(enabled);
} }
public void setHint(@NonNull String hint) {
composeText.setHint(hint, null);
}
private long onRecordHideEvent() { private long onRecordHideEvent() {
recordLockCancel.setVisibility(View.GONE); recordLockCancel.setVisibility(View.GONE);

View File

@ -426,6 +426,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
MessageNotifier.setVisibleThread(threadId); MessageNotifier.setVisibleThread(threadId);
markThreadAsRead(); markThreadAsRead();
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)));
} }
@ -2002,6 +2004,15 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
attachmentManager.cleanup(); attachmentManager.cleanup();
updateLinkPreviewState(); updateLinkPreviewState();
updateInputPanel();
}
private void updateInputPanel() {
boolean hasPendingFriendRequest = DatabaseFactory.getLokiThreadFriendRequestDatabase(this).hasPendingFriendRequest(threadId);
inputPanel.setEnabled(!hasPendingFriendRequest);
int hintID = hasPendingFriendRequest ? R.string.activity_conversation_pending_friend_request_hint : R.string.activity_conversation_default_hint;
inputPanel.setHint(getResources().getString(hintID));
} }
private void sendMessage() { private void sendMessage() {
@ -2154,7 +2165,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
message = new OutgoingTextMessage(recipient, messageBody, expiresIn, subscriptionId); message = new OutgoingTextMessage(recipient, messageBody, expiresIn, subscriptionId);
} }
// Loki - Always send friend requests if we're not friends with the user // Loki - Always send a friend request if we're not yet friends with the user
LokiThreadFriendRequestStatus friendRequestStatus = DatabaseFactory.getLokiThreadFriendRequestDatabase(context).getFriendRequestStatus(threadId); LokiThreadFriendRequestStatus friendRequestStatus = DatabaseFactory.getLokiThreadFriendRequestDatabase(context).getFriendRequestStatus(threadId);
message.isFriendRequest = (friendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS); message.isFriendRequest = (friendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS);

View File

@ -41,4 +41,10 @@ class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHel
database.insertOrUpdate(tableName, contentValues, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) database.insertOrUpdate(tableName, contentValues, "${Companion.threadID} = ?", arrayOf( threadID.toString() ))
notifyConversationListListeners() notifyConversationListListeners()
} }
fun hasPendingFriendRequest(threadID: Long): Boolean {
val friendRequestStatus = getFriendRequestStatus(threadID)
return friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENDING || friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENT
|| friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_RECEIVED
}
} }