Add Ability to Change the User Status Freely #90

Merged
delvh merged 7 commits from f/change-user-status into develop 2020-10-10 14:16:29 +02:00
3 changed files with 40 additions and 8 deletions
Showing only changes of commit 08bd915f04 - Show all commits

View File

@ -15,11 +15,14 @@ import envoy.data.*;
*/ */
public final class ContactControl extends VBox { public final class ContactControl extends VBox {
private final Contact contact;
/** /**
* @param contact the contact to display * @param contact the contact to display
* @since Envoy Client v0.2-beta * @since Envoy Client v0.2-beta
*/ */
public ContactControl(Contact contact) { public ContactControl(Contact contact) {
this.contact = contact;
// Name label // Name label
final var nameLabel = new Label(contact.getName()); final var nameLabel = new Label(contact.getName());
@ -30,4 +33,19 @@ public final class ContactControl extends VBox {
getStyleClass().add("list-element"); getStyleClass().add("list-element");
} }
/**
* Replaces the info label of this {@code ContactControl} with an updated
* version.
* <p>
* This method should be called when the status of the underlying user or the
* size of the underlying group has changed.
*
* @since Envoy Client v0.3-beta
* @apiNote will produce buggy results if contact control gets updated so that
* the info label is no longer on index 1.
*/
public void replaceInfoLabel() {
getChildren().set(1, contact instanceof User ? new UserStatusLabel((User) contact) : new GroupSizeLabel((Group) contact));
}
} }

View File

@ -261,6 +261,8 @@ public final class ChatScene implements EventListener, Restorable {
private void onUserStatusChange(UserStatusChange statusChange) { private void onUserStatusChange(UserStatusChange statusChange) {
Platform.runLater(() -> { Platform.runLater(() -> {
chatList.refresh(); chatList.refresh();
// Replacing the display in the top bar
if (currentChat != null && currentChat.getRecipient().getID() == statusChange.getID()) { if (currentChat != null && currentChat.getRecipient().getID() == statusChange.getID()) {
topBarStatusLabel.getStyleClass().clear(); topBarStatusLabel.getStyleClass().clear();
topBarStatusLabel.setText(statusChange.get().toString()); topBarStatusLabel.setText(statusChange.get().toString());
@ -718,10 +720,17 @@ public final class ChatScene implements EventListener, Restorable {
@Event(eventType = OwnStatusChange.class, priority = 50) @Event(eventType = OwnStatusChange.class, priority = 50)
private void generateOwnStatusControl() { private void generateOwnStatusControl() {
delvh marked this conversation as resolved
Review

You could annotate this as an event handler directly.

You could annotate this as an event handler directly.
// Update the own user status if present
if (ownContactControl.getChildren().get(0) instanceof ContactControl)
((ContactControl) ownContactControl.getChildren().get(0)).replaceInfoLabel();
else {
// Else prepend it to the HBox children
final var ownUserControl = new ContactControl(localDB.getUser()); final var ownUserControl = new ContactControl(localDB.getUser());
ownUserControl.setAlignment(Pos.CENTER_LEFT); ownUserControl.setAlignment(Pos.CENTER_LEFT);
if (ownContactControl.getChildren().get(0) instanceof ContactControl) ownContactControl.getChildren().set(0, ownUserControl); ownContactControl.getChildren().add(0, ownUserControl);
else ownContactControl.getChildren().add(0, ownUserControl); }
} }
// Context menu actions // Context menu actions

View File

@ -46,14 +46,19 @@ public final class UserUtil {
/** /**
* Notifies the application that the status of the currently logged in user has * Notifies the application that the status of the currently logged in user has
* changed * changed.
* *
* @param newStatus the new status * @param newStatus the new status
* @since Envoy Client v0.3-beta * @since Envoy Client v0.3-beta
*/ */
public static void changeStatus(UserStatus newStatus) { public static void changeStatus(UserStatus newStatus) {
// Sending the already active status is a valid action
if (newStatus.equals(Context.getInstance().getLocalDB().getUser().getStatus())) return;
else {
EventBus.getInstance().dispatch(new OwnStatusChange(newStatus)); EventBus.getInstance().dispatch(new OwnStatusChange(newStatus));
if (Context.getInstance().getClient().isOnline()) if (Context.getInstance().getClient().isOnline())
Context.getInstance().getClient().send(new UserStatusChange(Context.getInstance().getLocalDB().getUser().getID(), newStatus)); Context.getInstance().getClient().send(new UserStatusChange(Context.getInstance().getLocalDB().getUser().getID(), newStatus));
} }
}
} }