Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void Undelete()
        {
            // Contains the same references as in SelectedMessages,
            // these references can change when un-doing so keep a snapshot around
            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())
                {
                    message.MarkUndeleted();
                }

                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));
        }