public async Task GetThreadList(int startIndex, int endIndex) { try { var getThreadList = Edge.Func(NodeJSScriptConstant.METHOD_GET_THREADLIST); dynamic result = await getThreadList(new { startIndex = startIndex, endIndex = endIndex }); if ((string)result.status == FACEBOOK_STATUS_OK) { string threadsJson = (string)result.threadsJson; List <ChatThread> chatThreads = ChatThread.Parse(threadsJson); string message = (string)result.message; if (chatThreads.Count == 0) { message += "No result found."; } else { message += chatThreads.Count + " results found."; } ThreadGetEventArgs e = new ThreadGetEventArgs(chatThreads, message); OnThreadGet(e); } } catch (Exception ex) { var errMsg = "Exception occured at GetThreadList : " + ex.Message + "\nStack Trace : " + ex.StackTrace; throw new FacebookChatApiException(errMsg); } }
/// <summary> /// Parse a jSON consist of single Thread /// </summary> /// <param name="threadJson"></param> /// <returns></returns> public static ChatThread ParseSingle(string threadJson) { ChatThread thread = null; if (string.IsNullOrEmpty(threadJson)) { return(thread); } try { JObject jObj = JObject.Parse(threadJson); JArray jArrayParticipants = (JArray)jObj.GetValue(CHAT_THREAD_PARTICIPANTS); List <string> participants = new List <string>(); foreach (string participant in jArrayParticipants) { participants.Add(participant); } JArray jArrayFormerParticipants = (JArray)jObj.GetValue(CHAT_THREAD_FORMER_PARTICIPANTS); List <string> formerParticipants = new List <string>(); foreach (string formerParticipant in jArrayFormerParticipants) { participants.Add(formerParticipant); } thread = new ChatThread( jObj.GetValue(CHAT_THREAD_THREAD_ID).ToString(), participants, formerParticipants, jObj.GetValue(CHAT_THREAD_NAME).ToString(), jObj.GetValue(CHAT_THREAD_SNIPPET).ToString(), bool.Parse(jObj.GetValue(CHAT_THREAD_SNIPPET_HAS_ATTACHMENT).ToString()), jObj.GetValue(CHAT_THREAD_SNIPPET_SENDER).ToString(), int.Parse(jObj.GetValue(CHAT_THREAD_UNREAD_COUNT).ToString()), int.Parse(jObj.GetValue(CHAT_THREAD_MESSAGE_COUNT).ToString()), jObj.GetValue(CHAT_THREAD_IMAGE_SRC).ToString(), long.Parse(jObj.GetValue(CHAT_THREAD_TIMESTAMP).ToString()), long.Parse(jObj.GetValue(CHAT_THREAD_SERVER_TIMESTAMP).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_IS_CANONICAL_USER).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_IS_CANONICAL).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_IS_SUBCRIBED).ToString()), jObj.GetValue(CHAT_THREAD_FOLDER).ToString(), bool.Parse(jObj.GetValue(CHAT_THREAD_IS_ARCHIVED).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_IS_CANONICAL).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_HAS_EMAIL_PARTICIPANT).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_READONLY).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_CAN_REPLY).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_COMPOSER_ENABLED).ToString()), jObj.GetValue(CHAT_THREAD_LAST_MESSAGE_ID).ToString() ); } catch (Exception ex) { throw new FacebookChatApiException("ChatThread.ParseSingle :" + ex.Message); } return(thread); }
/// <summary> /// Parse a jSON consist of single Thread /// </summary> /// <param name="threadJson"></param> /// <returns></returns> public static ChatThread ParseSingle(string threadJson) { ChatThread thread = null; if (string.IsNullOrEmpty(threadJson)) { return thread; } try { JObject jObj = JObject.Parse(threadJson); JArray jArrayParticipants = (JArray)jObj.GetValue(CHAT_THREAD_PARTICIPANTS); List<string> participants = new List<string>(); foreach(string participant in jArrayParticipants) { participants.Add(participant); } JArray jArrayFormerParticipants = (JArray)jObj.GetValue(CHAT_THREAD_FORMER_PARTICIPANTS); List<string> formerParticipants = new List<string>(); foreach(string formerParticipant in jArrayFormerParticipants) { participants.Add(formerParticipant); } thread = new ChatThread( jObj.GetValue(CHAT_THREAD_THREAD_ID).ToString(), participants, formerParticipants, jObj.GetValue(CHAT_THREAD_NAME).ToString(), jObj.GetValue(CHAT_THREAD_SNIPPET).ToString(), bool.Parse(jObj.GetValue(CHAT_THREAD_SNIPPET_HAS_ATTACHMENT).ToString()), jObj.GetValue(CHAT_THREAD_SNIPPET_SENDER).ToString(), int.Parse(jObj.GetValue(CHAT_THREAD_UNREAD_COUNT).ToString()), int.Parse(jObj.GetValue(CHAT_THREAD_MESSAGE_COUNT).ToString()), jObj.GetValue(CHAT_THREAD_IMAGE_SRC).ToString(), long.Parse(jObj.GetValue(CHAT_THREAD_TIMESTAMP).ToString()), long.Parse(jObj.GetValue(CHAT_THREAD_SERVER_TIMESTAMP).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_IS_CANONICAL_USER).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_IS_CANONICAL).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_IS_SUBCRIBED).ToString()), jObj.GetValue(CHAT_THREAD_FOLDER).ToString(), bool.Parse(jObj.GetValue(CHAT_THREAD_IS_ARCHIVED).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_IS_CANONICAL).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_HAS_EMAIL_PARTICIPANT).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_READONLY).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_CAN_REPLY).ToString()), bool.Parse(jObj.GetValue(CHAT_THREAD_COMPOSER_ENABLED).ToString()), jObj.GetValue(CHAT_THREAD_LAST_MESSAGE_ID).ToString() ); } catch (Exception ex) { throw new FacebookChatApiException("ChatThread.ParseSingle :" + ex.Message); } return thread; }