private async void SaveClick(object sender, EventArgs e) { // Filter out special labels that don't match mailbox names. List <string> labelsBefore = GmailExtensions.GetNonSpecialLabels(Conversation.Labels); List <string> labelsAfter = LabelList.SelectedItems.Cast <LabelInfo>() .Select(info => info.Name).ToList(); Account account = App.AccountManager.GetCurrentAccount(); List <string> addTo = new List <string>(); List <string> removeFrom = new List <string>(); // Diff before and after. For new labels, add that label. // For old labels, remove that label. SyncUtilities.CompareLists(labelsBefore, labelsAfter, input => input, (before, after) => { }, // Match, do nothing (before) => removeFrom.Add(before), (after) => addTo.Add(after) // Added ); // Do additions before removals. Additions will fail if you first remove the current label because you'll // have deleted the message from the current mailbox. foreach (string label in addTo) { await account.AddLabelAsync(Conversation.Messages, label); // Added } foreach (string label in removeFrom) { await account.RemoveLabelAsync(Conversation.Messages, label); // Removed } NavigationService.GoBack(); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // TODO: For the mail list view, filter out the current mailbox name. I.e. don't show the Inbox label when in the Inbox. // Do show the current mailbox label when in the conversation view. List <string> labels = (List <string>)value; // Includes normal labels and special ones too. Filter out known special labels // "\\Sent" Family "\\Important" "\\Starred" Geeky // TODO: Label color return(string.Join(", ", GmailExtensions.GetNonSpecialLabels(labels))); }
private async void GetLabelsAsync() { var account = App.AccountManager.GetCurrentAccount(); if (account == null) { throw new InvalidOperationException("How did you get to this page without an account?"); } List <LabelInfo> labels = await account.GetLabelsAsync(); List <string> activeLabels = GmailExtensions.GetNonSpecialLabels(Conversation.Labels); LabelList.ItemsSource = labels; // Select all currently enabled labels // TODO: Special case the current label, and maybe the INBOX? foreach (var label in labels.Where(label => activeLabels.Contains(label.Name))) { LabelList.SelectedItems.Add(label); } }