Compare commits

..

No commits in common. "05ed5da41ba4ff6324b51b30ac6dfb0644360254" and "b653652f6d7164385a3c6e87723c7e0b24c9fea5" have entirely different histories.

27 changed files with 153 additions and 189 deletions

37
Jenkinsfile vendored
View File

@ -1,37 +0,0 @@
pipeline {
agent any
options {
ansiColor('xterm')
}
stages {
stage('Build') {
steps {
sh 'mvn -DskipTests clean package'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
post {
always {
junit '*/target/surefire-reports/*.xml'
}
}
}
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('KSKE SonarQube') {
sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar'
}
}
}
}
post {
success {
archiveArtifacts artifacts: 'client/target/envoy-client-*-shaded.jar, server/target/envoy-server-jar-with-dependencies.jar'
}
}
}

View File

@ -17,8 +17,6 @@ If you want to transfer a file to another user, you can attach it to a message.
On the settings page some convenience features can be configured, as well as the color theme.
Additional info on how to use Envoy can be found [here](https://git.kske.dev/zdm/envoy/wiki) in the client section.
### System requirements
To run Envoy, you have to install a Java Runtime Environment (JRE) of at least version 11.
@ -31,7 +29,7 @@ Most major Linux distributions like Debian, Arch and Gentoo have a Noto emoji pa
To set up an Envoy server, download the package from the release page.
To configure the behavior of Envoy Server, please have a look at the [documentation](https://git.kske.dev/zdm/envoy/wiki), specifically the server part.
Because the project lacks external documentation for the moment, please refer to the Javadoc inside the source code to configure your Envoy instance.
### System requirements

View File

@ -13,8 +13,9 @@ import java.util.stream.Stream;
import javafx.application.Platform;
import javafx.collections.*;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.core.Event;
import dev.kske.eventbus.Event;
import dev.kske.eventbus.EventBus;
import dev.kske.eventbus.EventListener;
import envoy.data.*;
import envoy.data.Message.MessageStatus;
@ -34,7 +35,7 @@ import envoy.client.event.*;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.3-alpha
*/
public final class LocalDB {
public final class LocalDB implements EventListener {
// Data
private User user;
@ -245,8 +246,7 @@ public final class LocalDB {
* @throws IOException if the saving process failed
* @since Envoy Client v0.3-alpha
*/
@Event(EnvoyCloseEvent.class)
@Priority(500)
@Event(eventType = EnvoyCloseEvent.class, priority = 500)
private synchronized void save() {
// Stop saving if this account has been deleted
@ -300,43 +300,37 @@ public final class LocalDB {
onLogout();
}
@Event
@Priority(500)
@Event(priority = 500)
private void onMessage(Message msg) {
if (msg.getStatus() == MessageStatus.SENT)
msg.nextStatus();
}
@Event
@Priority(500)
@Event(priority = 500)
private void onGroupMessage(GroupMessage msg) {
// TODO: Cancel event once EventBus is updated
if (msg.getStatus() == MessageStatus.WAITING || msg.getStatus() == MessageStatus.READ)
logger.warning("The groupMessage has the unexpected status " + msg.getStatus());
}
@Event
@Priority(500)
@Event(priority = 500)
private void onMessageStatusChange(MessageStatusChange evt) {
getMessage(evt.getID()).ifPresent(msg -> msg.setStatus(evt.get()));
}
@Event
@Priority(500)
@Event(priority = 500)
private void onGroupMessageStatusChange(GroupMessageStatusChange evt) {
this.<GroupMessage>getMessage(evt.getID())
.ifPresent(msg -> msg.getMemberStatuses().replace(evt.getMemberID(), evt.get()));
}
@Event
@Priority(500)
@Event(priority = 500)
private void onUserStatusChange(UserStatusChange evt) {
getChat(evt.getID()).map(Chat::getRecipient).map(User.class::cast)
.ifPresent(u -> u.setStatus(evt.get()));
}
@Event
@Priority(500)
@Event(priority = 500)
private void onUserOperation(UserOperation operation) {
final var eventUser = operation.get();
switch (operation.getOperationType()) {
@ -362,15 +356,13 @@ public final class LocalDB {
Platform.runLater(() -> chats.add(new GroupChat(user, newGroup)));
}
@Event
@Priority(500)
@Event(priority = 500)
private void onGroupResize(GroupResize evt) {
getChat(evt.getGroupID()).map(Chat::getRecipient).map(Group.class::cast)
.ifPresent(evt::apply);
}
@Event
@Priority(500)
@Event(priority = 500)
private void onNameChange(NameChange evt) {
chats.stream().map(Chat::getRecipient).filter(c -> c.getID() == evt.getID()).findAny()
.ifPresent(c -> c.setName(evt.get()));
@ -392,8 +384,7 @@ public final class LocalDB {
*
* @since Envoy Client v0.2-beta
*/
@Event(Logout.class)
@Priority(50)
@Event(eventType = Logout.class, priority = 50)
private void onLogout() {
autoSaver.cancel();
autoSaveRestart = true;
@ -425,26 +416,22 @@ public final class LocalDB {
});
}
@Event
@Priority(500)
@Event(priority = 500)
private void onOwnStatusChange(OwnStatusChange statusChange) {
user.setStatus(statusChange.get());
}
@Event(ContactsChangedSinceLastLogin.class)
@Priority(500)
@Event(eventType = ContactsChangedSinceLastLogin.class, priority = 500)
private void onContactsChangedSinceLastLogin() {
contactsChanged = true;
}
@Event
@Priority(500)
@Event(priority = 500)
private void onContactDisabled(ContactDisabled event) {
getChat(event.get().getID()).ifPresent(chat -> chat.setDisabled(true));
}
@Event
@Priority(500)
@Event(priority = 500)
private void onAccountDeletion(AccountDeletion deletion) {
if (user.getID() == deletion.get())
logger.log(Level.WARNING,
@ -509,8 +496,7 @@ public final class LocalDB {
* @param idGenerator the message ID generator to set
* @since Envoy Client v0.3-alpha
*/
@Event
@Priority(150)
@Event(priority = 150)
public void setIDGenerator(IDGenerator idGenerator) { this.idGenerator = idGenerator; }
/**

View File

@ -5,7 +5,8 @@ import java.util.*;
import java.util.logging.Level;
import java.util.prefs.Preferences;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.*;
import dev.kske.eventbus.EventListener;
import envoy.util.*;
@ -20,7 +21,7 @@ import envoy.client.event.EnvoyCloseEvent;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.2-alpha
*/
public final class Settings {
public final class Settings implements EventListener {
// Actual settings accessible by the rest of the application
private Map<String, SettingsItem<?>> items;
@ -68,7 +69,7 @@ public final class Settings {
* @throws IOException if an error occurs while saving the themes
* @since Envoy Client v0.2-alpha
*/
@Event(EnvoyCloseEvent.class)
@Event(eventType = EnvoyCloseEvent.class)
private void save() {
EnvoyLog.getLogger(Settings.class).log(Level.INFO, "Saving settings...");

View File

@ -1,6 +1,6 @@
package envoy.client.helper;
import dev.kske.eventbus.core.EventBus;
import dev.kske.eventbus.EventBus;
import envoy.client.data.*;
import envoy.client.event.EnvoyCloseEvent;

View File

@ -5,14 +5,14 @@ import java.net.Socket;
import java.util.concurrent.TimeoutException;
import java.util.logging.*;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.core.Event;
import dev.kske.eventbus.*;
import dev.kske.eventbus.Event;
import envoy.data.*;
import envoy.event.*;
import envoy.util.*;
import envoy.client.data.ClientConfig;
import envoy.client.data.*;
import envoy.client.event.EnvoyCloseEvent;
/**
@ -24,7 +24,7 @@ import envoy.client.event.EnvoyCloseEvent;
* @author Leon Hofmeister
* @since Envoy Client v0.1-alpha
*/
public final class Client implements Closeable {
public final class Client implements EventListener, Closeable {
// Connection handling
private Socket socket;
@ -55,12 +55,13 @@ public final class Client implements Closeable {
* the handshake does exceed this time limit, an exception is thrown.
*
* @param credentials the login credentials of the user
* @param cacheMap the map of all caches needed
* @throws TimeoutException if the server could not be reached
* @throws IOException if the login credentials could not be written
* @throws InterruptedException if the current thread is interrupted while waiting for the
* handshake response
*/
public void performHandshake(LoginCredentials credentials)
public void performHandshake(LoginCredentials credentials, CacheMap cacheMap)
throws TimeoutException, IOException, InterruptedException {
if (online)
throw new IllegalStateException("Handshake has already been performed successfully");
@ -78,6 +79,7 @@ public final class Client implements Closeable {
// Register user creation processor, contact list processor, message cache and
// authentication token
receiver.registerProcessor(User.class, sender -> this.sender = sender);
receiver.registerProcessors(cacheMap.getMap());
// Start receiver
receiver.start();
@ -99,20 +101,44 @@ public final class Client implements Closeable {
if (System.currentTimeMillis() - start > 5000) {
rejected = true;
socket.close();
receiver.removeAllProcessors();
throw new TimeoutException("Did not log in after 5 seconds");
}
Thread.sleep(500);
}
// Remove handshake specific processors
receiver.removeAllProcessors();
online = true;
logger.log(Level.INFO, "Handshake completed.");
}
/**
* Initializes the {@link Receiver} used to process data sent from the server to this client.
*
* @param localDB the local database used to persist the current {@link IDGenerator}
* @param cacheMap the map of all caches needed
* @throws IOException if no {@link IDGenerator} is present and none could be requested from the
* server
* @since Envoy Client v0.2-alpha
*/
public void initReceiver(LocalDB localDB, CacheMap cacheMap) throws IOException {
checkOnline();
// Remove all processors as they are only used during the handshake
receiver.removeAllProcessors();
// Relay cached messages and message status changes
cacheMap.get(Message.class).setProcessor(eventBus::dispatch);
cacheMap.get(GroupMessage.class).setProcessor(eventBus::dispatch);
cacheMap.get(MessageStatusChange.class).setProcessor(eventBus::dispatch);
cacheMap.get(GroupMessageStatusChange.class).setProcessor(eventBus::dispatch);
// Request a generator if none is present or the existing one is consumed
if (!localDB.hasIDGenerator() || !localDB.getIDGenerator().hasNext())
requestIDGenerator();
// Relay caches
cacheMap.getMap().values().forEach(Cache::relay);
}
/**
* Sends an object to the server.
*
@ -153,15 +179,13 @@ public final class Client implements Closeable {
send(new IDGeneratorRequest());
}
@Event(HandshakeRejection.class)
@Priority(1000)
@Event(eventType = HandshakeRejection.class, priority = 1000)
private void onHandshakeRejection() {
rejected = true;
}
@Override
@Event(EnvoyCloseEvent.class)
@Priority(50)
@Event(eventType = EnvoyCloseEvent.class, priority = 50)
public void close() {
if (online) {
logger.log(Level.INFO, "Closing connection...");

View File

@ -6,7 +6,7 @@ import java.util.*;
import java.util.function.Consumer;
import java.util.logging.*;
import dev.kske.eventbus.core.EventBus;
import dev.kske.eventbus.*;
import envoy.util.*;
@ -87,17 +87,15 @@ public final class Receiver extends Thread {
// Dispatch to the processor if present
if (processor != null)
processor.accept(obj);
// Dispatch to the event bus if the object has no processor
else
eventBus.dispatch(obj);
// TODO: Log DeadEvent from Event Bus 1.1.0
// Dispatch to the event bus if the object is an event without a processor
else if (obj instanceof IEvent)
eventBus.dispatch((IEvent) obj);
// Notify if no processor could be located
// else
// logger.log(Level.WARNING,
// String.format(
// "The received object has the %s for which no processor is defined.",
// obj.getClass()));
else
logger.log(Level.WARNING,
String.format(
"The received object has the %s for which no processor is defined.",
obj.getClass()));
}
} catch (final SocketException | EOFException e) {
// Connection probably closed by client.

View File

@ -8,7 +8,7 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.*;
import javafx.stage.Stage;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.*;
import envoy.util.EnvoyLog;
@ -25,7 +25,7 @@ import envoy.client.event.*;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
public final class SceneContext {
public final class SceneContext implements EventListener {
private final Stage stage;
private final Stack<Parent> roots = new Stack<>();
@ -126,15 +126,13 @@ public final class SceneContext {
}
}
@Event(Logout.class)
@Priority(150)
@Event(eventType = Logout.class, priority = 150)
private void onLogout() {
roots.clear();
controllers.clear();
}
@Event(ThemeChangeEvent.class)
@Priority(150)
@Event(priority = 150, eventType = ThemeChangeEvent.class)
private void onThemeChange() {
applyCSS();
}

View File

@ -12,7 +12,7 @@ import javafx.stage.Stage;
import envoy.data.*;
import envoy.data.User.UserStatus;
import envoy.event.UserStatusChange;
import envoy.event.*;
import envoy.exception.EnvoyException;
import envoy.util.EnvoyLog;
@ -115,20 +115,21 @@ public final class Startup extends Application {
* @since Envoy Client v0.2-beta
*/
public static boolean performHandshake(LoginCredentials credentials) {
final var cacheMap = new CacheMap();
cacheMap.put(Message.class, new Cache<Message>());
cacheMap.put(GroupMessage.class, new Cache<GroupMessage>());
cacheMap.put(MessageStatusChange.class, new Cache<MessageStatusChange>());
cacheMap.put(GroupMessageStatusChange.class, new Cache<GroupMessageStatusChange>());
final var originalStatus =
localDB.getUser() == null ? UserStatus.ONLINE : localDB.getUser().getStatus();
try {
client.performHandshake(credentials);
client.performHandshake(credentials, cacheMap);
if (client.isOnline()) {
// Restore the original status as the server automatically returns status ONLINE
client.getSender().setStatus(originalStatus);
loadChatScene();
// Request an ID generator if none is present or the existing one is consumed
if (!localDB.hasIDGenerator() || !localDB.getIDGenerator().hasNext())
client.requestIDGenerator();
client.initReceiver(localDB, cacheMap);
return true;
} else
return false;

View File

@ -9,8 +9,8 @@ import java.awt.image.BufferedImage;
import javafx.application.Platform;
import javafx.stage.Stage;
import dev.kske.eventbus.core.Event;
import dev.kske.eventbus.core.EventBus;
import dev.kske.eventbus.*;
import dev.kske.eventbus.Event;
import envoy.data.Message;
import envoy.data.User.UserStatus;
@ -31,7 +31,7 @@ import envoy.client.util.*;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.2-alpha
*/
public final class StatusTrayIcon {
public final class StatusTrayIcon implements EventListener {
/**
* The {@link TrayIcon} provided by the System Tray API for controlling the system tray. This
@ -136,7 +136,7 @@ public final class StatusTrayIcon {
*
* @since Envoy Client v0.2-beta
*/
@Event(Logout.class)
@Event(eventType = Logout.class)
public void hide() {
SystemTray.getSystemTray().remove(trayIcon);
}

View File

@ -21,14 +21,14 @@ import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.*;
import javafx.scene.input.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.FileChooser;
import javafx.util.Duration;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.core.Event;
import dev.kske.eventbus.*;
import dev.kske.eventbus.Event;
import envoy.data.*;
import envoy.data.Attachment.AttachmentType;
@ -55,7 +55,7 @@ import envoy.client.util.*;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
public final class ChatScene implements Restorable, KeyboardMapping {
public final class ChatScene implements EventListener, Restorable, KeyboardMapping {
@FXML
private ListView<Message> messageList;
@ -220,13 +220,12 @@ public final class ChatScene implements Restorable, KeyboardMapping {
});
}
@Event(BackEvent.class)
@Event(eventType = BackEvent.class)
private void onBackEvent() {
tabPane.getSelectionModel().select(Tabs.CONTACT_LIST.ordinal());
}
@Event
@Polymorphic
@Event(includeSubtypes = true)
private void onMessage(Message message) {
// The sender of the message is the recipient of the chat
@ -305,7 +304,7 @@ public final class ChatScene implements Restorable, KeyboardMapping {
}));
}
@Event(NoAttachments.class)
@Event(eventType = NoAttachments.class)
private void onNoAttachments() {
Platform.runLater(() -> {
attachmentButton.setDisable(true);
@ -318,13 +317,12 @@ public final class ChatScene implements Restorable, KeyboardMapping {
});
}
@Event
@Priority(150)
@Event(priority = 150)
private void onGroupCreationResult(GroupCreationResult result) {
Platform.runLater(() -> newGroupButton.setDisable(result.get() == null));
}
@Event(ThemeChangeEvent.class)
@Event(eventType = ThemeChangeEvent.class)
private void onThemeChange() {
ChatControl.reloadDefaultChatIcons();
settingsButton.setGraphic(
@ -348,13 +346,12 @@ public final class ChatScene implements Restorable, KeyboardMapping {
recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43));
}
@Event(Logout.class)
@Priority(200)
@Event(eventType = Logout.class, priority = 200)
private void onLogout() {
eventBus.removeListener(this);
}
@Event(AccountDeletion.class)
@Event(eventType = AccountDeletion.class)
private void onAccountDeletion() {
Platform.runLater(chatList::refresh);
}
@ -786,8 +783,7 @@ public final class ChatScene implements Restorable, KeyboardMapping {
attachmentView.setVisible(visible);
}
@Event(OwnStatusChange.class)
@Priority(50)
@Event(eventType = OwnStatusChange.class, priority = 50)
private void generateOwnStatusControl() {
// Update the own user status if present
@ -798,7 +794,7 @@ public final class ChatScene implements Restorable, KeyboardMapping {
// Else prepend it to the HBox children
final var ownUserControl = new ContactControl(localDB.getUser());
ownUserControl.setAlignment(Pos.CENTER_LEFT);
HBox.setHgrow(ownUserControl, javafx.scene.layout.Priority.NEVER);
HBox.setHgrow(ownUserControl, Priority.NEVER);
ownContactControl.getChildren().add(1, ownUserControl);
}
}

View File

@ -7,7 +7,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.*;
import envoy.data.User;
import envoy.event.ElementOperation;
@ -34,7 +34,7 @@ import envoy.client.ui.listcell.ListCellFactory;
* @author Maximilian K&auml;fer
* @since Envoy Client v0.1-beta
*/
public class ContactSearchTab {
public class ContactSearchTab implements EventListener {
@FXML
private TextArea searchBar;

View File

@ -10,11 +10,11 @@ import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.*;
import envoy.data.*;
import envoy.event.GroupCreation;
import envoy.event.contact.UserOperation;
import envoy.event.contact.*;
import envoy.util.Bounds;
import envoy.client.data.*;
@ -33,7 +33,7 @@ import envoy.client.ui.listcell.ListCellFactory;
* @author Maximilian K&auml;fer
* @since Envoy Client v0.1-beta
*/
public class GroupCreationTab {
public class GroupCreationTab implements EventListener {
@FXML
private Button createButton;

View File

@ -10,7 +10,7 @@ import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.ImageView;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.*;
import envoy.data.LoginCredentials;
import envoy.event.HandshakeRejection;
@ -27,7 +27,7 @@ import envoy.client.util.IconUtil;
* @author Maximilian K&auml;fer
* @since Envoy Client v0.1-beta
*/
public final class LoginScene {
public final class LoginScene implements EventListener {
@FXML
private TextField userTextField;

View File

@ -2,7 +2,7 @@ package envoy.client.ui.settings;
import javafx.scene.control.*;
import dev.kske.eventbus.core.EventBus;
import dev.kske.eventbus.EventBus;
import envoy.data.User.UserStatus;

View File

@ -15,7 +15,7 @@ import javafx.scene.layout.HBox;
import javafx.stage.FileChooser;
import javafx.util.Duration;
import dev.kske.eventbus.core.EventBus;
import dev.kske.eventbus.EventBus;
import envoy.event.*;
import envoy.util.*;

View File

@ -7,7 +7,7 @@ import java.util.logging.*;
import javafx.stage.FileChooser;
import dev.kske.eventbus.core.EventBus;
import dev.kske.eventbus.EventBus;
import envoy.data.Message;
import envoy.util.EnvoyLog;

View File

@ -5,7 +5,7 @@ import java.util.logging.*;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import dev.kske.eventbus.core.EventBus;
import dev.kske.eventbus.EventBus;
import envoy.data.*;
import envoy.data.User.UserStatus;

View File

@ -16,13 +16,12 @@ module envoy.client {
requires javafx.fxml;
requires javafx.base;
requires javafx.graphics;
requires dev.kske.eventbus.core;
opens envoy.client.ui to javafx.graphics, javafx.fxml, dev.kske.eventbus.core;
opens envoy.client.ui.controller to javafx.graphics, javafx.fxml, envoy.client.util, dev.kske.eventbus.core;
opens envoy.client.ui.chatscene to javafx.graphics, javafx.fxml, envoy.client.util, dev.kske.eventbus.core;
opens envoy.client.ui to javafx.graphics, javafx.fxml, dev.kske.eventbus;
opens envoy.client.ui.controller to javafx.graphics, javafx.fxml, envoy.client.util, dev.kske.eventbus;
opens envoy.client.ui.chatscene to javafx.graphics, javafx.fxml, envoy.client.util, dev.kske.eventbus;
opens envoy.client.ui.control to javafx.graphics, javafx.fxml;
opens envoy.client.ui.settings to envoy.client.util;
opens envoy.client.net to dev.kske.eventbus.core;
opens envoy.client.data to dev.kske.eventbus.core;
opens envoy.client.net to dev.kske.eventbus;
opens envoy.client.data to dev.kske.eventbus;
}

View File

@ -12,11 +12,18 @@
<version>0.2-beta</version>
</parent>
<repositories>
<repository>
<id>kske-repo</id>
<url>https://kske.dev/maven-repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>dev.kske</groupId>
<artifactId>event-bus-core</artifactId>
<version>1.0.0</version>
<artifactId>event-bus</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>

View File

@ -2,13 +2,15 @@ package envoy.data;
import java.io.Serializable;
import dev.kske.eventbus.IEvent;
/**
* Generates increasing IDs between two numbers.
*
* @author Kai S. K. Engelbart
* @since Envoy Common v0.2-alpha
*/
public final class IDGenerator implements Serializable {
public final class IDGenerator implements IEvent, Serializable {
private final long end;
private long current;

View File

@ -4,6 +4,8 @@ import java.io.Serializable;
import java.time.Instant;
import java.util.Objects;
import dev.kske.eventbus.IEvent;
/**
* Represents a unique message with a unique, numeric ID. Further metadata includes the sender and
* recipient {@link User}s, as well as the creation date and the current {@link MessageStatus}.<br>
@ -12,7 +14,7 @@ import java.util.Objects;
* @author Leon Hofmeister
* @since Envoy Common v0.2-alpha
*/
public class Message implements Serializable {
public class Message implements Serializable, IEvent {
/**
* This enumeration defines all possible statuses a {link Message} can have.

View File

@ -3,15 +3,18 @@ package envoy.event;
import java.io.Serializable;
import java.util.Objects;
import dev.kske.eventbus.IEvent;
/**
* This class serves as a convenience base class for all events. It provides a generic value. For
* events without a value there also is {@link envoy.event.Event.Valueless}.
* This class serves as a convenience base class for all events. It implements the {@link IEvent}
* interface and provides a generic value. For events without a value there also is
* {@link envoy.event.Event.Valueless}.
*
* @author Kai S. K. Engelbart
* @param <T> the type of the Event
* @since Envoy v0.2-alpha
*/
public abstract class Event<T> implements Serializable {
public abstract class Event<T> implements IEvent, Serializable {
protected final T value;

View File

@ -16,5 +16,5 @@ module envoy.common {
exports envoy.event.contact;
requires transitive java.logging;
requires transitive dev.kske.eventbus.core;
requires transitive dev.kske.eventbus;
}

View File

@ -18,10 +18,10 @@ import envoy.util.SerializationUtils;
* @author Leon Hofmeister
* @since Envoy Common v0.1-beta
*/
public class UserTest {
class UserTest {
@Test
public void test() throws IOException, ClassNotFoundException {
void test() throws IOException, ClassNotFoundException {
User user2 = new User(2, "kai");
User user3 = new User(3, "ai");
User user4 = new User(4, "ki", Set.of(user2, user3));

View File

@ -28,13 +28,6 @@
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</build>
<modules>

View File

@ -40,7 +40,6 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
// Cache this write proxy for user-independent notifications
UserStatusChangeProcessor.setWriteProxy(writeProxy);
// Check for compatible versions
if (!VersionUtil.verifyCompatibility(credentials.getClientVersion())) {
logger.info("The client has the wrong version.");
writeProxy.write(socketID, new HandshakeRejection(WRONG_VERSION));
@ -71,10 +70,10 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
writeProxy.write(socketID, new HandshakeRejection(INVALID_TOKEN));
return;
}
} else if (!PasswordUtil.validate(credentials.getPassword(),
user.getPasswordHash())) {
} else
// Check the password hash
// Check the password hash
if (!PasswordUtil.validate(credentials.getPassword(), user.getPasswordHash())) {
logger.info(user + " has entered the wrong password.");
writeProxy.write(socketID, new HandshakeRejection(WRONG_PASSWORD_OR_USER));
return;
@ -102,8 +101,7 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
writeProxy.write(socketID, new HandshakeRejection(USERNAME_TAKEN));
return;
} catch (final NoResultException e) {
// Create a new user
// Creation of a new user
user = new User();
user.setName(credentials.getIdentifier());
user.setLastSeen(Instant.now());
@ -140,15 +138,6 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
persistenceManager.updateContact(user);
writeProxy.write(socketID, new NewAuthToken(token));
}
// Notify the user if a contact deletion has happened since he last logged in
if (user.getLatestContactDeletion().isAfter(user.getLastSeen()))
writeProxy.write(socketID, new ContactsChangedSinceLastLogin());
// Complete the handshake
writeProxy.write(socketID, user.toCommon());
// Send pending (group) messages and status changes
final var pendingMessages =
PersistenceManager.getInstance().getPendingMessages(user, credentials.getLastSync());
pendingMessages.removeIf(GroupMessage.class::isInstance);
@ -173,9 +162,8 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
writeProxy.write(connectionManager.getSocketID(msg.getSender().getID()),
new MessageStatusChange(msgCommon));
}
} else {
} else
writeProxy.write(socketID, new MessageStatusChange(msgCommon));
}
}
final List<GroupMessage> pendingGroupMessages = PersistenceManager.getInstance()
@ -209,11 +197,10 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
}
PersistenceManager.getInstance().updateMessage(gmsg);
} else {
} else
// Just send the message without updating if it was received in the past
writeProxy.write(socketID, gmsgCommon);
}
} else {
// Sending group message status changes
@ -233,5 +220,11 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
writeProxy.write(socketID, new MessageStatusChange(gmsgCommon));
}
}
// Notify the user if a contact deletion has happened since he last logged in
if (user.getLatestContactDeletion().isAfter(user.getLastSeen()))
writeProxy.write(socketID, new ContactsChangedSinceLastLogin());
// Complete the handshake
writeProxy.write(socketID, user.toCommon());
}
}