Esempio n. 1
0
 /// <summary>
 /// Prompt and then mark the specified folder read.
 /// </summary>
 public void HandleMarkFolderRead(Folder folder)
 {
     string promptString = String.Format(Resources.MarkFolderRead, folder.Name);
     if (MessageBox.Show(promptString, Resources.Confirm, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
     {
         folder.MarkAllRead();
     }
 }
Esempio n. 2
0
        public void TestForumsFastSync()
        {
            string databasePath = Path.GetTempFileName();
            CIX.Init(databasePath);

            Folder forumFolder = new Folder
            {
                ParentID = -1,
                Name = "cix.beta",
                Unread = 0,
                UnreadPriority = 0
            };
            CIX.FolderCollection.Add(forumFolder);

            Folder topicFolder = new Folder
            {
                Name = "cixreader",
                ParentID = forumFolder.ID,
                Unread = 0,
                UnreadPriority = 0
            };
            CIX.FolderCollection.Add(topicFolder);

            // Seed message as fast sync doesn't work on empty topics
            CIXMessage seedMessage = new CIXMessage
            {
                RemoteID = 1,
                Author = "CIX",
                Body = "Seed message",
                CommentID = 0
            };
            topicFolder.Messages.Add(seedMessage);

            string userSyncData = Resource1.UserSyncData;
            DateTime sinceDate = default(DateTime);
            FolderCollection.AddMessages(Utilities.GenerateStreamFromString(userSyncData), ref sinceDate, true, false);

            // On completion, verify that there are no duplicates in the topic
            List<CIXMessage> messages = topicFolder.Messages.OrderBy(fld => fld.RemoteID).ToList();
            int lastMessageID = -1;
            foreach (CIXMessage cixMessage in messages)
            {
                Assert.AreNotEqual(cixMessage.RemoteID, 0);
                Assert.AreNotEqual(cixMessage.RemoteID, lastMessageID);
                Assert.AreNotEqual(cixMessage.ID, 0);
                lastMessageID = cixMessage.RemoteID;
            }

            // Verify that specific messages are marked read
            CIXMessage message = topicFolder.Messages.MessageByID(2323);
            Assert.IsNotNull(message);
            Assert.IsFalse(message.Unread);

            // Verify that specific messages are marked unread
            message = topicFolder.Messages.MessageByID(2333);
            Assert.IsNotNull(message);
            Assert.IsTrue(message.Unread);

            // Verify the total unread on the folder and globally
            Assert.AreEqual(topicFolder.Unread, 1);
            Assert.AreEqual(topicFolder.UnreadPriority, 6);
            Assert.AreEqual(CIX.FolderCollection.TotalUnread, 1);
            Assert.AreEqual(CIX.FolderCollection.TotalUnreadPriority, 6);
        }
Esempio n. 3
0
 /// <summary>
 /// Handle the forum joined event.
 /// </summary>
 /// <param name="folder">The folder for the forum that was joined</param>
 private void OnForumJoined(Folder folder)
 {
     Platform.UIThread(this, delegate
     {
         TreeNode node = FindFolder(_forumsTree.Nodes, folder.Name);
         if (node == null)
         {
             node = InsertFolder(folder, false);
         }
         else
         {
             UpdateFolder(folder);
         }
         SelectFolder(node, FolderOptions.None);
     });
 }
Esempio n. 4
0
        /// <summary>
        /// Locate and update the specified folder in the tree.
        /// </summary>
        private void UpdateFolder(Folder folderToUpdate)
        {
            int itemIndex = 0;
            TreeNodeCollection containerNodes = _forumsTree.Nodes;
            bool foundNode = false;

            // Find the top level folder to which this belongs.
            while (itemIndex < containerNodes.Count)
            {
                TreeNode node = containerNodes[itemIndex];
                FolderBase folder = (FolderBase)node.Tag;
                if (folderToUpdate.ParentID >= 0 && folder.ID == folderToUpdate.ParentID)
                {
                    containerNodes = node.Nodes;
                    itemIndex = 0;
                    continue;
                }
                if (folder.ID == folderToUpdate.ID)
                {
                    // Force an invalidate so we redraw the node with the
                    // changed information.
                    if (node.IsVisible)
                    {
                        frmList.InvalidateNode(node);
                    }
                    else if (node.Parent != null && node.Parent.IsVisible)
                    {
                        frmList.InvalidateNode(node.Parent);
                    }
                    foundNode = true;
                    break;
                }
                ++itemIndex;
            }

            // If we didn't find the node but the folder has unread messages AND
            // we're only showing recent then a non-recent folder got new messages.
            // So put that folder back in the list
            if (!foundNode && folderToUpdate.Unread > 0)
            {
                InsertFolder(folderToUpdate, false);
            }

            // Trigger an update to smart folders
            TriggerSmartFolderRefresh();
        }
Esempio n. 5
0
 /// <summary>
 /// Handle the folder deletion event.
 /// </summary>
 /// <param name="folder">The folder that was deleted</param>
 private void OnFolderDeleted(Folder folder)
 {
     Platform.UIThread(this, delegate
     {
         TreeNode nodeToSelect = null;
         TreeNode node;
         if (folder.IsRootFolder)
         {
             node = FindFolder(_forumsTree.Nodes, folder.Name);
         }
         else
         {
             node = FindFolder(_forumsTree.Nodes, folder.ParentFolder.Name);
             if (node == null)
             {
                 return;
             }
             node = FindFolder(node.Nodes, folder.Name);
         }
         if (node != null)
         {
             if (node.IsSelected)
             {
                 nodeToSelect = node.PrevNode ?? node.NextNode;
             }
             node.Remove();
         }
         if (nodeToSelect != null)
         {
             SelectFolder(nodeToSelect, FolderOptions.None);
         }
         MainForm.UpdateTotalUnreadCount();
     });
 }
Esempio n. 6
0
 /// <summary>
 /// Handle the folder update event to redraw the folder's node in the tree
 /// and then update the counts on the shortcut bar.
 /// </summary>
 /// <param name="folder">The folder that was updated</param>
 private void OnFolderUpdated(Folder folder)
 {
     Platform.UIThread(this, delegate
     {
         UpdateFolder(folder);
         MainForm.UpdateTotalUnreadCount();
     });
 }
Esempio n. 7
0
        /// <summary>
        /// Insert the specified folder into the tree if it isn't already present. The folder's
        /// parents are also added if they are missing in order to preserve the tree integrity.
        /// Subview filtering is respected so if the folder doesn't belong to the current subview
        /// then it is not added. If the folder is already present, we force a refresh on it to
        /// update it to show any modified data.
        /// </summary>
        private TreeNode InsertFolder(Folder newFolder, bool addChildren)
        {
            if (newFolder.ParentID != -1)
            {
                Folder parentFolder = newFolder.ParentFolder;
                if (parentFolder != null)
                {
                    InsertFolder(parentFolder, addChildren);
                }
            }

            int insertIndex = 0;
            int itemIndex = 0;
            TreeNode thisNode = null;
            TreeNodeCollection containerNodes = _forumsTree.Nodes;
            bool foundPosition = false;

            // Find the top level folder to which this belongs.
            while (itemIndex < containerNodes.Count)
            {
                TreeNode node = containerNodes[itemIndex];
                FolderBase folder = (FolderBase)node.Tag;
                if (folder != null)
                {
                    if (newFolder.ParentID >= 0 && folder.ID == newFolder.ParentID)
                    {
                        containerNodes = node.Nodes;
                        insertIndex = 0;
                        itemIndex = 0;
                        foundPosition = false;
                        continue;
                    }
                    if (folder.ID == newFolder.ID)
                    {
                        // Force an invalidate so we redraw the node with the
                        // changed information.
                        frmList.InvalidateNode(node);

                        thisNode = node;
                        break;
                    }
                    if (String.Compare(newFolder.Name, folder.Name, StringComparison.Ordinal) < 0 && folder.ID > 0 && !foundPosition)
                    {
                        insertIndex = itemIndex;
                        foundPosition = true;
                    }
                }
                ++itemIndex;
                if (folder != null && folder.ID < 0)
                {
                    // Skip special folders
                    insertIndex = itemIndex;
                }
            }
            if (!foundPosition)
            {
                insertIndex = itemIndex;
            }

            // This is an insertion task. At this point containerNodes will reference
            // the container nodes for the new folder and insertIndex will be the index
            // within that at which the new folder is added.
            if (thisNode == null)
            {
                thisNode = new TreeNode(newFolder.Name)
                {
                    Tag = new TopicFolder(newFolder) { Name = newFolder.Name }
                };
                if (newFolder.IsRootFolder && addChildren)
                {
                    foreach (Folder topic in newFolder.Children)
                    {
                        TreeNode subNode = new TreeNode(topic.Name)
                        {
                            Tag = new TopicFolder(topic) { Name = topic.Name }
                        };
                        thisNode.Nodes.Add(subNode);
                    }
                }

                containerNodes.Insert(insertIndex, thisNode);

                // Persist the index to the database.
                FixupNodeIndexes(_forumsTree.Nodes);
            }
            return thisNode;
        }
Esempio n. 8
0
 /// <summary>
 /// Notify that the specified forum has been joined on the server
 /// </summary>
 /// <param name="forum">The forum that was joined</param>
 internal void NotifyForumJoined(Folder forum)
 {
     if (ForumJoined != null)
     {
         ForumJoined(forum);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Initialises a new instance of the <see cref="TopicFolder"/> class 
 /// using the given folder as the data source.
 /// </summary>
 /// <param name="folder">A folder</param>
 public TopicFolder(Folder folder)
 {
     Folder = folder;
 }
Esempio n. 10
0
 /// <summary>
 /// Called when details of a forum are refreshed from the server. This may be the title
 /// or description.
 /// </summary>
 private void OnFolderUpdated(Folder folder)
 {
     Platform.UIThread(this, delegate
     {
         // Handle changes to the topic name or description
         if (folder == _currentFolder.Folder && frmCanvas.Items.Count > 0)
         {
             ForumPage forumFolderItem = (ForumPage) frmCanvas.Items[0];
             forumFolderItem.InvalidateItem();
         }
     });
 }
Esempio n. 11
0
        /// <summary>
        /// Join the specified forum.
        /// </summary>
        private void InternalJoin()
        {
            try
            {
                LogFile.WriteLine("Joining forum {0}", Name);

                HttpWebRequest request = APIRequest.GetWithQuery("forums/" + FolderCollection.EncodeForumName(Name) + "/join", APIRequest.APIFormat.XML, "mark=true");

                string responseString = APIRequest.ReadResponseString(request);
                if (responseString == "Success")
                {
                    LogFile.WriteLine("Successfully joined forum {0}", Name);

                    Folder folder = CIX.FolderCollection.Get(-1, Name);
                    if (folder == null)
                    {
                        folder = new Folder { Name = Name, Flags = FolderFlags.Recent, ParentID = -1 };
                        CIX.FolderCollection.Add(folder);
                    }

                    folder.Flags &= ~FolderFlags.Resigned;
                    lock (CIX.DBLock)
                    {
                        CIX.DB.Update(folder);
                    }

                    CIX.DirectoryCollection.NotifyForumJoined(folder);

                    CIX.FolderCollection.Refresh(false);
                }
                JoinPending = false;
                lock (CIX.DBLock)
                {
                    CIX.DB.Update(this);
                }
            }
            catch (Exception e)
            {
                CIX.ReportServerExceptions("DirForum.Join", e);
            }
        }