Add Ability to Delete Messages Locally (#70)
Merge branch 'develop' into f/delete-messages Additionally added system commands to copy, delete or save attachments of selected messages Reviewed-on: https://git.kske.dev/zdm/envoy/pulls/70 Reviewed-by: kske <kai@kske.dev> Reviewed-by: DieGurke <maxi@kske.dev>
This commit is contained in:
@ -74,7 +74,7 @@ public class Chat implements Serializable {
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Chat)) return false;
|
||||
final Chat other = (Chat) obj;
|
||||
final var other = (Chat) obj;
|
||||
return Objects.equals(recipient, other.recipient);
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ public class Chat implements Serializable {
|
||||
*/
|
||||
public void read(WriteProxy writeProxy) {
|
||||
for (int i = messages.size() - 1; i >= 0; --i) {
|
||||
final Message m = messages.get(i);
|
||||
final var m = messages.get(i);
|
||||
if (m.getSenderID() == recipient.getID()) if (m.getStatus() == MessageStatus.READ) break;
|
||||
else {
|
||||
m.setStatus(MessageStatus.READ);
|
||||
@ -121,6 +121,15 @@ public class Chat implements Serializable {
|
||||
messages.add(0, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the message with the given ID.
|
||||
*
|
||||
* @param messageID the ID of the message to remove
|
||||
* @return whether the message has been found and removed
|
||||
* @since Envoy Client v0.3-beta
|
||||
*/
|
||||
public boolean remove(long messageID) { return messages.removeIf(m -> m.getID() == messageID); }
|
||||
|
||||
/**
|
||||
* Increments the amount of unread messages.
|
||||
*
|
||||
|
@ -7,6 +7,7 @@ import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.*;
|
||||
|
||||
import envoy.client.event.*;
|
||||
@ -273,6 +274,24 @@ public final class LocalDB implements EventListener {
|
||||
cacheMap.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the message with the given ID, if present.
|
||||
*
|
||||
* @param message the event that was
|
||||
* @since Envoy Client v0.3-beta
|
||||
*/
|
||||
@Event
|
||||
private void onMessageDeletion(MessageDeletion message) {
|
||||
Platform.runLater(() -> {
|
||||
|
||||
// We suppose that messages have unique IDs, hence the search can be stopped
|
||||
// once a message was removed
|
||||
final var messageID = message.get();
|
||||
for (final var chat : chats)
|
||||
if (chat.remove(messageID)) break;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a {@code Map<String, User>} of all users stored locally with their
|
||||
* user names as keys
|
||||
|
Reference in New Issue
Block a user