From 16e750b946a07223939301188c6e5f88db9f320b Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Sun, 27 Jun 2010 14:28:36 +0000 Subject: [PATCH] NewThread implemented; some bugfixes --- Builder/IISMainHandler/build.txt | 2 +- Builder/IISUploadHandler/build.txt | 2 +- Common/Common.csproj | 4 +- Common/actions/ChangeSet.cs | 8 +- Common/dataobjects/Board.cs | 33 ++++++ Common/dataobjects/Post.cs | 89 +-------------- Common/dataobjects/Thread.cs | 105 ++++++++++++++++++ IISMainHandler/HandlersFactory.cs | 20 +++- IISMainHandler/IISMainHandler.csproj | 1 + .../request/AbstractNewMessageHandler.cs | 6 + .../handlers/request/CreateThreadHandler.cs | 23 ++-- .../handlers/request/ReplyHandler.cs | 6 - .../handlers/response/CreateThreadHandler.cs | 30 +++++ templates/Full/Board.xslt | 1 + templates/Full/BoardAsThread.xslt | 3 +- templates/Full/NewThread.xslt | 63 +++++++++++ templates/Full/PostReply.xslt | 6 +- 17 files changed, 290 insertions(+), 112 deletions(-) create mode 100644 IISMainHandler/handlers/response/CreateThreadHandler.cs create mode 100644 templates/Full/NewThread.xslt diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 1c34b96..903dc0f 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -377 \ No newline at end of file +390 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index 6d58c4e..3fdc173 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -109 \ No newline at end of file +122 \ No newline at end of file diff --git a/Common/Common.csproj b/Common/Common.csproj index e14444c..66cc857 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -24,9 +24,9 @@ pdbonly - true + false bin\Release\ - TRACE + DEBUG;TRACE prompt 4 diff --git a/Common/actions/ChangeSet.cs b/Common/actions/ChangeSet.cs index e9d3dee..9af2eaa 100644 --- a/Common/actions/ChangeSet.cs +++ b/Common/actions/ChangeSet.cs @@ -19,14 +19,14 @@ namespace FLocal.Common.actions { return Cache>.instance.get( tablesLockOrder_locker, () => new List() { - dataobjects.Account.TableSpec.TABLE, - dataobjects.User.TableSpec.TABLE, + dataobjects.Thread.TableSpec.TABLE, //thread should come first because of Board.newThread locking order with two changesets dataobjects.Board.TableSpec.TABLE, - dataobjects.Thread.TableSpec.TABLE, dataobjects.Post.TableSpec.TABLE, dataobjects.Post.RevisionTableSpec.TABLE, - dataobjects.Board.ReadMarkerTableSpec.TABLE, + dataobjects.Account.TableSpec.TABLE, + dataobjects.User.TableSpec.TABLE, dataobjects.Thread.ReadMarkerTableSpec.TABLE, + dataobjects.Board.ReadMarkerTableSpec.TABLE, dataobjects.Session.TableSpec.TABLE, } ); diff --git a/Common/dataobjects/Board.cs b/Common/dataobjects/Board.cs index e2e4d8c..0616386 100644 --- a/Common/dataobjects/Board.cs +++ b/Common/dataobjects/Board.cs @@ -308,5 +308,38 @@ namespace FLocal.Common.dataobjects { } } + public Thread CreateThread(User poster, string title, string body, int desiredLayerId) { + + int actualLayerId = Math.Max(poster.getMinAllowedLayer(this), desiredLayerId); + AbstractChange threadInsert = new InsertChange( + Thread.TableSpec.instance, + new Dictionary { + { Thread.TableSpec.FIELD_BOARDID, new ScalarFieldValue(this.id.ToString()) }, + { Thread.TableSpec.FIELD_ISANNOUNCEMENT, new ScalarFieldValue("0") }, + { Thread.TableSpec.FIELD_ISLOCKED, new ScalarFieldValue("0") }, + { Thread.TableSpec.FIELD_TITLE, new ScalarFieldValue(title) }, + { Thread.TableSpec.FIELD_TOPICSTARTERID, new ScalarFieldValue(poster.id.ToString()) }, + { Thread.TableSpec.FIELD_TOTALPOSTS, new ScalarFieldValue("0") }, + { Thread.TableSpec.FIELD_TOTALVIEWS, new ScalarFieldValue("0") }, + { Thread.TableSpec.FIELD_FIRSTPOSTID, new ScalarFieldValue(null) }, + { Thread.TableSpec.FIELD_LASTPOSTID, new ScalarFieldValue(null) }, + { Thread.TableSpec.FIELD_LASTPOSTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, + } + ); + + using(ChangeSet threadInsertSet = new ChangeSet(), dataInsertSet = new ChangeSet()) { + Config.Transactional(transaction => { + threadInsertSet.Add(threadInsert); + threadInsertSet.Apply(transaction); + foreach(AbstractChange change in Thread.getNewPostChanges(this, threadInsert.getId().Value, null, poster, actualLayerId, title, body).Value) { + dataInsertSet.Add(change); + } + dataInsertSet.Apply(transaction); + }); + } + + return Thread.LoadById(threadInsert.getId().Value); + } + } } diff --git a/Common/dataobjects/Post.cs b/Common/dataobjects/Post.cs index 5b04b65..b2b27af 100644 --- a/Common/dataobjects/Post.cs +++ b/Common/dataobjects/Post.cs @@ -108,7 +108,7 @@ namespace FLocal.Common.dataobjects { } public string bodyShort { get { - return this.body.Replace("
", Util.EOL).Substring(0, Math.Min(1000, this.body.IndexOf("<"))); + return this.body.Replace("
", Util.EOL).PHPSubstring(0, 1000); } } @@ -189,92 +189,11 @@ namespace FLocal.Common.dataobjects { } int actualLayerId = Math.Max(poster.getMinAllowedLayer(this.thread.board), desiredLayerId); - AbstractChange postInsert = new InsertChange( - TableSpec.instance, - new Dictionary { - { TableSpec.FIELD_THREADID, new ScalarFieldValue(this.thread.id.ToString()) }, - { TableSpec.FIELD_PARENTPOSTID, new ScalarFieldValue(this.id.ToString()) }, - { TableSpec.FIELD_POSTERID, new ScalarFieldValue(poster.id.ToString()) }, - { TableSpec.FIELD_POSTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, - { TableSpec.FIELD_REVISION, new ScalarFieldValue("0") }, - { TableSpec.FIELD_LASTCHANGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, - { TableSpec.FIELD_LAYERID, new ScalarFieldValue(layerId.ToString()) }, - { TableSpec.FIELD_TITLE, new ScalarFieldValue(title) }, - { TableSpec.FIELD_BODY, new ScalarFieldValue(UBBParser.UBBToIntermediate(body)) }, - } - ); - AbstractChange revisionInsert = new InsertChange( - RevisionTableSpec.instance, - new Dictionary { - { RevisionTableSpec.FIELD_POSTID, new ReferenceFieldValue(postInsert) }, - { RevisionTableSpec.FIELD_NUMBER, new ScalarFieldValue("0") }, - { RevisionTableSpec.FIELD_CHANGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, - { RevisionTableSpec.FIELD_TITLE, new ScalarFieldValue(title) }, - { RevisionTableSpec.FIELD_BODY, new ScalarFieldValue(body) }, - } - ); - AbstractChange threadUpdate = new UpdateChange( - Thread.TableSpec.instance, - new Dictionary { - { Thread.TableSpec.FIELD_LASTPOSTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, - { Thread.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() }, - { - Thread.TableSpec.FIELD_LASTPOSTID, - new TwoWayReferenceFieldValue( - postInsert, - (oldStringId, newStringId) => { - int oldId = int.Parse(oldStringId); - int newId = int.Parse(newStringId); - return Math.Max(oldId, newId).ToString(); - } - ) - } - }, - this.thread.id - ); - AbstractChange userUpdate = new UpdateChange( - User.TableSpec.instance, - new Dictionary { - { User.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() }, - }, - poster.id - ); - List changes = new List { - postInsert, - revisionInsert, - threadUpdate, - userUpdate, - }; - - int? boardId = thread.boardId; - do { - Board board = Board.LoadById(boardId.Value); - changes.Add( - new UpdateChange( - Board.TableSpec.instance, - new Dictionary { - { Board.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() }, - { - Board.TableSpec.FIELD_LASTPOSTID, - new TwoWayReferenceFieldValue( - postInsert, - (oldStringId, newStringId) => { - int oldId = int.Parse(oldStringId); - int newId = int.Parse(newStringId); - return Math.Max(oldId, newId).ToString(); - } - ) - } - }, - board.id - ) - ); - boardId = board.parentBoardId; - } while(boardId.HasValue); - ChangeSetUtil.ApplyChanges(changes.ToArray()); + var changes = Thread.getNewPostChanges(this.thread.board, this.threadId, this, poster, actualLayerId, title, body); + ChangeSetUtil.ApplyChanges(changes.Value.ToArray()); - return Post.LoadById(postInsert.getId().Value); + return Post.LoadById(changes.Key.getId().Value); } } diff --git a/Common/dataobjects/Thread.cs b/Common/dataobjects/Thread.cs index 20fd277..3f5e579 100644 --- a/Common/dataobjects/Thread.cs +++ b/Common/dataobjects/Thread.cs @@ -357,6 +357,111 @@ namespace FLocal.Common.dataobjects { }); } + internal static KeyValuePair> getNewPostChanges(Board board, int threadId, Post parentPost, User poster, int layerId, string title, string body) { + string parentPostId = null; + if(parentPost != null) parentPostId = parentPost.id.ToString(); + bool isNewThread = (parentPost == null); + AbstractChange postInsert = new InsertChange( + Post.TableSpec.instance, + new Dictionary { + { Post.TableSpec.FIELD_THREADID, new ScalarFieldValue(threadId.ToString()) }, + { Post.TableSpec.FIELD_PARENTPOSTID, new ScalarFieldValue(parentPostId) }, + { Post.TableSpec.FIELD_POSTERID, new ScalarFieldValue(poster.id.ToString()) }, + { Post.TableSpec.FIELD_POSTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, + { Post.TableSpec.FIELD_REVISION, new ScalarFieldValue("0") }, + { Post.TableSpec.FIELD_LASTCHANGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, + { Post.TableSpec.FIELD_LAYERID, new ScalarFieldValue(layerId.ToString()) }, + { Post.TableSpec.FIELD_TITLE, new ScalarFieldValue(title) }, + { Post.TableSpec.FIELD_BODY, new ScalarFieldValue(UBBParser.UBBToIntermediate(body)) }, + } + ); + AbstractChange revisionInsert = new InsertChange( + Post.RevisionTableSpec.instance, + new Dictionary { + { Post.RevisionTableSpec.FIELD_POSTID, new ReferenceFieldValue(postInsert) }, + { Post.RevisionTableSpec.FIELD_NUMBER, new ScalarFieldValue("0") }, + { Post.RevisionTableSpec.FIELD_CHANGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, + { Post.RevisionTableSpec.FIELD_TITLE, new ScalarFieldValue(title) }, + { Post.RevisionTableSpec.FIELD_BODY, new ScalarFieldValue(body) }, + } + ); + Dictionary threadData = new Dictionary { + { Thread.TableSpec.FIELD_LASTPOSTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, + { Thread.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() }, + { + Thread.TableSpec.FIELD_LASTPOSTID, + new TwoWayReferenceFieldValue( + postInsert, + (oldStringId, newStringId) => { + if((oldStringId == null) || (oldStringId == "")) { + return newStringId; + } + int oldId = int.Parse(oldStringId); + int newId = int.Parse(newStringId); + return Math.Max(oldId, newId).ToString(); + } + ) + } + }; + if(isNewThread) { + threadData[Thread.TableSpec.FIELD_FIRSTPOSTID] = new ReferenceFieldValue(postInsert); + } + AbstractChange threadUpdate = new UpdateChange( + Thread.TableSpec.instance, + threadData, + threadId + ); + AbstractChange userUpdate = new UpdateChange( + User.TableSpec.instance, + new Dictionary { + { User.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() }, + }, + poster.id + ); + List changes = new List { + postInsert, + revisionInsert, + threadUpdate, + userUpdate, + }; + + + Dictionary boardData = new Dictionary { + { Board.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() }, + { + Board.TableSpec.FIELD_LASTPOSTID, + new TwoWayReferenceFieldValue( + postInsert, + (oldStringId, newStringId) => { + if((oldStringId == null) || (oldStringId == "")) { + return newStringId; + } + int oldId = int.Parse(oldStringId); + int newId = int.Parse(newStringId); + return Math.Max(oldId, newId).ToString(); + } + ) + } + }; + if(isNewThread) { + boardData[Board.TableSpec.FIELD_TOTALTHREADS] = new IncrementFieldValue(); + } + int? boardId = board.id; + do { + Board _board = Board.LoadById(boardId.Value); + changes.Add( + new UpdateChange( + Board.TableSpec.instance, + boardData, + _board.id + ) + ); + boardId = _board.parentBoardId; + } while(boardId.HasValue); + + return new KeyValuePair>(postInsert, changes); + } + } } diff --git a/IISMainHandler/HandlersFactory.cs b/IISMainHandler/HandlersFactory.cs index 5e3c3e6..9714fd9 100644 --- a/IISMainHandler/HandlersFactory.cs +++ b/IISMainHandler/HandlersFactory.cs @@ -25,7 +25,18 @@ namespace FLocal.IISHandler { case "boards": return new handlers.BoardsHandler(); case "board": - return new handlers.BoardHandler(); + if(context.requestParts.Length < 2) { + return new handlers.WrongUrlHandler(); + } + if(context.requestParts.Length == 2) { + return new handlers.BoardHandler(); + } + switch(context.requestParts[2].ToLower()) { + case "newthread": + return new handlers.response.CreateThreadHandler(); + default: + return new handlers.WrongUrlHandler(); + } case "boardasthread": return new handlers.response.BoardAsThreadHandler(); case "thread": @@ -34,11 +45,14 @@ namespace FLocal.IISHandler { if(context.requestParts.Length < 2) { return new handlers.WrongUrlHandler(); } + if(context.requestParts.Length == 2) { + return new handlers.PostHandler(); + } switch(context.requestParts[2].ToLower()) { case "reply": return new handlers.response.ReplyHandler(); default: - return new handlers.PostHandler(); + return new handlers.WrongUrlHandler(); } case "login": return new handlers.response.LoginHandler(); @@ -77,6 +91,8 @@ namespace FLocal.IISHandler { return new handlers.request.MigrateAccountHandler(); case "reply": return new handlers.request.ReplyHandler(); + case "newthread": + return new handlers.request.CreateThreadHandler(); default: return new handlers.WrongUrlHandler(); } diff --git a/IISMainHandler/IISMainHandler.csproj b/IISMainHandler/IISMainHandler.csproj index 28ea5e3..8d1f8a5 100644 --- a/IISMainHandler/IISMainHandler.csproj +++ b/IISMainHandler/IISMainHandler.csproj @@ -67,6 +67,7 @@ + diff --git a/IISMainHandler/handlers/request/AbstractNewMessageHandler.cs b/IISMainHandler/handlers/request/AbstractNewMessageHandler.cs index e7b3b9e..9a976ea 100644 --- a/IISMainHandler/handlers/request/AbstractNewMessageHandler.cs +++ b/IISMainHandler/handlers/request/AbstractNewMessageHandler.cs @@ -7,6 +7,12 @@ using FLocal.Core; namespace FLocal.IISHandler.handlers.request { abstract class AbstractNewMessageHandler : AbstractPostHandler { + protected override string templateName { + get { + return "result/MessageCreated.xslt"; + } + } + protected string getTitle(WebContext context) { string title = context.httprequest.Form["title"].Trim(); if(title == "") { diff --git a/IISMainHandler/handlers/request/CreateThreadHandler.cs b/IISMainHandler/handlers/request/CreateThreadHandler.cs index 1d03ca1..ad5598b 100644 --- a/IISMainHandler/handlers/request/CreateThreadHandler.cs +++ b/IISMainHandler/handlers/request/CreateThreadHandler.cs @@ -3,18 +3,27 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; +using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.request { class CreateThreadHandler : AbstractNewMessageHandler { - protected override string templateName { - get { - throw new NotImplementedException(); - } - } - protected override XElement[] Do(WebContext context) { - throw new NotImplementedException(); + + Thread newThread = Board.LoadById( + int.Parse(context.httprequest.Form["board"]) + ).CreateThread( + context.session.account.user, + this.getTitle(context), + this.getBody(context), + int.Parse(context.httprequest.Form["layerId"]) + ); + + Post newPost = newThread.firstPost; + + newThread.markAsRead(context.session.account, newPost, newPost); + + return new XElement[] { newPost.exportToXmlWithoutThread(context, false) }; } } } diff --git a/IISMainHandler/handlers/request/ReplyHandler.cs b/IISMainHandler/handlers/request/ReplyHandler.cs index 50a4a36..fd23132 100644 --- a/IISMainHandler/handlers/request/ReplyHandler.cs +++ b/IISMainHandler/handlers/request/ReplyHandler.cs @@ -8,12 +8,6 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.request { class ReplyHandler : AbstractNewMessageHandler { - protected override string templateName { - get { - return "result/MessageCreated.xslt"; - } - } - protected override XElement[] Do(WebContext context) { // Post post = Post.LoadById(int.Parse(context.httprequest.Form["parent"])); //int desiredLayerId = Math.Min(context.session.account.user.getMinAllowedLayer(post.thread.board), int.Parse(context.httprequest.Form["layer"])); diff --git a/IISMainHandler/handlers/response/CreateThreadHandler.cs b/IISMainHandler/handlers/response/CreateThreadHandler.cs new file mode 100644 index 0000000..a39f637 --- /dev/null +++ b/IISMainHandler/handlers/response/CreateThreadHandler.cs @@ -0,0 +1,30 @@ +п»їusing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web; +using System.Xml.Linq; +using FLocal.Core; +using FLocal.Common; +using FLocal.Common.dataobjects; + +namespace FLocal.IISHandler.handlers.response { + + class CreateThreadHandler : AbstractGetHandler { + + override protected string templateName { + get { + return "NewThread.xslt"; + } + } + + override protected XElement[] getSpecificData(WebContext context) { + Board board = Board.LoadById(int.Parse(context.requestParts[1])); + + return new XElement[] { + board.exportToXml(context, false), + }; + } + } + +} \ No newline at end of file diff --git a/templates/Full/Board.xslt b/templates/Full/Board.xslt index a370b67..6c10931 100644 --- a/templates/Full/Board.xslt +++ b/templates/Full/Board.xslt @@ -21,6 +21,7 @@ + /Board//NewThread/ Новое сообщение Сообщение diff --git a/templates/Full/BoardAsThread.xslt b/templates/Full/BoardAsThread.xslt index 0a545bd..7395488 100644 --- a/templates/Full/BoardAsThread.xslt +++ b/templates/Full/BoardAsThread.xslt @@ -19,8 +19,9 @@ - Новое сообщение + /Board//NewThread/ + Новое сообщение Сообщение diff --git a/templates/Full/NewThread.xslt b/templates/Full/NewThread.xslt new file mode 100644 index 0000000..34ea165 --- /dev/null +++ b/templates/Full/NewThread.xslt @@ -0,0 +1,63 @@ + + + + + + + + + +
+ + + + + + + + + + +
+ Создание нового сообщения - Форум ( + + ) +
+ Заполните приведенную ниже форму для отправки сообщения в форум. HTML отключен. UBBCode включен, и вы можете использовать UBBCode в ваших сообщениях. Анонимные сообщения разрешены, и вы можете выбрать любое незарегистрированное имя. +
+
+ + + + Пользователь: + +
+
+ Тема: +
+ + Слой сообщения: + +
+
+ +
+ + Я хочу предварительно просмотреть сообщение перед отправкой +
+
+ + Проверить правописание +
+
+ + +
+
+
+ +
\ No newline at end of file diff --git a/templates/Full/PostReply.xslt b/templates/Full/PostReply.xslt index 2da3a4c..54c6994 100644 --- a/templates/Full/PostReply.xslt +++ b/templates/Full/PostReply.xslt @@ -33,7 +33,7 @@
- + @@ -54,11 +54,11 @@

- + Я хочу предварительно просмотреть сообщение перед отправкой

- + Проверить правописание