Merge remote-tracking branch 'origin/develop' into f/logout

Conflicts:
	client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java
This commit is contained in:
Leon Hofmeister 2020-09-25 23:16:25 +02:00
commit 618a4aa3cf
Signed by: delvh
GPG Key ID: 3DECE05F6D9A647C
2 changed files with 25 additions and 7 deletions

View File

@ -224,20 +224,21 @@ public final class ChatScene implements EventListener, Restorable {
// The sender of the message is the recipient of the chat
// Exceptions: this user is the sender (sync) or group message (group is
// recipient)
final var recipientID = message instanceof GroupMessage || message.getSenderID() == localDB.getUser().getID() ? message.getRecipientID()
: message.getSenderID();
final boolean ownMessage = message.getSenderID() == localDB.getUser().getID();
final var recipientID = message instanceof GroupMessage || ownMessage ? message.getRecipientID() : message.getSenderID();
localDB.getChat(recipientID).ifPresent(chat -> {
chat.insert(message);
// Read current chat or increment unread amount
if (chat.equals(currentChat)) {
try {
currentChat.read(writeProxy);
} catch (final IOException e1) {
logger.log(Level.WARNING, "Could not read current chat: ", e1);
} catch (final IOException e) {
logger.log(Level.WARNING, "Could not read current chat: ", e);
}
Platform.runLater(() -> { ListViewRefresh.deepRefresh(messageList); scrollToMessageListEnd(); });
// TODO: Increment unread counter for group messages with status < RECEIVED
} else
if (message.getSenderID() != localDB.getUser().getID() && message.getStatus() == MessageStatus.RECEIVED) chat.incrementUnreadAmount();
} else if (!ownMessage && message.getStatus() != MessageStatus.READ) chat.incrementUnreadAmount();
// Move chat with most recent unread messages to the top
Platform.runLater(() -> {

View File

@ -4,6 +4,7 @@ import static java.util.function.Predicate.not;
import java.util.stream.Collectors;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
@ -13,6 +14,7 @@ import envoy.client.event.*;
import envoy.client.ui.listcell.*;
import envoy.data.*;
import envoy.event.GroupCreation;
import envoy.event.contact.ContactOperation;
import envoy.util.Bounds;
import dev.kske.eventbus.*;
@ -70,6 +72,7 @@ public class GroupCreationTab implements EventListener {
userList.setCellFactory(new ListCellFactory<>(ContactControl::new));
userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
createButton.setDisable(true);
eventBus.registerListener(this);
userList.getItems()
.addAll(localDB.getChats()
.stream()
@ -199,4 +202,18 @@ public class GroupCreationTab implements EventListener {
errorProceedBox.setMinHeight(value);
errorProceedBox.setMaxHeight(value);
}
@Event
private void onContactOperation(ContactOperation operation) {
if (operation.get() instanceof User) Platform.runLater(() -> {
switch (operation.getOperationType()) {
case ADD:
userList.getItems().add((User) operation.get());
break;
case REMOVE:
userList.getItems().removeIf(u -> u.equals(operation.get()));
break;
}
});
}
}