From 232e1abf5932d911039c7d3f9fc35468b2b95f86 Mon Sep 17 00:00:00 2001 From: wtp <1813748440@qq.com> Date: Wed, 15 Mar 2023 16:27:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9C=AA=E8=AF=BB=E6=95=B0?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GDZZ.Application/Enum/SystemConst.cs | 6 +++++ GDZZ.Application/Help/CacheService.cs | 22 +++++++++++++++++++ GDZZ.Application/Help/ICacheService.cs | 3 +++ .../LiveHistoryContactsService.cs | 5 ++++- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/GDZZ.Application/Enum/SystemConst.cs b/GDZZ.Application/Enum/SystemConst.cs index 98726ff..bb46fec 100644 --- a/GDZZ.Application/Enum/SystemConst.cs +++ b/GDZZ.Application/Enum/SystemConst.cs @@ -23,6 +23,12 @@ namespace GDZZ.Application.Enum /// 聊天详情 /// public const string LIVE_MESSAGE = "Live_Message:"; + + + /// + /// 聊天详情 + /// + public const string LIVE_UNREAD = "Live_Unread:"; #endregion diff --git a/GDZZ.Application/Help/CacheService.cs b/GDZZ.Application/Help/CacheService.cs index 4b6d3d9..12542ce 100644 --- a/GDZZ.Application/Help/CacheService.cs +++ b/GDZZ.Application/Help/CacheService.cs @@ -91,6 +91,28 @@ namespace GDZZ.Application.Help await _redisCache.SetAsync(cacheKey, liveMessages, TimeSpan.FromHours(1)); } + /// + /// 设置未读数 + /// + /// + /// + /// + [NonAction] + public async Task SetUnreadAsync(long UserID) + { + string cacheKey = SystemConst.LIVE_UNREAD + $"{UserID}"; + var res = _redisCache.Get(cacheKey); + await _redisCache.SetAsync(cacheKey, 1+res); + } + + + public async Task GetUnreadAsync(long UserID) + { + string cacheKey = SystemConst.LIVE_UNREAD + $"{UserID}"; + return _redisCache.Get(cacheKey); + } + + /// /// 获取聊天列表 /// diff --git a/GDZZ.Application/Help/ICacheService.cs b/GDZZ.Application/Help/ICacheService.cs index d5dccb2..bfb9de0 100644 --- a/GDZZ.Application/Help/ICacheService.cs +++ b/GDZZ.Application/Help/ICacheService.cs @@ -17,6 +17,9 @@ namespace GDZZ.Application.Help #region 聊天详情接口 Task SetMessage(List liveMessages, long UserID, long ChatUserID); + Task SetUnreadAsync(long LiveID); + + Task GetUnreadAsync(long LiveID); #endregion diff --git a/GDZZ.Application/Service/LiveHistoryContacts/LiveHistoryContactsService.cs b/GDZZ.Application/Service/LiveHistoryContacts/LiveHistoryContactsService.cs index bf13832..34acb3d 100644 --- a/GDZZ.Application/Service/LiveHistoryContacts/LiveHistoryContactsService.cs +++ b/GDZZ.Application/Service/LiveHistoryContacts/LiveHistoryContactsService.cs @@ -140,7 +140,7 @@ namespace GDZZ.Application Id = item.FriendID, Index = sysUser.Name.Substring(0, 1), LastSendTime = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000, - Unread = 0 + Unread = await this.cacheService.GetUnreadAsync(UserManager.UserId) }; //查询聊天记录 @@ -203,7 +203,10 @@ namespace GDZZ.Application id = UserManager.UserId } }; + await this.cacheService.SetUnreadAsync(UserManager.UserId); + await this.cacheService.SetUnreadAsync(entity.OtherUserID); var livejson = livemes.ToJsonString(); + await _chatHubContext.Clients.Client(user.ConnectionId).SendMessage(livejson, "SendMessage"); } }