39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace SharpChat {
|
|
public class UserStatusContext {
|
|
private readonly Dictionary<long, UserStatusInfo> Statuses = new();
|
|
|
|
public UserStatusInfo Get(long userId) {
|
|
return Statuses.ContainsKey(userId)
|
|
? Statuses[userId]
|
|
: UserStatusInfo.EmptyInstance;
|
|
}
|
|
|
|
public UserStatusInfo Get(UserInfo userInfo) {
|
|
return Get(userInfo.UserId);
|
|
}
|
|
|
|
public UserStatus GetStatus(long userId) {
|
|
return Get(userId).Status;
|
|
}
|
|
|
|
public UserStatus GetStatus(UserInfo userInfo) {
|
|
return Get(userInfo.UserId).Status;
|
|
}
|
|
|
|
public UserStatusInfo Set(long userId, UserStatus status, string text) {
|
|
UserStatusInfo statusInfo = new(status, text);
|
|
if(Statuses.ContainsKey(userId))
|
|
Statuses[userId] = statusInfo;
|
|
else
|
|
Statuses.Add(userId, statusInfo);
|
|
|
|
return statusInfo;
|
|
}
|
|
|
|
public void Clear(long userId) {
|
|
Statuses.Remove(userId);
|
|
}
|
|
}
|
|
}
|