Example #1
0
        public void AddLabel(Label label, bool post)
        {
            var mailbox = VirtualMailBox.Current;

            using (mailbox.Labels.ReaderLock)
            {
                string key = label.Labelname.ToLower();

                if (!mailbox.Labels.ContainsKey(key))
                {
                    mailbox.Labels.Add(key, new List <Label>());

                    if (label.LabelType == LabelType.Custom)
                    {
                        EventBroker.Publish(AppEvents.LabelCreated, key);
                    }
                }

                if (LabelsList.Any(l => l.Equals(label)))
                {
                    return;
                }

                label.Messages.Add(this);

                mailbox.Labels[key].Add(label);

                LabelsList.Add(label);

                if (post)
                {
                    PostLabels.Add(label);

                    SendLabels = String.Join("|", PostLabels.Select(s => s.ToString()).ToArray());

                    EnqueueCloudNotification(ModifyAction.Label, String.Concat("%2B", label.Labelname));                     // + (url encoded)
                }
            }

            // Recreate and save labels list
            Labels = String.Join("|", LabelsList.Select(s => s.ToString()).ToArray());

            AsyncUpdateQueue.Enqueue(this);

            OnPropertyChanged("IsTodo");
            OnPropertyChanged("IsWaitingFor");
            OnPropertyChanged("IsSomeday");

            EventBroker.Publish(AppEvents.MessageUpdated);
            EventBroker.Publish(AppEvents.MessageLabelsUpdated, this);
        }
Example #2
0
        public void RemoveLabel(Label label, bool post)
        {
            LabelsList.Remove(label);

            label.Messages.Remove(this);

            if (post)
            {
                // If label allready is in post but has
                // not been posted yet, remove it
                if (PostLabels.Contains(label))
                {
                    PostLabels.Remove(label);
                }
                else
                {
                    PostLabels.Add(label);
                }

                SendLabels = String.Join("|", PostLabels.Select(s => s.ToString()).ToArray());

                EnqueueCloudNotification(ModifyAction.Label, String.Concat("-", label.Labelname));
            }

            // Recreate and save labels list
            Labels = String.Join("|", LabelsList.Select(s => s.ToString()).ToArray());

            AsyncUpdateQueue.Enqueue(this);

            OnPropertyChanged("IsTodo");
            OnPropertyChanged("IsWaitingFor");
            OnPropertyChanged("IsSomeday");

            EventBroker.Publish(AppEvents.MessageUpdated);
            EventBroker.Publish(AppEvents.MessageLabelsUpdated, this);
        }