Mentions dataobject implemented

main
Inga 🏳‍🌈 13 years ago
parent b0356fd6e3
commit e3a4a31819
  1. 1
      FLocal.Common/FLocal.Common.csproj
  2. 1
      FLocal.Common/actions/ChangeSet.cs
  3. 69
      FLocal.Common/dataobjects/Mention.cs
  4. 43
      FLocal.Common/dataobjects/Post.cs
  5. 16
      FLocal.Common/dataobjects/Thread.cs
  6. 3
      FLocal.Patcher.Common/FLocal.Patcher.Common.csproj
  7. 91
      FLocal.Patcher.Common/Resources/Patch_00002_mentions.xml

@ -100,6 +100,7 @@
<Compile Include="dataobjects\AnonymousUserSettings.cs" /> <Compile Include="dataobjects\AnonymousUserSettings.cs" />
<Compile Include="dataobjects\LocalNetwork.cs" /> <Compile Include="dataobjects\LocalNetwork.cs" />
<Compile Include="dataobjects\Machichara.cs" /> <Compile Include="dataobjects\Machichara.cs" />
<Compile Include="dataobjects\Mention.cs" />
<Compile Include="dataobjects\Moderator.cs" /> <Compile Include="dataobjects\Moderator.cs" />
<Compile Include="dataobjects\ModernSkin.cs" /> <Compile Include="dataobjects\ModernSkin.cs" />
<Compile Include="dataobjects\PMConversation.cs" /> <Compile Include="dataobjects\PMConversation.cs" />

@ -41,6 +41,7 @@ namespace FLocal.Common.actions {
dataobjects.PunishmentLayerChange.TableSpec.TABLE, dataobjects.PunishmentLayerChange.TableSpec.TABLE,
dataobjects.Restriction.TableSpec.TABLE, dataobjects.Restriction.TableSpec.TABLE,
dataobjects.TexImage.TableSpec.TABLE, dataobjects.TexImage.TableSpec.TABLE,
dataobjects.Mention.TableSpec.TABLE,
dataobjects.Session.TableSpec.TABLE, dataobjects.Session.TableSpec.TABLE,
} }
); );

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Web.Core;
using Web.Core.DB;
using Web.Core.DB.conditions;
using FLocal.Common.actions;
namespace FLocal.Common.dataobjects {
public class Mention : SqlObject<Mention> {
public class TableSpec : ISqlObjectTableSpec {
public const string TABLE = "Mentions";
public const string FIELD_ID = "Id";
public const string FIELD_MENTIONEDUSERID = "MentionedUserId";
public const string FIELD_POSTID = "PostId";
public const string FIELD_DATE = "Date";
public static readonly TableSpec instance = new TableSpec();
public string name { get { return TABLE; } }
public string idName { get { return FIELD_ID; } }
public void refreshSqlObject(int id) { Refresh(id); }
}
protected override ISqlObjectTableSpec table { get { return TableSpec.instance; } }
private int _mentionedUserId;
public int mentionedUserId {
get {
this.LoadIfNotLoaded();
return this._mentionedUserId;
}
}
public User mentionedUser {
get {
return User.LoadById(this.mentionedUserId);
}
}
private int _postId;
public int postId {
get {
this.LoadIfNotLoaded();
return this._postId;
}
}
public Post post {
get {
return Post.LoadById(this.postId);
}
}
private DateTime _date;
public DateTime date {
get {
this.LoadIfNotLoaded();
return this._date;
}
}
protected override void doFromHash(Dictionary<string, string> data) {
this._mentionedUserId = int.Parse(data[TableSpec.FIELD_MENTIONEDUSERID]);
this._postId = int.Parse(data[TableSpec.FIELD_POSTID]);
this._date = Util.ParseDateTimeFromTimestamp(data[TableSpec.FIELD_DATE]).Value;
}
}
}

@ -330,12 +330,21 @@ namespace FLocal.Common.dataobjects {
actualLayer = this.layer; actualLayer = this.layer;
} }
lock(this.Edit_locker) { lock(this.Edit_locker) {
DateTime date = DateTime.Now;
HashSet<int> newMentionedUsersIds = new HashSet<int>();
if(parentPost != null && parentPost.poster.id != poster.id) {
newMentionedUsersIds.Add(parentPost.poster.id);
}
string newBodyIntermediate = UBBParser.UBBToIntermediate(newBody);
List<AbstractChange> changes = new List<AbstractChange> { List<AbstractChange> changes = new List<AbstractChange> {
new InsertChange( new InsertChange(
Revision.TableSpec.instance, Revision.TableSpec.instance,
new Dictionary<string, AbstractFieldValue> { new Dictionary<string, AbstractFieldValue> {
{ Revision.TableSpec.FIELD_POSTID, new ScalarFieldValue(this.id.ToString()) }, { Revision.TableSpec.FIELD_POSTID, new ScalarFieldValue(this.id.ToString()) },
{ Revision.TableSpec.FIELD_CHANGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, { Revision.TableSpec.FIELD_CHANGEDATE, new ScalarFieldValue(date.ToUTCString()) },
{ Revision.TableSpec.FIELD_TITLE, new ScalarFieldValue(newTitle) }, { Revision.TableSpec.FIELD_TITLE, new ScalarFieldValue(newTitle) },
{ Revision.TableSpec.FIELD_BODY, new ScalarFieldValue(newBody) }, { Revision.TableSpec.FIELD_BODY, new ScalarFieldValue(newBody) },
{ Revision.TableSpec.FIELD_NUMBER, new ScalarFieldValue((this.revision + 1).ToString()) }, { Revision.TableSpec.FIELD_NUMBER, new ScalarFieldValue((this.revision + 1).ToString()) },
@ -345,8 +354,8 @@ namespace FLocal.Common.dataobjects {
TableSpec.instance, TableSpec.instance,
new Dictionary<string, AbstractFieldValue> { new Dictionary<string, AbstractFieldValue> {
{ TableSpec.FIELD_TITLE, new ScalarFieldValue(newTitle) }, { TableSpec.FIELD_TITLE, new ScalarFieldValue(newTitle) },
{ TableSpec.FIELD_BODY, new ScalarFieldValue(UBBParser.UBBToIntermediate(newBody)) }, { TableSpec.FIELD_BODY, new ScalarFieldValue(newBodyIntermediate) },
{ TableSpec.FIELD_LASTCHANGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, { TableSpec.FIELD_LASTCHANGEDATE, new ScalarFieldValue(date.ToUTCString()) },
{ TableSpec.FIELD_REVISION, new IncrementFieldValue() }, { TableSpec.FIELD_REVISION, new IncrementFieldValue() },
{ TableSpec.FIELD_LAYERID, new ScalarFieldValue(actualLayer.id.ToString()) }, { TableSpec.FIELD_LAYERID, new ScalarFieldValue(actualLayer.id.ToString()) },
}, },
@ -364,10 +373,38 @@ namespace FLocal.Common.dataobjects {
) )
); );
} }
foreach(var mentionedUserId in newMentionedUsersIds.Except(this.mentionedUsersIds)) {
changes.Add(
new InsertChange(
Mention.TableSpec.instance,
new Dictionary<string, AbstractFieldValue> {
{ Mention.TableSpec.FIELD_MENTIONEDUSERID, new ScalarFieldValue(mentionedUserId.ToString()) },
{ Mention.TableSpec.FIELD_POSTID, new ScalarFieldValue(this.id.ToString()) },
{ Mention.TableSpec.FIELD_DATE, new ScalarFieldValue(date.ToUTCString()) },
}
)
);
}
ChangeSetUtil.ApplyChanges(changes.ToArray()); ChangeSetUtil.ApplyChanges(changes.ToArray());
} }
} }
private IEnumerable<int> mentionedUsersIds {
get {
return from mention in Mention.LoadByIds(
from stringId in Config.instance.mainConnection.LoadIdsByConditions(
Mention.TableSpec.instance,
new ComparisonCondition(
Mention.TableSpec.instance.getColumnSpec(Mention.TableSpec.FIELD_POSTID),
ComparisonType.EQUAL,
this.id.ToString()
),
Diapasone.unlimited
) select int.Parse(stringId)
) select mention.mentionedUserId;
}
}
private IEnumerable<Post> subPosts { private IEnumerable<Post> subPosts {
get { get {
return Post.LoadByIds( return Post.LoadByIds(

@ -411,6 +411,10 @@ namespace FLocal.Common.dataobjects {
string parentPostId = null; string parentPostId = null;
if(parentPost != null) parentPostId = parentPost.id.ToString(); if(parentPost != null) parentPostId = parentPost.id.ToString();
bool isNewThread = (parentPost == null); bool isNewThread = (parentPost == null);
HashSet<int> mentionedUsersIds = new HashSet<int>();
if(parentPost != null && parentPost.poster.id != poster.id) {
mentionedUsersIds.Add(parentPost.poster.id);
}
string bodyIntermediate; string bodyIntermediate;
if(forcedPostId.HasValue) { if(forcedPostId.HasValue) {
//dirty hack //dirty hack
@ -484,6 +488,18 @@ namespace FLocal.Common.dataobjects {
changes.Add(threadUpdate); changes.Add(threadUpdate);
changes.Add(userUpdate); changes.Add(userUpdate);
foreach(var mentionedUserId in mentionedUsersIds) {
changes.Add(
new InsertChange(
Mention.TableSpec.instance,
new Dictionary<string, AbstractFieldValue> {
{ Mention.TableSpec.FIELD_MENTIONEDUSERID, new ScalarFieldValue(mentionedUserId.ToString()) },
{ Mention.TableSpec.FIELD_POSTID, new ReferenceFieldValue(postInsert) },
{ Mention.TableSpec.FIELD_DATE, new ScalarFieldValue(date.ToUTCString()) },
}
)
);
}
Dictionary<string, AbstractFieldValue> boardData = new Dictionary<string,AbstractFieldValue> { Dictionary<string, AbstractFieldValue> boardData = new Dictionary<string,AbstractFieldValue> {
{ Board.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() }, { Board.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() },

@ -69,6 +69,9 @@
<EmbeddedResource Include="Resources\Patch_00000_cleaninstall.xml" /> <EmbeddedResource Include="Resources\Patch_00000_cleaninstall.xml" />
<EmbeddedResource Include="Resources\Patch_00001_threadsindexes.xml" /> <EmbeddedResource Include="Resources\Patch_00001_threadsindexes.xml" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Patch_00002_mentions.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8" ?>
<patch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..\..\Patcher\Resources\IPatch.xsd">
<version>
<number>2</number>
<author>mentions</author>
</version>
<looseCommandSet>
<persistentCommand>
<createTable>
<table>Mentions</table>
<primaryKey>
<column>Id</column>
<type>serial</type>
<isNotNull/>
</primaryKey>
<column>
<column>MentionedUserId</column>
<type>int</type>
<isNotNull/>
</column>
<column>
<column>PostId</column>
<type>integer</type>
<isNotNull/>
</column>
<column>
<column>Date</column>
<type>timestamp with time zone</type>
</column>
</createTable>
</persistentCommand>
<persistentCommand>
<createConstraint>
<table>Mentions</table>
<constraintName>Mentions_MentionedUserId_PostId_key</constraintName>
<unique>
<column>MentionedUserId</column>
<column>PostId</column>
</unique>
</createConstraint>
</persistentCommand>
<persistentCommand>
<createConstraint>
<table>Mentions</table>
<constraintName>Mentions_MentionedUserId_fkey</constraintName>
<foreignKey>
<column>MentionedUserId</column>
<referencedTable>Users</referencedTable>
<onUpdate>restrict</onUpdate>
<onDelete>restrict</onDelete>
</foreignKey>
</createConstraint>
</persistentCommand>
<persistentCommand>
<createConstraint>
<table>Mentions</table>
<constraintName>Mentions_PostId_fkey</constraintName>
<foreignKey>
<column>PostId</column>
<referencedTable>Posts</referencedTable>
<onUpdate>restrict</onUpdate>
<onDelete>restrict</onDelete>
</foreignKey>
</createConstraint>
</persistentCommand>
<command>
<sql>
<installSql>
<query>
INSERT INTO
"Mentions"("MentionedUserId", "PostId", "Date")
(
SELECT
parent."PosterId" "MentionedUserId",
post."Id" "PostId",
post."LastChangeDate" "Date"
FROM "Posts" post
JOIN "Posts" parent
ON post."ParentPostId" = parent."Id"
WHERE
post."PosterId" != parent."PosterId"
ORDER BY
post."Id" asc
)
</query>
</installSql>
<uninstallSql/>
</sql>
</command>
</looseCommandSet>
</patch>
Loading…
Cancel
Save