From 43918d7a3d3d6a79876ce07e56c756a77a6664b6 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Fri, 2 Jul 2010 11:02:25 +0000 Subject: [PATCH] Thread.forceMarkAsRead implemented --- Builder/IISMainHandler/build.txt | 2 +- Builder/IISUploadHandler/build.txt | 2 +- Common/actions/IncrementFieldValue.cs | 10 +++++ Common/dataobjects/Thread.cs | 65 +++++++++++++++------------ IISMainHandler/HandlersFactory.cs | 2 + IISMainHandler/IISMainHandler.csproj | 2 + templates/Full/elems/ThreadInfo.xslt | 3 ++ 7 files changed, 56 insertions(+), 30 deletions(-) diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 495ae25..02416eb 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -464 \ No newline at end of file +467 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index ae4ee13..5e78f1e 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -200 \ No newline at end of file +203 \ No newline at end of file diff --git a/Common/actions/IncrementFieldValue.cs b/Common/actions/IncrementFieldValue.cs index 8b611c7..d1bffca 100644 --- a/Common/actions/IncrementFieldValue.cs +++ b/Common/actions/IncrementFieldValue.cs @@ -9,6 +9,16 @@ namespace FLocal.Common.actions { public static readonly Func INCREMENTOR = s => (int.Parse(s)+1).ToString(); public static readonly Func DECREMENTOR = s => (int.Parse(s)-1).ToString(); + public static Func GREATEST(int val) { + return s => { + if(s == null || s == "") { + return val.ToString(); + } else { + return Math.Max(int.Parse(s), val).ToString(); + } + }; + } + private readonly Func processor; public IncrementFieldValue(Func processor) { diff --git a/Common/dataobjects/Thread.cs b/Common/dataobjects/Thread.cs index 9bb1db9..263ec4a 100644 --- a/Common/dataobjects/Thread.cs +++ b/Common/dataobjects/Thread.cs @@ -44,6 +44,22 @@ namespace FLocal.Common.dataobjects { protected override ISqlObjectTableSpec table { get { return TableSpec.instance; } } + private AbstractCondition getReadmarkerSearchCondition(Account account) { + return new ComplexCondition( + ConditionsJoinType.AND, + new ComparisonCondition( + ReadMarkerTableSpec.instance.getColumnSpec(ReadMarkerTableSpec.FIELD_THREADID), + ComparisonType.EQUAL, + this.id.ToString() + ), + new ComparisonCondition( + ReadMarkerTableSpec.instance.getColumnSpec(ReadMarkerTableSpec.FIELD_ACCOUNTID), + ComparisonType.EQUAL, + account.id.ToString() + ) + ); + } + private int _boardId; public int boardId { get { @@ -255,19 +271,7 @@ namespace FLocal.Common.dataobjects { public int getLastReadId(Account account) { List stringIds = Config.instance.mainConnection.LoadIdsByConditions( ReadMarkerTableSpec.instance, - new ComplexCondition( - ConditionsJoinType.AND, - new ComparisonCondition( - ReadMarkerTableSpec.instance.getColumnSpec(ReadMarkerTableSpec.FIELD_THREADID), - ComparisonType.EQUAL, - this.id.ToString() - ), - new ComparisonCondition( - ReadMarkerTableSpec.instance.getColumnSpec(ReadMarkerTableSpec.FIELD_ACCOUNTID), - ComparisonType.EQUAL, - account.id.ToString() - ) - ), + this.getReadmarkerSearchCondition(account), Diapasone.unlimited ); if(stringIds.Count > 1) { @@ -283,8 +287,25 @@ namespace FLocal.Common.dataobjects { return int.Parse(data[ReadMarkerTableSpec.FIELD_POSTID]); } + public void forceMarkAsRead(Account account, Post maxPost) { + ChangeSetUtil.ApplyChanges( + new InsertOrUpdateChange( + ReadMarkerTableSpec.instance, + new Dictionary { + { ReadMarkerTableSpec.FIELD_ACCOUNTID, new ScalarFieldValue(account.id.ToString()) }, + { ReadMarkerTableSpec.FIELD_THREADID, new ScalarFieldValue(this.id.ToString()) }, + { ReadMarkerTableSpec.FIELD_POSTID, new ScalarFieldValue(maxPost.id.ToString()) }, + }, + new Dictionary { + { ReadMarkerTableSpec.FIELD_POSTID, new IncrementFieldValue(IncrementFieldValue.GREATEST(maxPost.id)) }, + }, + this.getReadmarkerSearchCondition(account) + ) + ); + } + public void markAsRead(Account account, Post minPost, Post maxPost) { - ChangeSetUtil.ApplyChanges(new AbstractChange[] { + ChangeSetUtil.ApplyChanges( new InsertOrUpdateChange( ReadMarkerTableSpec.instance, new Dictionary { @@ -347,21 +368,9 @@ namespace FLocal.Common.dataobjects { ) } }, - new ComplexCondition( - ConditionsJoinType.AND, - new ComparisonCondition( - ReadMarkerTableSpec.instance.getColumnSpec(ReadMarkerTableSpec.FIELD_THREADID), - ComparisonType.EQUAL, - this.id.ToString() - ), - new ComparisonCondition( - ReadMarkerTableSpec.instance.getColumnSpec(ReadMarkerTableSpec.FIELD_ACCOUNTID), - ComparisonType.EQUAL, - account.id.ToString() - ) - ) + this.getReadmarkerSearchCondition(account) ) - }); + ); } internal static KeyValuePair> getNewPostChanges(Board board, int threadId, Post parentPost, User poster, PostLayer layer, string title, string body) { diff --git a/IISMainHandler/HandlersFactory.cs b/IISMainHandler/HandlersFactory.cs index 191f470..de74123 100644 --- a/IISMainHandler/HandlersFactory.cs +++ b/IISMainHandler/HandlersFactory.cs @@ -109,6 +109,8 @@ namespace FLocal.IISHandler { return new handlers.request.SettingsHandler(); case "sendpm": return new handlers.request.SendPMHandler(); + case "markthreadasread": + return new handlers.request.MarkThreadAsReadHandler(); case "upload": return new handlers.request.UploadHandler(); default: diff --git a/IISMainHandler/IISMainHandler.csproj b/IISMainHandler/IISMainHandler.csproj index 1751623..dac0827 100644 --- a/IISMainHandler/IISMainHandler.csproj +++ b/IISMainHandler/IISMainHandler.csproj @@ -63,7 +63,9 @@ + + diff --git a/templates/Full/elems/ThreadInfo.xslt b/templates/Full/elems/ThreadInfo.xslt index 4414042..dc070a4 100644 --- a/templates/Full/elems/ThreadInfo.xslt +++ b/templates/Full/elems/ThreadInfo.xslt @@ -66,6 +66,9 @@ + + /do/MarkThreadAsRead//p/ + ()