Example #1
0
        private void joinedChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            switch (args.Action)
            {
            case NotifyCollectionChangedAction.Add:
                IEnumerable <Channel> newChannels = args.NewItems.OfType <Channel>().Where(isChatChannel);

                foreach (var channel in newChannels)
                {
                    channelList.AddChannel(channel);
                }

                break;

            case NotifyCollectionChangedAction.Remove:
                IEnumerable <Channel> leftChannels = args.OldItems.OfType <Channel>().Where(isChatChannel);

                foreach (var channel in leftChannels)
                {
                    channelList.RemoveChannel(channel);

                    if (loadedChannels.ContainsKey(channel))
                    {
                        ChatOverlayDrawableChannel loaded = loadedChannels[channel];
                        loadedChannels.Remove(channel);
                        // DrawableChannel removed from cache must be manually disposed
                        loaded.Dispose();
                    }
                }

                break;
            }
        }
Example #2
0
        private void currentChannelChanged(ValueChangedEvent <Channel> channel)
        {
            Channel?newChannel = channel.NewValue;

            // null channel denotes that we should be showing the listing.
            if (newChannel == null)
            {
                currentChannel.Value = channelList.ChannelListingChannel;
                return;
            }

            if (newChannel is ChannelListing.ChannelListingChannel)
            {
                currentChannelContainer.Clear(false);
                channelListing.Show();
                textBar.ShowSearch.Value = true;
            }
            else
            {
                channelListing.Hide();
                textBar.ShowSearch.Value = false;

                if (loadedChannels.ContainsKey(newChannel))
                {
                    currentChannelContainer.Clear(false);
                    currentChannelContainer.Add(loadedChannels[newChannel]);
                }
                else
                {
                    loading.Show();

                    // Ensure the drawable channel is stored before async load to prevent double loading
                    ChatOverlayDrawableChannel drawableChannel = CreateDrawableChannel(newChannel);
                    loadedChannels.Add(newChannel, drawableChannel);

                    LoadComponentAsync(drawableChannel, loadedDrawable =>
                    {
                        // Ensure the current channel hasn't changed by the time the load completes
                        if (currentChannel.Value != loadedDrawable.Channel)
                        {
                            return;
                        }

                        // Ensure the cached reference hasn't been removed from leaving the channel
                        if (!loadedChannels.ContainsKey(loadedDrawable.Channel))
                        {
                            return;
                        }

                        currentChannelContainer.Clear(false);
                        currentChannelContainer.Add(loadedDrawable);
                        loading.Hide();
                    });
                }
            }

            // Mark channel as read when channel switched
            if (newChannel.Messages.Any())
            {
                channelManager.MarkChannelAsRead(newChannel);
            }
        }