The "To Field" of Private Message automatically completes the name of the user.
Is there any way to:
a) Limit this feature, so it only displays the name of users that are in a certain role.
b) Limit this feature so it only displays the name of users that a person has previously contacted

Thanks for any help.

Comments

jonas28’s picture

Category: support » feature

sounds very cool, i´m interested in this feature, too!

bentonboomslang’s picture

Version: 5.x-1.8 » 6.x-1.0-rc3

I would like this feature too. Where should I look to in the code if I wanted to write this myself?

B

litwol’s picture

Look at user relationship module, it has integration with privatemsg that limits name autocompletion to people that you know.

mdih’s picture

subscribing...

berdir’s picture

Category: feature » support
Status: Active » Fixed

You can read about that here:

Introduction to our query builder: http://blog.worldempire.ch/de/api/group/sql/1
This is the hook you need to use: http://blog.worldempire.ch/de/api/function/hook_privatemsg_sql_autocompl...
And this is how the query looks by default: http://blog.worldempire.ch/de/api/function/privatemsg_sql_autocomplete/1

As you can see in the last link, the example hook is outdated, it should be $fragments['query_args']['where'][] instead of just $fragments['query_args'][]

A short example to limit the autocomplete to a specifc role:

function mymodule_privatemsg_sql_autocomplete_alter(&$fragments, $search, $names) {
  
  $fragments['inner_join'][] 'INNER JOIN {users_roles} ur ON (ur.uid = u.uid)';

  $fragments['where'][] = 'ur.rid = %d';
  // This is the role id you want it to be limited to.
  $fragments['query_args']['where'][] = 3; 
}

I consider this issue a fixed as the question was how to code it. If you are looking for integration with a specific module, I suggest to open a new issue for that module and point to this issue. However, if you have more technical questions, feel free to re-open this.

Status: Fixed » Closed (fixed)

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

boobaa’s picture

Version: 6.x-1.0-rc3 »
Component: User interface » Code
Category: support » feature
Status: Closed (fixed) » Needs review
StatusFileSize
new6.92 KB

Attached is a patch that adds a new submodule: privatemsg_limitroles. It provides a simple settings form: rows are sender roles, columns are recipient ones, cells are checkboxes, which must be ticked to allow sending private messages in that direction. The (sub)module prohibits sending messages to users that are not members of allowed recipient roles for any of the sender's roles. (Heck, it's much easier to understand the UI than these description...)

boobaa’s picture

Version: » 6.x-1.2
StatusFileSize
new7.32 KB

Above patch has one flaw: sending to authenticated users is not handled properly. Here is the corrected patch, now rolled against 6.x-1.2.

boobaa’s picture

Version: 6.x-1.2 »
StatusFileSize
new7.31 KB

Patch in #8 works fine for 6.x-1.3 as well. Here is the corrected patch for 6.x-2.x-dev.

berdir’s picture

pm_block_user.module already provides this functionality? What's the difference in your module? The description sounds pretty much the same, except that can set up rules and choose sender/recipient role from a select.

boobaa’s picture

Uh-oh, I wasn't aware of pm_block_user.module's functionality. While skimming through it, I can spot only one difference: while pm_block_user follows the "allow all, then deny some" way, privatemsg_limitroles goes the other: "deny all, then allow some" - which may be easier to set up in some particular use cases. YMMV.

berdir’s picture

Ah, yeah. We originally had the idea that there would be a way to switch between these two principles (not sure what the right word is here..)
:
Would be awesome if you could integrate that somehow into pm_block_user :)

First step before doing any code would be to find a way how the UI would work I guess, I'm not sure about that yet. The issue that added this feature is #267814: Setting to define certain roles (e.g. staff) which a user cannot block PMs from, don't remember the discussion we had there in detail.

berdir’s picture

Version: » 6.x-2.x-dev
Status: Needs review » Needs work

See above...

berdir’s picture

Title: Limit the auto-complete feature in To Field » Allow to configure explicitly allowed role to role rules instead of blocking rules

Trying to give this a better title so that I can more easily find it again.

berdir’s picture

Component: Code » Code (pm_block_user)
oadaeh’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

This issue is being closed because it is against a branch for a version of Drupal that is no longer supported.
If you feel that this issue is still valid, feel free to re-open and update it (and any possible patch) to work with the 7.x-1.x branch (bug fixes only) or the 7.x-2.x branch.
Thank you.