示例#1
0
        internal static void Create(Core core, ForumTopic topic, TopicPost lastVisiblePost)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (core.LoggedInMemberId > 0)
            {
                InsertQuery iQuery = new InsertQuery(GetTable(typeof(TopicReadStatus)));
                iQuery.AddField("topic_id", topic.Id);
                iQuery.AddField("user_id", core.LoggedInMemberId);
                iQuery.AddField("forum_id", topic.ForumId);
                iQuery.AddField("read_time_ut", lastVisiblePost.TimeCreatedRaw);

                core.Db.Query(iQuery);
            }
        }
示例#2
0
        public void Read(TopicPost lastVisiblePost)
        {
            //db.BeginTransaction();

            UpdateQuery uQuery = new UpdateQuery(ForumTopic.GetTable(typeof(ForumTopic)));
            uQuery.AddField("topic_views", new QueryOperation("topic_views", QueryOperations.Addition, 1));
            uQuery.AddCondition("topic_id", topicId);

            db.Query(uQuery);

            if ((!IsRead) && core.LoggedInMemberId > 0)
            {
                if (readStatus != null)
                {
                    if (readStatus.ReadTimeRaw < lastVisiblePost.TimeCreatedRaw)
                    {
                        UpdateQuery uQuery2 = new UpdateQuery(TopicReadStatus.GetTable(typeof(TopicReadStatus)));
                        uQuery2.AddField("read_time_ut", lastVisiblePost.TimeCreatedRaw);
                        uQuery2.AddCondition("topic_id", topicId);
                        uQuery2.AddCondition("user_id", core.LoggedInMemberId);

                        db.Query(uQuery2);
                    }
                }
                else
                {
                    TopicReadStatus.Create(core, this, lastVisiblePost);
                }
            }
        }
示例#3
0
        public static Dictionary<long, TopicPost> GetTopicLastPosts(Core core, List<ForumTopic> topics)
        {
            Dictionary<long, TopicPost> posts = new Dictionary<long, TopicPost>();
            Dictionary<long, ForumTopic> reverseLookup = new Dictionary<long, ForumTopic>();
            List<long> topicLastPostIds = new List<long>();

            foreach (ForumTopic topic in topics)
            {
                reverseLookup.Add(topic.LastPostId, topic);

                topicLastPostIds.Add(topic.LastPostId);
            }

            if (topicLastPostIds.Count > 0)
            {
                SelectQuery query = TopicPost.GetSelectQueryStub(core, typeof(TopicPost));
                query.AddCondition("post_id", ConditionEquality.In, topicLastPostIds);

                System.Data.Common.DbDataReader postsReader = core.Db.ReaderQuery(query);

                List<long> posterIds = new List<long>();

                while(postsReader.Read())
                {
                    long postId = (long)postsReader["post_id"];
                    TopicPost tp = new TopicPost(core, reverseLookup[postId], postsReader);
                    posterIds.Add(tp.UserId);
                    posts.Add(tp.Id, tp);
                }

                postsReader.Close();
                postsReader.Dispose();

                core.LoadUserProfiles(posterIds);
            }

            return posts;
        }
示例#4
0
        internal static TopicPost Create(Core core, Forum forum, ForumTopic topic, string subject, string text)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (forum == null)
            {
                if (topic.ForumId == forum.Id)
                {
                    forum = topic.Forum;
                }
            }
            else
            {
                if (topic.ForumId != forum.Id)
                {
                    forum = topic.Forum;
                }
            }

            if (forum == null)
            {
                throw new InvalidForumException();
            }

            if (topic == null)
            {
                throw new InvalidTopicException();
            }

            if (!forum.Access.Can("REPLY_TOPICS"))
            {
                // todo: throw new exception
                throw new UnauthorisedToCreateItemException();
            }

            InsertQuery iQuery = new InsertQuery(NumberedItem.GetTable(typeof(TopicPost)));
            iQuery.AddField("topic_id", topic.Id);
            iQuery.AddField("forum_id", forum.Id);
            iQuery.AddField("user_id", core.LoggedInMemberId);
            iQuery.AddField("post_title", subject);
            iQuery.AddField("post_text", text);
            iQuery.AddField("post_time_ut", UnixTime.UnixTimeStamp());
            iQuery.AddField("post_modified_ut", UnixTime.UnixTimeStamp());
            iQuery.AddField("post_ip", core.Session.IPAddress.ToString());

            long postId = core.Db.Query(iQuery);

            TopicPost newPost = new TopicPost(core, forum, topic, postId);

            core.Search.Index(newPost, new SearchField("forum_id", forum.Id.ToString()));

            return newPost;
        }
示例#5
0
        public static Dictionary<long, TopicPost> GetPosts(Core core, List<long> postIds)
        {
            Dictionary<long, TopicPost> posts = new Dictionary<long, TopicPost>();

            if (postIds.Count > 0)
            {
                SelectQuery query = TopicPost.GetSelectQueryStub(core, typeof(TopicPost));
                query.AddCondition("post_id", ConditionEquality.In, postIds);

                System.Data.Common.DbDataReader postsReader = core.Db.ReaderQuery(query);

                List<long> posterIds = new List<long>();

                while (postsReader.Read())
                {
                    TopicPost tp = new TopicPost(core, postsReader);
                    posterIds.Add(tp.UserId);
                    posts.Add(tp.Id, tp);
                }

                postsReader.Close();
                postsReader.Dispose();

                //core.LoadUserProfiles(posterIds);
            }

            return posts;
        }