Thread.forceMarkAsRead implemented

main
Inga 🏳‍🌈 15 years ago
parent 95c67edd0e
commit 43918d7a3d
  1. 2
      Builder/IISMainHandler/build.txt
  2. 2
      Builder/IISUploadHandler/build.txt
  3. 10
      Common/actions/IncrementFieldValue.cs
  4. 65
      Common/dataobjects/Thread.cs
  5. 2
      IISMainHandler/HandlersFactory.cs
  6. 2
      IISMainHandler/IISMainHandler.csproj
  7. 3
      templates/Full/elems/ThreadInfo.xslt

@ -9,6 +9,16 @@ namespace FLocal.Common.actions {
public static readonly Func<string, string> INCREMENTOR = s => (int.Parse(s)+1).ToString();
public static readonly Func<string, string> DECREMENTOR = s => (int.Parse(s)-1).ToString();
public static Func<string, string> GREATEST(int val) {
return s => {
if(s == null || s == "") {
return val.ToString();
} else {
return Math.Max(int.Parse(s), val).ToString();
}
};
}
private readonly Func<string, string> processor;
public IncrementFieldValue(Func<string, string> processor) {

@ -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<string> 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<string,AbstractFieldValue> {
{ 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<string,AbstractFieldValue> {
{ 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<string,AbstractFieldValue> {
@ -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<AbstractChange, IEnumerable<AbstractChange>> getNewPostChanges(Board board, int threadId, Post parentPost, User poster, PostLayer layer, string title, string body) {

@ -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:

@ -63,7 +63,9 @@
<Compile Include="handlers\request\CreateThreadHandler.cs" />
<Compile Include="handlers\request\LoginHandler.cs" />
<Compile Include="handlers\request\LogoutHandler.cs" />
<Compile Include="handlers\request\MarkThreadAsReadHandler.cs" />
<Compile Include="handlers\request\MigrateAccountHandler.cs" />
<Compile Include="handlers\request\ReturnPostHandler.cs" />
<Compile Include="handlers\request\ReplyHandler.cs" />
<Compile Include="handlers\request\SendPMHandler.cs" />
<Compile Include="handlers\request\SettingsHandler.cs" />

@ -66,6 +66,9 @@
<span class="separate"><xsl:value-of select="totalPosts"/></span>
<xsl:if test="totalNewPosts and totalNewPosts!='0'">
<a class="cup separate">
<xsl:if test="/root/session/sessionKey">
<xsl:attribute name="href">/do/MarkThreadAsRead/<xsl:value-of select="id"/>/p<xsl:value-of select="lastPostId"/>/</xsl:attribute>
</xsl:if>
<font class="new"><i>(<xsl:value-of select="totalNewPosts"/>)</i></font>
</a>
</xsl:if>

Loading…
Cancel
Save