Wedge

Public area => The Pub => Plugins => Topic started by: Dragooon on March 8th, 2013, 09:03 PM

Title: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 8th, 2013, 09:03 PM
ID: Dragooon:WeMentions
Version: 1.0
GitHub: http://github.com/Dragooon/WeMentions
License: New BSD
Requires: Dragooon:WeNotif
Permissions declared: mention_member
BBCodes declared: @

This is actually the first thing I thought when I was making the notification system, but I waited till the core was complete enough. So here it is, allows a user to mention another one via @username which then sends a notification. I took a bit of inspiration from XenForo's [bd] Tag Me plugin for some of the behaviour quirks that I couldn't decide upon.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on March 8th, 2013, 09:49 PM
Awesome :)
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 8th, 2013, 09:55 PM
Quote from Arantor on March 8th, 2013, 09:49 PM
Awesome :)
And thanks to you as well for the playground :)
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Nao on March 8th, 2013, 09:59 PM
Interesting!

Are these all stable enough to be installed here, at least for 'testing'...?
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 8th, 2013, 10:06 PM
Quote from Nao on March 8th, 2013, 09:59 PM
Interesting!

Are these all stable enough to be installed here, at least for 'testing'...?
Hopefully within a week, a couple of things are left in the core.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on March 8th, 2013, 10:09 PM
/medoes the 'core feature' chant...
...once we figure out where to put it to give it due prominence.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 9th, 2013, 06:45 AM
Pretty sure we can figure out a convenient way to include this in core. Just because its in core doesn't mean it has to be in sources folder, it can be a core plugin. IMO that gives the user more options which is a good thing.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on March 9th, 2013, 01:34 PM
I see that as being a great way to generate support requests if experience Is anything to go by, e.g. SMF "Core Features"
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 9th, 2013, 01:36 PM
Well fair enough, what do you suggest? Entirely including it in core?
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on March 9th, 2013, 01:40 PM
Ideally, yes. Probably even enabled by default if I'm honest. The feature is a big draw for some and given the "only triggers on @" there's not even a performance concern.

Interesting question, what would happen with the above sentence as typed?
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 9th, 2013, 01:45 PM
Quote from Arantor on March 9th, 2013, 01:40 PM
Ideally, yes. Probably even enabled by default if I'm honest. The feature is a big draw for some and given the "only triggers on @" there's not even a performance concern.

Interesting question, what would happen with the above sentence as typed?
Nothing, it'll search for " as an username on the server side (probably not even that since I don't think the regex will match it as a valid username[1]), find nothing and leave it alone. So will the JS interface (shouldn't even do a request since technically the username is less than three characters long).

If this goes in by default, so does the notification core. I don't mind it being in by default and enabled (i'd actually love that), as long as I can keep my GH repository. So if it gets a svn:external with a special status as a "core plugin" or something so that the UI can be simplified, I don't have a problem.
 1. currently I'm using /\@(\w+)/ (I'm not a regex expert, this'll probably fail on a few valid usernames)
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on March 9th, 2013, 02:08 PM
\w+ shouldn't match the ", but if you're doing that on the client side it should be fine.

(It is more of an issue on the server side because all display names and usernames are all pushed through htmlspecialchars first)


Regarding core vs not core, I found through bad experience that 'core plugins' do not work that well from a user perspective. They embody everything that is wrong with Core Features: having to go to an unrelated page that was convenient for the developers to just grab everything together, and it is a proven cause of support requests. Not that there won't be support requests anyway but at least some people will use search and just straight up exploration to find it otherwise.

I'd rather either have it totally as a plugin, or fully core, I don't see that any intermediate measure suits anyone but us from a purely convenient point of view.

I would love to see both this and the notifications core being core features and completely integrated. Seems to me that might be faster?
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 9th, 2013, 02:16 PM
Quote
\w+ shouldn't match the ", but if you're doing that on the client side it should be fine.

(It is more of an issue on the server side because all display names and usernames are all pushed through htmlspecialchars first)
No, I'm doing that on the server side. On the client side it's is from @ till the first whitespace.
Quote
Regarding core vs not core, I found through bad experience that 'core plugins' do not work that well from a user perspective. They embody everything that is wrong with Core Features: having to go to an unrelated page that was convenient for the developers to just grab everything together, and it is a proven cause of support requests. Not that there won't be support requests anyway but at least some people will use search and just straight up exploration to find it otherwise.

I'd rather either have it totally as a plugin, or fully core, I don't see that any intermediate measure suits anyone but us from a purely convenient point of view.

I would love to see both this and the notifications core being core features and completely integrated. Seems to me that might be faster?
Definitely wouldn't make much of a difference on speed, maybe through saving a bunch of call_hook hoops and perhaps one little query, but that's more or less about it (I've tried to keep the footprint as low as I can, so it doesn't leave me much scope either way). So it's merely a semantic choice. Plugin gives me the ability to independently work on it without having you to go through legal hoops (DCO, CLA etc.) for me and I get to maintain my GitHub repository (this is actually the only major factor stopping me). Perhaps a plugin distributed in core and enabled by default? That way it's a totally core plugin?
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 9th, 2013, 02:27 PM
Actually mentions would fail absolutely miserably for usernames with a space, I gotta figure something out for this.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: godboko71 on March 9th, 2013, 04:52 PM
I would like this default :) Nice work!
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 9th, 2013, 06:11 PM
Quote from Dragooon on March 9th, 2013, 02:27 PM
Actually mentions would fail absolutely miserably for usernames with a space, I gotta figure something out for this.
Okay, fixed this part. Had to make the whole name matching thing a bit slower and quite more complicated, but it's quite robust now. Since this only happens after a post is created, a bit of a performance hit shouldn't matter much (documented my algorithm on the function's docblock if anyone's interested).
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 9th, 2013, 09:54 PM
And I ran into even more issues, names with punctuations would work but what if someone does "@Nao: Would it work?", the colon would screw it up and it'll be an even bigger pain (and this happens fairly commonly in forums). So I decided to split the strings up even further, instead of splitting by spaces it now splits by everything that's not a alphanumeric character (regex \w boundary) and maks combinations like first part, first and second part, first, second and third part and so on. A stupid (and improbable) sentence like
Code: [Select]
@Admin: This is perhaps a crude test, but how would @Maxwel do for the later project? I'm not entire sure if this'll work like the way it's supposed to.
@Maxwel: What do you think of the project itself? Care to elaborate on your findings? Perhaps add another prospect given by @Trish to @Soxell?
What about @-Lük-? How would this really work? Would it work? Or would it not work? Does't it require a massive amount of overhead for bear that shouldn't be born?
generates 66 combinations in about 20ms, which is then queried against real_name in members table. It's definitely a hit on performance but shouldn't be by much.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on March 9th, 2013, 10:53 PM
Suggestion: take the first part, htmlspecialchars it then query members LIKE 'firstpart%', then sift the results post-query. It may be faster for the worst case scenarios.

Also, I'm thinking there's a bug in the flexbox on Chrome. I'll post a screenshot shortly.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 10th, 2013, 05:40 AM
I thought of that but wouldn't it be slower? 6 LIKES vs 66 elements in an IN statement.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on March 10th, 2013, 05:59 AM
Well, that's where it gets complicated. column IN (value1, value2, value3) ultimately parses as (column = value1 OR column = value2 OR column = value3), which is not efficient.

Now, there is an index on real_name, but I'm not sure how useful the index will be. Create a table with 1000 rows in it and try the 66 permutations on it with an EXPLAIN on the query to see how that ultimately parses out, but I'd be willing to bet it probably will be Using where, not Using index. If it's Using where, it's going to be table scanning anyway just as it would with a LIKE, bearing in mind you only need to do a like against the first part if I've understood you correctly.

If in doubt, try it and benchmark it. I'm only guessing based on what's been described thus far, but I wouldn't expect the index to be that useful.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 10th, 2013, 06:11 AM
I'll do some benchmarking on Monday or Tuesday, until then I'm leaving it as is. Its working fine atleast.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on March 10th, 2013, 04:26 PM
If it's working, that's all good :)
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 11th, 2013, 10:12 AM
Looks like the index is kicking in?

Code: (EXPLAIN) [Select]
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: smf_gallery_members
         type: range
possible_keys: real_name
          key: real_name
      key_len: 767
          ref: NULL
         rows: 44
        Extra: Using where*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: smf_gallery_members
         type: range
possible_keys: real_name
          key: real_name
      key_len: 767
          ref: NULL
         rows: 44
        Extra: Using where*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: smf_gallery_members
         type: range
possible_keys: real_name
          key: real_name
      key_len: 767
          ref: NULL
         rows: 44
        Extra: Using where*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: smf_gallery_members
         type: range
possible_keys: real_name
          key: real_name
      key_len: 767
          ref: NULL
         rows: 44
        Extra: Using where*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: smf_gallery_members
         type: range
possible_keys: real_name
          key: real_name
      key_len: 767
          ref: NULL
         rows: 44
        Extra: Using where

EDIT: This is actually on a SMF's member table with ~22k records, but I don't think that should make a difference
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on March 11th, 2013, 02:02 PM
I only dread how big the index is going to be for that table (since the index size is 3/4 of a KB PER ROW), but it's still relying primarily on the where to sift.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on March 11th, 2013, 03:35 PM
Index is about 1/3rd of the table itself, members has a lot of them
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Nao on April 4th, 2013, 09:14 AM
Thought I should mention... (Ah, ah.)
(Where do I post my updated files anyway..?)

Yesterday I fixed the silly bug where doing @Nao on a single line without any other punctuation would fail to 'detect' it.
For the record: it was due to the strip_tags call. It can be called, but it should add an exception parameter of '<br>'. Otherwise, multiple lines are put together without any separator, and you know what that means... Something like @NaoSecond line.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: agent47 on April 4th, 2013, 09:35 AM
This is so so awesome man! You have no idea how many times I've wanted to this on forums. So cool @Dragooon
Although I do have a couple of questions; do you plan on making this work on 'quick reply' too or does that complicate things?
Plus I also noticed that upon mentioning usernames, it seems to be duplicating entries on the ajax drop-down list.
Also, what happens when a members' real name/username differs from his/her display name? (Is that what causes the duplicate entries; one's the real name/username and the other is the display name?)
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Nao on April 4th, 2013, 11:00 AM
Didn't you notice earlier...? It's been installed for a couple of weeks at least...

Also, now there's this strange bug where I actually get a proper reference when doing @NaoSecond..?! Shouldn't it be ignored..?

Yes, I plan to have it work on quick reply, too, but I won't make any promises. The problem is mostly with loading extra files on topic load, which is always annoying. (I'm considering loading these scripts only when first clicking Quick Reply, though...)

Only the display name is taken into account. That's how Dragooon programmed it, and I don't have plans to change it.
The only place where you can see a user name (login) anyway is in the profile page...
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on April 4th, 2013, 11:06 AM
Quote from Nao on April 4th, 2013, 09:14 AM
Thought I should mention... (Ah, ah.)
(Where do I post my updated files anyway..?)

Yesterday I fixed the silly bug where doing @Nao on a single line without any other punctuation would fail to 'detect' it.
For the record: it was due to the strip_tags call. It can be called, but it should add an exception parameter of '<br>'. Otherwise, multiple lines are put together without any separator, and you know what that means... Something like @NaoSecond line.
@Nao I have no idea how that got triggered, but if you'd notice my previous post I had fixed this bug about a week ago (along with a couple others), they're in my repository. You can post a diff if they're something more than that bug fix and I'll add them into my repository.
Posted: April 4th, 2013, 11:03 AM

Oh and is markReadForNotifier disabled for this site? It isn't marking my notifications as read when I view this topic.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Nao on April 4th, 2013, 11:08 AM
Well, looks like it's working now, without changes... Something like @NaoSecond line.

Ah, your git repo... I don't tend to visit github often... :whistle:

Right now, I'm fighting with my caret position hack for your mentions popup. It's... quite interesting. I dunno why, this morning I decided I wanted to have it pixel perfect, and still überfast. I managed to do it, but then I realized my pixel-perfect code issues were mostly down to errors on my side, hmm...
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on April 4th, 2013, 11:11 AM
Heh, for my curiosity, what changes do you have in my mentions plug in apart from the Ui? Also,
Quote
Oh and is markReadForNotifier disabled for this site? It isn't marking my notifications as read when I view this topic.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Nao on April 4th, 2013, 12:14 PM
Err... I don't remember exactly... Not that many, though..?
I mostly tore the JS apart and added the avatar stuff.

And mark read is disabled, yes. On wedge.org only though. For tests.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Nao on April 4th, 2013, 07:26 PM
Notifications popup updated... It's a bit better now.
It's using the same template as on the notifications page, with a few minor modifications.
Also, everything is now pulled through Ajax (HTML included), so it makes for a shorter HTML container and JS file as well. (About 80 bytes saved in JS, dunno for HTML but it's all right too.)

I'm very close to being able to commit... Hopefully tomorrow. Then I'll just have to merge Dragooon's changes ;)

Which reminds me: id_member_notified sounds a bit strange... Instead of "ID of member who notified you", it implies to me "ID of member to be notified"... Wouldn't it be better to use something like 'id_issuer' or 'id_member_from'...?
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Nao on April 4th, 2013, 10:47 PM
Uploaded another version, which will excite @Dragooon because now the popup will only show unread items ;)
I also added a limit of 10 items in the popup, it's totally arbitrary though, maybe it should be higher..? Or unlimited?

There are also a few bugs in this version, but I don't have time to work on them tonight, so it'll have to wait, sorry. :)
Design is also still a WIP...

PS: everybody please like this post, so I can get some 'easy to remove' notifications... Thanks ;)
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: MultiformeIngegno on April 5th, 2013, 12:51 AM
What about read notifications greyed?
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on April 5th, 2013, 06:45 AM
Couple of things, I got mention notification in french. Although I should probably use email template but I'm not sure if that'll fix this problem. Secondly, the email is bloody useless as it is :P, I need to seriously improve it.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: live627 on April 5th, 2013, 06:59 AM
Quote
Although I should probably use email template but I'm not sure if that'll fix this problem.
No, won't  fix. Check the mailer for PMs. Gotta juggle languages manually.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on April 5th, 2013, 04:39 PM
The mailer for PMs is separate to loadEmailTemplate, and you can pass a language to it specifically for it to load if you so wish.

However if you have big batches to run, you would be strongly advised to batch them by language wherever possible.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on April 5th, 2013, 04:45 PM
Okay, I'll look into improving this. I'm not entirely sure how to handle Email templates here especially given the amount of notificaiton plugins.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on April 5th, 2013, 04:50 PM
I need to figure out how plugins and email templates in general should work ;)
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on April 5th, 2013, 04:52 PM
Quote from Arantor on April 5th, 2013, 04:50 PM
I need to figure out how plugins and email templates in general should work ;)
Well in that case I'll wait till then :P
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Nao on April 6th, 2013, 01:46 PM
Quote from MultiformeIngegno on April 5th, 2013, 12:51 AM
What about read notifications greyed?
They used to be shown and greyed out, yes. What exactly are you trying to say..?

The only reason I kept showing them in the popup was because I wanted to always have notifications in there for me to style the damn thing... :P Other than that, it probably makes more sense to have a separate page for all notifications, and a popup for unread ones.

Or did you prefer the 'all' solution...?
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on April 6th, 2013, 01:56 PM
Well I obviously prefer the current solution, but don't mind either way. As long as the unread ones are on the top.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: MultiformeIngegno on April 6th, 2013, 03:27 PM
Uhm I think I'd be fine with both solutions.. maybe the "all" solution with read notifs grayed/smaller is more common..
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on June 3rd, 2013, 10:04 AM
@Nao: Okay I can see you uploaded the mentions plugin but since it's not completely BSD anymore I can't merge the changes back to my GitHub repository, and I can't distribute it either. So...what happens now?
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on June 3rd, 2013, 02:28 PM
And this is where it gets thoroughly ugly :(
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Nao on June 3rd, 2013, 02:30 PM
Well I did say I uploaded it to satisfy your curiosity. And if you want to improve it even more. You have svn access on plugins, don't you..?

May I ask what the point of putting it on github is? It can only be used in Wedge... ^^
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on June 3rd, 2013, 03:03 PM
Quote from Nao on June 3rd, 2013, 02:30 PM
Well I did say I uploaded it to satisfy your curiosity. And if you want to improve it even more. You have svn access on plugins, don't you..?

May I ask what the point of putting it on github is? It can only be used in Wedge... ^^
Because all my repositories on GitHub, and I've always said I prefer for my plugins to be on GitHub. Plus my question was more towards me redistributing the plugin, I don't essentially mind it not being on github, it's just a preference. And I don't think I have commit access to the plugin repository? Plus if I start using SVN i'll be using git-svn and then I'll bombard with a lot of small commits.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on June 3rd, 2013, 10:45 PM
I hate licensing issues :(

On happier news, XenForo has added something similar to their core in 1.2. There are two key differences that I see... firstly they handle spaces (can't remember if we do or not, though I seem to remember talking about it)

Secondly, and this is more of a matter for @Nao: the auto suggester in XF also includes the user profile alongside the user name. Is this something we want to consider?

Thirdly, they don't worry quite so much about positioning for the suggester popup for mention purposes. It seems to align to the left of the window on the row directly below the cursor's current position. But they're now using Redactor rather than TinyMCE. It's much lighter than TMCE but I think it's still bigger than what we have - but it's probably a bit more reliable.

/methinks we really need to spend time with the WYSIWYG editor to make it a viable competitor... there is a reason everyone else uses off the shelf components (XF = Redactor, IPB = CKEditor, WordPress = TinyMCE, vB = CKEditor)
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Dragooon on June 4th, 2013, 06:08 AM
We handle spaces. So we're good there.
Title: Re: [Plugin] User Mentions v1.0 (9th March 2013)
Post by: Arantor on June 4th, 2013, 06:11 AM
Sweet. So then it's just about the display of avatars in the auto suggester, which would be awesome.