internal void Update(ClientState state, GuildSyncModel model) { var members = new ConcurrentDictionary <ulong, SocketGuildUser>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Members.Length * 1.05)); { for (int i = 0; i < model.Members.Length; i++) { var member = SocketGuildUser.Create(this, state, model.Members[i]); members.TryAdd(member.Id, member); } DownloadedMemberCount = members.Count; for (int i = 0; i < model.Presences.Length; i++) { if (members.TryGetValue(model.Presences[i].User.Id, out SocketGuildUser member)) { member.Update(state, model.Presences[i], true); } } } _members = members; var _ = _syncPromise.TrySetResultAsync(true); /*if (!model.Large) * _ = _downloaderPromise.TrySetResultAsync(true);*/ }
internal SocketGuildUser AddOrUpdateUser(PresenceModel model) { if (_members.TryGetValue(model.User.Id, out SocketGuildUser member)) { member.Update(Discord.State, model, false); } else { member = SocketGuildUser.Create(this, Discord.State, model); _members[member.Id] = member; DownloadedMemberCount++; } return(member); }
internal SocketGuildUser AddOrUpdateUser(UserModel model) { if (_members.TryGetValue(model.Id, out SocketGuildUser member)) { member.GlobalUser?.Update(Discord.State, model); } else { member = SocketGuildUser.Create(this, Discord.State, model); member.GlobalUser.AddRef(); _members[member.Id] = member; DownloadedMemberCount++; } return(member); }
internal void Update(Model model) { if (model.ChannelId.IsSpecified && model.ChannelId.Value != null) { Channel = Guild.GetChannel(model.ChannelId.Value.Value); } if (model.CreatorId.IsSpecified) { var guildUser = Guild.GetUser(model.CreatorId.Value); if (guildUser != null) { if (model.Creator.IsSpecified) { guildUser.Update(Discord.State, model.Creator.Value); } Creator = guildUser; } else if (guildUser == null && model.Creator.IsSpecified) { guildUser = SocketGuildUser.Create(Guild, Discord.State, model.Creator.Value); Creator = guildUser; } } Name = model.Name; Description = model.Description.GetValueOrDefault(); EntityId = model.EntityId; Location = model.EntityMetadata?.Location.GetValueOrDefault(); Type = model.EntityType; PrivacyLevel = model.PrivacyLevel; EndTime = model.ScheduledEndTime; StartTime = model.ScheduledStartTime; Status = model.Status; UserCount = model.UserCount.ToNullable(); CoverImageId = model.Image; }
internal void Update(ClientState state, ExtendedModel model) { IsAvailable = !(model.Unavailable ?? false); if (!IsAvailable) { if (_channels == null) { _channels = new ConcurrentHashSet <ulong>(); } if (_members == null) { _members = new ConcurrentDictionary <ulong, SocketGuildUser>(); } if (_roles == null) { _roles = new ConcurrentDictionary <ulong, SocketRole>(); } /*if (Emojis == null) * _emojis = ImmutableArray.Create<Emoji>(); * if (Features == null) * _features = ImmutableArray.Create<string>();*/ _syncPromise = new TaskCompletionSource <bool>(); _downloaderPromise = new TaskCompletionSource <bool>(); return; } Update(state, model as Model); var channels = new ConcurrentHashSet <ulong>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Channels.Length * 1.05)); { for (int i = 0; i < model.Channels.Length; i++) { var channel = SocketGuildChannel.Create(this, state, model.Channels[i]); state.AddChannel(channel); channels.TryAdd(channel.Id); } } _channels = channels; var members = new ConcurrentDictionary <ulong, SocketGuildUser>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Members.Length * 1.05)); { for (int i = 0; i < model.Members.Length; i++) { var member = SocketGuildUser.Create(this, state, model.Members[i]); members.TryAdd(member.Id, member); } DownloadedMemberCount = members.Count; for (int i = 0; i < model.Presences.Length; i++) { if (members.TryGetValue(model.Presences[i].User.Id, out SocketGuildUser member)) { member.Update(state, model.Presences[i], true); } } } _members = members; MemberCount = model.MemberCount; var voiceStates = new ConcurrentDictionary <ulong, SocketVoiceState>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.VoiceStates.Length * 1.05)); { for (int i = 0; i < model.VoiceStates.Length; i++) { SocketVoiceChannel channel = null; if (model.VoiceStates[i].ChannelId.HasValue) { channel = state.GetChannel(model.VoiceStates[i].ChannelId.Value) as SocketVoiceChannel; } var voiceState = SocketVoiceState.Create(channel, model.VoiceStates[i]); voiceStates.TryAdd(model.VoiceStates[i].UserId, voiceState); } } _voiceStates = voiceStates; _syncPromise = new TaskCompletionSource <bool>(); _downloaderPromise = new TaskCompletionSource <bool>(); var _ = _syncPromise.TrySetResultAsync(true); /*if (!model.Large) * _ = _downloaderPromise.TrySetResultAsync(true);*/ }