Skip to content

Commit

Permalink
general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
matush-v committed Jan 26, 2018
1 parent 6c81bba commit 0f74f84
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public class SlackPreparedMessage {
private final String message;
private final boolean unfurl;
private final boolean linkNames;
private final SlackAttachment[] attachments;
private final List<SlackAttachment> attachments;
private final String threadTimestamp;
private final boolean replyBroadcast;

private SlackPreparedMessage(String message, boolean unfurl, boolean linkNames, SlackAttachment[] attachments, String threadTimestamp, boolean replyBroadcast) {
this.message = message;
this.unfurl = unfurl;
this.linkNames = linkNames;
this.attachments = attachments;
this.attachments = Arrays.asList(attachments);
this.threadTimestamp = threadTimestamp;
this.replyBroadcast = replyBroadcast;
}
Expand All @@ -35,7 +35,7 @@ public boolean isLinkNames() {
}

public SlackAttachment[] getAttachments() {
return attachments;
return attachments.toArray(new SlackAttachment[]{});
}

public String getThreadTimestamp() {
Expand Down Expand Up @@ -120,7 +120,7 @@ public String toString() {
return "SlackPreparedMessage{" +
"message='" + message + '\'' +
", unfurl=" + unfurl +
", attachments=" + Arrays.toString(attachments) +
", attachments=" + attachments +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public List<SlackMessagePosted> fetchUpdatingHistoryOfChannel(String channelId,
return messages;
}

public class ChannelHistoryReactionAddedListener implements ReactionAddedListener {
public static class ChannelHistoryReactionAddedListener implements ReactionAddedListener {

List<SlackMessagePosted> messages = new ArrayList<>();

Expand All @@ -174,7 +174,7 @@ public void onEvent(ReactionAdded event, SlackSession session) {
for (String reaction : message.getReactions().keySet()) {
if (emojiName.equals(reaction)) {
int count = message.getReactions().get(emojiName);
message.getReactions().put(emojiName, count++);
message.getReactions().put(emojiName, ++count);
return;
}
}
Expand All @@ -183,7 +183,7 @@ public void onEvent(ReactionAdded event, SlackSession session) {
}
};

public class ChannelHistoryReactionRemovedListener implements ReactionRemovedListener {
public static class ChannelHistoryReactionRemovedListener implements ReactionRemovedListener {

List<SlackMessagePosted> messages = new ArrayList<>();

Expand All @@ -210,7 +210,7 @@ public void onEvent(ReactionRemoved event, SlackSession session) {
}
}

public class ChannelHistoryMessagePostedListener implements SlackMessagePostedListener {
public static class ChannelHistoryMessagePostedListener implements SlackMessagePostedListener {

List<SlackMessagePosted> messages = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class SlackJSONMessageParser {
private static final Logger LOGGER = LoggerFactory.getLogger(SlackJSONMessageParser.class);

public static enum SlackMessageSubType
{
Expand Down Expand Up @@ -270,6 +274,7 @@ private static void parseSlackFileFromRaw(JsonObject rawFile, SlackFile file) {
file.setImageExifRotation(GsonHelper.getLongOrNull(rawFile.get("image_exif_rotation")));
} catch(Exception e){
//this properties will be null if something goes wrong
LOGGER.error("Failed to parse slack file", e);
}
file.setPermalink(GsonHelper.getStringOrNull(rawFile.get("permalink")));
file.setPermalinkPublic(GsonHelper.getStringOrNull(rawFile.get("permalink_public")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static final SlackUser buildSlackUser(JsonObject jsonUser)
{
slackPresence = SlackPersona.SlackPresence.AWAY;
}
return new SlackUserImpl(id, name, realName, email, skype, title, phone, deleted, admin, owner, primaryOwner, restricted, ultraRestricted, bot, tz, tzLabel, tzOffset == null ? null : new Integer(tzOffset.intValue()), slackPresence);
return new SlackUserImpl(id, name, realName, email, skype, title, phone, deleted, admin, owner, primaryOwner, restricted, ultraRestricted, bot, tz, tzLabel, tzOffset, slackPresence);
}

static final SlackChannel buildSlackChannel(JsonObject jsonChannel, Map<String, SlackUser> knownUsersById) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.net.ConnectException;
import java.net.Proxy;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -234,7 +235,7 @@ void dispatch(SlackEvent event) {
case USER_TYPING:
dispatchImpl((UserTyping) event, userTypingListener);
break;
case UNKNOWN:
default:
LOGGER.warn("event of type " + event.getEventType() + " not handled: " + ((UnknownEvent)event).getJsonPayload());
}
}
Expand Down Expand Up @@ -867,7 +868,7 @@ private void postSlackCommandWithFile(Map<String, String> params, byte [] fileCo
builder.addBinaryBody("file",fileContent, ContentType.DEFAULT_BINARY,fileName);
request.setEntity(builder.build());
HttpResponse response = client.execute(request);
String jsonResponse = ReaderUtils.readAll(new InputStreamReader(response.getEntity().getContent()));
String jsonResponse = ReaderUtils.readAll(new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8")));
LOGGER.debug("PostMessage return: " + jsonResponse);
ParsedSlackReply reply = SlackJSONReplyParser.decode(parseObject(jsonResponse),this);
handle.setReply(reply);
Expand Down

0 comments on commit 0f74f84

Please sign in to comment.