@@ -169,32 +169,41 @@ public Observable<QiscusChatRoom> getChatRoom(List<String> withEmails, String di
169
169
170
170
public Observable <QiscusChatRoom > getChatRoom (int roomId ) {
171
171
return api .getChatRoom (Qiscus .getToken (), roomId )
172
+ .onErrorReturn (throwable -> null )
172
173
.map (jsonElement -> {
173
- JsonObject jsonChatRoom = jsonElement .getAsJsonObject ().get ("results" )
174
- .getAsJsonObject ().get ("room" ).getAsJsonObject ();
175
- QiscusChatRoom qiscusChatRoom = new QiscusChatRoom ();
176
- qiscusChatRoom .setId (jsonChatRoom .get ("id" ).getAsInt ());
177
- //TODO minta server ngasih tau distinctId biar bisa disimpen
178
- //qiscusChatRoom.setDistinctId("default");
179
- qiscusChatRoom .setLastCommentId (jsonChatRoom .get ("last_comment_id" ).getAsInt ());
180
- qiscusChatRoom .setLastCommentMessage (jsonChatRoom .get ("last_comment_message" ).getAsString ());
181
- qiscusChatRoom .setLastTopicId (jsonChatRoom .get ("last_topic_id" ).getAsInt ());
182
- qiscusChatRoom .setOptions (jsonChatRoom .get ("options" ).isJsonNull () ? null
183
- : jsonChatRoom .get ("options" ).getAsString ());
184
- //TODO minta server ngasih tau member room siapa aja
185
- //qiscusChatRoom.setMember(withEmails);
186
- JsonArray comments = jsonElement .getAsJsonObject ().get ("results" )
187
- .getAsJsonObject ().get ("comments" ).getAsJsonArray ();
188
-
189
- if (comments .size () > 0 ) {
190
- JsonObject lastComment = comments .get (0 ).getAsJsonObject ();
191
- qiscusChatRoom .setLastCommentSender (lastComment .get ("username" ).getAsString ());
192
- qiscusChatRoom .setLastCommentSenderEmail (lastComment .get ("email" ).getAsString ());
193
- try {
194
- qiscusChatRoom .setLastCommentTime (dateFormat .parse (lastComment .get ("timestamp" ).getAsString ()));
195
- } catch (ParseException e ) {
196
- e .printStackTrace ();
174
+ QiscusChatRoom qiscusChatRoom ;
175
+ if (jsonElement != null ) {
176
+ JsonObject jsonChatRoom = jsonElement .getAsJsonObject ().get ("results" )
177
+ .getAsJsonObject ().get ("room" ).getAsJsonObject ();
178
+ qiscusChatRoom = new QiscusChatRoom ();
179
+ qiscusChatRoom .setId (jsonChatRoom .get ("id" ).getAsInt ());
180
+ //TODO minta server ngasih tau distinctId biar bisa disimpen
181
+ //qiscusChatRoom.setDistinctId("default");
182
+ qiscusChatRoom .setLastCommentId (jsonChatRoom .get ("last_comment_id" ).getAsInt ());
183
+ qiscusChatRoom .setLastCommentMessage (jsonChatRoom .get ("last_comment_message" ).getAsString ());
184
+ qiscusChatRoom .setLastTopicId (jsonChatRoom .get ("last_topic_id" ).getAsInt ());
185
+ qiscusChatRoom .setOptions (jsonChatRoom .get ("options" ).isJsonNull () ? null
186
+ : jsonChatRoom .get ("options" ).getAsString ());
187
+ //TODO minta server ngasih tau member room siapa aja
188
+ //qiscusChatRoom.setMember(withEmails);
189
+ JsonArray comments = jsonElement .getAsJsonObject ().get ("results" )
190
+ .getAsJsonObject ().get ("comments" ).getAsJsonArray ();
191
+
192
+ if (comments .size () > 0 ) {
193
+ JsonObject lastComment = comments .get (0 ).getAsJsonObject ();
194
+ qiscusChatRoom .setLastCommentSender (lastComment .get ("username" ).getAsString ());
195
+ qiscusChatRoom .setLastCommentSenderEmail (lastComment .get ("email" ).getAsString ());
196
+ try {
197
+ qiscusChatRoom .setLastCommentTime (dateFormat .parse (lastComment .get ("timestamp" ).getAsString ()));
198
+ } catch (ParseException e ) {
199
+ e .printStackTrace ();
200
+ }
197
201
}
202
+ return qiscusChatRoom ;
203
+ }
204
+ qiscusChatRoom = Qiscus .getDataStore ().getChatRoom (roomId );
205
+ if (qiscusChatRoom == null ) {
206
+ throw new RuntimeException ("Unable to connect with qiscus server!" );
198
207
}
199
208
return qiscusChatRoom ;
200
209
});
0 commit comments