//-------------[ Get Messages ]---------------------// private RetrievedMessage BuildRetrievedMessage(Answer answer) { RetrievedMessage message = new RetrievedMessage(); message.cursorId = answer.Want <long>("id"); message.messageType = answer.Want <byte>("mtype"); message.attrs = answer.Want <string>("attrs"); message.modifiedTime = answer.Want <long>("mtime"); object originalMessage = answer.Want("msg"); if (!CheckBinaryType(originalMessage)) { message.stringMessage = (string)Convert.ChangeType(originalMessage, TypeCode.String); } else { message.binaryMessage = (byte[])originalMessage; } if (message.messageType >= 40 && message.messageType <= 50) { RTMClient.BuildFileInfo(message, errorRecorder); } return(message); }
private RTMMessage BuildRTMMessage(Quest quest, long from, long to, long mid) { RTMMessage rtmMessage = new RTMMessage { fromUid = from, toId = to, messageId = mid, messageType = quest.Want <byte>("mtype"), attrs = quest.Want <string>("attrs"), modifiedTime = quest.Want <long>("mtime") }; if (rtmMessage.messageType == (byte)MessageType.Chat) { rtmMessage.translatedInfo = ProcessChatMessage(quest); if (rtmMessage.translatedInfo != null) { if (rtmMessage.translatedInfo.targetText.Length > 0) { rtmMessage.stringMessage = rtmMessage.translatedInfo.targetText; } else { rtmMessage.stringMessage = rtmMessage.translatedInfo.sourceText; } } } else if (rtmMessage.messageType == (byte)MessageType.Cmd) { rtmMessage.stringMessage = quest.Want <string>("msg"); } else if (rtmMessage.messageType >= 40 && rtmMessage.messageType <= 50) { rtmMessage.stringMessage = quest.Want <string>("msg"); RTMClient.BuildFileInfo(rtmMessage, errorRecorder); } else { MessageInfo messageInfo = BuildMessageInfo(quest); if (messageInfo.isBinary) { rtmMessage.binaryMessage = messageInfo.binaryData; } else { rtmMessage.stringMessage = messageInfo.message; } } return(rtmMessage); }
/* * internal static byte[] ConvertStringToByteArray(string data) * { * //-- Please refer com.fpnn.msgpack.MsgPacker::UnpackString(...) * * UTF8Encoding utf8Encoding = new UTF8Encoding(false, true); //-- NO BOM. * return utf8Encoding.GetBytes(data); * } */ //===========================[ History Messages Utilities ]=========================// private HistoryMessageResult BuildHistoryMessageResult(long toId, Answer answer) { HistoryMessageResult result = new HistoryMessageResult(); result.count = answer.Want <int>("num"); result.lastCursorId = answer.Want <long>("lastid"); result.beginMsec = answer.Want <long>("begin"); result.endMsec = answer.Want <long>("end"); result.messages = new List <HistoryMessage>(); List <object> messages = (List <object>)answer.Want("msgs"); foreach (List <object> items in messages) { bool deleted = (bool)Convert.ChangeType(items[4], TypeCode.Boolean); if (deleted) { continue; } HistoryMessage message = new HistoryMessage(); message.cursorId = (long)Convert.ChangeType(items[0], TypeCode.Int64); message.fromUid = (long)Convert.ChangeType(items[1], TypeCode.Int64); message.toId = toId; 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); } result.messages.Add(message); } result.count = result.messages.Count; return(result); }