Search in sources :

Example 6 with StreamInfo

use of chatty.util.api.StreamInfo in project chatty by chatty.

the class StreamHighlightHelper method addHighlight.

/**
 * Adds a highlight for the given channel with the given comment.
 *
 * Thread-saftey: It should be safe to call this from several threads.
 * Instance variables and writing to the file is synchronized on this.
 *
 * @param channel The channel to add the highlight for
 * @param comment The comment to add (can be null or empty for no comment)
 * @return A textual response to adding the highlight
 */
public String addHighlight(String channel, String comment) {
    if (channel == null || channel.isEmpty() || !Helper.isRegularChannel(channel)) {
        return "Failed adding stream highlight (no channel).";
    }
    // Get StreamInfo
    StreamInfo streamInfo = api.getStreamInfo(Helper.toStream(channel), null);
    String streamTime = "Stream Time N/A";
    if (streamInfo.isValid() && streamInfo.getOnline()) {
        streamTime = DateTime.ago(streamInfo.getTimeStarted());
    }
    if (comment == null) {
        comment = "";
    }
    // Make the line to add to the file
    String line = String.format("%s %s [%s] %s", DateTime.fullDateTime(), channel, streamTime, comment);
    synchronized (this) {
        // Add seperator if probably new stream
        if (streamInfo.getTimeStarted() != lastStreamStartWritten) {
            addToFile("-");
        }
        // Add to file and make textual response
        boolean success = addToFile(line);
        if (success) {
            lastStreamStartWritten = streamInfo.getTimeStarted();
            String shortComment = "";
            if (!comment.isEmpty()) {
                shortComment = "(" + StringUtil.shortenTo(comment, 30) + ")";
            }
            return "Added stream highlight for " + channel + " [" + streamTime + "] " + shortComment;
        }
        return "Failed adding stream highlight (write error).";
    }
}
Also used : StreamInfo(chatty.util.api.StreamInfo)

Example 7 with StreamInfo

use of chatty.util.api.StreamInfo in project chatty by chatty.

the class LiveStreamsList method checkStreams.

/**
 * Checks all added streams and removes invalid ones.
 */
private void checkStreams() {
    if ((System.currentTimeMillis() - lastChecked) / 1000 < CHECK_DELAY) {
        return;
    }
    lastChecked = System.currentTimeMillis();
    Set<StreamInfo> toRemove = new HashSet<>();
    for (StreamInfo info : data) {
        if (!info.isValidEnough() || !info.getOnline()) {
            toRemove.add(info);
        }
    }
    // Remove invalid items
    for (StreamInfo info : toRemove) {
        data.remove(info);
        itemRemoved(info);
    }
    // Update and inform only if items were actually removed
    if (!toRemove.isEmpty()) {
        listDataChanged();
    }
}
Also used : StreamInfo(chatty.util.api.StreamInfo) HashSet(java.util.HashSet)

Aggregations

StreamInfo (chatty.util.api.StreamInfo)7 ContextMenuListener (chatty.gui.components.menus.ContextMenuListener)2 StreamInfosContextMenu (chatty.gui.components.menus.StreamInfosContextMenu)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Helper (chatty.Helper)1 Action (chatty.gui.components.JListActionHelper.Action)1 DateTime (chatty.util.DateTime)1 ModeratorActionData (chatty.util.api.pubsub.ModeratorActionData)1 Color (java.awt.Color)1 Component (java.awt.Component)1 ActionEvent (java.awt.event.ActionEvent)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 ComponentListener (java.awt.event.ComponentListener)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Set (java.util.Set)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1