internal Channel(JsonChannel restChannel, QuarrelClient context) : base(context) { Id = restChannel.Id; Name = restChannel.Name; Type = restChannel.Type; }
internal DirectChannel(JsonChannel restChannel, ChannelSettings?settings, QuarrelClient context) : base(restChannel, settings, context) { Guard.IsNotNull(restChannel.Recipients, nameof(restChannel.Recipients)); RecipientId = restChannel.Recipients[0].Id; }
internal override JsonChannel ToJsonChannel() { JsonChannel restChannel = base.ToJsonChannel(); restChannel.Position = Position; restChannel.GuildId = GuildId; return(restChannel); }
internal override void PrivateUpdateFromJsonChannel(JsonChannel jsonChannel) { base.PrivateUpdateFromJsonChannel(jsonChannel); if (jsonChannel.Recipients is not null) { Context.Users.AddUser(jsonChannel.Recipients[0]); } }
internal override JsonChannel ToJsonChannel() { JsonChannel restChannel = base.ToJsonChannel(); restChannel.OwnerId = OwnerId; restChannel.RTCRegion = RTCRegion; restChannel.Recipients = Recipients.Select(x => x.ToRestUser()).ToArray(); return(restChannel); }
internal PrivateChannel(JsonChannel restChannel, ChannelSettings?settings, QuarrelClient context) : base(restChannel, context) { LastMessageId = restChannel.LastMessageId; RTCRegion = restChannel.RTCRegion; IsMuted = settings?.Muted ?? false; _users = new HashSet <ulong>(); }
private void OnChannelCreated(JsonChannel arg) { var channel = Channels.AddChannel(arg); if (channel is null) { return; } ChannelCreated?.Invoke(this, channel); }
private void OnChannelDeleted(JsonChannel arg) { Channel?channel = Channels.RemoveChannel(arg.Id); if (channel is null) { return; } ChannelDeleted?.Invoke(this, channel); }
internal GroupChannel(JsonChannel restChannel, ChannelSettings?settings, QuarrelClient context) : base(restChannel, settings, context) { Guard.IsNotNull(restChannel.OwnerId, nameof(restChannel.OwnerId)); Guard.IsNotNull(restChannel.Recipients, nameof(restChannel.Recipients)); OwnerId = restChannel.OwnerId.Value; Recipients = restChannel.Recipients.Select(x => new User(x, context)).ToArray(); Icon = restChannel.Icon; }
internal override void PrivateUpdateFromJsonChannel(JsonChannel jsonChannel) { Position = jsonChannel.Position ?? Position; GuildId = jsonChannel.GuildId ?? GuildId; if (jsonChannel.PermissionOverwrites is not null) { PermissionOverwrites = CreateOverwrites(jsonChannel.PermissionOverwrites); } base.PrivateUpdateFromJsonChannel(jsonChannel); }
internal override JsonChannel ToJsonChannel() { JsonChannel restChannel = base.ToJsonChannel(); var recipient = Context.Users.GetUser(RecipientId)?.ToRestUser(); if (recipient is not null) { restChannel.Recipients = new[] { recipient }; } return(restChannel); }
internal GuildChannel(JsonChannel restChannel, ulong?guildId, QuarrelClient context) : base(restChannel, context) { guildId = restChannel.GuildId ?? guildId; Guard.IsNotNull(restChannel.Position, nameof(restChannel.Position)); Guard.IsNotNull(guildId, nameof(guildId)); Position = restChannel.Position.Value; GuildId = guildId.Value; if (restChannel.PermissionOverwrites is not null) { PermissionOverwrites = CreateOverwrites(restChannel.PermissionOverwrites); } }
/// <summary> /// Tries adding new channel into channels' concurrent dictionary /// </summary> /// <param name="webSocket">This goes inside a new channel</param> public void AddConnection(WebSocket webSocket, string uri) { //TODO: IF XML way is added, then implement a factory pattern to make both XML channel or Json channel. var channel = new JsonChannel(); _channels.TryAdd(uri, channel); channel.Closed += (s, e) => { _channels.TryRemove(uri, out var _); ChannelClosed?.Invoke(this, EventArgs.Empty); }; channel.Attach(webSocket); MessageDispatcher.Bind(channel); ChannelAccepted?.Invoke(this, EventArgs.Empty); }
internal static Channel?FromJsonChannel( JsonChannel jsonChannel, QuarrelClient context, ulong?guildId = null, ChannelSettings?settings = null) { return(jsonChannel.Type switch { ChannelType.GuildText => new GuildTextChannel(jsonChannel, guildId, settings, context), ChannelType.News => new GuildTextChannel(jsonChannel, guildId, settings, context), ChannelType.DirectMessage => new DirectChannel(jsonChannel, settings, context), ChannelType.GuildVoice => new VoiceChannel(jsonChannel, guildId, settings, context), ChannelType.StageVoice => new VoiceChannel(jsonChannel, guildId, settings, context), ChannelType.GroupDM => new GroupChannel(jsonChannel, settings, context), ChannelType.Category => new CategoryChannel(jsonChannel, guildId, context), _ => null, });
internal VoiceChannel(JsonChannel restChannel, ulong?guildId, ChannelSettings?settings, QuarrelClient context) : base(restChannel, guildId, context) { Guard.IsNotNull(restChannel.Bitrate, nameof(restChannel.Bitrate)); Bitrate = restChannel.Bitrate.Value; UserLimit = restChannel.UserLimit; RTCRegion = restChannel.RTCRegion; CategoryId = restChannel.CategoryId; IsMuted = settings?.Muted ?? false; _users = new HashSet <ulong>(); }
internal GuildTextChannel( JsonChannel restChannel, ulong?guildId, ChannelSettings?settings, QuarrelClient context) : base(restChannel, guildId, context) { Guard.IsNotNull(restChannel.SlowModeDelay, nameof(restChannel.SlowModeDelay)); Topic = restChannel.Topic; IsNSFW = restChannel.IsNSFW; SlowModeDelay = restChannel.SlowModeDelay.Value; LastMessageId = restChannel.LastMessageId; CategoryId = restChannel.CategoryId; IsMuted = settings?.Muted ?? false; }
internal void UpdateFromJsonChannel(JsonChannel jsonChannel) { Guard.IsEqualTo(Id, jsonChannel.Id, nameof(Id)); PrivateUpdateFromJsonChannel(jsonChannel); }
internal virtual void PrivateUpdateFromJsonChannel(JsonChannel jsonChannel) { Name = jsonChannel.Name ?? Name; Type = jsonChannel.Type; }
private void OnChannelUpdated(JsonChannel arg) { Channels.UpdateChannel(arg, out Channel channel); ChannelUpdated?.Invoke(this, channel); }
internal CategoryChannel(JsonChannel restChannel, ulong?guildId, QuarrelClient context) : base(restChannel, guildId, context) { }
private AnnounceChannelData(JsonChannel channel, bool isEnabled) { Channel = channel; IsEnabled = isEnabled; }