Mention Users with @ Download 1.9.1

This component/theme doesn't work with the latest OSSN version.
5.0
us bryce alvord 5 years ago

OSSN MENTION USERS COMPONENT

This component enables a user to mention other users in posts and comments by using the syntax @Full Name or conditionally @username and that will send the mentioned user a notification telling them that they were mentioned in a post or comment with a link to that item.

This can be used in conjunction with the Display Username component as of v1.2 if you want to display usernames and mention @username instead of display Full Name and mention @Full Name. It will dynamically switch based whether or not the Display Username component is installed and turned on. You can find more info on it here: https://www.opensource-socialnetwork.org/component/view/3065/display-username

  • When mentioning usernames using the Display Username component the exact casing must be used to match the user.

  • When mentioning user full names the casing DOES matter as that can help find uniqueness.

  • Mentions are not limited to the friends of the user, the entire user base can be mentioned

  • Multiple mentions can be done in a post or comment.

CHANGE LOG
-------------------1.9.1------------------

  • Added ability to parse off trailing '(apostrophe) and 's for use in plurals and ownership

  • Added recommended method and hooks from Z-Man

-------------------1.9--------------------

  • Added 'ossn:notifications:mention:post:created' to en locale

  • Added 'ossn:notifications:mention:comment:created' to en locale

  • Renamed init method from basic name to prevent potential collision with other components

POSSIBLE ENHANCEMENTS

  • No UI based on prototype having significant cons

  • ?

Comments
us Bryce alvord Replied 5 years ago

I think I got some of the scenarios solved so let me know what you think of 1.6. The tests all pass that failed earlier

us Bryce alvord Replied 5 years ago

Well this should be fun...

German Michael Zülsdorff Replied 5 years ago

Yep, it'll be tricky. And: Have in mind you might run into names like Robert B. Meyer. 🤧

us Bryce alvord Replied 5 years ago

Got it, thanks for the explanation, I was way off track lol. I will have 1.6 uploaded tonight. The toughest part time wise after work will be to get the regex knocked out for the punctuation and line feeds. Im kind of thinking that a NOT a-Z0-9 kind of thing is going to be better than trying to list out invalid characters to trim off

German Michael Zülsdorff Replied 5 years ago

You wrote:

   public function GetComments($subject, $type = 'post') {
                $vars                 = array();
                $vars['subject_guid'] = $subject;
                $vars['type']         = "comments:{$type}";

And I'm feeling a little puzzled. You aren't going to delete comment records, but notification records!

So after having another look: Why are you searching for notifications first at all in order to delete them as the next step?

When you delete a post, you KNOW the item_guid.
And if you look into the database, this id appears to be the subject_guid BOTH in notification records of type 'mention:post:created' AND mention:comment:created. So, to my opinion it would be sufficient to run simply 2 deletes like

$notifications->deleteNotification(array(
                    'type' =>'mention:post:created', 
                    'subject_guid' => $deleted_guid,
                   ));

and the same one with 'type' =>'mention:comment:created',

us Bryce alvord Replied 5 years ago

Hey one last question, Im not sure how the annotation response aligns to the notification payload. Here is the annotation response

                    "{$distinct}a.id", //no idea what this is from the db
                    'a.time_created', //dont need it
                    'a.owner_guid', // it has a match
                    'a.subject_guid', // it has a match
                    'a.type', // it has a match
                    'emd.value' // no idea what this is from the db

And here is the payload for the delete notification method

                'guid' // dont know what this matches to
                'type' // it has a match
                'poster_guid' // it does not have a match but I might not need this for comments
                'owner_guid' // it has a match
                'subject_guid' // it has a match
                'item_guid' // dont know what this matches to

Could you help me out understanding the mappings of these payloads?

us Bryce alvord Replied 5 years ago

Oh I just realized that may be a different type than I am thinking of.

us Bryce alvord Replied 5 years ago

Z,

Dude you are a rockstar. Its always tough to put your own code through all the right tests which is embarrassing for me because I was in QA for 2 years before I was qualified to do software development at my company lol. My bad and I will get those bugs fixed in v1.6.

I found an issue regarding collecting the comments on a deleted post that are mentions and just wanted to run this change by you. The problem is that the GetComments Method in the OssnComments class as shown below hard codes the word "comments:" to the beginning of the $type variable and my $type is "mention:comment:created" so I am thinking I just need to change that to be "comments:mention:created". What do you think of that?

public function GetComments($subject, $type = 'post') {
            $vars                 = array();
            $vars['subject_guid'] = $subject;
            $vars['type']         = "comments:{$type}";
German Michael Zülsdorff Replied 5 years ago

Some bugs on mentioning I found so far ...:

Met @User Ten
and
@User Eleven later

only User Eleven gets notified

Met @User Ten first
and
@User Eleven later

both users get notified. => linefeeds directly after Username are causing issues

First met @User Ten. Later met @User Eleven.

nobody gets notified

Met @User Ten first. Met @User Eleven later.

both users get notified. => punctuation handling needs improvement

German Michael Zülsdorff Replied 5 years ago

Hey Bryce,

I had a first look at 1.5 now. To start with the deleting part:

  • delete User: ok
  • delete Comment: ok
  • delete Post: 'mention:post:created' records ok, but may leave orphan 'mention:comment:created' records. That is: it needs some extra code to loop through attached comments and check for mentions

Aside from that I would add a $deleted_guid = false; right in the beginning because it's a good practise not to rely on undefiend vars. Next, valid guids are guaranteed to be > 0, checking for >= is wrong. Simply change it if ($deleted_guid) {. Finally $user = new OssnUser; is obsolete (and gets overwritten on the next line anyway)

Component

Developer: bryce
License GPL v2
Type: Communication
Requires Ossn Version : 5.x
Latest Version: 1.9.1
Last Updated 5 years ago
Repository Url View Repository

Versions