mirror of
https://github.com/igniterealtime/Spark.git
synced 2026-08-18 02:56:24 +00:00
XEP0392Utils: add colors cache
This commit is contained in:
@ -83,7 +83,6 @@ public class GroupChatRoom extends ChatRoom {
|
||||
private final MultiUserChat chat;
|
||||
private final SubjectPanel subjectPanel;
|
||||
private final List<EntityFullJid> currentUserList = new ArrayList<>();
|
||||
private final Map<Resourcepart, Color> participantColors = new HashMap<>();
|
||||
private final List<EntityFullJid> blockedUsers = new ArrayList<>();
|
||||
private final GroupChatParticipantList roomInfo;
|
||||
private final RolloverButton settings;
|
||||
@ -607,9 +606,6 @@ public class GroupChatRoom extends ChatRoom {
|
||||
scrollToBottom();
|
||||
}
|
||||
currentUserList.remove(from);
|
||||
synchronized (participantColors) {
|
||||
participantColors.remove(from.getResourcepart());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -963,10 +959,8 @@ public class GroupChatRoom extends ChatRoom {
|
||||
if (!pref.isMucRandomColors()) {
|
||||
return ChatManager.FROM_COLOR;
|
||||
}
|
||||
synchronized (participantColors) {
|
||||
Color userColor = participantColors.computeIfAbsent(nickname, XEP0392Utils::colorOfMucParticipant);
|
||||
return userColor;
|
||||
}
|
||||
Color userColor = XEP0392Utils.colorOfMucParticipant(nickname);
|
||||
return userColor;
|
||||
}
|
||||
|
||||
public void notifySettingsAccessRight() {
|
||||
|
||||
@ -3,22 +3,31 @@ package org.jivesoftware.spark.util;
|
||||
import org.jivesoftware.smackx.colors.ConsistentColor;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.parts.Resourcepart;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class XEP0392Utils {
|
||||
private static final Map<Jid, Color> jidColors = new WeakHashMap<>(64);
|
||||
private static final Map<Resourcepart, Color> participantColors = new WeakHashMap<>(64);
|
||||
|
||||
public static Color colorOfMucParticipant(Resourcepart userNickname) {
|
||||
return toColor(ConsistentColor.RGBFrom(userNickname));
|
||||
return participantColors.computeIfAbsent(userNickname, it -> toColor(ConsistentColor.RGBFrom(it)));
|
||||
}
|
||||
|
||||
public static Color colorOfMuc(EntityBareJid mucJid) {
|
||||
return toColor(ConsistentColor.RGBFrom(mucJid));
|
||||
return getColorOfJid(mucJid);
|
||||
}
|
||||
|
||||
public static Color colorOfContact(BareJid contactJid) {
|
||||
return toColor(ConsistentColor.RGBFrom(contactJid));
|
||||
return getColorOfJid(contactJid);
|
||||
}
|
||||
|
||||
private static Color getColorOfJid(Jid jid) {
|
||||
return jidColors.computeIfAbsent(jid, it -> toColor(ConsistentColor.RGBFrom(it)));
|
||||
}
|
||||
|
||||
private static Color toColor(float[] rgb) {
|
||||
|
||||
Reference in New Issue
Block a user