Skip to content

Commit

Permalink
Update comments, help, typo
Browse files Browse the repository at this point in the history
  • Loading branch information
tduva committed Sep 18, 2016
1 parent fc19683 commit ac393d3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/chatty/gui/components/help/help-releases.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ <h2>
<a name="0.8.4">Version 0.8.4</a> <a name="latest">(This one!)</a> (2016-??-??)
<a href="#top" class="top">[back to top]</a>
</h2>
<p>As broadcaster or mod you can now view the actions of other mods in a
separate window via <code>Extra - Moderation&nbsp;Log</code> or enable mod
actions to appear as extra messages directly in chat (<code>Main - Settings - Messages</code>).</p>
<pre>
- Added Emoji support
- Added displaying of received Cheers/Bits (Cheer Badges/sending Cheers not yet)
Expand Down
12 changes: 8 additions & 4 deletions src/chatty/util/api/pubsub/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public long getDelay() {
}

public synchronized void connect(String server) {
/**
* Only connect once, which is intended to stay connected forever. If
* manually disconnecting/connecting again should be a thing, some stuff
* may have to be changed.
*/
if (connecting) {
return;
}
Expand Down Expand Up @@ -159,11 +164,10 @@ private synchronized void close() {
}
}

public synchronized void send(String mesage) {
public synchronized void send(String message) {
if (s != null && s.isOpen()) {
s.getAsyncRemote().sendText(mesage);
handler.handleSent(mesage);
System.out.println("SENT:"+mesage);
s.getAsyncRemote().sendText(message);
handler.handleSent(message);
}
}

Expand Down
38 changes: 38 additions & 0 deletions src/chatty/util/api/pubsub/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ public class Manager {
private final Client c;
private final String server;

/**
* Storage of user ids for easier lookup to turn an id into a channel name.
*/
private final Map<Long, String> userIds = Collections.synchronizedMap(new HashMap<Long, String>());

/**
* Channels to listen on for the modlog, storing the id of the channel as
* well. If the id is -1, still waiting for the user id and not listening
* yet.
*/
private final Map<String, Long> modLogListen = Collections.synchronizedMap(new HashMap<String, Long>());

private volatile Timer pingTimer;
Expand Down Expand Up @@ -96,13 +105,26 @@ public String getStatus() {
return c.getStatus();
}

/**
* Set the username of this Chatty user, which is used for listening to the
* correct mod log topic (which requires the mod user id).
*
* @param username
*/
public void setLocalUsername(String username) {
if (localUsername == null || !localUsername.equals(username)) {
this.localUsername = username;
this.localUserId = getUserId(username);
}
}

/**
* Start receiving the modlog for the given channel (username). The token is
* requires to authenticate.
*
* @param username
* @param token
*/
public void listenModLog(String username, String token) {
if (!hasServer()) {
return;
Expand All @@ -120,6 +142,11 @@ public void listenModLog(String username, String token) {
}
}

/**
* Stop reciving the modlog for the given channel (username).
*
* @param username
*/
public void unlistenModLog(String username) {
synchronized(modLogListen) {
if (modLogListen.containsKey(username)) {
Expand All @@ -131,11 +158,22 @@ public void unlistenModLog(String username) {
}
}

/**
* Get the user id for the given username, or wait until it has been
* requested and act on it then.
*
* @param username A valid Twitch username
* @return The user id, or -1 if user id still has to be requested
*/
private long getUserId(String username) {
long userId = api.getUserId(username, new UserIDs.UserIDListener() {

@Override
public void setUserId(String username, long userId) {
/**
* When the user id has been requested. If the user id is
* already cached, this listener won't be stored.
*/
Manager.this.setUserId(username, userId);
}
});
Expand Down

0 comments on commit ac393d3

Please sign in to comment.