Add Ability to Change the User Status Freely #90
@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|||||||
|
|
||||||
|
// 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
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user
You could annotate this as an event handler directly.