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_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>
<!-- Conversation activity -->
<string name="activity_conversation_pending_friend_request_hint">Pending Friend Request…</string>
<string name="activity_conversation_default_hint">New Message</string>
</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.InputContentInfoCompat;
import android.support.v4.os.BuildCompat;
import android.text.Editable;
import android.text.InputType;
import android.text.Spannable;
import android.text.SpannableString;
@ -20,13 +19,12 @@ import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.text.style.RelativeSizeSpan;
import android.util.AttributeSet;
import org.thoughtcrime.securesms.logging.Log;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.TransportOption;
import org.thoughtcrime.securesms.components.emoji.EmojiEditText;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
public class ComposeText extends EmojiEditText {
@ -139,10 +137,12 @@ public class ComposeText extends EmojiEditText {
setInputType(inputType);
setImeOptions(imeOptions);
/*
setHint(transport.getComposeHint(),
transport.getSimName().isPresent()
? getContext().getString(R.string.conversation_activity__from_sim_name, transport.getSimName().get())
: null);
*/
}
@Override

View file

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

View file

@ -426,6 +426,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
MessageNotifier.setVisibleThread(threadId);
markThreadAsRead();
updateInputPanel();
Log.i(TAG, "onResume() Finished: " + (System.currentTimeMillis() - getIntent().getLongExtra(TIMING_EXTRA, 0)));
}
@ -2002,6 +2004,15 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
attachmentManager.cleanup();
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() {
@ -2154,7 +2165,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
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);
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() ))
notifyConversationListListeners()
}
fun hasPendingFriendRequest(threadID: Long): Boolean {
val friendRequestStatus = getFriendRequestStatus(threadID)
return friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENDING || friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENT
|| friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_RECEIVED
}
}