-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatModel.java
More file actions
31 lines (23 loc) · 811 Bytes
/
ChatModel.java
File metadata and controls
31 lines (23 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.example;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class ChatModel {
private final ObservableList<ChatMessage> messages = FXCollections.observableArrayList();
private final NtfyConnection ntfyConnection;
public ChatModel(NtfyConnection ntfyConnection) {
this.ntfyConnection = ntfyConnection;
}
public ObservableList<ChatMessage> getMessages() {
return messages;
}
public void sendMessage(String text) {
ntfyConnection.send(text);
}
public void startReceiving() {
ntfyConnection.receive(ntfyDto -> {
ChatMessage chatMsg = new ChatMessage(ntfyDto.message(), ntfyDto.time());
messages.add(chatMsg);
});
}
}