public static MenuFlyout MakeTextChnMenu(LocalModels.GuildChannel chn) { MenuFlyout menu = new MenuFlyout(); menu.MenuFlyoutPresenterStyle = (Style)App.Current.Resources["MenuFlyoutPresenterStyle1"]; // Add "Edit Channel" button MenuFlyoutItem editchannel = new MenuFlyoutItem() { Text = App.GetString("/Flyouts/EditChannel"), Tag = chn.raw.Id, Icon = new SymbolIcon(Symbol.Edit), Margin = new Thickness(-26, 0, 0, 0) }; editchannel.Click += FlyoutManager.EditChannel; menu.Items.Add(editchannel); // Add Separator MenuFlyoutSeparator sep1 = new MenuFlyoutSeparator(); menu.Items.Add(sep1); // Create "Mute/Unmute" button ToggleMenuFlyoutItem mute = new ToggleMenuFlyoutItem() { Icon = new SymbolIcon(Symbol.Mute), Tag = chn.raw.Id, Margin = new Thickness(-26, 0, 0, 0) }; mute.Click += FlyoutManager.MuteChannel; //mute.IsChecked = LocalState.GuildSettings.Contains(chn.Raw.Id); // If muted, unmute if (LocalState.GuildSettings.ContainsKey(App.CurrentGuildId) && LocalState.GuildSettings[App.CurrentGuildId].channelOverrides.ContainsKey(chn.raw.Id) && LocalState.GuildSettings[App.CurrentGuildId].channelOverrides[chn.raw.Id].Muted) { mute.Text = App.GetString("/Flyouts/UnmuteChannel"); } // If not muted, mute else { mute.Text = App.GetString("/Flyouts/MuteChannel"); } // Add "Mute/Unmute" button menu.Items.Add(mute); // Add "Mark as Read" button MenuFlyoutItem markasread = new MenuFlyoutItem() { Text = App.GetString("/Flyouts/MarkAsRead"), Tag = chn.raw.Id, Icon = new SymbolIcon(Symbol.View), Margin = new Thickness(-26, 0, 0, 0), //IsEnabled = false //IsEnabled = (TextChannels.Items.FirstOrDefault(x => (x as SimpleChannel).Id == chn.Raw.Id) as SimpleChannel).IsUnread }; markasread.Click += FlyoutManager.MarkChannelasRead; menu.Items.Add(markasread); // Add Separator MenuFlyoutSeparator sep2 = new MenuFlyoutSeparator(); menu.Items.Add(sep2); // Create "Delete Channel" button MenuFlyoutItem deleteChannel = new MenuFlyoutItem() { Text = App.GetString("/Flyouts/DeleteChannel"), Tag = chn.raw.Id, Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)), Icon = new SymbolIcon(Symbol.Delete), Margin = new Thickness(-26, 0, 0, 0), }; deleteChannel.Click += FlyoutManager.DeleteChannel; // If permissions to delete channel if (chn.permissions.ManageChannels || chn.permissions.Administrator || LocalState.Guilds[chn.raw.GuildId].Raw.OwnerId == LocalState.CurrentUser.Id) { // Add "Delete Channel" button menu.Items.Add(deleteChannel); } return(menu); }
/// <summary> /// Make SimpleChannel based on GuildChannel /// </summary> /// <param name="channel">GuildChannel</param> /// <returns>SimpleChannel</returns> public static SimpleChannel MakeChannel(LocalModels.GuildChannel channel) { // Create basic SimpleChannel SimpleChannel sc = new SimpleChannel { Id = channel.raw.Id, Name = channel.raw.Name, Type = channel.raw.Type, Nsfw = channel.raw.NSFW, Position = channel.raw.Position, ParentId = channel.raw.ParentId, Icon = channel.raw.Icon }; switch (channel.raw.Type) { // Text Channel case 0: // Determine muted status sc.IsMuted = LocalState.GuildSettings.ContainsKey(channel.raw.GuildId) && (LocalState.GuildSettings[channel.raw.GuildId].channelOverrides .ContainsKey(channel.raw.Id) && LocalState.GuildSettings[channel.raw.GuildId] .channelOverrides[channel.raw.Id].Muted); // Determine is unread and notification count if (LocalState.RPC.ContainsKey(sc.Id)) { ReadState readstate = LocalState.RPC[sc.Id]; sc.NotificationCount = readstate.MentionCount; var StorageChannel = LocalState.Guilds[App.CurrentGuildId].channels[sc.Id]; sc.IsUnread = StorageChannel?.raw.LastMessageId != null && readstate.LastMessageId != StorageChannel.raw.LastMessageId; } // Assing if user has read permissions sc.HavePermissions = LocalState.Guilds[App.CurrentGuildId].channels[sc.Id].permissions.ReadMessages || App.CurrentGuildId == sc.Id; // Determine if SimpleChannel should be shown if (!(sc.IsMuted && Storage.Settings.HideMutedChannels) && (sc.HavePermissions || Storage.Settings.ShowNoPermissionChannels)) { return(sc); } break; // Voice channel case 2: sc.HavePermissions = LocalState.Guilds[App.CurrentGuildId].channels[sc.Id].permissions.Connect || App.CurrentGuildId == sc.Id; if (!(sc.IsMuted && Storage.Settings.HideMutedChannels) && (sc.HavePermissions || Storage.Settings.ShowNoPermissionChannels)) { return(sc); } break; // Category channel case 4: //TODO: Categories break; } return(null); }