Automatically make new user friends w/ admin?

Rishi B Posted in Technical Support 6 years ago

anybody know of a way to automatically make new users friends with the administrator(s) of the site? sort of like how Tom was everybody's first friend on myspace? I'm thinking the easiest way would be a mysql trigger, but I don't want to mess with the database directly if anybody has a better suggestion.

Replies
us Rishi B Replied 6 years ago

I mean, yeah, it's not hard to edit the welcome email to say "add me as a friend if you like", but that isn't what I asked. I asked how to replicate the functionality on myspace of automatically making new users friends with admins (or somebody else as deemed appropriate). Seeing as how many of us run OSSN for smaller networks, I would think the idea of "getting a new user started" by giving them 1 or 2 friends upon registration would actually be a feature that many might benefit from. I was able to implement it via a mysql trigger on the ossn-users table. The following trigger will make new users friends with guid 1. Simply change that value if your admin has a different guid.

CREATE TRIGGER auto_add_friend_for_new_user
AFTER INSERT ON ossn_users
FOR EACH ROW 
  INSERT INTO ossn_relationships (relation_from, relation_to, type, time)
  VALUES (1, NEW.guid, 'friend:request', unix_timestamp(now())),
            (NEW.guid,1,'friend:request',unix_timestamp(now())+1);

It should be pretty self explanatory what this is doing, but it's creating 2 rows in ossn-relationships for each new row in ossn-users. Users are considered friends when there exist rows to and from that pair of userids of type 'friend:request'. If there is only a row in ossn-relationships where relation-from=UserA and relation-to=UserB with type 'friend:request', then UserA has sent UserB a request for friendship, but UserB has not accepted. Once UserB accepts, an entry with relation-from=UserB, relation-to=UserB, and type='friend:request' is created in ossn-relationships. This is why the trigger needs to create 2 rows in ossn-relationships.

Alternatively, this could be done from within the PHP code by using the function ossn-add-relation(), but the solution I mentioned above is probably easier to implement as it can be done with a single trigger. Replace the -'s with an underscore.

German Michael Zülsdorff Replied 6 years ago

Strange idea perhaps, but why not dropping a simple 'I'm your friend' mail to every new user? No database action included this way.