use of chatty.util.api.usericons.Usericon in project chatty by chatty.
the class LinkController method openContextMenu.
private void openContextMenu(MouseEvent e) {
// the click)
if (!e.getComponent().isShowing()) {
return;
}
User user = getUser(e);
String url = getUrl(e);
EmoticonImage emote = getEmoticon(e);
Usericon usericon = getUsericon(e);
JPopupMenu m;
if (user != null) {
m = new UserContextMenu(user, getAutoModMsgId(e), contextMenuListener);
} else if (url != null) {
m = new UrlContextMenu(url, isUrlDeleted(e), contextMenuListener);
} else if (emote != null) {
m = new EmoteContextMenu(emote, contextMenuListener);
} else if (usericon != null) {
m = new UsericonContextMenu(usericon, contextMenuListener);
} else {
if (defaultContextMenu == null) {
m = new ChannelContextMenu(contextMenuListener);
} else {
m = defaultContextMenu;
}
}
m.show(e.getComponent(), e.getX(), e.getY());
}
use of chatty.util.api.usericons.Usericon in project chatty by chatty.
the class FrankerFaceZ method parseResult.
private void parseResult(Type type, String stream, String result) {
if (result == null) {
return;
}
if (type == Type.FEATURE_FRIDAY && stream == null) {
// Response of the first request having only the info which channel
handleFeatureFriday(result);
return;
}
// Determine whether these emotes should be global
final boolean global = type == Type.GLOBAL || type == Type.FEATURE_FRIDAY;
String globalText = global ? "global" : "local";
Set<Emoticon> emotes = new HashSet<>();
List<Usericon> usericons = new ArrayList<>();
// Parse depending on type
if (type == Type.GLOBAL) {
emotes = FrankerFaceZParsing.parseGlobalEmotes(result);
} else if (type == Type.ROOM) {
emotes = FrankerFaceZParsing.parseRoomEmotes(result);
Usericon modIcon = FrankerFaceZParsing.parseModIcon(result);
if (modIcon != null) {
usericons.add(modIcon);
}
} else if (type == Type.FEATURE_FRIDAY) {
emotes = FrankerFaceZParsing.parseSetEmotes(result, Emoticon.SubType.FEATURE_FRIDAY, null);
for (Emoticon emote : emotes) {
if (featureFridayChannel != null) {
emote.setStream(featureFridayChannel);
}
}
}
LOGGER.info("[FFZ] (" + stream + ", " + globalText + "): " + emotes.size() + " emotes received.");
if (!usericons.isEmpty()) {
LOGGER.info("[FFZ] (" + stream + "): " + usericons.size() + " usericons received.");
}
// Package accordingly and send the result to the listener
EmoticonUpdate emotesUpdate;
if (type == Type.FEATURE_FRIDAY) {
emotesUpdate = new EmoticonUpdate(emotes, Emoticon.Type.FFZ, Emoticon.SubType.FEATURE_FRIDAY, null);
} else {
emotesUpdate = new EmoticonUpdate(emotes);
}
listener.channelEmoticonsReceived(emotesUpdate);
// Return icons if mod icon was found (will be empty otherwise)
listener.usericonsReceived(usericons);
}
use of chatty.util.api.usericons.Usericon in project chatty by chatty.
the class BadgeManager method parseBadgeVersions.
private static void parseBadgeVersions(List<Usericon> result, JSONObject data, String room, String id) {
for (Object key : data.keySet()) {
JSONObject versionData = (JSONObject) data.get(key);
String version = (String) key;
String url = (String) versionData.get("image_url_1x");
String title = (String) versionData.get("title");
String description = (String) versionData.get("description");
String clickUrl = (String) versionData.get("click_url");
if (id != null && version != null && url != null) {
Usericon icon = UsericonFactory.createTwitchBadge(id, version, url, room, title, description, clickUrl);
if (icon != null) {
result.add(icon);
}
}
}
}
use of chatty.util.api.usericons.Usericon in project chatty by chatty.
the class BadgeManager method parseBadges.
private static List<Usericon> parseBadges(String json, String room) {
List<Usericon> result = new ArrayList<>();
if (json == null) {
return result;
}
try {
JSONParser parser = new JSONParser();
JSONObject root = (JSONObject) parser.parse(json);
JSONObject badges = (JSONObject) root.get("badge_sets");
if (badges != null) {
for (Object key : badges.keySet()) {
JSONObject data = (JSONObject) badges.get(key);
String id = (String) key;
JSONObject versions = (JSONObject) data.get("versions");
if (versions != null) {
parseBadgeVersions(result, versions, room, id);
}
}
}
} catch (Exception ex) {
LOGGER.warning("Error parsing badges: " + ex);
}
return result;
}
use of chatty.util.api.usericons.Usericon in project chatty by chatty.
the class LinkController method mousePressed.
/**
* Handles mouse presses. This is favourable to mouseClicked because it
* might work better in a fast moving chat and you won't select text
* instead of opening userinfo etc.
*
* @param e
*/
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 1 && SwingUtilities.isLeftMouseButton(e)) {
String url = getUrl(e);
if (url != null && !isUrlDeleted(e)) {
if (linkListener != null) {
linkListener.linkClicked(url);
}
return;
}
User user = getUser(e);
if (user != null) {
for (UserListener listener : userListener) {
listener.userClicked(user, getMsgId(e), getAutoModMsgId(e), e);
}
return;
}
EmoticonImage emote = getEmoticon(e);
if (emote != null) {
for (UserListener listener : userListener) {
listener.emoteClicked(emote.getEmoticon(), e);
}
return;
}
Usericon usericon = getUsericon(e);
if (usericon != null) {
for (UserListener listener : userListener) {
listener.usericonClicked(usericon, e);
}
}
} else if (e.isPopupTrigger()) {
openContextMenu(e);
}
}
Aggregations