One byte-size format and one chat scope
text.ByteSize writes sizes and rates as TeamSpeak does and replaces the formatters in ChatHtml, FileBrowserDialog and ConnectionStatsFormat. chat.ChatScope replaces ConnectionListener.ChatScope, ChatLogScope and ChatPanel.Target, and the mappings between them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package eu.lixko.ts3j.client.android
|
||||
|
||||
import android.net.Uri
|
||||
import eu.lixko.ts3j.client.chat.ChatScope
|
||||
import eu.lixko.ts3j.client.config.Bookmark
|
||||
import eu.lixko.ts3j.client.contacts.ContactType
|
||||
import eu.lixko.ts3j.client.config.WhisperList
|
||||
@@ -16,7 +17,6 @@ import eu.lixko.ts3j.client.net.Whisper
|
||||
import eu.lixko.ts3j.client.net.ban.BanEntry
|
||||
import eu.lixko.ts3j.client.net.ban.BanRule
|
||||
import eu.lixko.ts3j.client.net.filetransfer.RemoteFile
|
||||
import eu.lixko.ts3j.client.net.ConnectionListener.ChatScope
|
||||
import eu.lixko.ts3j.client.session.ServerLink
|
||||
import eu.lixko.ts3j.client.session.ServerSession
|
||||
import eu.lixko.ts3j.client.text.ChatHtml
|
||||
|
||||
@@ -19,8 +19,11 @@ Items are worked through in the order below. Status: open, done (commit), or clo
|
||||
| 5 | Two front doors: frontends use both `ServerSession` and `session.connection()` with no rule for which | done (`de42429`): `connection()` is gone; frontends reach the model, our ids, devices and the helpers through `ServerSession`. New helpers took the remaining actions off the connection: `ClientAdmin` (move, kick, ban, groups, talk power, poke, details), `ChannelFiles`, `ClientContacts`; `ChannelAdmin` also joins, moves and subscribes. Dialogs take the session, or only the helper they use |
|
||||
| 6 | Menu bar, toolbar and hotkeys each implement the same commands: `MainMenuBar.Listener` (~50 methods, ~210 lines of forwarding in `MainFrame`), `MainToolbar.Listener`, `HotkeyActions` | done (`f7cf040`): `MainCommands` holds each command once, acting on the server on screen or, for hotkeys, on a list of sessions; the menu, toolbar and hotkeys call it directly and both `Listener` interfaces are gone. The menu's mute items no longer click the toolbar's buttons, and the menu's commander toggle now repaints the toolbar and tray |
|
||||
| 7 | The admin list dialogs (bans, complaints, offline messages, privilege keys, server log) repeat the load/status/table-model scaffolding | done (`e214f21`): the five extend `AbstractServerListDialog`, which lays out the toolbar, list, status line and Reload/Close, follows the server's name, binds F5/Ctrl+W/Escape, guards loading, reloads after a change and reports its failure; `ServerTab` keeps them in one map. All five now take F5, show load failures in red, and keep the status line's height; the ban list's own placeholder field is FlatLaf's. The table models stay per dialog: their rows and columns share nothing |
|
||||
| 8 | `Settings`: 58 public fields, each key spelled twice (load and save), no change notification, so callers fan changes out by hand | done: each value is a `Setting<T>` (`get`/`set`, listeners), declared once with its key, type and range, and loaded and saved from that list. Output device, volume and receive buffer reach every connection, and the status bar and master volume slider follow their toggles, through listeners instead of calls at each place that changes them; Android puts output settings and country flags into effect the same way. `SplitRatio` takes the setting itself. The sections with their own load/store (row colours, server log, notifications, contact defaults) are unchanged. The Playback page now previews the voice volume with the master volume applied, as Apply sets it |
|
||||
| 9 | Duplicates: three byte-size formatters (`FileBrowserDialog`, `ChatHtml`, `ConnectionStatsFormat`); four "which chat" enums (`ChatScope`, `ChatLogScope`, `ChatPanel.Target`, Android `ChatKey`); the conversation model lives in each frontend | open |
|
||||
| 8 | `Settings`: 58 public fields, each key spelled twice (load and save), no change notification, so callers fan changes out by hand | done (`203082d`): each value is a `Setting<T>` (`get`/`set`, listeners), declared once with its key, type and range, and loaded and saved from that list. Output device, volume and receive buffer reach every connection, and the status bar and master volume slider follow their toggles, through listeners instead of calls at each place that changes them; Android puts output settings and country flags into effect the same way. `SplitRatio` takes the setting itself. The sections with their own load/store (row colours, server log, notifications, contact defaults) are unchanged. The Playback page now previews the voice volume with the master volume applied, as Apply sets it |
|
||||
| 9 | Duplicates: three byte-size formatters (`FileBrowserDialog`, `ChatHtml`, `ConnectionStatsFormat`); four "which chat" enums (`ChatScope`, `ChatLogScope`, `ChatPanel.Target`, Android `ChatKey`); the conversation model lives in each frontend | in progress, in sub-steps: |
|
||||
| 9a | … byte-size formatters | done: `text.ByteSize` writes sizes and rates as TeamSpeak does (`1023 Bytes`, `353.98 KiB`); chat attachments and the file browser now use it too, so they show KiB/MiB with two decimals |
|
||||
| 9b | … "which chat" enums | done: one `chat.ChatScope` replaces `ConnectionListener.ChatScope`, `ChatLogScope` and `ChatPanel.Target`, and the mappings between them are gone. Android's `ChatKey` also carries the peer, so it goes with the conversation model |
|
||||
| 9c | … the conversation model (Swing `ChatPanel.Tab`, Android `Chats`) | open |
|
||||
| 10 | Android `ServerScreen`: one 456-line composable holding ~25 pieces of state | open |
|
||||
| 11 | Android `SessionController` (669 lines) is the app-wide view model and service locator; every screen gets all of it | open |
|
||||
| 12 | Swing `ui` package: 118 files, flat | open |
|
||||
|
||||
@@ -249,9 +249,10 @@ core/ eu.lixko.ts3j.client
|
||||
│ ├── processing port of TS3's WebRTC capture chain: HPF, NS, transients, AGC2
|
||||
│ ├── vad port of WebRTC's rnn_vad speech detector
|
||||
│ └── opus codec interfaces
|
||||
├── chat ChatScope: the server, channel or a private chat
|
||||
├── chatlog TS3-compatible chat logs, shared with the TS3 client by default
|
||||
├── contacts friends and blocked clients, in TS3's own record format
|
||||
├── text BBCode, TeamSpeak links, chat search
|
||||
├── text BBCode, TeamSpeak links, chat search, byte sizes
|
||||
├── gfx
|
||||
│ ├── IconPack an icon pack zip/folder/classpath folder + its settings.ini mapping
|
||||
│ ├── IconPacks discovery of installed packs, the shipped Material one, lookup order
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package eu.lixko.ts3j.client.chat;
|
||||
|
||||
/** Which chat a message is in: the server's, the channel's, or a private one with a client. */
|
||||
public enum ChatScope {
|
||||
SERVER,
|
||||
CHANNEL,
|
||||
PRIVATE
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package eu.lixko.ts3j.client.chatlog;
|
||||
|
||||
public enum ChatLogScope {
|
||||
SERVER,
|
||||
CHANNEL,
|
||||
PRIVATE
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.lixko.ts3j.client.chatlog;
|
||||
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.config.AppDirs;
|
||||
import eu.lixko.ts3j.client.text.BBCode;
|
||||
import eu.lixko.ts3j.client.text.HtmlText;
|
||||
@@ -59,21 +60,21 @@ public final class ChatLogStore {
|
||||
|
||||
public synchronized void begin() throws IOException {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
appendRaw(log(ChatLogScope.SERVER), "*** Log begins " + BEGIN.format(now), beginHtml("Log", now));
|
||||
appendRaw(log(ChatLogScope.CHANNEL), "*** Chat begins " + BEGIN.format(now), beginHtml("Chat", now));
|
||||
appendRaw(log(ChatScope.SERVER), "*** Log begins " + BEGIN.format(now), beginHtml("Log", now));
|
||||
appendRaw(log(ChatScope.CHANNEL), "*** Chat begins " + BEGIN.format(now), beginHtml("Chat", now));
|
||||
}
|
||||
|
||||
public List<String> serverHtmlHistory() throws IOException {
|
||||
return last(readHtml(log(ChatLogScope.SERVER), HISTORY_TAIL_BYTES), HISTORY_LIMIT);
|
||||
return last(readHtml(log(ChatScope.SERVER), HISTORY_TAIL_BYTES), HISTORY_LIMIT);
|
||||
}
|
||||
|
||||
public List<String> channelHtmlHistory() throws IOException {
|
||||
return last(readTextMessages(log(ChatLogScope.CHANNEL), ChatLogScope.CHANNEL, HISTORY_TAIL_BYTES),
|
||||
return last(readTextMessages(log(ChatScope.CHANNEL), ChatScope.CHANNEL, HISTORY_TAIL_BYTES),
|
||||
HISTORY_LIMIT);
|
||||
}
|
||||
|
||||
public List<String> privateHtmlHistory(String clientUniqueId) throws IOException {
|
||||
return last(readTextMessages(privateLog(clientUniqueId), ChatLogScope.PRIVATE, HISTORY_TAIL_BYTES),
|
||||
return last(readTextMessages(privateLog(clientUniqueId), ChatScope.PRIVATE, HISTORY_TAIL_BYTES),
|
||||
HISTORY_LIMIT);
|
||||
}
|
||||
|
||||
@@ -87,14 +88,14 @@ public final class ChatLogStore {
|
||||
/**
|
||||
* Searches a whole log, not only the part {@link #HISTORY_LIMIT} loads into a chat.
|
||||
*
|
||||
* @param clientUniqueId the peer, for {@link ChatLogScope#PRIVATE}; ignored otherwise
|
||||
* @param clientUniqueId the peer, for {@link ChatScope#PRIVATE}; ignored otherwise
|
||||
* @param limit how many of the newest matches to return
|
||||
*/
|
||||
public SearchResult search(ChatLogScope scope, String clientUniqueId, TextQuery query, int limit)
|
||||
public SearchResult search(ChatScope scope, String clientUniqueId, TextQuery query, int limit)
|
||||
throws IOException {
|
||||
List<String> all = scope == ChatLogScope.SERVER
|
||||
List<String> all = scope == ChatScope.SERVER
|
||||
? readHtml(log(scope), Long.MAX_VALUE)
|
||||
: readTextMessages(scope == ChatLogScope.PRIVATE ? privateLog(clientUniqueId) : log(scope), scope,
|
||||
: readTextMessages(scope == ChatScope.PRIVATE ? privateLog(clientUniqueId) : log(scope), scope,
|
||||
Long.MAX_VALUE);
|
||||
List<String> hits = new ArrayList<>();
|
||||
for (String entry : all) {
|
||||
@@ -104,9 +105,9 @@ public final class ChatLogStore {
|
||||
}
|
||||
|
||||
/** Logs a message; a private one goes to the log of the client it came from. */
|
||||
public synchronized String appendMessage(ChatLogScope scope, boolean outgoing, int clientId, String uniqueId,
|
||||
public synchronized String appendMessage(ChatScope scope, boolean outgoing, int clientId, String uniqueId,
|
||||
String nickname, String message) throws IOException {
|
||||
LogFiles files = scope == ChatLogScope.PRIVATE ? privateLog(uniqueId) : log(scope);
|
||||
LogFiles files = scope == ChatScope.PRIVATE ? privateLog(uniqueId) : log(scope);
|
||||
return append(files, scope, outgoing, clientId, uniqueId, nickname, message);
|
||||
}
|
||||
|
||||
@@ -114,11 +115,11 @@ public final class ChatLogStore {
|
||||
public synchronized String appendPrivateMessage(String peerUniqueId, boolean outgoing, int clientId,
|
||||
String uniqueId, String nickname, String message)
|
||||
throws IOException {
|
||||
return append(privateLog(peerUniqueId), ChatLogScope.PRIVATE, outgoing, clientId, uniqueId, nickname,
|
||||
return append(privateLog(peerUniqueId), ChatScope.PRIVATE, outgoing, clientId, uniqueId, nickname,
|
||||
message);
|
||||
}
|
||||
|
||||
private String append(LogFiles files, ChatLogScope scope, boolean outgoing, int clientId, String uniqueId,
|
||||
private String append(LogFiles files, ChatScope scope, boolean outgoing, int clientId, String uniqueId,
|
||||
String nickname, String message) throws IOException {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String text = "<" + TIME.format(now) + "> " + safe(nickname) + ": " + safe(message);
|
||||
@@ -131,7 +132,7 @@ public final class ChatLogStore {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String text = "<" + TIME.format(now) + "> " + safe(message);
|
||||
String html = eventHtml(now, BBCode.linksToHtml(message));
|
||||
appendRaw(log(ChatLogScope.SERVER), text, html);
|
||||
appendRaw(log(ChatScope.SERVER), text, html);
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -143,7 +144,7 @@ public final class ChatLogStore {
|
||||
return new String(Base64.getDecoder().decode(value), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private LogFiles log(ChatLogScope scope) {
|
||||
private LogFiles log(ChatScope scope) {
|
||||
return switch (scope) {
|
||||
case SERVER -> new LogFiles(serverDir.resolve("server.txt"), serverDir.resolve("server.html"));
|
||||
case CHANNEL -> new LogFiles(serverDir.resolve("channel.txt"), serverDir.resolve("channel.html"));
|
||||
@@ -197,7 +198,7 @@ public final class ChatLogStore {
|
||||
* A message is written as it was sent, so one with line breaks spans several lines of the
|
||||
* log: a line that starts no entry of its own continues the message before it.
|
||||
*/
|
||||
private static List<String> readTextMessages(LogFiles files, ChatLogScope scope, long tailBytes)
|
||||
private static List<String> readTextMessages(LogFiles files, ChatScope scope, long tailBytes)
|
||||
throws IOException {
|
||||
if (!Files.isRegularFile(files.txt)) return Collections.emptyList();
|
||||
List<String> entries = new ArrayList<>();
|
||||
@@ -250,7 +251,7 @@ public final class ChatLogStore {
|
||||
+ BBCode.escape(line) + "</span></div>";
|
||||
}
|
||||
|
||||
private static String messageLineHtml(Matcher m, CharSequence text, ChatLogScope scope) {
|
||||
private static String messageLineHtml(Matcher m, CharSequence text, ChatScope scope) {
|
||||
String target = switch (scope) {
|
||||
case PRIVATE -> "Private";
|
||||
case CHANNEL -> "Channel";
|
||||
@@ -268,7 +269,7 @@ public final class ChatLogStore {
|
||||
+ "*** " + kind + " begins " + BEGIN.format(timestamp) + "</span></p>";
|
||||
}
|
||||
|
||||
private static String messageHtml(ChatLogScope scope, boolean outgoing, LocalDateTime timestamp,
|
||||
private static String messageHtml(ChatScope scope, boolean outgoing, LocalDateTime timestamp,
|
||||
int clientId, String uniqueId, String nickname, String message) {
|
||||
String target = switch (scope) {
|
||||
case PRIVATE -> "Private";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package eu.lixko.ts3j.client.net;
|
||||
|
||||
import eu.lixko.ts3j.client.chatlog.ChatLogScope;
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.chatlog.ChatLogStore;
|
||||
import eu.lixko.ts3j.client.config.Settings;
|
||||
|
||||
@@ -44,8 +44,8 @@ final class ChatLog {
|
||||
logs.begin();
|
||||
List<String> serverHistory = logs.serverHtmlHistory();
|
||||
List<String> channelHistory = logs.channelHtmlHistory();
|
||||
ui.onChatHistory(ConnectionListener.ChatScope.SERVER, serverHistory);
|
||||
ui.onChatHistory(ConnectionListener.ChatScope.CHANNEL, channelHistory);
|
||||
ui.onChatHistory(ChatScope.SERVER, serverHistory);
|
||||
ui.onChatHistory(ChatScope.CHANNEL, channelHistory);
|
||||
ui.onStatus("Loaded chat logs from " + logs.serverDir()
|
||||
+ " (" + serverHistory.size() + " server, " + channelHistory.size() + " channel)");
|
||||
} catch (Exception e) {
|
||||
@@ -69,28 +69,28 @@ final class ChatLog {
|
||||
}
|
||||
}
|
||||
|
||||
void received(ConnectionListener.ChatScope scope, int fromClientId, String fromUniqueId, String fromName,
|
||||
void received(ChatScope scope, int fromClientId, String fromUniqueId, String fromName,
|
||||
String message) {
|
||||
ChatLogStore logs = store;
|
||||
if (logs == null) return;
|
||||
try {
|
||||
logs.appendMessage(scope(scope), false, fromClientId, fromUniqueId, fromName, message);
|
||||
logs.appendMessage(scope, false, fromClientId, fromUniqueId, fromName, message);
|
||||
} catch (IOException e) {
|
||||
ui.onStatus("Could not write chat log: " + RequestException.rootMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
/** What we said; a private message is kept with {@code peerUniqueId}'s log, and dropped without one. */
|
||||
void sent(ConnectionListener.ChatScope scope, int selfClientId, String selfUniqueId, String selfName,
|
||||
void sent(ChatScope scope, int selfClientId, String selfUniqueId, String selfName,
|
||||
String peerUniqueId, String message) {
|
||||
ChatLogStore logs = store;
|
||||
if (logs == null) return;
|
||||
try {
|
||||
if (scope == ConnectionListener.ChatScope.PRIVATE) {
|
||||
if (scope == ChatScope.PRIVATE) {
|
||||
if (peerUniqueId == null || peerUniqueId.isBlank()) return;
|
||||
logs.appendPrivateMessage(peerUniqueId, true, selfClientId, selfUniqueId, selfName, message);
|
||||
} else {
|
||||
logs.appendMessage(scope(scope), true, selfClientId, selfUniqueId, selfName, message);
|
||||
logs.appendMessage(scope, true, selfClientId, selfUniqueId, selfName, message);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ui.onStatus("Could not write chat log: " + RequestException.rootMessage(e));
|
||||
@@ -111,12 +111,4 @@ final class ChatLog {
|
||||
ui.onStatus("Could not write server log: " + RequestException.rootMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
private static ChatLogScope scope(ConnectionListener.ChatScope scope) {
|
||||
return switch (scope) {
|
||||
case SERVER -> ChatLogScope.SERVER;
|
||||
case CHANNEL -> ChatLogScope.CHANNEL;
|
||||
case PRIVATE -> ChatLogScope.PRIVATE;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package eu.lixko.ts3j.client.net;
|
||||
import com.github.manevolent.ts3j.event.*;
|
||||
import com.github.manevolent.ts3j.api.TextMessageTargetMode;
|
||||
import eu.lixko.ts3j.client.audio.VoiceOutput;
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.contacts.Contact;
|
||||
import eu.lixko.ts3j.client.sound.SoundEvent;
|
||||
import eu.lixko.ts3j.client.sound.SoundNotifier;
|
||||
@@ -651,19 +652,19 @@ final class ConnectionEventHandler implements TS3Listener {
|
||||
boolean isPrivate = e.getTargetMode() == TextMessageTargetMode.CLIENT;
|
||||
if (isPrivate ? contact.ignorePrivateMessages : contact.ignorePublicMessages) return;
|
||||
}
|
||||
ConnectionListener.ChatScope scope;
|
||||
ChatScope scope;
|
||||
SoundEvent notification;
|
||||
switch (e.getTargetMode()) {
|
||||
case CLIENT:
|
||||
scope = ConnectionListener.ChatScope.PRIVATE;
|
||||
scope = ChatScope.PRIVATE;
|
||||
notification = SoundEvent.CHAT_RECEIVED_MESSAGE_CLIENT;
|
||||
break;
|
||||
case CHANNEL:
|
||||
scope = ConnectionListener.ChatScope.CHANNEL;
|
||||
scope = ChatScope.CHANNEL;
|
||||
notification = SoundEvent.CHAT_RECEIVED_MESSAGE_CHANNEL;
|
||||
break;
|
||||
default:
|
||||
scope = ConnectionListener.ChatScope.SERVER;
|
||||
scope = ChatScope.SERVER;
|
||||
notification = SoundEvent.CHAT_RECEIVED_MESSAGE_SERVER;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package eu.lixko.ts3j.client.net;
|
||||
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -8,9 +10,6 @@ import java.util.List;
|
||||
*/
|
||||
public interface ConnectionListener {
|
||||
|
||||
/** Message scope for chat display. */
|
||||
enum ChatScope {SERVER, CHANNEL, PRIVATE}
|
||||
|
||||
void onStatus(String status);
|
||||
|
||||
void onConnected();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.lixko.ts3j.client.net;
|
||||
|
||||
import eu.lixko.ts3j.client.audio.VoiceReceiveStats;
|
||||
import eu.lixko.ts3j.client.text.ByteSize;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -13,7 +14,7 @@ import java.util.List;
|
||||
*/
|
||||
public final class ConnectionStatsFormat {
|
||||
|
||||
public static final String UNKNOWN = "—";
|
||||
public static final String UNKNOWN = ByteSize.UNKNOWN;
|
||||
public static final String HIDDEN = "Hidden";
|
||||
public static final String UNLIMITED = "Unlimited";
|
||||
public static final String EXCEEDED = "Exceeded";
|
||||
@@ -73,15 +74,15 @@ public final class ConnectionStatsFormat {
|
||||
List<TrafficRow> rows = new ArrayList<>(List.of(
|
||||
new TrafficRow("Packet loss", loss(t.lossTotal()), loss(t.lossIn), loss(t.lossOut)),
|
||||
new TrafficRow("Packets transferred", "", count(t.packetsIn), count(t.packetsOut)),
|
||||
new TrafficRow("Bytes transferred", "", bytes(t.bytesIn), bytes(t.bytesOut)),
|
||||
new TrafficRow("Bytes transferred", "", ByteSize.format(t.bytesIn), ByteSize.format(t.bytesOut)),
|
||||
new TrafficRow("Bandwidth last second", "",
|
||||
rate(t.bandwidthInLastSecond), rate(t.bandwidthOutLastSecond)),
|
||||
ByteSize.rate(t.bandwidthInLastSecond), ByteSize.rate(t.bandwidthOutLastSecond)),
|
||||
new TrafficRow("Bandwidth last minute", "",
|
||||
rate(t.bandwidthInLastMinute), rate(t.bandwidthOutLastMinute))));
|
||||
ByteSize.rate(t.bandwidthInLastMinute), ByteSize.rate(t.bandwidthOutLastMinute))));
|
||||
if (kind == null) {
|
||||
long in = s == null ? -1 : s.filetransferBandwidthReceived;
|
||||
long out = s == null ? -1 : s.filetransferBandwidthSent;
|
||||
rows.add(new TrafficRow("File transfer bandwidth", "", rate(in), rate(out)));
|
||||
rows.add(new TrafficRow("File transfer bandwidth", "", ByteSize.rate(in), ByteSize.rate(out)));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
@@ -98,14 +99,14 @@ public final class ConnectionStatsFormat {
|
||||
}
|
||||
|
||||
private static List<Row> quota(ConnectionStats s, String direction, String label, long used, long quotaMb) {
|
||||
Row month = new Row(label, bytes(used));
|
||||
Row month = new Row(label, ByteSize.format(used));
|
||||
if (!s.self) return List.of(month);
|
||||
String available = quotaMb < 0 ? UNLIMITED : bytes(quotaMb * 1024 * 1024);
|
||||
String available = quotaMb < 0 ? UNLIMITED : ByteSize.format(quotaMb * 1024 * 1024);
|
||||
String remaining;
|
||||
if (quotaMb < 0) remaining = UNLIMITED;
|
||||
else if (used < 0) remaining = UNKNOWN;
|
||||
else if (used > quotaMb * 1024 * 1024) remaining = EXCEEDED;
|
||||
else remaining = bytes(quotaMb * 1024 * 1024 - used);
|
||||
else remaining = ByteSize.format(quotaMb * 1024 * 1024 - used);
|
||||
return List.of(month,
|
||||
new Row("Available " + direction + " quota:", available),
|
||||
new Row("Remaining " + direction + " this month:", remaining));
|
||||
@@ -157,21 +158,6 @@ public final class ConnectionStatsFormat {
|
||||
return count(n) + " (" + new DecimalFormat("0.0").format(100.0 * n / of) + " %)";
|
||||
}
|
||||
|
||||
public static String bytes(long bytes) {
|
||||
if (bytes < 0) return UNKNOWN;
|
||||
if (bytes < 1024) return bytes + " Bytes";
|
||||
DecimalFormat f = new DecimalFormat("0.00");
|
||||
double kib = bytes / 1024.0;
|
||||
if (kib < 1024) return f.format(kib) + " KiB";
|
||||
double mib = kib / 1024.0;
|
||||
if (mib < 1024) return f.format(mib) + " MiB";
|
||||
return f.format(mib / 1024.0) + " GiB";
|
||||
}
|
||||
|
||||
public static String rate(long bytesPerSecond) {
|
||||
return bytesPerSecond < 0 ? UNKNOWN : bytes(bytesPerSecond) + "/s";
|
||||
}
|
||||
|
||||
/** {@code 04:34}, or {@code 15:35:17} from an hour on. */
|
||||
public static String duration(long ms) {
|
||||
if (ms < 0) return UNKNOWN;
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.github.manevolent.ts3j.protocol.socket.client.LocalTeamspeakClientSoc
|
||||
import com.github.manevolent.ts3j.util.Ts3Crypt;
|
||||
import eu.lixko.ts3j.client.audio.AudioBackend;
|
||||
import eu.lixko.ts3j.client.audio.VoiceOutput;
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.config.Settings;
|
||||
import eu.lixko.ts3j.client.contacts.ContactStore;
|
||||
import eu.lixko.ts3j.client.myts.MyTeamSpeakIdentity;
|
||||
@@ -561,7 +562,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
ClientEntry self = own.entry();
|
||||
int cid = self != null ? self.channelId : 0;
|
||||
sock.sendChannelMessage(cid, text);
|
||||
keepSentChat(ConnectionListener.ChatScope.CHANNEL, "", text);
|
||||
keepSentChat(ChatScope.CHANNEL, "", text);
|
||||
announce.sound(SoundEvent.CHAT_SENT_MESSAGE_CHANNEL, announce.channelVars(cid, null));
|
||||
});
|
||||
}
|
||||
@@ -569,7 +570,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
public void sendServerMessage(String text) {
|
||||
act("Message failed: ", sock -> {
|
||||
sock.sendServerMessage(text);
|
||||
keepSentChat(ConnectionListener.ChatScope.SERVER, "", text);
|
||||
keepSentChat(ChatScope.SERVER, "", text);
|
||||
announce.sound(SoundEvent.CHAT_SENT_MESSAGE_SERVER, announce.serverVars());
|
||||
});
|
||||
}
|
||||
@@ -586,7 +587,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
keepSentChat(ConnectionListener.ChatScope.PRIVATE, peerUid, text);
|
||||
keepSentChat(ChatScope.PRIVATE, peerUid, text);
|
||||
announce.sound(SoundEvent.CHAT_SENT_MESSAGE_CLIENT, announce.clientVars(clientId, null));
|
||||
});
|
||||
}
|
||||
@@ -798,7 +799,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
chatLog.loadPrivateHistory(clientId, c != null ? c.nickname : "Client " + clientId, uniqueId);
|
||||
}
|
||||
|
||||
private void keepSentChat(ConnectionListener.ChatScope scope, String peerUniqueId, String message) {
|
||||
private void keepSentChat(ChatScope scope, String peerUniqueId, String message) {
|
||||
ClientEntry self = own.entry();
|
||||
String uid = identity != null ? identity.getUid().toBase64() : "";
|
||||
String nickname = self != null ? self.nickname : settings.nickname.get();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.lixko.ts3j.client.session;
|
||||
|
||||
import eu.lixko.ts3j.client.audio.AudioBackend;
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.config.Bookmark;
|
||||
import eu.lixko.ts3j.client.config.IdentityEntry;
|
||||
import eu.lixko.ts3j.client.config.IdentityStore;
|
||||
@@ -648,7 +649,7 @@ public final class ServerSession {
|
||||
*
|
||||
* @param clientId the recipient of a private message; ignored otherwise
|
||||
*/
|
||||
public void sendChat(ConnectionListener.ChatScope scope, int clientId, String text) {
|
||||
public void sendChat(ChatScope scope, int clientId, String text) {
|
||||
if (!conn.isConnected()) {
|
||||
listener.onSystemMessage("Not connected.");
|
||||
return;
|
||||
@@ -676,7 +677,7 @@ public final class ServerSession {
|
||||
*
|
||||
* @param data read and closed in the background
|
||||
*/
|
||||
public void sendAttachment(ConnectionListener.ChatScope scope, int clientId, ChatAttachments attachments,
|
||||
public void sendAttachment(ChatScope scope, int clientId, ChatAttachments attachments,
|
||||
InputStream data, long size, String fileName) {
|
||||
String room = conn.serverUniqueId();
|
||||
if (!conn.isConnected() || room == null) {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package eu.lixko.ts3j.client.text;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/** Byte counts the way the TeamSpeak client writes them: {@code 1023 Bytes}, {@code 353.98 KiB}. */
|
||||
public final class ByteSize {
|
||||
|
||||
/** What an unknown (negative) size shows as. */
|
||||
public static final String UNKNOWN = "—";
|
||||
|
||||
private ByteSize() {
|
||||
}
|
||||
|
||||
public static String format(long bytes) {
|
||||
if (bytes < 0) return UNKNOWN;
|
||||
if (bytes < 1024) return bytes + " Bytes";
|
||||
DecimalFormat f = new DecimalFormat("0.00");
|
||||
double kib = bytes / 1024.0;
|
||||
if (kib < 1024) return f.format(kib) + " KiB";
|
||||
double mib = kib / 1024.0;
|
||||
if (mib < 1024) return f.format(mib) + " MiB";
|
||||
return f.format(mib / 1024.0) + " GiB";
|
||||
}
|
||||
|
||||
public static String rate(long bytesPerSecond) {
|
||||
return bytesPerSecond < 0 ? UNKNOWN : format(bytesPerSecond) + "/s";
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import eu.lixko.ts3j.client.myts.ChatAttachments;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -73,7 +72,7 @@ public final class ChatHtml {
|
||||
if (attachment.isImage() && attachment.fileSize() <= ChatAttachments.MAX_PREVIEW_BYTES) {
|
||||
return "<br>" + open + "<img src=\"" + href + "\"></a>" + caption;
|
||||
}
|
||||
String size = attachment.fileSize() >= 0 ? " " + span(MUTED_CLASS, "(" + size(attachment.fileSize()) + ")") : "";
|
||||
String size = attachment.fileSize() >= 0 ? " " + span(MUTED_CLASS, "(" + ByteSize.format(attachment.fileSize()) + ")") : "";
|
||||
return open + name + "</a>" + size + caption;
|
||||
}
|
||||
|
||||
@@ -131,13 +130,6 @@ public final class ChatHtml {
|
||||
return html.substring(0, m.start(2)) + attachment(attachment, room) + html.substring(m.end(2));
|
||||
}
|
||||
|
||||
/** A file size as people read it. */
|
||||
static String size(long bytes) {
|
||||
if (bytes < 1024) return bytes + " B";
|
||||
if (bytes < 1024 * 1024) return String.format(Locale.ROOT, "%.0f KB", bytes / 1024.0);
|
||||
return String.format(Locale.ROOT, "%.1f MB", bytes / (1024.0 * 1024));
|
||||
}
|
||||
|
||||
private static String stamp() {
|
||||
return "[" + TIME.format(LocalTime.now()) + "] ";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.lixko.ts3j.client.chatlog;
|
||||
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.text.TextQuery;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@@ -45,23 +46,23 @@ class ChatLogStoreTest {
|
||||
@Test
|
||||
void searchReachesPastTheLoadedHistory() throws Exception {
|
||||
ChatLogStore logs = new ChatLogStore(temp, "+Tyg2JtxE8vRNZp+JiUBnmBh0MY=");
|
||||
logs.appendMessage(ChatLogScope.CHANNEL, false, 5, "uid", "alice", "the needle is here");
|
||||
logs.appendMessage(ChatScope.CHANNEL, false, 5, "uid", "alice", "the needle is here");
|
||||
for (int i = 0; i < ChatLogStore.HISTORY_LIMIT; i++) {
|
||||
logs.appendMessage(ChatLogScope.CHANNEL, false, 5, "uid", "alice", "filler " + i);
|
||||
logs.appendMessage(ChatScope.CHANNEL, false, 5, "uid", "alice", "filler " + i);
|
||||
}
|
||||
logs.appendServerEvent("a NEEDLE of the server");
|
||||
|
||||
assertTrue(logs.channelHtmlHistory().stream().noneMatch(e -> e.contains("needle")));
|
||||
ChatLogStore.SearchResult channel = logs.search(ChatLogScope.CHANNEL, null,
|
||||
ChatLogStore.SearchResult channel = logs.search(ChatScope.CHANNEL, null,
|
||||
new TextQuery("needle", false, false, false), 10);
|
||||
assertEquals(1, channel.total());
|
||||
assertTrue(channel.entries().get(0).contains("the needle is here"));
|
||||
|
||||
ChatLogStore.SearchResult server = logs.search(ChatLogScope.SERVER, null,
|
||||
ChatLogStore.SearchResult server = logs.search(ChatScope.SERVER, null,
|
||||
new TextQuery("needle", true, false, false), 10);
|
||||
assertEquals(0, server.total());
|
||||
|
||||
ChatLogStore.SearchResult capped = logs.search(ChatLogScope.CHANNEL, null,
|
||||
ChatLogStore.SearchResult capped = logs.search(ChatScope.CHANNEL, null,
|
||||
new TextQuery("filler", false, false, false), 10);
|
||||
assertEquals(ChatLogStore.HISTORY_LIMIT, capped.total());
|
||||
assertEquals(10, capped.entries().size());
|
||||
@@ -72,8 +73,8 @@ class ChatLogStoreTest {
|
||||
@Test
|
||||
void readsAMessageWithLineBreaksBackWhole() throws Exception {
|
||||
ChatLogStore logs = new ChatLogStore(temp, "+Tyg2JtxE8vRNZp+JiUBnmBh0MY=");
|
||||
logs.appendMessage(ChatLogScope.CHANNEL, false, 5, "uid", "alice", "first line\n\nthird line");
|
||||
logs.appendMessage(ChatLogScope.CHANNEL, false, 5, "uid", "bob", "reply");
|
||||
logs.appendMessage(ChatScope.CHANNEL, false, 5, "uid", "alice", "first line\n\nthird line");
|
||||
logs.appendMessage(ChatScope.CHANNEL, false, 5, "uid", "bob", "reply");
|
||||
|
||||
List<String> history = logs.channelHtmlHistory();
|
||||
assertEquals(2, history.size());
|
||||
@@ -84,12 +85,12 @@ class ChatLogStoreTest {
|
||||
@Test
|
||||
void historyComesFromTheEndOfALongLog() throws Exception {
|
||||
ChatLogStore logs = new ChatLogStore(temp, "+Tyg2JtxE8vRNZp+JiUBnmBh0MY=");
|
||||
logs.appendMessage(ChatLogScope.CHANNEL, false, 5, "uid", "alice", "start");
|
||||
logs.appendMessage(ChatScope.CHANNEL, false, 5, "uid", "alice", "start");
|
||||
Path txt = logs.serverDir().resolve("channel.txt");
|
||||
StringBuilder filler = new StringBuilder();
|
||||
for (int i = 0; i < 200_000; i++) filler.append("<12:00:00> alice: žluťoučký kůň ").append(i).append('\n');
|
||||
Files.writeString(txt, filler, java.nio.file.StandardOpenOption.APPEND);
|
||||
logs.appendMessage(ChatLogScope.CHANNEL, false, 5, "uid", "bob", "the latest");
|
||||
logs.appendMessage(ChatScope.CHANNEL, false, 5, "uid", "bob", "the latest");
|
||||
|
||||
List<String> history = logs.channelHtmlHistory();
|
||||
assertEquals(ChatLogStore.HISTORY_LIMIT, history.size());
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.github.manevolent.ts3j.event.ClientUpdatedEvent;
|
||||
import com.github.manevolent.ts3j.event.ServerGroupClientAddedEvent;
|
||||
import com.github.manevolent.ts3j.event.ServerGroupClientDeletedEvent;
|
||||
import com.github.manevolent.ts3j.protocol.ProtocolRole;
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.config.Settings;
|
||||
import eu.lixko.ts3j.client.contacts.ContactStore;
|
||||
import eu.lixko.ts3j.client.sound.SoundNotifier;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package eu.lixko.ts3j.client.text;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ByteSizeTest {
|
||||
|
||||
private Locale locale;
|
||||
|
||||
@BeforeEach
|
||||
void englishDecimals() {
|
||||
locale = Locale.getDefault();
|
||||
Locale.setDefault(Locale.ROOT);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void restoreLocale() {
|
||||
Locale.setDefault(locale);
|
||||
}
|
||||
|
||||
@Test
|
||||
void writesSizesAsTeamSpeakDoes() {
|
||||
assertEquals("1023 Bytes", ByteSize.format(1023));
|
||||
assertEquals("353.98 KiB", ByteSize.format(362_475));
|
||||
assertEquals("1.50 MiB", ByteSize.format(1_572_864));
|
||||
assertEquals("2.00 GiB", ByteSize.format(2L << 30));
|
||||
assertEquals("1.00 KiB/s", ByteSize.rate(1024));
|
||||
assertEquals(ByteSize.UNKNOWN, ByteSize.format(-1));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package eu.lixko.ts3j.client.text;
|
||||
|
||||
import eu.lixko.ts3j.client.chatlog.ChatLogScope;
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.chatlog.ChatLogStore;
|
||||
import eu.lixko.ts3j.client.myts.ChatAttachment;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -30,7 +30,7 @@ class ChatHtmlAttachmentTest {
|
||||
void showsAnyOtherFileAsALinkWithItsSize() {
|
||||
String html = ChatHtml.message(5, "uid", "alice", FILE.toMessage(), ROOM);
|
||||
assertTrue(html.contains("href=\"" + FILE.href(ROOM) + "\">notes <1>.txt</a>"), html);
|
||||
assertTrue(html.contains("(3.0 MB)"), html);
|
||||
assertTrue(html.contains("(" + ByteSize.format(FILE.fileSize()) + ")"), html);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +43,7 @@ class ChatHtmlAttachmentTest {
|
||||
@Test
|
||||
void showsTheFileInLogHistory(@TempDir Path temp) throws Exception {
|
||||
ChatLogStore logs = new ChatLogStore(temp, ROOM);
|
||||
logs.appendMessage(ChatLogScope.CHANNEL, false, 5, "uid", "alice", PICTURE.toMessage());
|
||||
logs.appendMessage(ChatScope.CHANNEL, false, 5, "uid", "alice", PICTURE.toMessage());
|
||||
List<String> history = logs.channelHtmlHistory();
|
||||
String html = ChatHtml.logEntry(history.get(history.size() - 1), ROOM);
|
||||
assertTrue(html.contains("<img src=\"" + PICTURE.href(ROOM) + "\">"), html);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package eu.lixko.ts3j.client.ui;
|
||||
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.myts.ChatAttachment;
|
||||
import eu.lixko.ts3j.client.myts.ChatAttachments;
|
||||
import eu.lixko.ts3j.client.myts.MyTsException;
|
||||
import eu.lixko.ts3j.client.net.ConnectionListener.ChatScope;
|
||||
import eu.lixko.ts3j.client.net.PictureDownloads;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Shares files in one server's chats through myTeamSpeak, and shows and saves the files
|
||||
@@ -37,19 +36,16 @@ final class ChatAttachmentActions implements ChatPanel.AttachmentHandler {
|
||||
private final ServerSession session;
|
||||
private final ChatPanel chat;
|
||||
private final PictureDownloads pictures;
|
||||
private final Function<ChatPanel.Target, ChatScope> scopes;
|
||||
|
||||
ChatAttachmentActions(MainFrame host, ServerSession session, ChatPanel chat, PictureDownloads pictures,
|
||||
Function<ChatPanel.Target, ChatScope> scopes) {
|
||||
ChatAttachmentActions(MainFrame host, ServerSession session, ChatPanel chat, PictureDownloads pictures) {
|
||||
this.host = host;
|
||||
this.session = session;
|
||||
this.chat = chat;
|
||||
this.pictures = pictures;
|
||||
this.scopes = scopes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void choose(ChatPanel.Target target, int clientId) {
|
||||
public void choose(ChatScope scope, int clientId) {
|
||||
if (!signedIn()) return;
|
||||
JFileChooser chooser = new JFileChooser(lastDirectory);
|
||||
chooser.setMultiSelectionEnabled(true);
|
||||
@@ -57,11 +53,11 @@ final class ChatAttachmentActions implements ChatPanel.AttachmentHandler {
|
||||
if (chooser.showOpenDialog(host) != JFileChooser.APPROVE_OPTION) return;
|
||||
File[] files = chooser.getSelectedFiles();
|
||||
if (files.length > 0) lastDirectory = files[0].getParentFile();
|
||||
share(target, clientId, List.of(files));
|
||||
share(scope, clientId, List.of(files));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void share(ChatPanel.Target target, int clientId, List<File> files) {
|
||||
public void share(ChatScope scope, int clientId, List<File> files) {
|
||||
if (!signedIn()) return;
|
||||
for (File file : files) {
|
||||
if (!file.isFile()) continue;
|
||||
@@ -70,7 +66,7 @@ final class ChatAttachmentActions implements ChatPanel.AttachmentHandler {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
session.sendAttachment(scopes.apply(target), clientId, host.attachments(),
|
||||
session.sendAttachment(scope, clientId, host.attachments(),
|
||||
new FileInputStream(file), file.length(), file.getName());
|
||||
} catch (IOException e) {
|
||||
chat.appendSystem("Could not share " + file.getName() + ": " + e.getMessage());
|
||||
@@ -79,7 +75,7 @@ final class ChatAttachmentActions implements ChatPanel.AttachmentHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void share(ChatPanel.Target target, int clientId, BufferedImage image) {
|
||||
public void share(ChatScope scope, int clientId, BufferedImage image) {
|
||||
if (!signedIn()) return;
|
||||
ByteArrayOutputStream png = new ByteArrayOutputStream();
|
||||
try {
|
||||
@@ -88,7 +84,7 @@ final class ChatAttachmentActions implements ChatPanel.AttachmentHandler {
|
||||
chat.appendSystem("Could not share the picture: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
session.sendAttachment(scopes.apply(target), clientId, host.attachments(),
|
||||
session.sendAttachment(scope, clientId, host.attachments(),
|
||||
new ByteArrayInputStream(png.toByteArray()), png.size(), PASTED_NAME);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package eu.lixko.ts3j.client.ui;
|
||||
|
||||
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.config.Settings;
|
||||
import eu.lixko.ts3j.client.myts.ChatAttachment;
|
||||
import eu.lixko.ts3j.client.net.PictureDownloads;
|
||||
@@ -62,12 +63,9 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
public final class ChatPanel extends JPanel {
|
||||
|
||||
/** Where an outgoing message should go. */
|
||||
public enum Target {CHANNEL, SERVER, PRIVATE}
|
||||
|
||||
public interface SendHandler {
|
||||
/** {@code clientId} is only meaningful for {@link Target#PRIVATE}. */
|
||||
void send(Target target, int clientId, String text);
|
||||
/** {@code clientId} is only meaningful for {@link ChatScope#PRIVATE}. */
|
||||
void send(ChatScope scope, int clientId, String text);
|
||||
}
|
||||
|
||||
/** Invoked when a client or channel link in the log is clicked. */
|
||||
@@ -83,11 +81,11 @@ public final class ChatPanel extends JPanel {
|
||||
/** Files shared in the chats, which the host sends, fetches and shows. */
|
||||
public interface AttachmentHandler {
|
||||
/** Asks which files to share in the conversation. */
|
||||
void choose(Target target, int clientId);
|
||||
void choose(ChatScope scope, int clientId);
|
||||
|
||||
void share(Target target, int clientId, List<File> files);
|
||||
void share(ChatScope scope, int clientId, List<File> files);
|
||||
|
||||
void share(Target target, int clientId, BufferedImage image);
|
||||
void share(ChatScope scope, int clientId, BufferedImage image);
|
||||
|
||||
/**
|
||||
* A shared file was clicked.
|
||||
@@ -110,8 +108,8 @@ public final class ChatPanel extends JPanel {
|
||||
private static final String NO_SERVER = "Server";
|
||||
private static final String NO_CHANNEL = "Channel";
|
||||
|
||||
private final Tab serverTab = new Tab(Target.SERVER, 0, NO_SERVER, Icons.server());
|
||||
private final Tab channelTab = new Tab(Target.CHANNEL, 0, NO_CHANNEL, Icons.channelChat());
|
||||
private final Tab serverTab = new Tab(ChatScope.SERVER, 0, NO_SERVER, Icons.server());
|
||||
private final Tab channelTab = new Tab(ChatScope.CHANNEL, 0, NO_CHANNEL, Icons.channelChat());
|
||||
/** Private chats keyed by the peer's client id. */
|
||||
private final Map<Integer, Tab> privateTabs = new LinkedHashMap<>();
|
||||
/** Static-content tabs (e.g. a moved-out description), keyed by caller-chosen id. */
|
||||
@@ -197,8 +195,8 @@ public final class ChatPanel extends JPanel {
|
||||
attach.setFocusable(false);
|
||||
attach.addActionListener(e -> {
|
||||
Tab tab = selectedTab();
|
||||
if (attachmentHandler != null && tab != null && tab.target != null) {
|
||||
attachmentHandler.choose(tab.target, tab.clientId);
|
||||
if (attachmentHandler != null && tab != null && tab.scope != null) {
|
||||
attachmentHandler.choose(tab.scope, tab.clientId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -278,16 +276,16 @@ public final class ChatPanel extends JPanel {
|
||||
@Override
|
||||
public boolean files(List<File> files) {
|
||||
Tab tab = selectedTab();
|
||||
if (attachmentHandler == null || tab == null || tab.target == null) return false;
|
||||
attachmentHandler.share(tab.target, tab.clientId, files);
|
||||
if (attachmentHandler == null || tab == null || tab.scope == null) return false;
|
||||
attachmentHandler.share(tab.scope, tab.clientId, files);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean image(BufferedImage image) {
|
||||
Tab tab = selectedTab();
|
||||
if (attachmentHandler == null || tab == null || tab.target == null) return false;
|
||||
attachmentHandler.share(tab.target, tab.clientId, image);
|
||||
if (attachmentHandler == null || tab == null || tab.scope == null) return false;
|
||||
attachmentHandler.share(tab.scope, tab.clientId, image);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -365,8 +363,8 @@ public final class ChatPanel extends JPanel {
|
||||
String text = input.getText().trim();
|
||||
if (text.isEmpty() || sendHandler == null) return;
|
||||
Tab tab = selectedTab();
|
||||
if (tab == null || tab.target == null) return;
|
||||
sendHandler.send(tab.target, tab.clientId, text);
|
||||
if (tab == null || tab.scope == null) return;
|
||||
sendHandler.send(tab.scope, tab.clientId, text);
|
||||
input.setText("");
|
||||
}
|
||||
|
||||
@@ -424,7 +422,7 @@ public final class ChatPanel extends JPanel {
|
||||
private Tab privateTab(int clientId, String uniqueId, String nickname) {
|
||||
Tab tab = privateTabs.get(clientId);
|
||||
if (tab == null) {
|
||||
tab = new Tab(Target.PRIVATE, clientId, uniqueId, nickname, Icons.privateChat());
|
||||
tab = new Tab(ChatScope.PRIVATE, clientId, uniqueId, nickname, Icons.privateChat());
|
||||
privateTabs.put(clientId, tab);
|
||||
addTab(tab, true);
|
||||
} else {
|
||||
@@ -509,7 +507,7 @@ public final class ChatPanel extends JPanel {
|
||||
/** One conversation: its HTML log, its scroll pane and the tab-strip header. */
|
||||
private final class Tab {
|
||||
|
||||
final Target target;
|
||||
final ChatScope scope;
|
||||
final int clientId;
|
||||
private String clientUniqueId;
|
||||
private String title;
|
||||
@@ -530,22 +528,22 @@ public final class ChatPanel extends JPanel {
|
||||
private String pictureState = "";
|
||||
private int renderedPictureWidth;
|
||||
|
||||
Tab(Target target, int clientId, String title, Icon icon) {
|
||||
this(target, clientId, "", title, icon, null, null);
|
||||
Tab(ChatScope scope, int clientId, String title, Icon icon) {
|
||||
this(scope, clientId, "", title, icon, null, null);
|
||||
}
|
||||
|
||||
Tab(Target target, int clientId, String clientUniqueId, String title, Icon icon) {
|
||||
this(target, clientId, clientUniqueId, title, icon, null, null);
|
||||
Tab(ChatScope scope, int clientId, String clientUniqueId, String title, Icon icon) {
|
||||
this(scope, clientId, clientUniqueId, title, icon, null, null);
|
||||
}
|
||||
|
||||
/** A static-content tab: no send target, closing it runs {@code onClose}. */
|
||||
/** A static-content tab: no send scope, closing it runs {@code onClose}. */
|
||||
Tab(String noteKey, Icon icon, String title, Runnable onClose) {
|
||||
this(null, 0, "", title, icon, noteKey, onClose);
|
||||
}
|
||||
|
||||
private Tab(Target target, int clientId, String clientUniqueId, String title,
|
||||
private Tab(ChatScope scope, int clientId, String clientUniqueId, String title,
|
||||
Icon icon, String noteKey, Runnable onClose) {
|
||||
this.target = target;
|
||||
this.scope = scope;
|
||||
this.clientId = clientId;
|
||||
this.clientUniqueId = clientUniqueId == null ? "" : clientUniqueId;
|
||||
this.title = title;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package eu.lixko.ts3j.client.ui;
|
||||
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.config.Settings;
|
||||
import eu.lixko.ts3j.client.net.ConnectionListener.ChatScope;
|
||||
import eu.lixko.ts3j.client.notify.desktop.DesktopNotifications;
|
||||
import eu.lixko.ts3j.client.notify.desktop.DesktopNotifications.Notice;
|
||||
import eu.lixko.ts3j.client.notify.desktop.FreedesktopNotifications;
|
||||
|
||||
@@ -6,6 +6,7 @@ import eu.lixko.ts3j.client.net.ChannelNode;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
import eu.lixko.ts3j.client.net.filetransfer.FileTransfer;
|
||||
import eu.lixko.ts3j.client.net.filetransfer.RemoteFile;
|
||||
import eu.lixko.ts3j.client.text.ByteSize;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Box;
|
||||
@@ -29,7 +30,6 @@ import java.awt.Frame;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -360,11 +360,11 @@ public final class FileBrowserDialog extends JDialog {
|
||||
label.setText(head + " — starting…");
|
||||
break;
|
||||
case ACTIVE:
|
||||
label.setText(head + " — " + formatBytes(t.getTransferredBytes()) + " / "
|
||||
+ formatBytes(t.getTotalBytes()) + " (" + formatRate(t.getAverageSpeed()) + ")");
|
||||
label.setText(head + " — " + ByteSize.format(t.getTransferredBytes()) + " / "
|
||||
+ ByteSize.format(t.getTotalBytes()) + " (" + formatRate(t.getAverageSpeed()) + ")");
|
||||
break;
|
||||
case COMPLETED:
|
||||
label.setText(head + " — done (" + formatBytes(t.getTotalBytes()) + ")");
|
||||
label.setText(head + " — done (" + ByteSize.format(t.getTotalBytes()) + ")");
|
||||
break;
|
||||
case CANCELLED:
|
||||
label.setText(head + " — cancelled");
|
||||
@@ -428,7 +428,7 @@ public final class FileBrowserDialog extends JDialog {
|
||||
case 0:
|
||||
return f.getName();
|
||||
case 1:
|
||||
return f.isDirectory() ? "" : formatBytes(f.getSize());
|
||||
return f.isDirectory() ? "" : ByteSize.format(f.getSize());
|
||||
case 2:
|
||||
return f.isDirectory() ? "Folder" : "File";
|
||||
case 3:
|
||||
@@ -454,19 +454,8 @@ public final class FileBrowserDialog extends JDialog {
|
||||
|
||||
// ---- formatting ----
|
||||
|
||||
private static String formatBytes(long bytes) {
|
||||
if (bytes < 0) return "—";
|
||||
if (bytes < 1024) return bytes + " B";
|
||||
double kib = bytes / 1024.0;
|
||||
if (kib < 1024) return new DecimalFormat("0.0").format(kib) + " KiB";
|
||||
double mib = kib / 1024.0;
|
||||
if (mib < 1024) return new DecimalFormat("0.00").format(mib) + " MiB";
|
||||
return new DecimalFormat("0.00").format(mib / 1024.0) + " GiB";
|
||||
}
|
||||
|
||||
private static String formatRate(double bytesPerSecond) {
|
||||
if (bytesPerSecond <= 0) return "—";
|
||||
return formatBytes(Math.round(bytesPerSecond)) + "/s";
|
||||
return bytesPerSecond > 0 ? ByteSize.rate(Math.round(bytesPerSecond)) : ByteSize.UNKNOWN;
|
||||
}
|
||||
|
||||
private static String orEmpty(String s) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import eu.lixko.ts3j.client.config.Settings;
|
||||
import eu.lixko.ts3j.client.contacts.ContactStore;
|
||||
import eu.lixko.ts3j.client.net.ChannelNode;
|
||||
import eu.lixko.ts3j.client.net.ClientEntry;
|
||||
import eu.lixko.ts3j.client.net.ConnectionListener.ChatScope;
|
||||
import eu.lixko.ts3j.client.net.OfflineMessage;
|
||||
import eu.lixko.ts3j.client.net.PictureDownloads;
|
||||
import eu.lixko.ts3j.client.net.avatar.Avatar;
|
||||
@@ -79,7 +78,7 @@ final class ServerTab {
|
||||
treeActions.attach(treePanel);
|
||||
events.attach(session, treePanel, chatPanel, treeActions);
|
||||
|
||||
chatPanel.setSendHandler(this::onSendChat);
|
||||
chatPanel.setSendHandler(session::sendChat);
|
||||
chatPanel.setLinkHandler(new ChatPanel.LinkHandler() {
|
||||
@Override
|
||||
public void onClientLink(TsLink.Ref ref, Component source, int x, int y) {
|
||||
@@ -96,7 +95,7 @@ final class ServerTab {
|
||||
showOfflineMessages();
|
||||
}
|
||||
});
|
||||
chatPanel.setAttachmentHandler(new ChatAttachmentActions(host, session, chatPanel, pictures, ServerTab::scope));
|
||||
chatPanel.setAttachmentHandler(new ChatAttachmentActions(host, session, chatPanel, pictures));
|
||||
chatPanel.setSharingAvailable(host.canShareFiles());
|
||||
chatPanel.setInputEnabled(false);
|
||||
|
||||
@@ -280,18 +279,6 @@ final class ServerTab {
|
||||
|
||||
// ---- chat ----
|
||||
|
||||
private void onSendChat(ChatPanel.Target target, int clientId, String text) {
|
||||
session.sendChat(scope(target), clientId, text);
|
||||
}
|
||||
|
||||
private static ChatScope scope(ChatPanel.Target target) {
|
||||
return switch (target) {
|
||||
case SERVER -> ChatScope.SERVER;
|
||||
case PRIVATE -> ChatScope.PRIVATE;
|
||||
default -> ChatScope.CHANNEL;
|
||||
};
|
||||
}
|
||||
|
||||
/** Opens the file repository browser for a channel, as the "Browse Files" hotkey/menu action does. */
|
||||
void browseFiles(ChannelNode channel) {
|
||||
treeActions.browseFiles(channel);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.lixko.ts3j.client.ui;
|
||||
|
||||
import eu.lixko.ts3j.client.chat.ChatScope;
|
||||
import eu.lixko.ts3j.client.config.Settings;
|
||||
import eu.lixko.ts3j.client.net.ChannelNode;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
|
||||
Reference in New Issue
Block a user