Skip to content

Commit

Permalink
修改ImClient api
Browse files Browse the repository at this point in the history
  • Loading branch information
yihango committed Jun 1, 2021
1 parent f299fb8 commit 4918802
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
22 changes: 10 additions & 12 deletions src/LiteIM.CSRedisCore/CsRedisCoreImClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace LiteIM
{
public abstract class CsRedisCoreImClient : IImClient
public class CsRedisCoreImClient : IImClient
{
protected readonly string _prefix;
protected readonly CSRedisClient _redis;
Expand All @@ -24,7 +24,6 @@ public CsRedisCoreImClient(CsRedisCoreImClientOptions options)
_redis = _options.Redis;
}

public abstract void SendMessage(string senderClientId, IEnumerable<string> receiveClientId, object message, bool receipt = false);

public virtual IEnumerable<string> GetClientListByOnline()
{
Expand Down Expand Up @@ -89,6 +88,15 @@ public virtual void LeaveChan(string clientId, params string[] chans)
}
}


public virtual void LeaveChan(string clientId)
{
// 所有的聊天室
var chans = this.GetChanListByClientId(clientId);
// 离开所有聊天室
this.LeaveChan(clientId, chans.ToArray());
}

public virtual IEnumerable<string> GetChanClientList(string chan)
{
return _redis.HKeys(
Expand Down Expand Up @@ -126,16 +134,6 @@ public virtual long GetChanOnline(string chan)
chan);
}

public virtual void SendChanMessage(string chan, object message)
{
var clientIdList = _redis.HKeys(_prefix.Chan(chan));

SendMessage(
null,
clientIdList.Where(o => !string.IsNullOrWhiteSpace(o)),
message
);
}
#endregion


Expand Down
21 changes: 6 additions & 15 deletions src/LiteIM.Core/IImClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ namespace LiteIM
{
public interface IImClient
{
/// <summary>
/// 向指定的多个客户端id发送消息
/// </summary>
/// <param name="senderClientId">发送者的客户端id</param>
/// <param name="receiveClientId">接收者的客户端id</param>
/// <param name="message">消息</param>
/// <param name="receipt">是否回执</param>
void SendMessage(string senderClientId, IEnumerable<string> receiveClientId, object message, bool receipt = false);

/// <summary>
/// 获取所在线客户端id
Expand Down Expand Up @@ -45,6 +37,12 @@ public interface IImClient
/// <param name="chans">群聊频道名</param>
void LeaveChan(string clientId, params string[] chans);

/// <summary>
/// 离开所有群聊频道
/// </summary>
/// <param name="clientId">客户端id</param>
void LeaveChan(string clientId);

/// <summary>
/// 获取群聊频道所有客户端id(测试)
/// </summary>
Expand Down Expand Up @@ -81,13 +79,6 @@ public interface IImClient
/// <returns>在线人数</returns>
long GetChanOnline(string chan);

/// <summary>
/// 系统广播发送群聊消息,所有在线的用户将收到消息
/// </summary>
/// <param name="chan">群聊频道名</param>
/// <param name="message">消息</param>
void SendChanMessage(string chan, object message);

#endregion
}
}

0 comments on commit 4918802

Please sign in to comment.