Skip to content

Commit 4fab366

Browse files
authored
Merge branch 'master' into issue-477
2 parents 0b1e8e1 + fb7ee61 commit 4fab366

File tree

9 files changed

+88
-72
lines changed

9 files changed

+88
-72
lines changed

json-logs/raw/status/api/v1.0.0/current.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@
233233
{
234234
"date_created": "2020-05-26T11:19:03-07:00",
235235
"body": "Our team is investigating an issue that is causing custom emoji to go missing from some workspaces. We\u0027ll keep you updated as soon as we have more information."
236+
},
237+
{
238+
"date_created": "2020-06-01T11:23:40-07:00",
239+
"body": "Some Android users may notice that new messages are not showing up in channels and DMs immediately. We\u0027re actively investigating this issue and will keep you posted as more information becomes available. For now, quitting and reopening the Slack app should allow new messages to load. We\u0027re sorry for any disruption this brings to your day."
236240
}
237241
]
238242
}

json-logs/raw/status/api/v2.0.0/current.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,24 @@
293293
"body": "Our team is investigating an issue that is causing custom emoji to go missing from some workspaces. We\u0027ll keep you updated as soon as we have more information."
294294
}
295295
]
296+
},
297+
{
298+
"id": 857,
299+
"date_created": "2020-06-01T11:23:40-07:00",
300+
"date_updated": "2020-06-01T11:23:40-07:00",
301+
"title": "Some new messages are not appearing on Android",
302+
"type": "incident",
303+
"status": "active",
304+
"url": "https://status.slack.com/2020-06/9cd5efa0af2dbfad",
305+
"services": [
306+
"Messaging"
307+
],
308+
"notes": [
309+
{
310+
"date_created": "2020-06-01T11:23:40-07:00",
311+
"body": "Some Android users may notice that new messages are not showing up in channels and DMs immediately. We\u0027re actively investigating this issue and will keep you posted as more information becomes available. For now, quitting and reopening the Slack app should allow new messages to load. We\u0027re sorry for any disruption this brings to your day."
312+
}
313+
]
296314
}
297315
]
298316
}

json-logs/samples/api/channels.history.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@
667667
],
668668
"count": 12345
669669
}
670-
]
670+
],
671+
"client_msg_id": ""
671672
}
672673
],
673674
"has_more": false,

json-logs/samples/api/conversations.history.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@
657657
"display_as_bot": false,
658658
"x_files": [
659659
"F00000000"
660-
]
660+
],
661+
"client_msg_id": ""
661662
}
662663
],
663664
"has_more": false,

json-logs/samples/api/mpim.replies.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
},
3232
"team_id": "T00000000"
3333
},
34-
"parent_user_id": "U00000000"
34+
"parent_user_id": "U00000000",
35+
"last_read": "0000000000.000000"
3536
}
3637
],
3738
"has_more": false,

json-logs/samples/api/rtm.start.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@
331331
"pt-BR": "",
332332
"ja-JP": ""
333333
},
334-
"channel_sidebar_hide_browse_dms_link": false
334+
"channel_sidebar_hide_browse_dms_link": false,
335+
"enable_all_dms_view": false
335336
},
336337
"created": 12345,
337338
"first_login": 12345,
@@ -558,7 +559,8 @@
558559
""
559560
]
560561
},
561-
"invites_limit": false
562+
"invites_limit": false,
563+
"ntlm_credential_domains": ""
562564
},
563565
"icon": {
564566
"image_34": "https://www.example.com/",

json-logs/samples/scim/v1/Users.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,22 @@
110110
"Errors": {
111111
"description": "",
112112
"code": 12345
113+
},
114+
"addresses": [
115+
{}
116+
],
117+
"phoneNumbers": [
118+
{
119+
"type": "",
120+
"primary": false
121+
}
122+
],
123+
"roles": [
124+
{
125+
"primary": false
126+
}
127+
],
128+
"urn:scim:schemas:extension:enterprise:1.0": {
129+
"manager": {}
113130
}
114131
}
Lines changed: 21 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.slack.api.rtm;
22

3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonObject;
5+
import com.google.gson.JsonParser;
36
import com.slack.api.model.event.Event;
47
import com.slack.api.util.json.GsonFactory;
58
import lombok.extern.slf4j.Slf4j;
@@ -40,8 +43,12 @@ public void deregister(RTMEventHandler<? extends Event> handler) {
4043

4144
@Override
4245
public void dispatch(String json) {
43-
String eventType = detectEventType(json);
44-
String eventSubType = detectEventSubType(json);
46+
JsonElement jsonMessage = JsonParser.parseString(json);
47+
if (jsonMessage.isJsonObject() == false)
48+
return;
49+
50+
String eventType = detectEventType(jsonMessage.getAsJsonObject());
51+
String eventSubType = detectEventSubType(jsonMessage.getAsJsonObject());
4552

4653
if (eventType == null) {
4754
log.debug("Failed to detect event type from the given JSON data: {}", json);
@@ -59,7 +66,7 @@ public void dispatch(String json) {
5966
if (rtmEventHandlers.isEmpty() == false) {
6067
Class<?> clazz = rtmEventHandlers.get(0).getEventClass();
6168
for (RTMEventHandler<?> handler : rtmEventHandlers) {
62-
Event event = (Event) GsonFactory.createSnakeCase().fromJson(json, clazz);
69+
Event event = (Event) GsonFactory.createSnakeCase().fromJson(jsonMessage, clazz);
6370
handler.acceptUntypedObject(event);
6471
}
6572
}
@@ -78,72 +85,20 @@ public void handle(String message) {
7885
return messageHandler;
7986
}
8087

81-
public static String detectEventType(String json) {
82-
StringBuilder sb = new StringBuilder();
83-
char[] chars = json.toCharArray();
84-
for (int idx = 0; idx < (chars.length - 6); idx++) {
85-
if (chars[idx] == '"'
86-
&& chars[idx + 1] == 't'
87-
&& chars[idx + 2] == 'y'
88-
&& chars[idx + 3] == 'p'
89-
&& chars[idx + 4] == 'e'
90-
&& chars[idx + 5] == '"'
91-
&& chars[idx + 6] == ':') {
92-
idx = idx + 7;
93-
int doubleQuoteCount = 0;
94-
boolean isPreviousCharEscape = false;
95-
while (doubleQuoteCount < 2 && idx < chars.length) {
96-
char c = chars[idx];
97-
if (c == '"' && !isPreviousCharEscape) {
98-
doubleQuoteCount++;
99-
} else {
100-
if (doubleQuoteCount == 1) {
101-
sb.append(c);
102-
}
103-
}
104-
isPreviousCharEscape = c == '\\';
105-
idx++;
106-
}
107-
break;
108-
}
109-
}
110-
return sb.toString();
88+
public static String detectEventType(JsonObject json) {
89+
JsonElement type = json.get("type");
90+
if (type == null || type.isJsonPrimitive() == false)
91+
return "";
92+
return type.getAsString();
11193
}
11294

11395

114-
public static String detectEventSubType(String json) {
115-
StringBuilder sb = new StringBuilder();
116-
char[] chars = json.toCharArray();
117-
for (int idx = 0; idx < (chars.length - 9); idx++) {
118-
if (chars[idx] == '"'
119-
&& chars[idx + 1] == 's'
120-
&& chars[idx + 2] == 'u'
121-
&& chars[idx + 3] == 'b'
122-
&& chars[idx + 4] == 't'
123-
&& chars[idx + 5] == 'y'
124-
&& chars[idx + 6] == 'p'
125-
&& chars[idx + 7] == 'e'
126-
&& chars[idx + 8] == '"'
127-
&& chars[idx + 9] == ':') {
128-
idx = idx + 10;
129-
int doubleQuoteCount = 0;
130-
boolean isPreviousCharEscape = false;
131-
while (doubleQuoteCount < 2 && idx < chars.length) {
132-
char c = chars[idx];
133-
if (c == '"' && !isPreviousCharEscape) {
134-
doubleQuoteCount++;
135-
} else {
136-
if (doubleQuoteCount == 1) {
137-
sb.append(c);
138-
}
139-
}
140-
isPreviousCharEscape = c == '\\';
141-
idx++;
142-
}
143-
break;
144-
}
145-
}
146-
return sb.toString();
96+
public static String detectEventSubType(JsonObject json) {
97+
98+
JsonElement type = json.get("subtype");
99+
if (type == null || type.isJsonPrimitive() == false)
100+
return "";
101+
return type.getAsString();
147102
}
148103

149104
}

slack-api-client/src/test/java/test_locally/api/rtm/RTMEventsDispatcherImplTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package test_locally.api.rtm;
22

3+
import com.google.gson.JsonObject;
4+
import com.google.gson.JsonParser;
35
import com.slack.api.model.event.Event;
46
import com.slack.api.model.event.MessageEvent;
57
import com.slack.api.rtm.RTMEventHandler;
@@ -15,10 +17,25 @@ public class RTMEventsDispatcherImplTest {
1517

1618
@Test
1719
public void eventDetection() {
18-
String type = RTMEventsDispatcherImpl.detectEventType("{\"type\": \"hello\"}");
20+
JsonObject jsonMessage = JsonParser.parseString("{\"type\": \"hello\"}").getAsJsonObject();
21+
String type = RTMEventsDispatcherImpl.detectEventType(jsonMessage);
1922
assertThat(type, is("hello"));
2023
}
2124

25+
@Test
26+
public void eventSubtypeDetection() {
27+
JsonObject jsonMessage = JsonParser.parseString("{ \"type\": \"message\", \"subtype\": \"bot_message\" }").getAsJsonObject();
28+
String subtype = RTMEventsDispatcherImpl.detectEventSubType(jsonMessage);
29+
assertThat(subtype, is("bot_message"));
30+
}
31+
32+
@Test
33+
public void eventInnerSubtypeDetection() {
34+
JsonObject jsonMessage = JsonParser.parseString("{\"type\": \"pin_added\", \"item\": { \"type\": \"message\", \"subtype\": \"bot_message\" } }").getAsJsonObject();
35+
String subtype = RTMEventsDispatcherImpl.detectEventSubType(jsonMessage);
36+
assertThat(subtype, is(""));
37+
}
38+
2239
@Test
2340
public void factory() {
2441
RTMEventsDispatcher dispatcher = RTMEventsDispatcherFactory.getInstance();

0 commit comments

Comments
 (0)