Add offline messages: inbox, compose and reply, unread notice
Tools > Offline Messages (Ctrl+O) lists the server inbox, shows a message and marks it read; compose and reply follow the official windows. The unread count comes from client_unread_messages: new mail is logged with a link to the inbox and shown as an envelope in the status bar. Recipients can be given by unique id, which needs no search permission. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,8 @@ public final class ClientEntry {
|
||||
/** The message published with the away state, empty when there is none. */
|
||||
public volatile String awayMessage = "";
|
||||
public volatile boolean channelCommander;
|
||||
/** Unread messages in the client's offline message inbox ({@code client_unread_messages}). */
|
||||
public volatile int unreadMessages;
|
||||
public volatile boolean self;
|
||||
|
||||
public ClientEntry(int id, String nickname) {
|
||||
|
||||
@@ -52,6 +52,7 @@ final class ConnectionEventHandler implements TS3Listener {
|
||||
c.databaseId = e.getClientDatabaseId();
|
||||
c.serverGroupIds = parseIntList(e.getClientServerGroups());
|
||||
c.channelGroupId = e.getClientChannelGroupId();
|
||||
c.unreadMessages = safeInt(e, "client_unread_messages");
|
||||
c.self = (e.getClientId() == conn.getSelfClientId());
|
||||
// Query clients stay out of sight, as they do in the tree and in TS3's log.
|
||||
if (!c.self && !c.isQuery()) {
|
||||
@@ -350,6 +351,11 @@ final class ConnectionEventHandler implements TS3Listener {
|
||||
c.channelCommander = e.getBoolean("client_is_channel_commander");
|
||||
if (reported(e, "client_flag_avatar")) c.avatarFlag = TeamspeakConnection.orEmpty(e.get("client_flag_avatar"));
|
||||
if (reported(e, "client_country")) c.country = TeamspeakConnection.orEmpty(e.get("client_country"));
|
||||
if (has(e, "client_unread_messages")) {
|
||||
int before = c.unreadMessages;
|
||||
c.unreadMessages = safeInt(e, "client_unread_messages");
|
||||
if (c.id == conn.getSelfClientId()) conn.unreadMessagesChanged(before);
|
||||
}
|
||||
announceClientUpdate(e, c, renamed, oldName);
|
||||
conn.ui.onModelChanged();
|
||||
}
|
||||
@@ -676,6 +682,7 @@ final class ConnectionEventHandler implements TS3Listener {
|
||||
else if ("notifytokenadd".equals(e.getCommand())) conn.privilegeKeys.onAdded(e);
|
||||
else if ("notifycomplainlist".equals(e.getCommand())) conn.complaints.onListEntry(e);
|
||||
else if ("notifyserverlog".equals(e.getCommand())) conn.serverLog.onLine(e);
|
||||
else conn.offlineMessages.onReply(e);
|
||||
}
|
||||
|
||||
// ---- helpers ----
|
||||
|
||||
@@ -51,6 +51,10 @@ public interface ConnectionListener {
|
||||
*/
|
||||
void onServerLog(String message);
|
||||
|
||||
/** Our offline message inbox's unread count changed, or became known on connecting. */
|
||||
default void onUnreadMessagesChanged(int unread) {
|
||||
}
|
||||
|
||||
/** A server-log line already rendered in TS3's HTML log format. */
|
||||
default void onServerLogHtml(String html) {
|
||||
onServerLog(html == null ? "" : html);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.ts3client.net;
|
||||
|
||||
/**
|
||||
* A client the server's database knows, online or not: what an offline message is addressed to.
|
||||
*
|
||||
* @param nickname the nickname they last used on this server
|
||||
*/
|
||||
public record DatabaseClient(String uniqueId, int databaseId, String nickname) {
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.ts3client.net;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A message in our offline message inbox on the server, without its body: {@code messagelist}
|
||||
* leaves that out, and reading it costs a {@code messageget} each.
|
||||
*
|
||||
* @param senderName the sender's last known nickname, or their unique id when the server has forgotten them
|
||||
*/
|
||||
public record OfflineMessage(int id, String senderUid, String senderName, String subject,
|
||||
long timestampEpochSeconds, boolean read) {
|
||||
|
||||
/** Reads a message off a {@code notifymessagelist} event's fields. */
|
||||
static OfflineMessage from(Map<String, String> fields, String senderName) {
|
||||
return new OfflineMessage((int) parseLong(fields.get("msgid")),
|
||||
orEmpty(fields.get("cluid")),
|
||||
senderName,
|
||||
orEmpty(fields.get("subject")),
|
||||
parseLong(fields.get("timestamp")),
|
||||
"1".equals(fields.get("flag_read")));
|
||||
}
|
||||
|
||||
public OfflineMessage withRead(boolean read) {
|
||||
return new OfflineMessage(id, senderUid, senderName, subject, timestampEpochSeconds, read);
|
||||
}
|
||||
|
||||
static String orEmpty(String s) {
|
||||
return s == null || s.equals("null") ? "" : s;
|
||||
}
|
||||
|
||||
private static long parseLong(String s) {
|
||||
try {
|
||||
return s == null ? 0 : Long.parseLong(s.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package com.ts3client.net;
|
||||
|
||||
import com.github.manevolent.ts3j.command.CommandException;
|
||||
import com.github.manevolent.ts3j.command.SingleCommand;
|
||||
import com.github.manevolent.ts3j.command.parameter.CommandParameter;
|
||||
import com.github.manevolent.ts3j.command.parameter.CommandSingleParameter;
|
||||
import com.github.manevolent.ts3j.event.UnknownTeamspeakEvent;
|
||||
import com.github.manevolent.ts3j.protocol.ProtocolRole;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Our offline message inbox on the server, sending offline messages, and finding the
|
||||
* database clients to send them to.
|
||||
*
|
||||
* <p>Split out of {@link TeamspeakConnection} like {@link ComplaintAdmin}. Every reply comes as
|
||||
* notifications ahead of the command's completion, collected into {@link #replies}; calls are
|
||||
* serialised so two requests never share it. Every call blocks and must run off the UI thread.
|
||||
*/
|
||||
final class OfflineMessageAdmin {
|
||||
|
||||
/** What a listing answers when it has nothing to list. */
|
||||
private static final int ERROR_DATABASE_EMPTY_RESULT = 0x0501;
|
||||
/** What a unique id or database id lookup answers when the server has no such client. */
|
||||
private static final int ERROR_INVALID_CLIENT_ID = 0x0200;
|
||||
/** The most matches a nickname search names; each costs a lookup, and lookups flood quickly. */
|
||||
private static final int MAX_SEARCH_RESULTS = 10;
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
/** Senders' nicknames by unique id; they cost a lookup each, so a connection asks once. */
|
||||
private final Map<String, String> names = new ConcurrentHashMap<>();
|
||||
|
||||
/** The notification the request in flight is answered by, and what has arrived of it. */
|
||||
private volatile String awaited;
|
||||
private volatile List<Map<String, String>> replies;
|
||||
|
||||
OfflineMessageAdmin(TeamspeakConnection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
/** Forgets what the last server told us; a reconnect may be to another server. */
|
||||
void reset() {
|
||||
names.clear();
|
||||
}
|
||||
|
||||
void onReply(UnknownTeamspeakEvent e) {
|
||||
List<Map<String, String>> collected = replies;
|
||||
if (collected != null && e.getCommand().equals(awaited)) collected.add(e.getMap());
|
||||
}
|
||||
|
||||
/** Runs a command and returns the {@code notification} rows it was answered with; none when the result is empty. */
|
||||
private synchronized List<Map<String, String>> query(String notification, String command,
|
||||
CommandParameter... params) throws Exception {
|
||||
List<Map<String, String>> collected = Collections.synchronizedList(new ArrayList<>());
|
||||
awaited = notification;
|
||||
replies = collected;
|
||||
try {
|
||||
conn.socket().executeCommand(new SingleCommand(command, ProtocolRole.CLIENT, params)).complete();
|
||||
conn.awaitEventsProcessed();
|
||||
} catch (CommandException e) {
|
||||
if (e.getErrorId() != ERROR_DATABASE_EMPTY_RESULT) throw e;
|
||||
} finally {
|
||||
replies = null;
|
||||
awaited = null;
|
||||
}
|
||||
return new ArrayList<>(collected);
|
||||
}
|
||||
|
||||
private synchronized void execute(String command, CommandParameter... params) throws Exception {
|
||||
conn.socket().executeCommand(new SingleCommand(command, ProtocolRole.CLIENT, params)).complete();
|
||||
}
|
||||
|
||||
private static CommandSingleParameter param(String key, Object value) {
|
||||
return new CommandSingleParameter(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
// ---- inbox ----
|
||||
|
||||
List<OfflineMessage> list() throws Exception {
|
||||
List<OfflineMessage> messages = new ArrayList<>();
|
||||
for (Map<String, String> row : query("notifymessagelist", "messagelist")) {
|
||||
String sender = OfflineMessage.orEmpty(row.get("cluid"));
|
||||
messages.add(OfflineMessage.from(row, senderName(sender)));
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
private String senderName(String uniqueId) throws Exception {
|
||||
if (uniqueId.isEmpty()) return "";
|
||||
String known = names.get(uniqueId);
|
||||
if (known != null) return known;
|
||||
DatabaseClient client = lookupUid(uniqueId);
|
||||
String name = client != null ? client.nickname() : uniqueId;
|
||||
names.put(uniqueId, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
/** Reads a message's body; this does not mark it read. */
|
||||
String body(int messageId) throws Exception {
|
||||
List<Map<String, String>> rows = query("notifymessage", "messageget", param("msgid", messageId));
|
||||
if (rows.isEmpty()) throw new IllegalStateException("The message is gone.");
|
||||
return OfflineMessage.orEmpty(rows.get(0).get("message"));
|
||||
}
|
||||
|
||||
void setRead(int messageId, boolean read) throws Exception {
|
||||
execute("messageupdateflag", param("msgid", messageId), param("flag", read ? 1 : 0));
|
||||
}
|
||||
|
||||
void delete(int messageId) throws Exception {
|
||||
execute("messagedel", param("msgid", messageId));
|
||||
}
|
||||
|
||||
void send(String recipientUid, String subject, String message) throws Exception {
|
||||
execute("messageadd", param("cluid", recipientUid), param("subject", subject), param("message", message));
|
||||
}
|
||||
|
||||
// ---- recipients ----
|
||||
|
||||
/** @return the client with this unique id, or {@code null} when the server has never seen them */
|
||||
DatabaseClient lookupUid(String uniqueId) throws Exception {
|
||||
try {
|
||||
List<Map<String, String>> rows = query("notifyclientnamefromuid", "clientgetnamefromuid",
|
||||
param("cluid", uniqueId));
|
||||
return rows.isEmpty() ? null : fromNameReply(rows.get(0));
|
||||
} catch (CommandException e) {
|
||||
if (e.getErrorId() == ERROR_INVALID_CLIENT_ID) return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clients whose last nickname contains {@code nickname}. Needs
|
||||
* {@code b_virtualserver_client_dbsearch}, which the server never reports to us up front.
|
||||
*/
|
||||
List<DatabaseClient> search(String nickname) throws Exception {
|
||||
List<Map<String, String>> found = query("notifyclientdbfind", "clientdbfind",
|
||||
param("pattern", "%" + nickname + "%"));
|
||||
List<DatabaseClient> clients = new ArrayList<>();
|
||||
for (Map<String, String> row : found) {
|
||||
if (clients.size() == MAX_SEARCH_RESULTS) break;
|
||||
List<Map<String, String>> named = query("notifyclientnamefromdbid", "clientgetnamefromdbid",
|
||||
param("cldbid", OfflineMessage.orEmpty(row.get("cldbid"))));
|
||||
if (!named.isEmpty()) clients.add(fromNameReply(named.get(0)));
|
||||
}
|
||||
for (DatabaseClient c : clients) names.put(c.uniqueId(), c.nickname());
|
||||
return clients;
|
||||
}
|
||||
|
||||
private static DatabaseClient fromNameReply(Map<String, String> row) {
|
||||
int dbId;
|
||||
try {
|
||||
dbId = Integer.parseInt(OfflineMessage.orEmpty(row.get("cldbid")).trim());
|
||||
} catch (NumberFormatException e) {
|
||||
dbId = 0;
|
||||
}
|
||||
return new DatabaseClient(OfflineMessage.orEmpty(row.get("cluid")), dbId,
|
||||
OfflineMessage.orEmpty(row.get("name")));
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,12 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
public static final int KICK_REASON_LIMIT = 40;
|
||||
/** The longest reason a complaint may carry. */
|
||||
public static final int COMPLAINT_REASON_LIMIT = 200;
|
||||
/** The longest subject and body an offline message may carry, in characters. */
|
||||
public static final int OFFLINE_MESSAGE_SUBJECT_LIMIT = 200;
|
||||
public static final int OFFLINE_MESSAGE_LIMIT = 4096;
|
||||
/** What {@link #searchDatabaseClients} reports when the server will not let us search. */
|
||||
public static final String SEARCH_NOT_PERMITTED =
|
||||
"You have no permission to search for users on this server, so you can only use contacts or unique IDs.";
|
||||
|
||||
/** The protocol's reason ids for the two flavours of <b>clientkick</b>. */
|
||||
private static final int REASON_KICK_CHANNEL = 4;
|
||||
@@ -105,6 +111,8 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
final PrivilegeKeyAdmin privilegeKeys = new PrivilegeKeyAdmin(this);
|
||||
final ComplaintAdmin complaints = new ComplaintAdmin(this);
|
||||
final ServerLogAdmin serverLog = new ServerLogAdmin(this);
|
||||
/** Our offline message inbox; package-private for {@link ConnectionEventHandler}. */
|
||||
final OfflineMessageAdmin offlineMessages = new OfflineMessageAdmin(this);
|
||||
private final AvatarAdmin avatarAdmin = new AvatarAdmin(this);
|
||||
|
||||
/*
|
||||
@@ -364,6 +372,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
leaving = false;
|
||||
disconnectAnnounced = false;
|
||||
deafened = false;
|
||||
offlineMessages.reset();
|
||||
loadChatLogs();
|
||||
ui.onConnected();
|
||||
requestPermissionNames();
|
||||
@@ -375,6 +384,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
joinDefaultChannelIfNeeded(channel, channelPassword);
|
||||
ui.onStatus("Connected to " + model.getServerName());
|
||||
sound(SoundEvent.CONNECTION_CONNECTED, serverVars());
|
||||
unreadMessagesChanged(0);
|
||||
|
||||
// Only captures if this connection holds the microphone.
|
||||
applyMicrophoneState();
|
||||
@@ -1129,6 +1139,94 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
});
|
||||
}
|
||||
|
||||
// ---- offline messages ----
|
||||
|
||||
/** Unread messages in our offline message inbox on this server. */
|
||||
public int unreadOfflineMessages() {
|
||||
ClientEntry self = model.getClient(selfClientId);
|
||||
return self == null ? 0 : self.unreadMessages;
|
||||
}
|
||||
|
||||
/** Whether the server lets us send offline messages. */
|
||||
public boolean canSendOfflineMessages() {
|
||||
return model.permits("b_client_offline_textmessage_send");
|
||||
}
|
||||
|
||||
/** Our unread count changed from {@code before}; more unread means new mail, which the log announces. */
|
||||
void unreadMessagesChanged(int before) {
|
||||
int unread = unreadOfflineMessages();
|
||||
if (unread > before) {
|
||||
String count = unread == 1 ? "1 unread offline message" : unread + " unread offline messages";
|
||||
log("You have " + TsLink.offlineMessagesBBCode(count));
|
||||
}
|
||||
ui.onUnreadMessagesChanged(unread);
|
||||
}
|
||||
|
||||
/** Lists our offline message inbox, delivering it (or a failure message) off the UI thread. */
|
||||
public void requestOfflineMessages(BiConsumer<List<OfflineMessage>, String> callback) {
|
||||
run(callback, offlineMessages::list);
|
||||
}
|
||||
|
||||
/** Reads a message's body, delivering it (or a failure message) off the UI thread. */
|
||||
public void requestOfflineMessageBody(int messageId, BiConsumer<String, String> callback) {
|
||||
run(callback, () -> offlineMessages.body(messageId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks messages read or unread, stopping at the first the server refuses.
|
||||
*
|
||||
* @param callback given {@code null} on success, or the failure message
|
||||
*/
|
||||
public void markOfflineMessages(Collection<Integer> messageIds, boolean read, Consumer<String> callback) {
|
||||
run((ignored, error) -> callback.accept(error), () -> {
|
||||
for (int id : messageIds) offlineMessages.setRead(id, read);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/** @param callback given {@code null} on success, or the failure message */
|
||||
public void deleteOfflineMessages(Collection<Integer> messageIds, Consumer<String> callback) {
|
||||
run((ignored, error) -> callback.accept(error), () -> {
|
||||
for (int id : messageIds) offlineMessages.delete(id);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends one offline message to each recipient, stopping at the first the server refuses.
|
||||
*
|
||||
* @param callback given {@code null} on success, or the failure message
|
||||
*/
|
||||
public void sendOfflineMessage(Collection<String> recipientUids, String subject, String message,
|
||||
Consumer<String> callback) {
|
||||
run((ignored, error) -> callback.accept(error), () -> {
|
||||
for (String uid : recipientUids) offlineMessages.send(uid, subject, message);
|
||||
log("Offline message sent.");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/** Looks a client up by unique id; delivers {@code null} when the server has never seen them. */
|
||||
public void lookupDatabaseClient(String uniqueId, BiConsumer<DatabaseClient, String> callback) {
|
||||
run(callback, () -> offlineMessages.lookupUid(uniqueId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds clients whose last nickname contains {@code nickname}.
|
||||
*
|
||||
* @param callback given the matches, or {@link #SEARCH_NOT_PERMITTED} or another failure message
|
||||
*/
|
||||
public void searchDatabaseClients(String nickname, BiConsumer<List<DatabaseClient>, String> callback) {
|
||||
run(callback, () -> {
|
||||
try {
|
||||
return offlineMessages.search(nickname);
|
||||
} catch (CommandException e) {
|
||||
if (isPermissionError(e)) throw new IllegalStateException(SEARCH_NOT_PERMITTED);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---- server log ----
|
||||
|
||||
/**
|
||||
@@ -1792,7 +1890,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
}
|
||||
|
||||
/** Whether the server refused for lack of permission, wherever in the cause chain it said so. */
|
||||
private static boolean isPermissionError(Throwable t) {
|
||||
static boolean isPermissionError(Throwable t) {
|
||||
for (Throwable c = t; c != null; c = c.getCause() == c ? null : c.getCause()) {
|
||||
if (c instanceof CommandException ce) {
|
||||
int id = ce.getErrorId();
|
||||
|
||||
@@ -678,5 +678,10 @@ public final class ServerSession {
|
||||
public void onServerLogHtml(String html) {
|
||||
listener.onServerLogHtml(html);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnreadMessagesChanged(int unread) {
|
||||
listener.onUnreadMessagesChanged(unread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ public final class BBCode {
|
||||
private static final Pattern COLOR = Pattern.compile("#[0-9a-fA-F]{3,6}|[a-zA-Z]{3,20}");
|
||||
/** Web links plus TeamSpeak's own {@code client://} / {@code channel://} / {@code ts3server://} schemes. */
|
||||
private static final Pattern SAFE_URL =
|
||||
Pattern.compile("(?i)(https?|ftp|client|channel|ts3server|ts3file)://[^\\s\"'<>]*");
|
||||
Pattern.compile("(?i)(https?|ftp|client|channel|ts3server|ts3file|offline)://[^\\s\"'<>]*");
|
||||
/** TeamSpeak's own protocols, which are rendered without an underline. */
|
||||
private static final Pattern TS_PROTOCOL =
|
||||
Pattern.compile("(?i)^(client|channel|ts3server|ts3file)://");
|
||||
Pattern.compile("(?i)^(client|channel|ts3server|ts3file|offline)://");
|
||||
private static final Pattern CLIENT_PROTOCOL = Pattern.compile("(?i)^client://");
|
||||
|
||||
/** CSS class on {@code client://} links, styled like a message author's name. */
|
||||
|
||||
@@ -13,6 +13,8 @@ public final class TsLink {
|
||||
|
||||
public static final String CLIENT_SCHEME = "client://";
|
||||
public static final String CHANNEL_SCHEME = "channel://";
|
||||
/** Opens the offline message inbox, as the "unread offline messages" log line does. */
|
||||
public static final String OFFLINE_MESSAGES_HREF = "offline://";
|
||||
|
||||
/** A parsed {@code client://} or {@code channel://} link. */
|
||||
public static final class Ref {
|
||||
@@ -67,6 +69,14 @@ public final class TsLink {
|
||||
return new Ref(client, id, decode(uid), decode(name));
|
||||
}
|
||||
|
||||
public static boolean isOfflineMessages(String href) {
|
||||
return href != null && startsWithIgnoreCase(href, OFFLINE_MESSAGES_HREF);
|
||||
}
|
||||
|
||||
public static String offlineMessagesBBCode(String label) {
|
||||
return "[URL=" + OFFLINE_MESSAGES_HREF + "]" + label + "[/URL]";
|
||||
}
|
||||
|
||||
public static String clientHref(int clientId, String uniqueId, String nickname) {
|
||||
return CLIENT_SCHEME + clientId + "/" + encode(uniqueId) + "~" + encode(nickname);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
class ConnectionEventHandlerTest {
|
||||
|
||||
private int modelChanges;
|
||||
private int unreadReports;
|
||||
private final Settings settings = new Settings();
|
||||
private final TeamspeakConnection conn = new TeamspeakConnection(settings, null, new ConnectionListener() {
|
||||
@Override
|
||||
@@ -76,6 +77,11 @@ class ConnectionEventHandlerTest {
|
||||
@Override
|
||||
public void onServerLog(String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnreadMessagesChanged(int unread) {
|
||||
unreadReports++;
|
||||
}
|
||||
}, new SoundNotifier(settings), ContactStore.load());
|
||||
private final ConnectionEventHandler events = new ConnectionEventHandler(conn);
|
||||
private final ServerModel model = conn.getModel();
|
||||
@@ -136,6 +142,17 @@ class ConnectionEventHandlerTest {
|
||||
assertEquals("abc", alice.avatarFlag);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tracksAClientsUnreadOfflineMessages() {
|
||||
model.putChannel(1, "Lobby", 0, 0);
|
||||
join(5, "alice", 1);
|
||||
assertEquals(0, model.getClient(5).unreadMessages);
|
||||
|
||||
events.onClientChanged(new ClientUpdatedEvent(fields("notifyclientupdated clid=5 client_unread_messages=3")));
|
||||
assertEquals(3, model.getClient(5).unreadMessages);
|
||||
assertEquals(0, unreadReports, "only our own count is reported");
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearedFieldsAreCleared() {
|
||||
model.putChannel(1, "Lobby", 0, 0);
|
||||
|
||||
@@ -22,6 +22,14 @@ class BBCodeLinksTest {
|
||||
assertTrue(html.contains(">Lobby</a>"), html);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rendersTheOfflineMessagesLink() {
|
||||
String html = BBCode.linksToHtml("You have " + TsLink.offlineMessagesBBCode("2 unread offline messages"));
|
||||
assertTrue(html.contains("href=\"offline://\""), html);
|
||||
assertTrue(html.contains(">2 unread offline messages</a>"), html);
|
||||
assertTrue(TsLink.isOfflineMessages("offline://"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void leavesOtherMarkupLiteral() {
|
||||
assertEquals("[b]not bold[/b] & <i>", BBCode.linksToHtml("[b]not bold[/b] & <i>"));
|
||||
|
||||
Reference in New Issue
Block a user