allow sending username taken message
This commit is contained in:
parent
030e9b3b0a
commit
e5c518d078
1 changed files with 10 additions and 2 deletions
|
@ -166,12 +166,20 @@ public class PeerUser extends User implements Comparable<PeerUser> {
|
||||||
Log.v(this.getClass().getSimpleName(), "Received message from " + id);
|
Log.v(this.getClass().getSimpleName(), "Received message from " + id);
|
||||||
if (msg instanceof UserInformation) {
|
if (msg instanceof UserInformation) {
|
||||||
assert ((UserInformation) msg).id == getId();
|
assert ((UserInformation) msg).id == getId();
|
||||||
Log.v(this.getClass().getSimpleName(), "Message username: " + ((UserInformation) msg).getUsername());
|
final String receivedUsername = ((UserInformation) msg).getUsername();
|
||||||
setUsername(((UserInformation) msg).getUsername());
|
Log.v(this.getClass().getSimpleName(), "Message username: " + receivedUsername);
|
||||||
|
if (CurrentUser.getInstance().getUsername().equals(receivedUsername)) {
|
||||||
|
sendUsernameTaken(connection);
|
||||||
|
} else {
|
||||||
|
setUsername(receivedUsername);
|
||||||
|
}
|
||||||
} else if (msg instanceof Message) {
|
} else if (msg instanceof Message) {
|
||||||
assert ((Message) msg).getRecipient().id != id;
|
assert ((Message) msg).getRecipient().id != id;
|
||||||
Log.v(this.getClass().getSimpleName(), "Message text: " + ((Message) msg).getText());
|
Log.v(this.getClass().getSimpleName(), "Message text: " + ((Message) msg).getText());
|
||||||
history.addMessage((Message) msg);
|
history.addMessage((Message) msg);
|
||||||
|
} else if (msg instanceof UsernameTakenException) {
|
||||||
|
disconnect();
|
||||||
|
errorCallback.onError(new Exception("Received username already taken message"));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
e -> {
|
e -> {
|
||||||
|
|
Loading…
Reference in a new issue