Hello,

I would like to integrate the privatemsg module with the userpoints API. Basically, what I am trying to reach is that everytime a messages is sent, the user sending the message will get a certain number of points.

The assistance I need is just to know if there is a hook that I can utilize in my module in order to grant point, once the private message has been successfully sent. If not a hook, then could you provide me with the information on how to do it?

Many thanks in advance. Yoel

Comments

berdir’s picture

Status: Active » Fixed

Sure, see http://blog.worldempire.ch/de/api/group/message_hooks/1 and especially, http://blog.worldempire.ch/de/api/function/hook_privatemsg_message_insert/1. Note that author in hook_insert() (and most other hooks) is a user object, not just the uid.

yoeld’s picture

Super! hooks_privatemsg_message_insert($message) does exactly the job

Thanks!

Bilmar’s picture

yoeld - if you could share your code for the custom module it would be very much appreciated!
thanks in advance

berdir’s picture

You can probably also use rules module, since userpoints does have Rules integration and privatemsg does have #327938: Rules Integration

Bilmar’s picture

Tested with Rules and it worked great - allows for 'when message is sent' (however, if anyone needs, not 'when message is received').

igorik’s picture

Hi
is it possible to have "when message is read" rule option ?

berdir’s picture

Wrong issue, post that to the other one (privatemsg_rules).

There is already an hook for that (hook_privatemsg_message_view), but you might want to check if the message is unread ($message['is_new'] = 1) so that you only give points when the message is read the first time... I suppose.

yoeld’s picture

As a response for #3:

function communitypoints_privatemsg_message_insert($message) {
  global $user;
	$params = array (
		'uid' => $user->uid,
		'points' => 5,
		'description' => 'You have sent a private message to a user of the community [msg id: 15]',
		);
		userpoints_userpointsapi($params); 
}

As a response for #4:

The rules can do the job, but the standard implementation of userpoint UI does not enables to add a describtion. Since it is important for my project to have a comprehensive description of the points I had to create customized functions.

berdir’s picture

Thanks for sharing your code, I've created a first version of a book page which also includes a modified version of your code, see http://drupal.org/node/646512.

Bilmar’s picture

yoeld - thank you very much!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.