Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Topic Subscribe/Quick Reply Subscribe checkboxes have different values #653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dnn.CommunityForums/CustomControls/UserControls/SubmitForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ private string GetOptions()
if (canSubscribe)
{
var subControl = new ToggleSubscribe(ForumModuleId, ForumInfo.ForumID, TopicId, 1);
subControl.Checked = (UserPrefTopicSubscribe || Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumInfo.ForumID, TopicId, SubscriptionTypes.Instant, this.UserId));
subControl.Text = "[RESX:TopicSubscribe:" + (UserPrefTopicSubscribe || Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumInfo.ForumID, TopicId, SubscriptionTypes.Instant, this.UserId)).ToString().ToUpper() + "]";
subControl.Checked = (Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumInfo.ForumID, TopicId, SubscriptionTypes.Instant, this.UserId));
subControl.Text = "[RESX:TopicSubscribe:" + (Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumInfo.ForumID, TopicId, SubscriptionTypes.Instant, this.UserId)).ToString().ToUpper() + "]";
sb.Append("<tr><td colspan=\"2\">" + subControl.Render() +"</td></tr>");
bHasOptions = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private void LoadData(int pageId)
_topicURL = _drForum["URL"].ToString();
_topicDateCreated = Utilities.GetUserFormattedDateTime(Utilities.SafeConvertDateTime(_drForum["DateCreated"]), PortalId, UserId);
_topicData = _drForum["TopicData"].ToString();
_isSubscribedTopic = UserId > 0 && Utilities.SafeConvertInt(_drForum["IsSubscribedTopic"]) > 0;
_isSubscribedTopic = (Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumId, TopicId, SubscriptionTypes.Instant, this.UserId));

if (Page.IsPostBack)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ protected override void OnLoad(EventArgs e)
ForumSubscriberCount = Utilities.SafeConvertInt(drForum["ForumSubscriberCount"]);
if (UserId > 0)
{
IsSubscribedForum = Convert.ToBoolean(((Convert.ToInt32(drForum["IsSubscribedForum"]) > 0) ? true : false));
IsSubscribedForum = (Subscriptions.IsSubscribed(PortalId, ModuleId: ForumModuleId, ForumId, SubscriptionType: SubscriptionTypes.Instant, UserId: UserId));
}
if (MainSettings.UseSkinBreadCrumb)
{
Expand Down
9 changes: 6 additions & 3 deletions Dnn.CommunityForums/class/Subscriptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ public List<SubscriptionInfo> Subscription_GetSubscribers(int PortalId, int Foru
}
public abstract class Subscriptions
{
public static bool IsSubscribed(int PortalId, int ModuleId, int ForumId, int TopicId, SubscriptionTypes SubscriptionType, int AuthorId)
public static bool IsSubscribed(int PortalId, int ModuleId, int ForumId, int TopicId, SubscriptionTypes SubscriptionType, int UserId)
{
return new DotNetNuke.Modules.ActiveForums.Controllers.SubscriptionController().Subscribed(PortalId, ModuleId, AuthorId, ForumId, TopicId);
return new DotNetNuke.Modules.ActiveForums.Controllers.SubscriptionController().Subscribed(PortalId, ModuleId, UserId, ForumId, TopicId);
}
public static bool IsSubscribed(int PortalId, int ModuleId, int ForumId, SubscriptionTypes SubscriptionType, int UserId)
{
return new DotNetNuke.Modules.ActiveForums.Controllers.SubscriptionController().Subscribed(PortalId, ModuleId, UserId, ForumId);
}

public static void SendSubscriptions(int PortalId, int ModuleId, int TabId, int ForumId, int TopicId, int ReplyId, int AuthorId)
{
var fc = new ForumController();
Expand Down
12 changes: 10 additions & 2 deletions Dnn.CommunityForums/controls/af_post.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,11 @@ private void SaveTopic()

ti = tc.Topics_Get(PortalId, ForumModuleId, TopicId, ForumId, -1, false);
ti.TopicType = TopicTypes.Poll;
tc.TopicSave(PortalId, ForumModuleId, ti);
tc.TopicSave(PortalId, ForumModuleId, ti);
if (UserPrefTopicSubscribe)
{
new DotNetNuke.Modules.ActiveForums.Controllers.SubscriptionController().Subscribe(PortalId, ForumModuleId, UserId, ForumId, ti.TopicId);
}
tc.UpdateModuleLastContentModifiedOnDate(ForumModuleId);
}

Expand Down Expand Up @@ -1009,7 +1013,11 @@ private void SaveReply()
var bSend = ri.IsApproved;
ri.IsDeleted = false;
ri.StatusId = ctlForm.StatusId;
ri.TopicId = TopicId;
ri.TopicId = TopicId;
if (UserPrefTopicSubscribe)
{
new DotNetNuke.Modules.ActiveForums.Controllers.SubscriptionController().Subscribe(PortalId, ForumModuleId, UserId, ForumId, ri.TopicId);
}
var tmpReplyId = rc.Reply_Save(PortalId, ForumModuleId, ri);
rc.UpdateModuleLastContentModifiedOnDate(ForumModuleId);
ri = rc.Reply_Get(PortalId, ForumModuleId, TopicId, tmpReplyId);
Expand Down
11 changes: 9 additions & 2 deletions Dnn.CommunityForums/controls/af_quickreply.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
using DotNetNuke.Services.Social.Notifications;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DotNetNuke.Modules.ActiveForums.Data;
using DotNetNuke.UI.UserControls;
using System.Reflection;

namespace DotNetNuke.Modules.ActiveForums
{
Expand Down Expand Up @@ -93,8 +96,8 @@ protected override void OnLoad(EventArgs e)
if (AllowSubscribe)
{
var subControl = new ToggleSubscribe(ForumModuleId, ForumId, TopicId, 1);
subControl.Checked = (UserPrefTopicSubscribe || Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumId, TopicId, SubscriptionTypes.Instant, this.UserId));
subControl.Text = "[RESX:TopicSubscribe:" + (UserPrefTopicSubscribe || Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumId, TopicId, SubscriptionTypes.Instant, this.UserId)).ToString().ToUpper() + "]";
subControl.Checked = (Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumId, TopicId, SubscriptionTypes.Instant, this.UserId));
subControl.Text = "[RESX:TopicSubscribe:" + (Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumId, TopicId, SubscriptionTypes.Instant, this.UserId)).ToString().ToUpper() + "]";
divSubscribe.InnerHtml = subControl.Render();
}
if (Utilities.InputIsValid(Request.Form["txtBody"]) && Request.IsAuthenticated & ((!(string.IsNullOrEmpty(Request.Form["hidReply1"])) && string.IsNullOrEmpty(Request.Form["hidReply2"])) | Request.Browser.IsMobileDevice))
Expand Down Expand Up @@ -315,6 +318,10 @@ private void SaveQuickReply()
ri.IsApproved = isApproved;
ri.IsDeleted = false;
ri.Content.IPAddress = Request.UserHostAddress;
if (UserPrefTopicSubscribe)
{
new DotNetNuke.Modules.ActiveForums.Controllers.SubscriptionController().Subscribe(PortalId, ForumModuleId, UserId, ForumId, ri.TopicId);
}
ReplyId = rc.Reply_Save(PortalId, ModuleId, ri);
rc.UpdateModuleLastContentModifiedOnDate(ModuleId);
DataCache.ContentCacheClear(ModuleId, string.Format(CacheKeys.TopicViewForUser, ModuleId, ri.TopicId, ri.Content.AuthorId));
Expand Down
150 changes: 150 additions & 0 deletions Dnn.CommunityForums/sql/08.00.02.SqlDataProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/* issue 649 -begin - mismatched topic subscriber checkbox - no longer retrieve forum/topic subscriber flag from stored procedure */

/*activeforums_UI_TopicView*/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_UI_TopicView]') AND type in (N'P', N'PC'))
DROP PROCEDURE {databaseOwner}[{objectQualifier}activeforums_UI_TopicView]
GO
CREATE PROCEDURE {databaseOwner}{objectQualifier}activeforums_UI_TopicView
@PortalId int,
@ModuleId int,
@ForumId int,
@TopicId int,
@UserId int,
@RowIndex int,
@MaxRows int,
@IsSuperUser bit = 0,
@Sort varchar(10) = 'ASC'
AS
--Forum/Group/Topic Info
DECLARE @LastPostId int
DECLARE @ReplyCount int
SET @ReplyCount = (Select Count(ReplyId) from {databaseOwner}{objectQualifier}activeforums_Replies WHERE TopicId = @TopicId AND IsDeleted = 0 AND IsApproved = 1)
DECLARE @Tags nvarchar(1000)
SET @Tags= RTRIM(IsNull({databaseOwner}{objectQualifier}activeforums_Topics_GetTags(@TopicId),''))
BEGIN
SELECT
v.ForumGroupId,
v.ModuleId,
v.GroupName,
v.GroupActive,
v.GroupHidden,
v.ForumId,
v.ParentForumId,
v.ForumName,
v.ForumDesc,
v.ForumActive,
v.ForumHidden,
v.TotalTopics,
ISNULL(v.TotalReplies, 0) AS TotalReplies,
v.LastPostId,
v.GroupSettingsKey,
v.ForumSettingsKey,
TopicTemplateId = IsNull((SELECT SettingValue FROM {databaseOwner}{objectQualifier}activeforums_Settings WHERE SettingName = 'TOPICTEMPLATEID' and GroupKey = v.ForumSettingsKey),0),

IsNull((SELECT SettingValue
FROM {databaseOwner}{objectQualifier}activeforums_Settings AS {objectQualifier}activeforums_Settings_1
WHERE (SettingName = 'ALLOWRSS') AND (GroupKey = v.ForumSettingsKey)),0) AS AllowRSS,
IsNull((SELECT SettingValue
FROM {databaseOwner}{objectQualifier}activeforums_Settings AS {objectQualifier}activeforums_Settings_3
WHERE (SettingName = 'ALLOWHTML') AND (GroupKey = v.ForumSettingsKey)),0) AS AllowHTML,
IsNull((SELECT SettingValue
FROM {databaseOwner}{objectQualifier}activeforums_Settings AS activeforums_Settings_3
WHERE (SettingName = 'ALLOWLIKES') AND (GroupKey = v.ForumSettingsKey)),0) AS AllowLikes,
IsNull((SELECT SettingValue
FROM {databaseOwner}{objectQualifier}activeforums_Settings AS {objectQualifier}activeforums_Settings_2
WHERE (SettingName = 'ALLOWSCRIPT') AND (GroupKey = v.ForumSettingsKey)),0) AS AllowScript,
IsNull((SELECT SettingValue
FROM {databaseOwner}{objectQualifier}activeforums_Settings
WHERE (SettingName = 'ALLOWTAGS') AND (GroupKey = v.ForumSettingsKey)),0) AS AllowTags,
FT.TopicId,
(SELECT ISNULL(AVG(Rating), 0) AS Expr1
FROM {databaseOwner}{objectQualifier}activeforums_Topics_Ratings
WHERE (TopicId = @TopicId)) AS TopicRating,
CASE WHEN FT.LastReplyId is NULL THEN IsNull(T.DateCreated,'') ELSE IsNull(R.DateCreated,'') END AS LastPostDate,
CASE WHEN FT.LastReplyId is NULL THEN IsNull(T.AuthorId,'') ELSE IsNull(R.AuthorId,'') END AS LastPostAuthorId,
CASE WHEN FT.LastReplyId is NULL THEN IsNull(T.AuthorName,'') ELSE IsNull(R.AuthorName,'') END AS LastPostAuthorName,
CASE WHEN FT.LastReplyId is NULL THEN IsNull(T.UserName,'') ELSE IsNull(R.Username,'') END AS LastPostUserName,
CASE WHEN FT.LastReplyId is NULL THEN IsNull(T.FirstName,'') ELSE IsNull(R.FirstName,'') END AS LastPostFirstName,
CASE WHEN FT.LastReplyId is NULL THEN IsNull(T.LastName,'') ELSE IsNull(R.LastName,'') END AS LastPostLastName,
CASE WHEN FT.LastReplyId is NULL THEN IsNull(T.DisplayName,'') ELSE IsNull(R.DisplayName,'') END AS LastPostDisplayName, T.Subject, T.Summary, T.Body, T.AuthorId, T.AuthorName, T.Username, T.FirstName, T.LastName,
T.DisplayName, T.DateCreated, T.DateUpdated, T.ViewCount, @ReplyCount as ReplyCount, T.IsPinned, T.IsLocked, T.StatusId, T.TopicIcon, T.TopicType, @Tags as Tags,ISNULL(t.TopicData,'') as TopicData,
{databaseOwner}{objectQualifier}activeforums_Poll.PollID,
aft.NextTopic,
aft.PrevTopic,
t.URL,
T.AuthorName as TopicAuthor,
COALESCE((SELECT COUNT(*)
FROM {databaseOwner}{objectQualifier}activeforums_Subscriptions
WHERE (ForumId = @ForumId) AND (TopicId = @TopicId)), 0) AS TopicSubscriberCount,
COALESCE((SELECT COUNT(*)
FROM {databaseOwner}{objectQualifier}activeforums_Subscriptions
WHERE (ForumId = @ForumId) AND (TopicId = 0)), 0) AS ForumSubscriberCount
FROM
{databaseOwner}{objectQualifier}activeforums_Topics aft INNER JOIN
{databaseOwner}{objectQualifier}activeforums_ForumTopics AS FT ON aft.TopicId = FT.TopicId INNER JOIN
{databaseOwner}{objectQualifier}vw_activeforums_GroupForum AS v ON FT.ForumId = v.ForumId INNER JOIN
{databaseOwner}{objectQualifier}vw_activeforums_ForumTopics AS T ON FT.TopicId = T.TopicId LEFT OUTER JOIN
{databaseOwner}{objectQualifier}vw_activeforums_ForumReplies AS R ON FT.LastReplyId = R.ReplyId AND FT.LastReplyId IS NOT NULL LEFT OUTER JOIN
{databaseOwner}{objectQualifier}activeforums_Poll ON T.TopicId = {databaseOwner}{objectQualifier}activeforums_Poll.TopicId
WHERE (v.ForumActive = 1) AND (v.ModuleId = @ModuleId) AND (v.ForumId = @ForumId) AND (FT.TopicId = @TopicId)
END
--Forum Security
BEGIN
Select p.* from {databaseOwner}{objectQualifier}activeforums_Permissions as p INNER JOIN {databaseOwner}{objectQualifier}activeforums_Forums as f ON f.PermissionsId = p.PermissionsId WHERE f.ForumId = @ForumId

END
--Get Topic and Replies
SELECT ForumId, TopicId, ReplyId, [Subject], Summary, AuthorId, StatusId, AuthorName, UserName, FirstName, LastName,
DisplayName, DateCreated, DateUpdated, Body, TopicCount, ReplyCount, ViewCount, AnswerCount,
RewardPoints, UserDateCreated, DateLastActivity, UserCaption, [Signature], SignatureDisabled,
UserPostCount, UserTotalPoints,IPAddress,Avatar,AvatarType,AvatarDisabled,Yahoo,MSN,ICQ,AOL,Occupation,Location,Interests,WebSite,MemberSince,
ContentId,IsUserOnline,ReplyToId, UserRoles = {databaseOwner}{objectQualifier}activeforums_UserProfiles_GetUserRoles(AuthorId, @PortalID, GETUTCDATE(),0),
@Tags as Tags

FROM
(
SELECT T.ForumId, T.TopicId, T.ReplyId, T.Subject, T.Summary, T.AuthorId, T.StatusId, IsNull(T.AuthorName,'anon') as AuthorName, IsNull(T.Username,IsNull(T.AuthorName,'anon')) as Username,
IsNull(T.FirstName,'') as FirstName, IsNull(T.LastName,'') as LastName,IsNull(T.DisplayName,T.AuthorName) as DisplayName,
T.DateCreated, T.DateUpdated, C.Body, IsNull(P.TopicCount,0) as TopicCount, IsNull(P.ReplyCount,0) as ReplyCount,
IsNull(P.ViewCount,0) as ViewCount, IsNull(P.AnswerCount,0) as AnswerCount, IsNull(P.RewardPoints,0) as RewardPoints,
IsNull(P.DateCreated,'') AS UserDateCreated, IsNull(P.DateLastActivity,'') as DateLastActivity,
IsNull(P.UserCaption,'') as UserCaption, IsNull(P.Signature,'') as [Signature], IsNull(P.SignatureDisabled,0) as SignatureDisabled,
UserPostCount = (IsNull(P.TopicCount,0) + IsNull(P.ReplyCount,0)),
UserTotalPoints = (IsNull(P.TopicCount,0) + IsNull(P.ReplyCount,0) + IsNull(P.AnswerCount,0) + IsNull(P.RewardPoints,0)),
C.IPAddress, IsNull(P.Avatar,'') as Avatar, IsNull(P.AvatarType,0) as AvatarType, IsNull(P.AvatarDisabled,0) as AvatarDisabled,
IsNull(P.Yahoo,'') as Yahoo, IsNull(P.MSN,'') as MSN, IsNull(P.ICQ,'') as ICQ, IsNull(P.AOL,'') as AOL, IsNull(P.Occupation,'') as Occupation,
IsNull(P.Location,'') as Location, IsNull(P.Interests,'') as Interests, IsNull(P.WebSite,'') as WebSite, IsNull(P.DateCreated,'') as MemberSince,
C.ContentId, IsUserOnline = (CASE WHEN DATEDIFF(mi,p.DateLastActivity,GETUTCDATE()) <=1 THEN 1 ELSE 0 END),T.ReplyToId,
ROW_NUMBER() OVER (Order By
CASE
WHEN @Sort = 'DESC' THEN T.DateCreated END DESC,
CASE
WHEN @Sort = 'ASC' THEN T.DateCreated END ASC
) as RowRank
FROM {databaseOwner}{objectQualifier}vw_activeforums_TopicView AS T INNER JOIN
{databaseOwner}{objectQualifier}activeforums_Content AS C ON T.ContentId = C.ContentId LEFT OUTER JOIN
{databaseOwner}{objectQualifier}activeforums_UserProfiles AS P ON C.AuthorId = P.UserId AND P.PortalId = @PortalId AND P.ModuleId = -1
WHERE (T.TopicId = @TopicId)
)
AS TopicWithRowNumbers
WHERE RowRank > @RowIndex AND RowRank <= (@RowIndex + @MaxRows)

--Get Attachments
SELECT A.AttachId, A.ContentId, A.UserID, A.[FileName], A.ContentType, A.FileSize, A.FileID
FROM {databaseOwner}{objectQualifier}activeforums_Attachments AS A inner join
{databaseOwner}{objectQualifier}vw_activeforums_TopicView AS T ON A.ContentId = T.ContentId
WHERE (T.TopicId = @TopicId AND (A.AllowDownload = 1 OR A.AllowDownload IS NULL))

--Update View Count
UPDATE {databaseOwner}{objectQualifier}activeforums_Topics SET ViewCount = (ViewCount+1) WHERE TopicId = @TopicId
If @UserId > 0
BEGIN
SELECT @LastPostId = IsNull(LastReplyId,0) FROM {databaseOwner}{objectQualifier}activeforums_ForumTopics WHERE ForumId = @ForumId AND TopicId = @TopicId
exec {databaseOwner}{objectQualifier}activeforums_Forums_Tracking_UpdateUser @ModuleId, @UserId, @ForumId
SET @LastPostId = IsNull(@LastPostId,0)
exec {databaseOwner}{objectQualifier}activeforums_Topics_Tracking_UpdateUser @ForumId, @TopicId, @LastPostId, @UserId
exec {databaseOwner}{objectQualifier}activeforums_UserProfiles_UpdateActivity @PortalId, @ModuleId, @UserId
END

GO
/* issue 649 - end - mismatched topic subscriber checkbox - no longer retrieve forum/topic subscriber flag from stored procedure */