コード例 #1
0
        /// <summary>
        /// 从本地查询消息
        /// </summary>
        /// <param name="sessionId">会话ID</param>
        /// <param name="chatType">聊天类型</param>
        /// <param name="first">第一次查询,传true;其他传false</param>
        /// <param name="msgCount">查询数量,范围在[1,20],超出的话,会报错</param>
        /// <param name="index">起始chatIndex,如果第一次查询的话,可以传0;如果不是第一次查询,那么查询出来的消息的index都是小于这个chatIndex的</param>
        /// <returns></returns>
        public static List <AntSdkChatMsg.ChatBase> QueryMessageFromLocal(string sessionId, AntSdkchatType chatType, bool first, int msgCount, int index)
        {
            var input = new AntSdkSynchronusMsgInput
            {
                sessionId = sessionId,
                chatType  = (int)chatType,
                flag      = 0,
                userId    = AntSdkService.AntSdkLoginOutput.userId,
                isFirst   = first,
                count     = msgCount,
                chatIndex = index,
            };
            var listChatdata = new List <AntSdkChatMsg.ChatBase>();
            var result       = AntSdkService.GetLocalMsgData(input, ref listChatdata, false);

            return(result ? listChatdata : null);
        }
コード例 #2
0
        /// <summary>
        /// 从网络查询消息
        /// </summary>
        /// <param name="sessionId">会话ID</param>
        /// <param name="chatType">聊天类型</param>
        /// <param name="first">第一次查询,传true;其他传false</param>
        /// <param name="msgCount">查询数量,范围在[1,20],超出的话,会报错</param>
        /// <param name="index">起始chatIndex,如果第一次查询的话,可以传0;如果不是第一次查询,那么查询出来的消息的index都是小于这个chatIndex的</param>
        /// <returns></returns>
        public static List <AntSdkChatMsg.ChatBase> QueryMessageFromServer(string sessionId, AntSdkchatType chatType, bool first, int msgCount, int index)
        {
            var input = new AntSdkSynchronusMsgInput
            {
                sessionId = sessionId,
                chatType  = (int)chatType,
                flag      = 0,
                userId    = AntSdkService.AntSdkLoginOutput.userId,
                isFirst   = first,
                count     = msgCount,
                chatIndex = index,
            };
            var    chatMsgList = new List <AntSdkChatMsg.ChatBase>();
            int    errorCode   = 0;
            string errorMsg    = string.Empty;

            AntSdkService.SynchronusMsgs(input, ref chatMsgList, ref errorCode, ref errorMsg);
            if (chatMsgList == null || chatMsgList.Count == 0)
            {
                return(null);
            }
            else
            {
                var tempChatMsg     = chatMsgList[chatMsgList.Count - 1];
                var localMsgSession = t_sessionBll.GetModelByKey(tempChatMsg.sessionId);
                var chatIndex       = 0;
                int.TryParse(tempChatMsg.chatIndex, out chatIndex);

                if (localMsgSession != null)
                {
                    var localChatIndex = 0;
                    var burnChatIndex  = 0;
                    if (!string.IsNullOrEmpty(localMsgSession.LastChatIndex))
                    {
                        int.TryParse(localMsgSession.LastChatIndex, out localChatIndex);
                    }
                    if (!string.IsNullOrEmpty(localMsgSession.BurnLastChatIndex))
                    {
                        int.TryParse(localMsgSession.BurnLastChatIndex, out burnChatIndex);
                    }
                    if (localChatIndex < burnChatIndex)
                    {
                        localChatIndex = burnChatIndex;
                    }
                    if (chatIndex > localChatIndex)
                    {
                        var antSdkContactUser = AntSdkService.AntSdkListContactsEntity.users.FirstOrDefault(c => c.userId == tempChatMsg.sendUserId);
                        localMsgSession.LastChatIndex = tempChatMsg.chatIndex;
                        localMsgSession.LastMsg       = antSdkContactUser != null?
                                                        FormatLastMessageContent(tempChatMsg.MsgType, tempChatMsg, chatType == AntSdkchatType.Group,
                                                                                 antSdkContactUser.userNum != null?antSdkContactUser.userNum + antSdkContactUser.userName : antSdkContactUser.userName) :
                                                            PublicMessageFunction.FormatLastMessageContent(tempChatMsg.MsgType, tempChatMsg, chatType == AntSdkchatType.Group);

                        localMsgSession.LastMsgTimeStamp = tempChatMsg.sendTime;
                        t_sessionBll.Update(localMsgSession);
                        tempChatMsg.chatType = (int)chatType;
                        SessionMonitor.AddSessionItemOnlineMsg(tempChatMsg.MsgType, tempChatMsg, false);
                    }
                }
                return(chatMsgList);
            }
        }