using System; using System.Collections.Generic; using com.fpnn.proto; namespace com.fpnn.rtm { public partial class RTMClient { private List BuildP2PConversationList(List conversations, List unreads, List messages) { List conversationList = new List(); int i = 0; foreach (List items in messages) { HistoryMessage message = new HistoryMessage(); message.cursorId = (long)Convert.ChangeType(items[0], TypeCode.Int64); if (message.cursorId != 0) { long direction = (long)Convert.ChangeType(items[1], TypeCode.Int64); if (direction == 1) { message.fromUid = Uid; message.toId = conversations[i]; } else { message.fromUid = conversations[i]; message.toId = Uid; } message.messageType = (byte)Convert.ChangeType(items[2], TypeCode.Byte); message.messageId = (long)Convert.ChangeType(items[3], TypeCode.Int64); if (!CheckBinaryType(items[5])) message.stringMessage = (string)Convert.ChangeType(items[5], TypeCode.String); else message.binaryMessage = (byte[])items[5]; message.attrs = (string)Convert.ChangeType(items[6], TypeCode.String); message.modifiedTime = (long)Convert.ChangeType(items[7], TypeCode.Int64); if (message.messageType >= 40 && message.messageType <= 50) RTMClient.BuildFileInfo(message, errorRecorder); } Conversation conversation = new Conversation(); conversation.id = conversations[i]; conversation.conversationType = ConversationType.P2P; conversation.unreadCount = unreads[i]; conversation.lastMessage = message; conversationList.Add(conversation); i += 1; } return conversationList; } public bool GetP2PConversationList(Action, int> callback, HashSet mTypes = null, long startTime = 0, int timeout = 0) { TCPClient client = GetCoreClient(); if (client == null) { if (RTMConfig.triggerCallbackIfAsyncMethodReturnFalse) ClientEngine.RunTask(() => { callback(null, fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION); }); return false; } Quest quest = new Quest("getp2pconversationlist"); if (mTypes != null) quest.Param("mtypes", mTypes); if (startTime != 0) quest.Param("mtime", startTime); bool asyncStarted = client.SendQuest(quest, (Answer answer, int errorCode) => { List conversationList = null; if (errorCode == fpnn.ErrorCode.FPNN_EC_OK) { try { List conversations = WantLongList(answer, "conversations"); List unreads = GetIntList(answer, "unreads"); List messages = (List)answer.Want("msgs"); conversationList = BuildP2PConversationList(conversations, unreads, messages); } catch (Exception) { errorCode = fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE; } } callback(conversationList, errorCode); }, timeout); if (!asyncStarted && RTMConfig.triggerCallbackIfAsyncMethodReturnFalse) ClientEngine.RunTask(() => { callback(null, fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION); }); return asyncStarted; } public int GetP2PConversationList(out List conversationList, HashSet mTypes = null, long startTime = 0, int timeout = 0) { conversationList = null; TCPClient client = GetCoreClient(); if (client == null) return fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION; Quest quest = new Quest("getp2pconversationlist"); if (mTypes != null) quest.Param("mtypes", mTypes); if (startTime != 0) quest.Param("mtime", startTime); Answer answer = client.SendQuest(quest, timeout); if (answer.IsException()) return answer.ErrorCode(); try { List conversations = WantLongList(answer, "conversations"); List unreads = GetIntList(answer, "unreads"); List messages = (List)answer.Want("msgs"); conversationList = BuildP2PConversationList(conversations, unreads, messages); return fpnn.ErrorCode.FPNN_EC_OK; } catch (Exception) { return fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE; } } public bool GetP2PUnreadConversationList(Action, int> callback, HashSet mTypes = null, long startTime = 0, int timeout = 0) { TCPClient client = GetCoreClient(); if (client == null) { if (RTMConfig.triggerCallbackIfAsyncMethodReturnFalse) ClientEngine.RunTask(() => { callback(null, fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION); }); return false; } Quest quest = new Quest("getp2punreadconversationlist"); if (mTypes != null) quest.Param("mtypes", mTypes); if (startTime != 0) quest.Param("mtime", startTime); bool asyncStarted = client.SendQuest(quest, (Answer answer, int errorCode) => { List conversationList = null; if (errorCode == fpnn.ErrorCode.FPNN_EC_OK) { try { List conversations = WantLongList(answer, "conversations"); List unreads = GetIntList(answer, "unreads"); List messages = (List)answer.Want("msgs"); conversationList = BuildP2PConversationList(conversations, unreads, messages); } catch (Exception) { errorCode = fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE; } } callback(conversationList, errorCode); }, timeout); if (!asyncStarted && RTMConfig.triggerCallbackIfAsyncMethodReturnFalse) ClientEngine.RunTask(() => { callback(null, fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION); }); return asyncStarted; } public int GetP2PUnreadConversationList(out List conversationList, HashSet mTypes = null, long startTime = 0, int timeout = 0) { conversationList = null; TCPClient client = GetCoreClient(); if (client == null) return fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION; Quest quest = new Quest("getp2punreadconversationlist"); if (mTypes != null) quest.Param("mtypes", mTypes); if (startTime != 0) quest.Param("mtime", startTime); Answer answer = client.SendQuest(quest, timeout); if (answer.IsException()) return answer.ErrorCode(); try { List conversations = WantLongList(answer, "conversations"); List unreads = GetIntList(answer, "unreads"); List messages = (List)answer.Want("msgs"); conversationList = BuildP2PConversationList(conversations, unreads, messages); return fpnn.ErrorCode.FPNN_EC_OK; } catch (Exception) { return fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE; } } private List BuildGroupConversationList(List conversations, List unreads, List messages) { List conversationList = new List(); int i = 0; foreach (List items in messages) { HistoryMessage message = new HistoryMessage(); message.cursorId = (long)Convert.ChangeType(items[0], TypeCode.Int64); if (message.cursorId != 0) { message.fromUid = (long)Convert.ChangeType(items[1], TypeCode.Int64); message.toId = conversations[i]; message.messageType = (byte)Convert.ChangeType(items[2], TypeCode.Byte); message.messageId = (long)Convert.ChangeType(items[3], TypeCode.Int64); if (!CheckBinaryType(items[5])) message.stringMessage = (string)Convert.ChangeType(items[5], TypeCode.String); else message.binaryMessage = (byte[])items[5]; message.attrs = (string)Convert.ChangeType(items[6], TypeCode.String); message.modifiedTime = (long)Convert.ChangeType(items[7], TypeCode.Int64); if (message.messageType >= 40 && message.messageType <= 50) RTMClient.BuildFileInfo(message, errorRecorder); } Conversation conversation = new Conversation(); conversation.id = conversations[i]; conversation.conversationType = ConversationType.GROUP; conversation.unreadCount = unreads[i]; conversation.lastMessage = message; conversationList.Add(conversation); i += 1; } return conversationList; } public bool GetGroupConversationList(Action, int> callback, HashSet mTypes = null, long startTime = 0, int timeout = 0) { TCPClient client = GetCoreClient(); if (client == null) { if (RTMConfig.triggerCallbackIfAsyncMethodReturnFalse) ClientEngine.RunTask(() => { callback(null, fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION); }); return false; } Quest quest = new Quest("getgroupconversationlist"); if (mTypes != null) quest.Param("mtypes", mTypes); if (startTime != 0) quest.Param("mtime", startTime); bool asyncStarted = client.SendQuest(quest, (Answer answer, int errorCode) => { List conversationList = null; if (errorCode == fpnn.ErrorCode.FPNN_EC_OK) { try { List conversations = WantLongList(answer, "conversations"); List unreads = GetIntList(answer, "unreads"); List messages = (List)answer.Want("msgs"); conversationList = BuildGroupConversationList(conversations, unreads, messages); } catch (Exception) { errorCode = fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE; } } callback(conversationList, errorCode); }, timeout); if (!asyncStarted && RTMConfig.triggerCallbackIfAsyncMethodReturnFalse) ClientEngine.RunTask(() => { callback(null, fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION); }); return asyncStarted; } public int GetGroupConversationList(out List conversationList, HashSet mTypes = null, long startTime = 0, int timeout = 0) { conversationList = null; TCPClient client = GetCoreClient(); if (client == null) return fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION; Quest quest = new Quest("getgroupconversationlist"); if (mTypes != null) quest.Param("mtypes", mTypes); if (startTime != 0) quest.Param("mtime", startTime); Answer answer = client.SendQuest(quest, timeout); if (answer.IsException()) return answer.ErrorCode(); try { List conversations = WantLongList(answer, "conversations"); List unreads = GetIntList(answer, "unreads"); List messages = (List)answer.Want("msgs"); conversationList = BuildGroupConversationList(conversations, unreads, messages); return fpnn.ErrorCode.FPNN_EC_OK; } catch (Exception) { return fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE; } } public bool GetGroupUnreadConversationList(Action, int> callback, HashSet mTypes = null, long startTime = 0, int timeout = 0) { TCPClient client = GetCoreClient(); if (client == null) { if (RTMConfig.triggerCallbackIfAsyncMethodReturnFalse) ClientEngine.RunTask(() => { callback(null, fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION); }); return false; } Quest quest = new Quest("getgroupunreadconversationlist"); if (mTypes != null) quest.Param("mtypes", mTypes); if (startTime != 0) quest.Param("mtime", startTime); bool asyncStarted = client.SendQuest(quest, (Answer answer, int errorCode) => { List conversationList = null; if (errorCode == fpnn.ErrorCode.FPNN_EC_OK) { try { List conversations = WantLongList(answer, "conversations"); List unreads = GetIntList(answer, "unreads"); List messages = (List)answer.Want("msgs"); conversationList = BuildGroupConversationList(conversations, unreads, messages); } catch (Exception) { errorCode = fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE; } } callback(conversationList, errorCode); }, timeout); if (!asyncStarted && RTMConfig.triggerCallbackIfAsyncMethodReturnFalse) ClientEngine.RunTask(() => { callback(null, fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION); }); return asyncStarted; } public int GetGroupUnreadConversationList(out List conversationList, HashSet mTypes = null, long startTime = 0, int timeout = 0) { conversationList = null; TCPClient client = GetCoreClient(); if (client == null) return fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION; Quest quest = new Quest("getgroupunreadconversationlist"); if (mTypes != null) quest.Param("mtypes", mTypes); if (startTime != 0) quest.Param("mtime", startTime); Answer answer = client.SendQuest(quest, timeout); if (answer.IsException()) return answer.ErrorCode(); try { List conversations = WantLongList(answer, "conversations"); List unreads = GetIntList(answer, "unreads"); List messages = (List)answer.Want("msgs"); conversationList = BuildGroupConversationList(conversations, unreads, messages); return fpnn.ErrorCode.FPNN_EC_OK; } catch (Exception) { return fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE; } } public bool GetUnreadConversationList(Action, List, int> callback, bool clear = true, HashSet mTypes = null, long startTime = 0, int timeout = 0) { TCPClient client = GetCoreClient(); if (client == null) { if (RTMConfig.triggerCallbackIfAsyncMethodReturnFalse) ClientEngine.RunTask(() => { callback(null, null, fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION); }); return false; } Quest quest = new Quest("getunreadconversationlist"); quest.Param("clear", clear); if (mTypes != null) quest.Param("mtypes", mTypes); if (startTime != 0) quest.Param("mtime", startTime); bool asyncStarted = client.SendQuest(quest, (Answer answer, int errorCode) => { List groupConversationList = null; List p2pConversationList = null; if (errorCode == fpnn.ErrorCode.FPNN_EC_OK) { try { List groupConversations = WantLongList(answer, "groupConversations"); List groupUnreads = GetIntList(answer, "groupUnreads"); List groupMsgs = (List)answer.Want("groupMsgs"); List p2pConversations = WantLongList(answer, "p2pConversations"); List p2pUnreads = GetIntList(answer, "p2pUnreads"); List p2pMsgs = (List)answer.Want("p2pMsgs"); groupConversationList = BuildGroupConversationList(groupConversations, groupUnreads, groupMsgs); p2pConversationList = BuildP2PConversationList(p2pConversations, p2pUnreads, p2pMsgs); } catch (Exception) { errorCode = fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE; } } callback(groupConversationList, p2pConversationList, errorCode); }, timeout); if (!asyncStarted && RTMConfig.triggerCallbackIfAsyncMethodReturnFalse) ClientEngine.RunTask(() => { callback(null, null, fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION); }); return asyncStarted; } public int GetUnreadConversationList(out List groupConversationList, out List p2pConversationList, bool clear = true, HashSet mTypes = null, long startTime = 0, int timeout = 0) { groupConversationList = null; p2pConversationList = null; TCPClient client = GetCoreClient(); if (client == null) return fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION; Quest quest = new Quest("getunreadconversationlist"); quest.Param("clear", clear); if (mTypes != null) quest.Param("mtypes", mTypes); if (startTime != 0) quest.Param("mtime", startTime); Answer answer = client.SendQuest(quest, timeout); if (answer.IsException()) return answer.ErrorCode(); try { List groupConversations = WantLongList(answer, "groupConversations"); List groupUnreads = GetIntList(answer, "groupUnreads"); List groupMsgs = (List)answer.Want("groupMsgs"); List p2pConversations = WantLongList(answer, "p2pConversations"); List p2pUnreads = GetIntList(answer, "p2pUnreads"); List p2pMsgs = (List)answer.Want("p2pMsgs"); groupConversationList = BuildGroupConversationList(groupConversations, groupUnreads, groupMsgs); p2pConversationList = BuildP2PConversationList(p2pConversations, p2pUnreads, p2pMsgs); return fpnn.ErrorCode.FPNN_EC_OK; } catch (Exception) { return fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE; } } } }