新增未读数显示

development
温天培 2 years ago
parent 6c1d1da4b8
commit 232e1abf59

@ -23,6 +23,12 @@ namespace GDZZ.Application.Enum
/// 聊天详情 /// 聊天详情
/// </summary> /// </summary>
public const string LIVE_MESSAGE = "Live_Message:"; public const string LIVE_MESSAGE = "Live_Message:";
/// <summary>
/// 聊天详情
/// </summary>
public const string LIVE_UNREAD = "Live_Unread:";
#endregion #endregion

@ -91,6 +91,28 @@ namespace GDZZ.Application.Help
await _redisCache.SetAsync(cacheKey, liveMessages, TimeSpan.FromHours(1)); await _redisCache.SetAsync(cacheKey, liveMessages, TimeSpan.FromHours(1));
} }
/// <summary>
/// 设置未读数
/// </summary>
/// <param name="UserID"></param>
/// <param name="ChatUserID"></param>
/// <returns></returns>
[NonAction]
public async Task SetUnreadAsync(long UserID)
{
string cacheKey = SystemConst.LIVE_UNREAD + $"{UserID}";
var res = _redisCache.Get<int>(cacheKey);
await _redisCache.SetAsync(cacheKey, 1+res);
}
public async Task<int> GetUnreadAsync(long UserID)
{
string cacheKey = SystemConst.LIVE_UNREAD + $"{UserID}";
return _redisCache.Get<int>(cacheKey);
}
/// <summary> /// <summary>
/// 获取聊天列表 /// 获取聊天列表
/// </summary> /// </summary>

@ -17,6 +17,9 @@ namespace GDZZ.Application.Help
#region 聊天详情接口 #region 聊天详情接口
Task SetMessage(List<LiveMessageList> liveMessages, long UserID, long ChatUserID); Task SetMessage(List<LiveMessageList> liveMessages, long UserID, long ChatUserID);
Task SetUnreadAsync(long LiveID);
Task<int> GetUnreadAsync(long LiveID);
#endregion #endregion

@ -140,7 +140,7 @@ namespace GDZZ.Application
Id = item.FriendID, Id = item.FriendID,
Index = sysUser.Name.Substring(0, 1), Index = sysUser.Name.Substring(0, 1),
LastSendTime = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000, 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 id = UserManager.UserId
} }
}; };
await this.cacheService.SetUnreadAsync(UserManager.UserId);
await this.cacheService.SetUnreadAsync(entity.OtherUserID);
var livejson = livemes.ToJsonString(); var livejson = livemes.ToJsonString();
await _chatHubContext.Clients.Client(user.ConnectionId).SendMessage(livejson, "SendMessage"); await _chatHubContext.Clients.Client(user.ConnectionId).SendMessage(livejson, "SendMessage");
} }
} }

Loading…
Cancel
Save