Example #1
0
 private void C_UnreadMessagesUpdated(object sender, ModmailConversationsEventArgs e)
 {
     foreach (KeyValuePair <string, Reddit.Things.ConversationMessage> pair in e.AddedMessages)
     {
         NewMessages++;
     }
 }
Example #2
0
 private static void C_UnreadMessagesUpdated(object sender, ModmailConversationsEventArgs e)
 {
     foreach (KeyValuePair <string, ConversationMessage> pair in e.AddedMessages)
     {
         NewMessages.Add(pair.Value);
     }
 }
Example #3
0
        protected void TriggerUpdate(ModmailConversationsEventArgs args, string type)
        {
            switch (type)
            {
            case "recent":
                OnRecentUpdated(args);
                break;

            case "mod":
                OnModUpdated(args);
                break;

            case "user":
                OnUserUpdated(args);
                break;

            case "unread":
                OnUnreadUpdated(args);
                break;
            }
        }
Example #4
0
        private void MonitorModmailMessagesThread(ConversationContainer conversationContainer, string key, string type, int startDelayMs = 0, int?monitoringDelayMs = null)
        {
            if (startDelayMs > 0)
            {
                Thread.Sleep(startDelayMs);
            }

            monitoringDelayMs = (monitoringDelayMs.HasValue ? monitoringDelayMs : Monitoring.Count() * MonitoringWaitDelayMS);

            while (!Terminate &&
                   Monitoring.Get(key).Contains("ModmailMessages"))
            {
                if (MonitoringExpiration.HasValue &&
                    DateTime.Now > MonitoringExpiration.Value)
                {
                    MonitorModel.RemoveMonitoringKey(key, "ModmailMessages", ref Monitoring);
                    Threads.Remove(key);

                    break;
                }

                while (!IsScheduled())
                {
                    if (Terminate)
                    {
                        break;
                    }

                    Thread.Sleep(15000);
                }

                if (Terminate)
                {
                    break;
                }

                Dictionary <string, Conversation>        oldConversationList;
                Dictionary <string, Conversation>        newConversationList;
                Dictionary <string, ConversationMessage> oldMessageList;
                Dictionary <string, ConversationMessage> newMessageList;

                ConversationContainer res;
                try
                {
                    switch (type)
                    {
                    default:
                        throw new RedditControllerException("Unrecognized type '" + type + "'.");

                    case "recent":
                        res = GetRecentConversations();
                        break;

                    case "mod":
                        res = GetModConversations();
                        break;

                    case "user":
                        res = GetUserConversations();
                        break;

                    case "unread":
                        res = GetUnreadConversations();
                        break;
                    }

                    oldConversationList = conversationContainer?.Conversations;
                    newConversationList = res.Conversations;
                    oldMessageList      = conversationContainer?.Messages;
                    newMessageList      = res.Messages;

                    if (Diff(oldConversationList, newConversationList, out Dictionary <string, Conversation> addedC, out Dictionary <string, Conversation> removedC))
                    {
                        if (Diff(oldMessageList, newMessageList, out Dictionary <string, ConversationMessage> addedM, out Dictionary <string, ConversationMessage> removedM))
                        {
                            // Event handler to alert the calling app that the list has changed.  --Kris
                            ModmailConversationsEventArgs args = new ModmailConversationsEventArgs
                            {
                                NewConversations     = newConversationList,
                                OldConversations     = oldConversationList,
                                AddedConversations   = addedC,
                                RemovedConversations = removedC,
                                NewMessages          = newMessageList,
                                OldMessages          = oldMessageList,
                                AddedMessages        = addedM,
                                RemovedMessages      = removedM
                            };
                            TriggerUpdate(args, type);
                        }
                    }
                }
                catch (Exception) when(!BreakOnFailure)
                {
                }

                Wait(monitoringDelayMs.Value);
            }
        }
Example #5
0
 protected virtual void OnUnreadUpdated(ModmailConversationsEventArgs e)
 {
     UnreadUpdated?.Invoke(this, e);
 }
Example #6
0
 protected virtual void OnRecentUpdated(ModmailConversationsEventArgs e)
 {
     RecentUpdated?.Invoke(this, e);
 }
Example #7
0
        private void MonitorModmailMessagesThread(ConversationContainer conversationContainer, string key, string type, int startDelayMs = 0)
        {
            if (startDelayMs > 0)
            {
                Thread.Sleep(startDelayMs);
            }

            while (!Terminate &&
                   Monitoring.Get(key).Contains("ModmailMessages"))
            {
                Dictionary <string, Conversation>        oldConversationList;
                Dictionary <string, Conversation>        newConversationList;
                Dictionary <string, ConversationMessage> oldMessageList;
                Dictionary <string, ConversationMessage> newMessageList;

                ConversationContainer res;
                switch (type)
                {
                default:
                    throw new RedditControllerException("Unrecognized type '" + type + "'.");

                case "recent":
                    res = GetRecentConversations();
                    break;

                case "mod":
                    res = GetModConversations();
                    break;

                case "user":
                    res = GetUserConversations();
                    break;

                case "unread":
                    res = GetUnreadConversations();
                    break;
                }

                oldConversationList = conversationContainer?.Conversations;
                newConversationList = res.Conversations;
                oldMessageList      = conversationContainer?.Messages;
                newMessageList      = res.Messages;

                if (Diff(oldConversationList, newConversationList, out Dictionary <string, Conversation> addedC, out Dictionary <string, Conversation> removedC))
                {
                    if (Diff(oldMessageList, newMessageList, out Dictionary <string, ConversationMessage> addedM, out Dictionary <string, ConversationMessage> removedM))
                    {
                        // Event handler to alert the calling app that the list has changed.  --Kris
                        ModmailConversationsEventArgs args = new ModmailConversationsEventArgs
                        {
                            NewConversations     = newConversationList,
                            OldConversations     = oldConversationList,
                            AddedConversations   = addedC,
                            RemovedConversations = removedC,
                            NewMessages          = newMessageList,
                            OldMessages          = oldMessageList,
                            AddedMessages        = addedM,
                            RemovedMessages      = removedM
                        };
                        TriggerUpdate(args, type);
                    }
                }

                Thread.Sleep(Monitoring.Count() * MonitoringWaitDelayMS);
            }
        }