43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
namespace SharpChat.Channels;
|
|
|
|
public class Channel(
|
|
string name,
|
|
string password = "",
|
|
bool isTemporary = false,
|
|
int rank = 0,
|
|
string ownerId = ""
|
|
) {
|
|
public string Name { get; internal set; } = name;
|
|
public string Password { get; internal set; } = password ?? string.Empty;
|
|
public bool IsTemporary { get; internal set; } = isTemporary;
|
|
public int Rank { get; internal set; } = rank;
|
|
public string OwnerId { get; internal set; } = ownerId;
|
|
|
|
public bool HasPassword
|
|
=> !string.IsNullOrWhiteSpace(Password);
|
|
|
|
public bool IsPublic
|
|
=> !HasPassword && Rank < 1;
|
|
|
|
public bool NameEquals(string name) {
|
|
return string.Equals(name, Name, StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
|
|
public bool IsOwner(string userId) {
|
|
return !string.IsNullOrEmpty(OwnerId)
|
|
&& !string.IsNullOrEmpty(userId)
|
|
&& OwnerId == userId;
|
|
}
|
|
|
|
public override int GetHashCode() {
|
|
return Name.GetHashCode();
|
|
}
|
|
|
|
public static bool CheckName(string name) {
|
|
return !string.IsNullOrWhiteSpace(name) && name.All(CheckNameChar);
|
|
}
|
|
|
|
public static bool CheckNameChar(char c) {
|
|
return char.IsLetter(c) || char.IsNumber(c) || c == '-' || c == '_';
|
|
}
|
|
}
|