예제 #1
0
        public static void Delete(Message source)
        {
            var oldMessage = source.DuckCopy <Message>();

            #region Do action

            Action doAction = delegate
            {
                source.MessageFolder      = Folders.Trash;
                source.TargetMessageState = EntityStates.Deleted;

                AsyncUpdateQueue.Enqueue(source);
            };

            #endregion

            #region Undo action

            Action undoAction = delegate
            {
                source.MessageFolder      = oldMessage.MessageFolder;
                source.TargetMessageState = oldMessage.TargetMessageState;

                AsyncUpdateQueue.Enqueue(source);
            };

            #endregion

            ClientState.Current.UndoManager.Execute(new HistoryAction(doAction, undoAction));
        }
예제 #2
0
        protected void StarCore()
        {
            var previousSelection = new List <Message>(SelectedMessages);

            // Contains instance copies of messages, this will be the old data
            // before the do is applied.
            var messagesCopy = SelectedMessages
                               .Select(m => m.DuckCopy <Message>())
                               .ToList();

            #region Do action

            Action doAction = delegate
            {
                foreach (var message in SelectedMessages.ToList())
                {
                    if (SelectedMessage.IsStarred)
                    {
                        SelectedMessage.SetUnstarred();
                    }
                    else
                    {
                        SelectedMessage.SetStarred();
                    }
                }

                viewFilter.UpdateCurrentViewAsync();

                flipper.Delay();
            };

            #endregion

            #region Undo action

            Action undoAction = delegate
            {
                foreach (var message in previousSelection)
                {
                    // Get old message from copied data
                    Message message1 = message;

                    var oldMessage = messagesCopy.Single(m => m.MessageId == message1.MessageId);

                    // Reverts the previous action
                    message.IsStarred          = oldMessage.IsStarred;
                    message.TargetMessageState = oldMessage.TargetMessageState;

                    AsyncUpdateQueue.Enqueue(message);
                }

                // We cannot use the IEditableObject appraoch here because the conversation in question
                // probably might not be in view anymore. So instead we will refresh the whole view.
                viewFilter.RebuildCurrentViewAsync();
            };

            #endregion

            ClientState.Current.UndoManager.Execute(new HistoryAction(doAction, undoAction));
        }
예제 #3
0
        public void JoinWith(Person person)
        {
            // Remove profile from old person
            if (Person != null)
            {
                Person.Profiles.Remove(this);
                Person.Messages.RemoveAll(m => Messages.Contains(m));
                Person.Documents.RemoveAll(d => Documents.Contains(d));

                if (Person.Profiles.Count == 0)
                {
                    // If no profiles left, update person to indicate redirection
                    Person.RedirectPersonId = Person.PersonId;

                    AsyncUpdateQueue.Enqueue(Person);
                }
            }

            // Add profile to new person
            Person = person;
            Person.Profiles.Add(this);
            Person.Messages.AddRange(Messages);
            Person.Documents.AddRange(Documents);

            // Update person reference
            PersonId = Person.PersonId.Value;

            // Save profile to database
            AsyncUpdateQueue.Enqueue(this);
        }
예제 #4
0
        public void Delete(bool deleteConversations)
        {
            // Contains the same references as in SelectedMessages,
            // these references can change when un-doing so keep a snapshot around
            var previousSelection = deleteConversations ?
                                    SelectedMessages.SelectMany(m => m.Conversation.Messages)
                                    .Distinct()             // Select all messages from selected conversations
                                    .ToList()
                                : new List <Message>(SelectedMessages);

            // Contains instance copies of messages, this will be the old data
            // before the do is applied.
            var messagesCopy = previousSelection
                               .Select(m => m.DuckCopy <Message>())
                               .ToList();

            #region Do action

            Action doAction = delegate
            {
                foreach (var message in previousSelection)
                {
                    message.MarkDeleted();
                }

                viewFilter.UpdateCurrentViewAsync();

                flipper.Delay();
            };

            #endregion

            #region Undo action

            Action undoAction = delegate
            {
                foreach (var message in previousSelection)
                {
                    // Get old message from copied data
                    Message message1 = message;

                    var oldMessage = messagesCopy.Single(m => m.MessageId == message1.MessageId);

                    message.IsRead             = oldMessage.IsRead;
                    message.TargetMessageState = oldMessage.TargetMessageState;
                    message.MessageFolder      = oldMessage.MessageFolder;

                    AsyncUpdateQueue.Enqueue(message);
                }

                // We cannot use the IEditableObject appraoch here because the conversation in question
                // probably might not be in view anymore. So instead we will refresh the whole view.
                viewFilter.RebuildCurrentViewAsync();
            };

            #endregion

            ClientState.Current.UndoManager.Execute(new HistoryAction(doAction, undoAction));
        }
예제 #5
0
        public void RemoveLabel(Label label)
        {
            var previousSelection = new List <Message>(
                SelectedMessages.SelectMany(m => m.Conversation.Messages)
                .Distinct());

            // Contains instance copies of messages, this will be the old data
            // before the do is applied.
            var messagesCopy = previousSelection
                               .Select(m => m.DuckCopy <Message>())
                               .ToList();

            #region Do action

            Action doAction = delegate
            {
                foreach (var message in SelectedMessages.ToList())
                {
                    message.RemoveLabel(label);
                }

                viewFilter.UpdateCurrentViewAsync();

                flipper.Delay();
            };

            #endregion

            #region Undo action

            Action undoAction = delegate
            {
                foreach (var message in previousSelection)
                {
                    // Get old message from copied data
                    Message message1 = message;

                    var oldMessage = messagesCopy.Single(m => m.MessageId == message1.MessageId);

                    // Reverts the previous action
                    message.Labels = oldMessage.Labels;
                    message.LabelsList.Replace(oldMessage.LabelsList);
                    message.SendLabels = oldMessage.SendLabels;

                    AsyncUpdateQueue.Enqueue(message);
                }

                // We cannot use the IEditableObject appraoch here because the conversation in question
                // probably might not be in view anymore. So instead we will refresh the whole view.
                viewFilter.RebuildCurrentViewAsync();
            };

            #endregion

            ClientState.Current.UndoManager.Execute(new HistoryAction(doAction, undoAction));

            EventBroker.Publish(AppEvents.MessageLabelsUpdated, this);
        }
예제 #6
0
        protected override void DeleteCore()
        {
            var previousSelection = new List <Document>(SelectedDocuments);

            var documentsCopy = SelectedDocuments.Select(d => d.DuckCopy <Document>()).ToList();

            #region Do action

            Action doAction = delegate
            {
                var documentsView = DetailsViewType == DetailsViewType.Documents ?
                                    (IEditableCollectionView)DocumentsViewSource.View :
                                    (IEditableCollectionView)ImagesViewSource.View;

                foreach (var document in SelectedDocuments.ToList())
                {
                    documentsView.EditItem(document);

                    document.DocumentFolder = Folders.Trash;

                    AsyncUpdateQueue.Enqueue(document);

                    documentsView.CommitEdit();
                }
            };

            #endregion

            #region Undo action

            Action undoAction = delegate
            {
                foreach (var document in previousSelection)
                {
                    Document document1   = document;
                    var      oldDocument = documentsCopy.Single(d => d.DocumentId == document1.DocumentId);

                    document.DocumentFolder = oldDocument.DocumentFolder;

                    AsyncUpdateQueue.Enqueue(document);
                }

                // We cannot use the IEditableObject appraoch here because the document in question
                // probably might not be in view anymore. So instead we will refresh the whole view.
                if (DetailsViewType == DetailsViewType.Documents)
                {
                    DocumentsViewSource.View.Refresh();
                }
                else
                {
                    ImagesViewSource.View.Refresh();
                }
            };

            #endregion

            ClientState.Current.UndoManager.Execute(new HistoryAction(doAction, undoAction));
        }
예제 #7
0
        protected override void MarkUnreadCore()
        {
            var previousSelection = new List <Document>(SelectedDocuments);

            var documentsCopy = SelectedDocuments.Select(d => d.DuckCopy <Document>()).ToList();

            #region Do action

            Action doAction = delegate
            {
                foreach (var document in SelectedDocuments.ToList())
                {
                    var documentsView = DetailsViewType == DetailsViewType.Documents ?
                                        (IEditableCollectionView)DocumentsViewSource.View :
                                        (IEditableCollectionView)ImagesViewSource.View;

                    documentsView.EditItem(document);

                    document.MarkUnread();

                    AsyncUpdateQueue.Enqueue(document);

                    documentsView.CommitEdit();
                }
            };

            #endregion

            #region Undo action

            Action undoAction = delegate
            {
                foreach (var document in previousSelection)
                {
                    Document document1   = document;
                    var      oldDocument = documentsCopy.Single(d => d.DocumentId == document1.DocumentId);

                    document.IsRead = oldDocument.IsRead;
                    document.UpdateProperty("IsRead");

                    AsyncUpdateQueue.Enqueue(document);
                }

                if (DetailsViewType == DetailsViewType.Documents)
                {
                    DocumentsViewSource.View.Refresh();
                }
                else
                {
                    ImagesViewSource.View.Refresh();
                }
            };

            #endregion

            ClientState.Current.UndoManager.Execute(new HistoryAction(doAction, undoAction));
        }
예제 #8
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);
        }
예제 #9
0
        public void MoveToFolder(int folder)
        {
            MessageFolder = folder;

            TrackAction(ActionType.Action, false);

            OnPropertyChanged("MessageFolder");

            AsyncUpdateQueue.Enqueue(this);

            EnqueueCloudNotification(ModifyAction.Folder, folder);

            EventBroker.Publish(AppEvents.MessageUpdated);
        }
예제 #10
0
        public void MarkDeleted()
        {
            MessageFolder = Folders.Trash;

            TrackAction(ActionType.Action, false);

            UpdateProperty("MessageFolder");

            TargetMessageState = EntityStates.Deleted;

            AsyncUpdateQueue.Enqueue(this);

            EnqueueCloudNotification(ModifyAction.Delete, true);

            EventBroker.Publish(AppEvents.MessageUpdated);
        }
예제 #11
0
        public void Archive()
        {
            if (MessageFolder != Folders.Archive)
            {
                MessageFolder = Folders.Archive;

                TrackAction(ActionType.Action, false);

                TargetMessageState = EntityStates.Archived;

                AsyncUpdateQueue.Enqueue(this);

                EnqueueCloudNotification(ModifyAction.Archive, true);

                EventBroker.Publish(AppEvents.MessageUpdated);
            }
        }
예제 #12
0
        public void Purge()
        {
            MessageFolder = Folders.None;
            UpdateProperty("MessageFolder");

            TargetMessageState = EntityStates.Purged;

            BodyPreview            = String.Empty;
            Context                = String.Empty;
            ConversationIdentifier = "-1";

            if (BodyTextStreamName.HasValue)
            {
                ClientState.Current.Storage.Delete("m", BodyTextStreamName.ToString());
            }

            if (BodyHtmlStreamName.HasValue)
            {
                ClientState.Current.Storage.Delete("m", BodyHtmlStreamName.ToString());
            }

            AsyncUpdateQueue.Enqueue(this);

            ClientState.Current.Search.Delete(this);

            EventBroker.Publish(AppEvents.MessageUpdated);

            if (Conversation != null)
            {
                var mailbox = VirtualMailBox.Current;

                Conversation.Messages.Remove(this);

                // If this was the last message in the conversation, also delete the conversation
                if (Conversation.Messages.Count == 0)
                {
                    using (mailbox.Conversations.WriterLock)
                        mailbox.Conversations.Remove(Conversation);

                    ClientState.Current.DataService.Delete(Conversation);
                }
            }
        }
예제 #13
0
        public void Unarchive()
        {
            if (MessageFolder == Folders.Archive)
            {
                MessageFolder = Folders.Inbox;

                TrackAction(ActionType.Action, false);

                OnPropertyChanged("MessageFolder");
                OnPropertyChanged("IsArchived");

                TargetMessageState = EntityStates.Unarchived;

                AsyncUpdateQueue.Enqueue(this);

                EnqueueCloudNotification(ModifyAction.Archive, false);

                EventBroker.Publish(AppEvents.MessageUpdated);
            }
        }
예제 #14
0
        public void MarkRead(bool post)
        {
            if (!IsRead)
            {
                IsRead = true;

                UpdateProperty("IsRead");

                if (post)
                {
                    TargetMessageState = EntityStates.Read;
                }

                AsyncUpdateQueue.Enqueue(this);

                EnqueueCloudNotification(ModifyAction.IsRead, true);

                EventBroker.Publish(AppEvents.MessageUpdated);
            }
        }
예제 #15
0
        void TrackAction(ActionType action, DateTime date, bool save)
        {
            bool changed = false;

            switch (action)
            {
            case ActionType.Read:
                if (!DateRead.HasValue)
                {
                    changed  = true;
                    DateRead = date;
                }

                break;
            }

            if (changed && save)
            {
                AsyncUpdateQueue.Enqueue(this);
            }
        }
        void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ClientStats.LogEvent("Change realtime stream selection");

            var lv = (ListView)sender;

            if (lv.SelectedItem != null)
            {
                var status = (UserStatus)lv.SelectedItem;

                if (!status.IsRead)
                {
                    status.MarkRead();

                    AsyncUpdateQueue.Enqueue(status);

                    // Forces update of unread counts
                    EventBroker.Publish(AppEvents.SyncStatusUpdatesFinished);
                }
            }
        }
예제 #17
0
        public void SetUnstarred(bool post)
        {
            if (!IsStarred)
            {
                IsStarred = false;

                TrackAction(ActionType.Action, false);

                OnPropertyChanged("IsStarred");

                if (post)
                {
                    TargetMessageState = EntityStates.Unstarred;
                }

                AsyncUpdateQueue.Enqueue(this);

                EnqueueCloudNotification(ModifyAction.Star, false);

                EventBroker.Publish(AppEvents.MessageUpdated);
            }
        }
예제 #18
0
        public void MarkUnread(bool post)
        {
            if (IsRead)
            {
                IsRead = false;

                TrackAction(ActionType.Action, false);

                UpdateProperty("IsRead");

                if (post)
                {
                    TargetMessageState = EntityStates.Unread;
                }

                AsyncUpdateQueue.Enqueue(this);

                EnqueueCloudNotification(ModifyAction.IsRead, false);

                EventBroker.Publish(AppEvents.MessageUpdated);
            }
        }
예제 #19
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);
        }