I have a question about some cool functionality I'd like to see, and that I'm going to try to create. Has anyone worked on adding a default friend to new user's buddylist? This post may be better served in "module development," by the way.

I'd like to have someone, like the site admin or a 'public face', to automatically be in every user's buddy list when they register, as Tom is in Myspace.

I haven't started to tackle the project yet, but it seems like it would just take a few extra lines of code in whatever the registration function is (which I don't have a clue about).

I did find an issue that was posted a while back: http://drupal.org/node/75884

However, my question isn't really for someone else to do this, rather if anyone can point me in the right direction to get started. What happens in the registration process? Is there a function that is executed that I can add a query to or something like that?

Any help is greatly appreciated.

-Jesse

Comments

apt94jesse’s picture

Here is the direction I'm heading first. I have entered this line of code:

db_query('INSERT INTO {buddylist} (received, uid, buddy, timestamp) VALUES (1, %d, %d, %d)' , $user->uid , '1', time());

into a function that is executed when a user registers. I found the user_register function in the api and that's really the only one I found. Doesn't seem to work how I plan though.

vm’s picture

suggestion:

http://drupal.org/node/add/project_issue/buddylist/feature if you post it there, mr. douglass and the other maintainers will surely help you with specifics of adding on to this module.

apt94jesse’s picture

Good idea, here's the link: http://drupal.org/node/90437

apt94jesse’s picture

I got my functionality to work like this. I added these lines in the page.tpl.php:

$buddycount = db_query('SELECT COUNT(*) FROM {buddylist} WHERE uid = %d', $GLOBALS['user']->uid);
  $buddyobject=db_result($buddycount, $row=0);
  if ($buddyobject=='0') {
  db_query('INSERT INTO {buddylist} (received, uid, buddy, timestamp) VALUES (1, %d, %d, %d)' , $GLOBALS['user']->uid , '1' , time());
  }

As you can see, I query the buddylist table, count the entries where the current user has buddies. If that count is 0, then it executes the insert query adding the default buddy. This way, whenever a new user logs in for the first time, their buddy count is of course 0, so it adds the buddy into the table.

vm’s picture

nicely done. Saved in my favs in the case that I need this at a later date. I can see where it would be handy to add a support user to automagically be added to the buddylist. :applause:

Willdex’s picture

I tried doing that, it just gave me this text at the top of the page. Could you please point me at the line I should put it in?

apt94jesse’s picture

What version of drupal are you using? This trick was used in 4.7.2 I believe, and has not been tested with anything else.

Also, what is the text it displays when you attempt it?

kevinwalsh’s picture

i don't know what message he was getting, but i'm getting a:

Parse error: syntax error, unexpected T_VARIABLE in /home/utopics/public_html/modules/user.module on line 212

i'm using 4.7.4 and buddylist 1.48.2.40

i thought it might have something to do with the fact that i turned "require approval", which i could see creating problems for this function, but when it turned approval off i had the same error.

best,
-kev

Willdex’s picture

I'm using Drupal 5.