Ejemplo n.º 1
0
        override protected IEnumerable <XElement> getSpecificNewMessageData(WebContext context)
        {
            Post    post     = this.url.post;
            Account receiver = Account.LoadByUser(post.poster);

            if (receiver.needsMigration)
            {
                throw new ApplicationException("User is not migrated");
            }

            string quoted = context.httprequest.Form["data"];

            if (quoted != null)
            {
                quoted = quoted.Trim();
            }
            if (quoted == null || quoted == "")
            {
                if (post.revision.HasValue)
                {
                    quoted = UBBParser.StripQuotes(post.latestRevision.body).Trim();
                }
            }

            return(new XElement[] {
                new XElement("currentLocation", post.exportToXmlSimpleWithParent(context)),
                post.thread.board.exportToXml(context, Board.SubboardsOptions.None),
                post.thread.exportToXml(context),
                post.exportToXml(context),
                new XElement("receiver", receiver.exportToXml(context)),
                new XElement("quoted", quoted),
            });
        }
Ejemplo n.º 2
0
 public void UpdateData(UserData newData)
 {
     if (newData.location.Length > 30)
     {
         throw new FLocalException("Location is too long");
     }
     if (newData.title.Length > 30)
     {
         throw new FLocalException("Title is too long");
     }
     if (newData.signatureUbb.Length > 1024)
     {
         throw new FLocalException("Signature is too long");
     }
     ChangeSetUtil.ApplyChanges(
         new UpdateChange(
             TableSpec.instance,
             new Dictionary <string, AbstractFieldValue> {
         { TableSpec.FIELD_LOCATION, new ScalarFieldValue(newData.location) },
         { TableSpec.FIELD_TITLE, new ScalarFieldValue(newData.title) },
         { TableSpec.FIELD_BIOGRAPHYUBB, new ScalarFieldValue(newData.biographyUbb) },
         { TableSpec.FIELD_BIOGRAPHY, new ScalarFieldValue(UBBParser.UBBToIntermediate(newData.biographyUbb)) },
         { TableSpec.FIELD_SIGNATUREUBB, new ScalarFieldValue(newData.signatureUbb) },
         { TableSpec.FIELD_SIGNATURE, new ScalarFieldValue(UBBParser.UBBToIntermediate(newData.signatureUbb)) },
     },
             this.id
             )
         );
 }
Ejemplo n.º 3
0
        override protected IEnumerable <XElement> getSpecificNewMessageData(WebContext context)
        {
            Post post = this.url.post;

            string quoted = context.httprequest.Form["data"];

            if (quoted != null)
            {
                quoted = quoted.Trim();
            }
            if (quoted == null || quoted == "")
            {
                if (post.revision.HasValue)
                {
                    quoted = UBBParser.StripQuotes(post.latestRevision.body).Trim();
                }
            }

            return(new XElement[] {
                new XElement("currentLocation", post.exportToXmlSimpleWithParent(context)),
                post.thread.board.exportToXml(context, Board.SubboardsOptions.None),
                post.thread.exportToXml(context),
                post.exportToXml(context),
                post.thread.board.exportLayersInfoForUser(context),
                new XElement("quoted", quoted),
            });
        }
Ejemplo n.º 4
0
        public static Poll Create(User poster, bool isDetailed, bool isMultiOption, string titleUbb, List <string> optionsUbb)
        {
            List <XElement> options = new List <XElement>();

            for (int i = 0; i < optionsUbb.Count; i++)
            {
                options.Add(
                    new XElement(
                        "option",
                        new XAttribute("id", i + 1),
                        new XAttribute("name", UBBParser.UBBToIntermediate(optionsUbb[i]))
                        )
                    );
            }
            AbstractChange pollInsert = new InsertChange(
                TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { TableSpec.FIELD_ISDETAILED, new ScalarFieldValue(isDetailed ? "1" : "0") },
                { TableSpec.FIELD_ISMULTIOPTION, new ScalarFieldValue(isMultiOption ? "1" : "0") },
                { TableSpec.FIELD_POSTERID, new ScalarFieldValue(poster.id.ToString()) },
                { TableSpec.FIELD_POSTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
                { TableSpec.FIELD_TITLE, new ScalarFieldValue(UBBParser.UBBToIntermediate(titleUbb)) },
                { TableSpec.FIELD_OPTIONS, new ScalarFieldValue((new XElement("options", options)).ToString()) },
            }
                );

            ChangeSetUtil.ApplyChanges(pollInsert);
            return(Poll.LoadById(pollInsert.getId().Value));
        }
Ejemplo n.º 5
0
        override protected IEnumerable <XElement> getSpecificNewMessageData(WebContext context)
        {
            PMMessage message = this.url.pm;
            string    quoted  = UBBParser.StripQuotes(message.bodyUBB).Trim();

            return(new XElement[] {
                message.exportToXml(context),
                new XElement("quoted", quoted),
            });
        }
Ejemplo n.º 6
0
        public static PMMessage SendPMMessage(Account sender, Account receiver, string title, string bodyUBB)
        {
            string         bodyIntermediate = UBBParser.UBBToIntermediate(bodyUBB);
            AbstractChange insertPmReceiver = new InsertChange(
                PMMessage.TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { PMMessage.TableSpec.FIELD_OWNERID, new ScalarFieldValue(receiver.id.ToString()) },
                { PMMessage.TableSpec.FIELD_INTERLOCUTORID, new ScalarFieldValue(sender.id.ToString()) },
                { PMMessage.TableSpec.FIELD_DIRECTION, new ScalarFieldValue(PMMessage.ENUM_DIRECTION_INCOMING) },
                { PMMessage.TableSpec.FIELD_POSTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
                { PMMessage.TableSpec.FIELD_TITLE, new ScalarFieldValue(title) },
                { PMMessage.TableSpec.FIELD_BODY, new ScalarFieldValue(bodyIntermediate) },
                { PMMessage.TableSpec.FIELD_BODYUBB, new ScalarFieldValue(bodyUBB) },
                { PMMessage.TableSpec.FIELD_INCOMINGPMID, new ScalarFieldValue(null) },
                { PMMessage.TableSpec.FIELD_ISREAD, new ScalarFieldValue("0") },
            }
                );
            AbstractChange insertPmSender = new InsertChange(
                PMMessage.TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { PMMessage.TableSpec.FIELD_OWNERID, new ScalarFieldValue(sender.id.ToString()) },
                { PMMessage.TableSpec.FIELD_INTERLOCUTORID, new ScalarFieldValue(receiver.id.ToString()) },
                { PMMessage.TableSpec.FIELD_DIRECTION, new ScalarFieldValue(PMMessage.ENUM_DIRECTION_OUTGOING) },
                { PMMessage.TableSpec.FIELD_POSTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
                { PMMessage.TableSpec.FIELD_TITLE, new ScalarFieldValue(title) },
                { PMMessage.TableSpec.FIELD_BODY, new ScalarFieldValue(bodyIntermediate) },
                { PMMessage.TableSpec.FIELD_BODYUBB, new ScalarFieldValue(bodyUBB) },
                { PMMessage.TableSpec.FIELD_INCOMINGPMID, new ReferenceFieldValue(insertPmReceiver) },
                { PMMessage.TableSpec.FIELD_ISREAD, new ScalarFieldValue("1") },
            }
                );
            AbstractChange updateConversationSender = new InsertOrUpdateChange(
                TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { TableSpec.FIELD_OWNERID, new ScalarFieldValue(sender.id.ToString()) },
                { TableSpec.FIELD_INTERLOCUTORID, new ScalarFieldValue(receiver.id.ToString()) },
                { TableSpec.FIELD_TOTALMESSAGES, new ScalarFieldValue("1") },
                { TableSpec.FIELD_LASTMESSAGEID, new ReferenceFieldValue(insertPmSender) },
                { TableSpec.FIELD_LASTMESSAGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
                { TableSpec.FIELD_LASTREADMESSAGEID, new ReferenceFieldValue(insertPmSender) },
            },
                new Dictionary <string, AbstractFieldValue> {
                { TableSpec.FIELD_TOTALMESSAGES, new IncrementFieldValue() },
                { TableSpec.FIELD_LASTMESSAGEID, new TwoWayReferenceFieldValue(insertPmSender, TwoWayReferenceFieldValue.GREATEST) },
                { TableSpec.FIELD_LASTMESSAGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
            },
                new ComplexCondition(
                    ConditionsJoinType.AND,
                    new ComparisonCondition(
                        TableSpec.instance.getColumnSpec(TableSpec.FIELD_OWNERID),
                        ComparisonType.EQUAL,
                        sender.id.ToString()
                        ),
                    new ComparisonCondition(
                        TableSpec.instance.getColumnSpec(TableSpec.FIELD_INTERLOCUTORID),
                        ComparisonType.EQUAL,
                        receiver.id.ToString()
                        )
                    )
                );
            AbstractChange updateConversationReceiver = new InsertOrUpdateChange(
                TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { TableSpec.FIELD_OWNERID, new ScalarFieldValue(receiver.id.ToString()) },
                { TableSpec.FIELD_INTERLOCUTORID, new ScalarFieldValue(sender.id.ToString()) },
                { TableSpec.FIELD_TOTALMESSAGES, new ScalarFieldValue("1") },
                { TableSpec.FIELD_LASTMESSAGEID, new ReferenceFieldValue(insertPmReceiver) },
                { TableSpec.FIELD_LASTMESSAGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
                { TableSpec.FIELD_LASTREADMESSAGEID, new ScalarFieldValue(null) },
            },
                new Dictionary <string, AbstractFieldValue> {
                { TableSpec.FIELD_TOTALMESSAGES, new IncrementFieldValue() },
                { TableSpec.FIELD_LASTMESSAGEID, new TwoWayReferenceFieldValue(insertPmReceiver, TwoWayReferenceFieldValue.GREATEST) },
                { TableSpec.FIELD_LASTMESSAGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
            },
                new ComplexCondition(
                    ConditionsJoinType.AND,
                    new ComparisonCondition(
                        TableSpec.instance.getColumnSpec(TableSpec.FIELD_OWNERID),
                        ComparisonType.EQUAL,
                        receiver.id.ToString()
                        ),
                    new ComparisonCondition(
                        TableSpec.instance.getColumnSpec(TableSpec.FIELD_INTERLOCUTORID),
                        ComparisonType.EQUAL,
                        sender.id.ToString()
                        )
                    )
                );
            AbstractChange updateIndicatorReceiver = new UpdateChange(
                AccountIndicator.TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { AccountIndicator.TableSpec.FIELD_PRIVATEMESSAGES, new IncrementFieldValue() },
                { AccountIndicator.TableSpec.FIELD_UNREADPRIVATEMESSAGES, new IncrementFieldValue() },
            },
                AccountIndicator.LoadByAccount(receiver).id
                );

            ChangeSetUtil.ApplyChanges(
                insertPmReceiver,
                insertPmSender,
                updateConversationReceiver,
                updateConversationSender,
                updateIndicatorReceiver
                );
            return(PMMessage.LoadById(insertPmSender.getId().Value));
        }
Ejemplo n.º 7
0
        internal static KeyValuePair <AbstractChange, IEnumerable <AbstractChange> > getNewPostChanges(Board board, int threadId, Post parentPost, User poster, PostLayer layer, string title, string body, DateTime date, int?forcedPostId)
        {
            string parentPostId = null;

            if (parentPost != null)
            {
                parentPostId = parentPost.id.ToString();
            }
            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;

            if (forcedPostId.HasValue)
            {
                //dirty hack
                bodyIntermediate = body;
            }
            else
            {
                bodyIntermediate = UBBParser.UBBToIntermediate(
                    new DelegatePostParsingContext(mentionedUser => mentionedUsersIds.Add(mentionedUser.id)),
                    body
                    );
            }
            var postInsertData = new Dictionary <string, AbstractFieldValue> {
                { 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(date.ToUTCString()) },
                //{ Post.TableSpec.FIELD_REVISION, new ScalarFieldValue("0") },
                { Post.TableSpec.FIELD_LASTCHANGEDATE, new ScalarFieldValue(date.ToUTCString()) },
                { Post.TableSpec.FIELD_LAYERID, new ScalarFieldValue(layer.id.ToString()) },
                { Post.TableSpec.FIELD_TITLE, new ScalarFieldValue(title) },
                { Post.TableSpec.FIELD_BODY, new ScalarFieldValue(bodyIntermediate) },
                { Post.TableSpec.FIELD_TOTALPUNISHMENTS, new ScalarFieldValue("0") },
            };

            if (!forcedPostId.HasValue)
            {
                postInsertData[Post.TableSpec.FIELD_REVISION] = new ScalarFieldValue("0");
            }
            else
            {
                postInsertData[Post.TableSpec.FIELD_ID] = new ScalarFieldValue(forcedPostId.Value.ToString());
            }
            AbstractChange postInsert = new InsertChange(
                Post.TableSpec.instance,
                postInsertData
                );
            AbstractFieldValue postReference      = new ReferenceFieldValue(postInsert);
            AbstractFieldValue postIndexReference = new TwoWayReferenceFieldValue(postInsert, TwoWayReferenceFieldValue.GREATEST);
            AbstractChange     revisionInsert     = new InsertChange(
                Revision.TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { Revision.TableSpec.FIELD_POSTID, postReference },
                { Revision.TableSpec.FIELD_NUMBER, new ScalarFieldValue("0") },
                { Revision.TableSpec.FIELD_CHANGEDATE, new ScalarFieldValue(date.ToUTCString()) },
                { Revision.TableSpec.FIELD_TITLE, new ScalarFieldValue(title) },
                { Revision.TableSpec.FIELD_BODY, new ScalarFieldValue(body) },
            }
                );
            Dictionary <string, AbstractFieldValue> threadData = new Dictionary <string, AbstractFieldValue> {
                { Thread.TableSpec.FIELD_LASTPOSTDATE, new ScalarFieldValue(date.ToUTCString()) },
                { Thread.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() },
                {
                    Thread.TableSpec.FIELD_LASTPOSTID,
                    postIndexReference
                }
            };

            if (isNewThread)
            {
                threadData[Thread.TableSpec.FIELD_FIRSTPOSTID] = postReference;
            }
            AbstractChange threadUpdate = new UpdateChange(
                Thread.TableSpec.instance,
                threadData,
                threadId
                );
            AbstractChange userUpdate = new UpdateChange(
                User.TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { User.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() },
            },
                poster.id
                );

            List <AbstractChange> changes = new List <AbstractChange>();

            changes.Add(postInsert);
            if (!forcedPostId.HasValue)
            {
                //dirty hack
                changes.Add(revisionInsert);
            }
            changes.Add(threadUpdate);
            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> {
                { Board.TableSpec.FIELD_TOTALPOSTS, new IncrementFieldValue() },
                {
                    Board.TableSpec.FIELD_LASTPOSTID,
                    postIndexReference
                }
            };

            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 <AbstractChange, IEnumerable <AbstractChange> >(postInsert, changes));
        }
Ejemplo n.º 8
0
        protected override IEnumerable <XElement> getSpecificData(WebContext context)
        {
            var result = new List <XElement>();

            if (context.httprequest.Form.AllKeys.Contains("title"))
            {
                result.Add(new XElement("newTitle", context.httprequest.Form["title"]));
            }
            if (context.httprequest.Form.AllKeys.Contains("Body"))
            {
                result.Add(new XElement("bodyUBB", context.httprequest.Form["Body"]));
                result.Add(new XElement("bodyIntermediate", context.outputParams.preprocessBodyIntermediate(UBBParser.UBBToIntermediate(context.httprequest.Form["Body"]))));
            }
            return(result.Concat(this.getSpecificNewMessageData(context)));
        }
Ejemplo n.º 9
0
        private readonly object Edit_locker = new object();         //TODO: move locking to DB
        public void Edit(User user, string newTitle, string newBody, PostLayer newDesiredLayer)
        {
            if (this.poster.id != user.id)
            {
                throw new AccessDeniedException();
            }
            PostLayer actualLayer = poster.getActualLayer(this.thread.board, newDesiredLayer);

            if (actualLayer.id < this.layer.id)
            {
                actualLayer = this.layer;
            }
            lock (this.Edit_locker) {
                DateTime date = DateTime.Now;

                HashSet <int> newMentionedUsersIds = new HashSet <int>();
                if (this.parentPostId != null && this.parentPost.poster.id != this.poster.id)
                {
                    newMentionedUsersIds.Add(this.parentPost.poster.id);
                }
                string newBodyIntermediate = UBBParser.UBBToIntermediate(
                    new DelegatePostParsingContext(mentionedUser => newMentionedUsersIds.Add(mentionedUser.id)),
                    newBody
                    );

                List <AbstractChange> changes = new List <AbstractChange> {
                    new InsertChange(
                        Revision.TableSpec.instance,
                        new Dictionary <string, AbstractFieldValue> {
                        { Revision.TableSpec.FIELD_POSTID, new ScalarFieldValue(this.id.ToString()) },
                        { Revision.TableSpec.FIELD_CHANGEDATE, new ScalarFieldValue(date.ToUTCString()) },
                        { Revision.TableSpec.FIELD_TITLE, new ScalarFieldValue(newTitle) },
                        { Revision.TableSpec.FIELD_BODY, new ScalarFieldValue(newBody) },
                        { Revision.TableSpec.FIELD_NUMBER, new ScalarFieldValue((this.revision + 1).ToString()) },
                    }
                        ),
                    new UpdateChange(
                        TableSpec.instance,
                        new Dictionary <string, AbstractFieldValue> {
                        { TableSpec.FIELD_TITLE, new ScalarFieldValue(newTitle) },
                        { TableSpec.FIELD_BODY, new ScalarFieldValue(newBodyIntermediate) },
                        { TableSpec.FIELD_LASTCHANGEDATE, new ScalarFieldValue(date.ToUTCString()) },
                        { TableSpec.FIELD_REVISION, new IncrementFieldValue() },
                        { TableSpec.FIELD_LAYERID, new ScalarFieldValue(actualLayer.id.ToString()) },
                    },
                        this.id
                        )
                };
                if (this.thread.firstPost.id == this.id)
                {
                    changes.Add(
                        new UpdateChange(
                            Thread.TableSpec.instance,
                            new Dictionary <string, AbstractFieldValue> {
                        { TableSpec.FIELD_TITLE, new ScalarFieldValue(newTitle) },
                    },
                            this.thread.id
                            )
                        );
                }
                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());
            }
        }