make it possible to set a client-side nickname

This commit is contained in:
Ryan ZHAO 2021-04-22 14:41:00 +10:00
parent d78dc83307
commit b94597a1f6
4 changed files with 39 additions and 6 deletions

View File

@ -56,7 +56,9 @@ import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
@ -91,6 +93,7 @@ import org.session.libsession.messaging.sending_receiving.attachments.Attachment
import org.session.libsession.messaging.threads.DistributionTypes;
import org.session.libsession.utilities.GroupUtil;
import org.session.libsession.utilities.MediaTypes;
import org.session.libsession.utilities.SSKEnvironment;
import org.session.libsignal.libsignal.InvalidMessageException;
import org.session.libsignal.libsignal.util.guava.Optional;
import org.session.libsignal.service.loki.api.opengroups.PublicChat;
@ -258,7 +261,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private ImageButton sendButton;
private ImageButton attachButton;
private ProfilePictureView profilePictureView;
private TextView titleTextView;
private EditText titleTextView;
private ConversationFragment fragment;
private Button unblockButton;
private Button makeDefaultSmsButton;
@ -374,6 +377,35 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
}
});
if (isGroupConversation()) {
titleTextView.setEnabled(false);
} else {
titleTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
titleTextView.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE) {
String nickname = v.getText().toString().trim();
SSKEnvironment.shared.getProfileManager().setDisplayName(this, getRecipient(), nickname);
v.clearFocus();
return true;
}
return false;
});
titleTextView.setOnFocusChangeListener((v, hasFocus) -> {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (!hasFocus) {
EditText textView = (EditText) v;
if (textView.getText().toString().isEmpty()) {
textView.setText(getRecipient().getName());
}
imm.hideSoftInputFromWindow(v.getWindowToken(),0);
} else {
String nickname = DatabaseFactory.getStorage(this).getDisplayName(getRecipient().getAddress().serialize());
titleTextView.setText(nickname);
imm.showSoftInput(v, 0);
}
});
}
MentionManagerUtilities.INSTANCE.populateUserPublicKeyCacheIfNeeded(threadId, this);
PublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(this).getPublicChat(threadId);

View File

@ -11,7 +11,7 @@ class ProfileManager: SSKEnvironment.ProfileManagerProtocol {
override fun setDisplayName(context: Context, recipient: Recipient, displayName: String) {
val database = DatabaseFactory.getLokiUserDatabase(context)
val publicKey = recipient.address.serialize()
if (recipient.profileName == null) {
if (recipient.name == null) {
// Migrate the profile name in LokiUserDatabase to recipient
database.getDisplayName(publicKey)?.let { setProfileName(context, recipient, it) }
}

View File

@ -51,15 +51,18 @@
android:layout_marginStart="@dimen/medium_spacing"
android:orientation="vertical">
<TextView
<EditText
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:maxLines="1"
android:ellipsize="end"
android:text="Conversation"
android:hint="Enter a name"
android:textColor="@color/text"
android:textSize="@dimen/large_font_size"
android:inputType="text"
android:fontFamily="sans-serif-medium" />
<LinearLayout

View File

@ -287,9 +287,7 @@ public class Recipient implements RecipientModifiedListener {
public synchronized @Nullable String getName() {
String displayName = MessagingConfiguration.shared.getStorage().getDisplayName(this.address.toString());
if (displayName != null) { return displayName; }
if (this.profileName != null) { return this.profileName; }
if (displayName != null && !displayName.isEmpty()) { return displayName; }
if (this.name == null && isMmsGroupRecipient()) {
List<String> names = new LinkedList<>();