Example #1
0
        /// <summary>
        /// 获取消息时间字符串
        /// </summary>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static string GetMessageTime(EMMessage message)
        {
            if (message == null)
            {
                return(string.Empty);
            }
            DateTime now     = DateTime.Now;
            DateTime msgTime = DCUtilTool.NewDate(message.timestamp());

            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day == now.Day)
            {
                return(msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day + 1 == now.Day)
            {
                return("昨天 " + msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day + 2 == now.Day)
            {
                return("前天 " + msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year)
            {
                return(msgTime.ToString("MM-dd HH:mm"));
            }
            return(msgTime.ToString("yyyy-MM-dd"));
        }
Example #2
0
        /// <summary>
        /// 获取时间字符串
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static string GetMessageTime(long time)
        {
            DateTime now     = DateTime.Now;
            DateTime msgTime = DCUtilTool.NewDate(time);

            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day == now.Day)
            {
                return(msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day + 1 == now.Day)
            {
                return("昨天 " + msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day + 2 == now.Day)
            {
                return("前天 " + msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year)
            {
                return(msgTime.ToString("MM-dd HH:mm"));
            }
            return(msgTime.ToString("yyyy-MM-dd"));
        }
Example #3
0
        private void downloadVideoMainAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite)
        {
            EMVideoMessageBody body = mMessage.bodies()[0] as EMVideoMessageBody;

            body.setDownloadStatus(EMDownloadStatus.DOWNLOADING);
            mMessage.clearBodies();
            mMessage.addBody(body);
            var conversation = EaseHelper.shard.client.getChatManager().conversationWithType(mMessage.conversationId(), DCUtilTool.GetMConversationType(mMessage.chatType()), true);

            conversation.updateMessage(mMessage);
            string dir = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\Changliao" + "\\ChangLiao\\" + SettingMenager.shard.idCard;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string path = dir + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".mp4";

            HttpUitls.Instance.DownloadFile(body.remotePath(), path, (p) =>
            {
                Console.WriteLine(p);
                if (progress != null)
                {
                    progress(p);
                }
            }, (b) =>
            {
                if (b)
                {
                    var fi = new FileInfo(path);
                    body.setFileLength(fi.Length);
                    body.setLocalPath(path);
                    body.setDownloadStatus(EMDownloadStatus.SUCCESSED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
                else
                {
                    body.setDownloadStatus(EMDownloadStatus.FAILED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
            });
        }
Example #4
0
        private void downloadFileMainAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite)
        {
            EMFileMessageBody body = mMessage.bodies()[0] as EMFileMessageBody;

            body.setDownloadStatus(EMDownloadStatus.DOWNLOADING);
            mMessage.clearBodies();
            mMessage.addBody(body);
            var conversation = EaseHelper.shard.client.getChatManager().conversationWithType(mMessage.conversationId(), DCUtilTool.GetMConversationType(mMessage.chatType()), true);

            conversation.updateMessage(mMessage);
            string dir = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\Changliao" + "\\ChangLiao\\" + SettingMenager.shard.idCard;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string path = dir + "\\" + body.displayName();
            var    p    = path;
            int    i    = 0;

            while (File.Exists(p))
            {
                i += 1;
                var arr = path.Split('.');
                if (arr.Length > 2)
                {
                    p = "";
                    for (int j = 0; j < arr.Length - 1; j++)
                    {
                        p += arr[j];
                    }
                    p = p + "(" + i + ")." + arr[arr.Length - 1];
                }
                else if (arr.Length == 2)
                {
                    p = arr[0] + "(" + i + ")." + arr[1];
                }
                else
                {
                    p = path + "(" + i + ")";
                }
            }
            HttpUitls.Instance.DownloadFile(body.remotePath(), p, (p1) =>
            {
                if (progress != null)
                {
                    progress(p1);
                }
            }, (b) =>
            {
                if (b)
                {
                    var fi = new FileInfo(path);
                    body.setFileLength(fi.Length);
                    body.setLocalPath(path);
                    body.setDownloadStatus(EMDownloadStatus.SUCCESSED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
                else
                {
                    body.setDownloadStatus(EMDownloadStatus.FAILED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
            });
        }