Trim message text to prohibit sending empty whitespace messages

Closes #6788
This commit is contained in:
AndHell 2017-07-04 19:09:36 +02:00 committed by Moxie Marlinspike
parent f62fa2dc4e
commit 10de144b77
2 changed files with 10 additions and 6 deletions

View File

@ -1401,7 +1401,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
Drafts drafts = new Drafts(); Drafts drafts = new Drafts();
if (!Util.isEmpty(composeText)) { if (!Util.isEmpty(composeText)) {
drafts.add(new Draft(Draft.TEXT, composeText.getText().toString())); drafts.add(new Draft(Draft.TEXT, composeText.getTextTrimmed()));
} }
for (Slide slide : attachmentManager.buildSlideDeck().getSlides()) { for (Slide slide : attachmentManager.buildSlideDeck().getSlides()) {
@ -1480,7 +1480,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
} }
private void calculateCharactersRemaining() { private void calculateCharactersRemaining() {
String messageBody = composeText.getText().toString(); String messageBody = composeText.getTextTrimmed();
TransportOption transportOption = sendButton.getSelectedTransport(); TransportOption transportOption = sendButton.getSelectedTransport();
CharacterState characterState = transportOption.calculateCharacters(messageBody); CharacterState characterState = transportOption.calculateCharacters(messageBody);
@ -1537,7 +1537,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
} }
private String getMessage() throws InvalidMessageException { private String getMessage() throws InvalidMessageException {
String rawText = composeText.getText().toString(); String rawText = composeText.getTextTrimmed();
if (rawText.length() < 1 && !attachmentManager.isAttachmentPresent()) if (rawText.length() < 1 && !attachmentManager.isAttachmentPresent())
throw new InvalidMessageException(getString(R.string.ConversationActivity_message_is_empty_exclamation)); throw new InvalidMessageException(getString(R.string.ConversationActivity_message_is_empty_exclamation));
@ -1715,7 +1715,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
} }
private void updateToggleButtonState() { private void updateToggleButtonState() {
if (composeText.getText().length() == 0 && !attachmentManager.isAttachmentPresent()) { if (composeText.getTextTrimmed().length() == 0 && !attachmentManager.isAttachmentPresent()) {
buttonToggle.display(attachButton); buttonToggle.display(attachButton);
quickAttachmentToggle.show(); quickAttachmentToggle.show();
} else { } else {
@ -1957,14 +1957,14 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) { public void beforeTextChanged(CharSequence s, int start, int count,int after) {
beforeLength = composeText.getText().length(); beforeLength = composeText.getTextTrimmed().length();
} }
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
calculateCharactersRemaining(); calculateCharactersRemaining();
if (composeText.getText().length() == 0 || beforeLength == 0) { if (composeText.getTextTrimmed().length() == 0 || beforeLength == 0) {
composeText.postDelayed(new Runnable() { composeText.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -47,6 +47,10 @@ public class ComposeText extends EmojiEditText {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
} }
public String getTextTrimmed(){
return getText().toString().trim();
}
@Override @Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);