Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
fix #444
Browse files Browse the repository at this point in the history
Strip ' (IRC)' when autocompleting
  • Loading branch information
ylecollen committed Sep 2, 2016
1 parent 9d67090 commit bbacfad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
32 changes: 18 additions & 14 deletions vector/src/main/java/im/vector/activity/VectorRoomActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ protected void onActivityResult(int requestCode, int resultCode, final Intent da
if ((requestCode == REQUEST_FILES_REQUEST_CODE) || (requestCode == TAKE_IMAGE_REQUEST_CODE)) {
sendMediasIntent(data);
} else if (requestCode == GET_MENTION_REQUEST_CODE) {
appendInTextEditor(data.getStringExtra(VectorMemberDetailsActivity.RESULT_MENTION_ID));
insertUserDisplayenInTextEditor(data.getStringExtra(VectorMemberDetailsActivity.RESULT_MENTION_ID));
} else if (requestCode == REQUEST_ROOM_AVATAR_CODE) {
onActivityResultRoomAvatarUpdate(data);
}
Expand Down Expand Up @@ -1657,29 +1657,33 @@ private void refreshSelfAvatar() {
}

/**
* Insert a text in the message editor.
* @param text the text to insert.
* Sanitize the display name.
* @param displayName the display name to sanitize
* @return the sanitized display name
*/
public void insertInTextEditor(String text) {
if (null != text) {
if (TextUtils.isEmpty(mEditText.getText())) {
mEditText.append(text + ": ");
} else {
mEditText.getText().insert(mEditText.getSelectionStart(), text);
private static String sanitizeDisplayname(String displayName) {
// sanity checks
if (!TextUtils.isEmpty(displayName)) {
final String ircPattern = " (IRC)";

if (displayName.endsWith(ircPattern)) {
displayName = displayName.substring(0, displayName.length() - ircPattern.length());
}
}

return displayName;
}

/**
* Append a text in the message editor.
* @param text the text to append
* Insert a text in the message editor.
* @param text the text to insert.
*/
private void appendInTextEditor(String text) {
public void insertUserDisplayenInTextEditor(String text) {
if (null != text) {
if (TextUtils.isEmpty(mEditText.getText())) {
mEditText.append(text + ": ");
mEditText.append(sanitizeDisplayname(text) + ": ");
} else {
mEditText.append(text + " ");
mEditText.getText().insert(mEditText.getSelectionStart(), sanitizeDisplayname(text) + " ");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ public boolean onAvatarLongClick(String userId) {
if (null != state) {
String displayName = state.getMemberName(userId);
if (!TextUtils.isEmpty(displayName)) {
((VectorRoomActivity)getActivity()).insertInTextEditor(displayName);
((VectorRoomActivity)getActivity()).insertUserDisplayenInTextEditor(displayName);
}
}
}
Expand All @@ -744,7 +744,7 @@ public boolean onAvatarLongClick(String userId) {
@Override
public void onSenderNameClick(String userId, String displayName) {
if (getActivity() instanceof VectorRoomActivity) {
((VectorRoomActivity)getActivity()).insertInTextEditor(displayName);
((VectorRoomActivity)getActivity()).insertUserDisplayenInTextEditor(displayName);
}
}

Expand Down

0 comments on commit bbacfad

Please sign in to comment.