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"); } }