Ejemplo n.º 1
0
        /// <summary>
        /// Get the thread subscribe state.
        /// </summary>
        /// <param name="creator"></param>
        /// <param name="userId"></param>
        /// <param name="threadId"></param>
        /// <param name="forumId"></param>
        /// <returns></returns>
        static public SubscribeState GetSubscriptionState(IDnaDataReaderCreator creator, int userId, int threadId, int forumId)
        {
            SubscribeState state = new SubscribeState()
            {
                UserId = userId,
                ThreadId = threadId,
                ForumId = forumId
            };

            if (userId > 0)
            {
                using (IDnaDataReader reader = creator.CreateDnaDataReader("isusersubscribed"))
                {
                    reader.AddParameter("userid", userId);
                    reader.AddParameter("threadid", threadId);
                    reader.AddParameter("forumid", forumId);
                    reader.Execute();

                    if (reader.HasRows && reader.Read())
                    {
                        bool threadSubscribed = reader.GetInt32NullAsZero("ThreadSubscribed") == 1;
                        bool forumSubscribed = reader.GetInt32NullAsZero("ForumSubscribed") == 1;
                        int lastPostCountRead = reader.GetInt32NullAsZero("LastPostCountRead");
                        int lastUserPostID = reader.GetInt32NullAsZero("LastUserPostID");

                        state = new SubscribeState()
                        {
                            UserId = userId,
                            ThreadId = threadId,
                            ForumId = forumId
                        };

                        if (threadSubscribed)
                        {
                            state.Thread = 1;
                            state.LastPostCountRead = lastPostCountRead;
                            state.LastUserPostId = lastUserPostID;
                        }
                        else
                        {
                            state.Thread = 0;
                        }
                        if (forumSubscribed)
                        {
                            state.Forum = 1;
                        }
                    }
                }
            }
            return state;
        }
Ejemplo n.º 2
0
        /*

        /// <summary>
        /// This is legacy ripley code which is not supported in this version of forums
        /// </summary>
        private void ProcessTypeParameter()
        {
            //ProcessCommand base on type
            switch (_framePart.ToUpper())
            {
                case "FUP":
                    UpdatePageType("TOPFRAME");
                    break;

                case "TEST":

                    break;

                case "FLFT":
                    UpdatePageType("SIDEFRAME");
                    break;

                case "FSRC":
                    break;

                case "FTH":
                    UpdatePageType("FRAMETHREADS");
                    break;

                case "FMSG":
                    UpdatePageType("MESSAGEFRAME");
                    break;

                case "HEAD":
                    UpdatePageType("THREADPAGE");
                    //TODO check out forumpage element?
                    break;

                case "FTHR":
                    break;

                case "BIGP":
                    break;

                case "SUBS":
                    break;

                default:
                    if (_threadId > 0)
                    {
                        UpdatePageType("MULTIPOSTS");
                    }
                    break;
            }
        }
         */

        /// <summary>
        /// Processes the thread posts
        /// </summary>
        private void ProcessThreadPosts(SubscribeState subscribeState)
        {
            ForumThreadPosts thread = ForumThreadPosts.CreateThreadPosts(_creator, _cache, _viewingUser,
                                                                         InputContext.TheSiteList,
                                                                         InputContext.CurrentSite.SiteID, _forumId,
                                                                         _threadId, POSTSTOSHOW, _skip, _postId,
                                                                         _orderByDatePostedDesc, _ignoreCache, false);

            if (thread == null)
            {
                AddErrorXml("ThreadNotFound", "Unable to find the specified forum thread.", null);
                return;
            }

            //process subscription information
            SerialiseAndAppend(thread, String.Empty);


            if (subscribeState != null && subscribeState.Thread != 0 && thread != null && thread.Post.Count > 0)
            {
//update the last read post if the user is subscribed, increment by 1 because its a 0 based index
                if (subscribeState.LastPostCountRead < thread.Post[thread.Post.Count - 1].Index + 1)
                {
                    _forumHelper.MarkThreadRead(InputContext.ViewingUser.UserID, _threadId,
                                                thread.Post[thread.Post.Count - 1].Index + 1, true);
                }
            }
        }