コード例 #1
0
        public static void ApproveMessage(int approvedMessageID, DbConnection cn)
        {
            bool openConn = (cn.State == ConnectionState.Open);

            if (!openConn)
            {
                cn.Open();
            }

            cn.ExecuteNonQuery("UPDATE ForumMessages SET Visible=? WHERE MessageID=?", true, approvedMessageID);

            int topicId;
            var res = cn.ExecuteScalar("SELECT TopicID FROM ForumMessages WHERE MessageID=?", approvedMessageID);

            topicId = Convert.ToInt32(res);

            //approving the topic as well (just in case)
            cn.ExecuteNonQuery("UPDATE ForumTopics SET Visible=? WHERE TopicID=?", true, topicId);

            //updating LastMessageID in Topics table
            RefreshLastMessageIdForTopic(topicId, cn);

            //clear cache
            int forumId = Topic.GetForumIdForTopic(topicId, cn);

            Forum.ClearTopicsCache(forumId);
            ModeratorStats.ResetUnapprovedCountCache();

            if (!openConn)
            {
                cn.Close();
            }

            //send notification to subscribed users
            SendNotifications.SendNewMsgNotificationEmails(topicId, approvedMessageID, false, true);
        }
コード例 #2
0
        public static int AddMessage(DbConnection cn, int topicId, string msg, bool visible, string posterIpAddress, bool suppressNotification, string WhoAmI)
        {
            if (Formatting.ContainsBadWords(msg))
            {
                return(0);
            }
            if (WhoAmI == "")
            {
                return(0);
            }

            //to save performance and prevent close/reopn connection a thousand times we do this
            bool openConn = (cn.State == ConnectionState.Open);

            if (!openConn)
            {
                cn.Open();
            }

            cn.ExecuteNonQuery("INSERT INTO ForumMessages (TopicID, UserID, Body, WhoAmI, CreationDate, Visible, IPAddress) VALUES (?, ?, ?, ?, ?, ?, ?)",
                               topicId,
                               User.CurrentUserID,
                               msg,
                               WhoAmI,
                               Utils.Various.GetCurrTime(),
                               visible,
                               posterIpAddress);

            //get the last message's ID
            var res       = cn.ExecuteScalar("SELECT MAX(MessageID) FROM ForumMessages WHERE TopicID=" + topicId + " AND UserID=" + User.CurrentUserID);
            int messageId = (res == null || res == DBNull.Value) ? 0 : Convert.ToInt32(res);

            //incrementing repliescount (well... actually - re-calculating it)
            res = cn.ExecuteScalar("SELECT Count(MessageID) FROM ForumMessages WHERE TopicID=" + topicId);
            cn.ExecuteNonQuery("UPDATE ForumTopics SET RepliesCount=" + res.ToString() + " WHERE TopicID=" + topicId);

            //incrementing PostsCount in Users table
            //only for registered users (if guestmode is on)
            if (User.CurrentUserID != 0)
            {
                cn.ExecuteNonQuery("UPDATE ForumUsers SET PostsCount=PostsCount+1 WHERE UserID=" + User.CurrentUserID);
            }

            //updating LastMessageID in Topics table
            if (visible)
            {
                cn.ExecuteNonQuery("UPDATE ForumTopics SET LastMessageID=" + messageId + " WHERE TopicID=" + topicId);
            }

            if (!openConn)
            {
                cn.Close();
            }

            if (!suppressNotification)
            {
                SendNotifications.SendNewMsgNotificationEmails(topicId, messageId, !visible, false);
            }

            //clearing cache
            Forum.ClearFrontPageCacheForGuests();

            //clear cache
            int forumId = Topic.GetForumIdForTopic(topicId, cn);

            Forum.ClearTopicsCache(forumId);

            Achievements.AddSuccess(AchievementType.WelcomeAboard, User.CurrentUserID);
            Achievements.TestAchievements(User.CurrentUserID, AchievementType.Lonely, AchievementType.SomethingToSay, AchievementType.FreeTime);

            return(messageId);
        }