IPostParsingContext.OnUserMention implemented and used

main
Inga 🏳‍🌈 12 years ago
parent e9898a90d6
commit 7a59df325e
  1. 1
      FLocal.Common/BBCodes/User.cs
  2. 2
      FLocal.Common/BBCodes/helpers/IPostParsingContext.cs
  3. 8
      FLocal.Common/UBBParser.cs
  4. 6
      FLocal.Common/dataobjects/Post.cs
  5. 6
      FLocal.Common/dataobjects/Thread.cs
  6. 18
      FLocal.Common/helpers/DelegatePostParsingContext.cs

@ -13,6 +13,7 @@ namespace FLocal.Common.BBCodes {
public override string Format(IPostParsingContext context, ITextFormatter formatter) {
var user = dataobjects.User.LoadByName(this.DefaultOrValue);
context.OnUserMention(user);
var url = new URL.users.user.Info(user.id.ToString(), null);
return String.Format("<a class=\"separate UG_{0}\" href=\"{1}\">{2}</a>", this.Safe(user.userGroup.name), url.canonical, this.Safe(user.name));
}

@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.BBCodes {
public interface IPostParsingContext {
void OnUserMention(dataobjects.User user);
}
}

@ -161,18 +161,22 @@ namespace FLocal.Common {
}
public string ParseQuote(string input) {
string result = this.quotesParser.Parse(input).Format(new DelegatePostParsingContext(), this.simpleFormatter);
string result = this.quotesParser.Parse(input).Format(CreateStubContext(), this.simpleFormatter);
return result;
}
}
private static BBCodes.IPostParsingContext CreateStubContext() {
return new DelegatePostParsingContext(user => {});
}
public static string UBBToIntermediate(BBCodes.IPostParsingContext context, string UBB) {
return BBParserGateway.instance.Parse(context, UBB);
}
public static string UBBToIntermediate(string UBB) {
return UBBToIntermediate(new DelegatePostParsingContext(), UBB);
return UBBToIntermediate(CreateStubContext(), UBB);
}
public static string ShallerToUBB(string shaller) {

@ -8,6 +8,7 @@ using Web.Core.DB;
using Web.Core.DB.conditions;
using FLocal.Common;
using FLocal.Common.actions;
using FLocal.Common.helpers;
namespace FLocal.Common.dataobjects {
public class Post : SqlObject<Post> {
@ -337,7 +338,10 @@ namespace FLocal.Common.dataobjects {
if(parentPost != null && parentPost.poster.id != poster.id) {
newMentionedUsersIds.Add(parentPost.poster.id);
}
string newBodyIntermediate = UBBParser.UBBToIntermediate(newBody);
string newBodyIntermediate = UBBParser.UBBToIntermediate(
new DelegatePostParsingContext(mentionedUser => newMentionedUsersIds.Add(mentionedUser.id)),
newBody
);
List<AbstractChange> changes = new List<AbstractChange> {
new InsertChange(

@ -7,6 +7,7 @@ using Web.Core;
using Web.Core.DB;
using Web.Core.DB.conditions;
using FLocal.Common.actions;
using FLocal.Common.helpers;
namespace FLocal.Common.dataobjects {
public class Thread : SqlObject<Thread> {
@ -420,7 +421,10 @@ namespace FLocal.Common.dataobjects {
//dirty hack
bodyIntermediate = body;
} else {
bodyIntermediate = UBBParser.UBBToIntermediate(body);
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()) },

@ -3,9 +3,23 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Common.dataobjects;
using FLocal.Common.BBCodes;
namespace FLocal.Common.helpers {
class DelegatePostParsingContext : IPostParsingContext {
class DelegatePostParsingContext : BBCodes.IPostParsingContext {
private readonly Action<User> onUserMention;
public DelegatePostParsingContext(Action<User> onUserMention) {
this.onUserMention = onUserMention;
}
#region IPostParsingContext Members
public void OnUserMention(User user) {
this.onUserMention(user);
}
#endregion
}
}

Loading…
Cancel
Save