As I found out, reacting on new messages via Rules is very limited.

I can catch the event "privatemsg_insert" when a new PM is created. I need to delete the entity in certain situations, but that doesn't work. The message is sent as is. Changing PM values (subject, body, author, recipien) doesn't seem to work, either. But it would be okay for me to just cancel the message.

Maybe I just didn't find out how to use this feature. If so, some documentation would be greatly appreciated!

Comments

ptmkenny’s picture

Category: bug » support

In which situations do you need to delete the entity? One possibility is structuring your rules with components so that private messages are only created when necessary.

There's a patch here that may also be of use:
https://drupal.org/node/1387740

Anonymous’s picture

Category: support » feature

It's quite common to use callbacks for modifying or canceling the object in question. I can neither modify nor cancel the new message. Thus it's still a bug for my understanding, because this callback is so surprisingly incomplete. Beyond that it lacks any documentation. Deleting the entity fails without further notice.

My usecase is a keyword based abuse blocker. Not really a spam blocker, but a user promoting competing products shall not reach my audience. Currently the Rule disables the user's account and send an alert to the admin via email. The malicious message is delivered anyway, so the damage done.

I'll go the hook_privatemsg_message_validate() way, but the time for all this is lost.

I make it a feature request, as no support required.

Berdir’s picture

Category: feature » support
Status: Active » Fixed

The insert hook/event is, like all other insert/update hooks/events, invoked *after* the messages was stored, so changing it does not have any effect.

The available hooks are documented on http://api.worldempire.ch/api/privatemsg/privatemsg.api.php/group/messag....

Anonymous’s picture

Status: Fixed » Active

Okay, that's internal stuff and (from a Rules user's perspective) unexpected, as other events can modify entities. There is still one question that comes to mind:

If the message is already stored, how comes deleting the message entity fails? My assumption was the entity is about to be created (yet not persistent) and thus I can't delete it via Rules. But if it's already a stored entity, shouldn't I be able to delete it?

ivnish’s picture

Issue summary: View changes
Status: Active » Closed (outdated)