MDL-55942 core_message: moved added functionality from message/lib.php
[moodle.git] / message / classes / api.php
blobb863d26dedf5ffc828c9cac67f51d97604d920b9
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Contains class used to return information to display for the message area.
20 * @package core_message
21 * @copyright 2016 Mark Nelson <markn@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_message;
27 require_once($CFG->dirroot . '/lib/messagelib.php');
29 defined('MOODLE_INTERNAL') || die();
31 /**
32 * Class used to return information to display for the message area.
34 * @copyright 2016 Mark Nelson <markn@moodle.com>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class api {
39 /**
40 * Handles searching for messages in the message area.
42 * @param int $userid The user id doing the searching
43 * @param string $search The string the user is searching
44 * @param int $limitfrom
45 * @param int $limitnum
46 * @return \core_message\output\messagearea\message_search_results
48 public static function search_messages($userid, $search, $limitfrom = 0, $limitnum = 0) {
49 global $DB;
51 // Get the user fields we want.
52 $ufields = \user_picture::fields('u', array('lastaccess'), 'userfrom_id', 'userfrom_');
53 $ufields2 = \user_picture::fields('u2', array('lastaccess'), 'userto_id', 'userto_');
55 // Get all the messages for the user.
56 $sql = "SELECT m.id, m.useridfrom, m.useridto, m.subject, m.fullmessage, m.fullmessagehtml, m.fullmessageformat,
57 m.smallmessage, m.notification, m.timecreated, 0 as isread, $ufields, mc.blocked as userfrom_blocked,
58 $ufields2, mc2.blocked as userto_blocked
59 FROM {message} m
60 JOIN {user} u
61 ON m.useridfrom = u.id
62 LEFT JOIN {message_contacts} mc
63 ON (mc.contactid = u.id AND mc.userid = ?)
64 JOIN {user} u2
65 ON m.useridto = u2.id
66 LEFT JOIN {message_contacts} mc2
67 ON (mc2.contactid = u2.id AND mc2.userid = ?)
68 WHERE ((useridto = ? AND timeusertodeleted = 0)
69 OR (useridfrom = ? AND timeuserfromdeleted = 0))
70 AND notification = 0
71 AND u.deleted = 0
72 AND u2.deleted = 0
73 AND " . $DB->sql_like('smallmessage', '?', false) . "
74 UNION ALL
75 SELECT mr.id, mr.useridfrom, mr.useridto, mr.subject, mr.fullmessage, mr.fullmessagehtml, mr.fullmessageformat,
76 mr.smallmessage, mr.notification, mr.timecreated, 1 as isread, $ufields, mc.blocked as userfrom_blocked,
77 $ufields2, mc2.blocked as userto_blocked
78 FROM {message_read} mr
79 JOIN {user} u
80 ON mr.useridfrom = u.id
81 LEFT JOIN {message_contacts} mc
82 ON (mc.contactid = u.id AND mc.userid = ?)
83 JOIN {user} u2
84 ON mr.useridto = u2.id
85 LEFT JOIN {message_contacts} mc2
86 ON (mc2.contactid = u2.id AND mc2.userid = ?)
87 WHERE ((useridto = ? AND timeusertodeleted = 0)
88 OR (useridfrom = ? AND timeuserfromdeleted = 0))
89 AND notification = 0
90 AND u.deleted = 0
91 AND u2.deleted = 0
92 AND " . $DB->sql_like('smallmessage', '?', false) . "
93 ORDER BY timecreated DESC";
94 $params = array($userid, $userid, $userid, $userid, '%' . $search . '%',
95 $userid, $userid, $userid, $userid, '%' . $search . '%');
97 // Convert the messages into searchable contacts with their last message being the message that was searched.
98 $contacts = array();
99 if ($messages = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum)) {
100 foreach ($messages as $message) {
101 $prefix = 'userfrom_';
102 if ($userid == $message->useridfrom) {
103 $prefix = 'userto_';
104 // If it from the user, then mark it as read, even if it wasn't by the receiver.
105 $message->isread = true;
107 $blockedcol = $prefix . 'blocked';
108 $message->blocked = $message->$blockedcol;
110 $message->messageid = $message->id;
111 $contacts[] = \core_message\helper::create_contact($message, $prefix);
115 return new \core_message\output\messagearea\message_search_results($userid, $contacts);
119 * Handles searching for people in a particular course in the message area.
121 * @param int $userid The user id doing the searching
122 * @param int $courseid The id of the course we are searching in
123 * @param string $search The string the user is searching
124 * @param int $limitfrom
125 * @param int $limitnum
126 * @return \core_message\output\messagearea\people_search_results
128 public static function search_people_in_course($userid, $courseid, $search, $limitfrom = 0, $limitnum = 0) {
129 global $DB;
131 // Get all the users in the course.
132 list($esql, $params) = get_enrolled_sql(\context_course::instance($courseid), '', 0, true);
133 $sql = "SELECT u.*, mc.blocked
134 FROM {user} u
135 JOIN ($esql) je
136 ON je.id = u.id
137 LEFT JOIN {message_contacts} mc
138 ON (mc.contactid = u.id AND mc.userid = :userid)
139 WHERE u.deleted = 0";
140 // Add more conditions.
141 $fullname = $DB->sql_fullname();
142 $sql .= " AND u.id != :userid2
143 AND " . $DB->sql_like($fullname, ':search', false) . "
144 ORDER BY " . $DB->sql_fullname();
145 $params = array_merge(array('userid' => $userid, 'userid2' => $userid, 'search' => '%' . $search . '%'), $params);
148 // Convert all the user records into contacts.
149 $contacts = array();
150 if ($users = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum)) {
151 foreach ($users as $user) {
152 $contacts[] = \core_message\helper::create_contact($user);
156 return new \core_message\output\messagearea\people_search_results($contacts);
160 * Handles searching for people in the message area.
162 * @param int $userid The user id doing the searching
163 * @param string $search The string the user is searching
164 * @param int $limitnum
165 * @return \core_message\output\messagearea\people_search_results
167 public static function search_people($userid, $search, $limitnum = 0) {
168 global $CFG, $DB;
170 require_once($CFG->dirroot . '/lib/coursecatlib.php');
172 // Used to search for contacts.
173 $fullname = $DB->sql_fullname();
174 $ufields = \user_picture::fields('u', array('lastaccess'));
176 // Users not to include.
177 $excludeusers = array($userid, $CFG->siteguest);
178 list($exclude, $excludeparams) = $DB->get_in_or_equal($excludeusers, SQL_PARAMS_NAMED, 'param', false);
180 // Ok, let's search for contacts first.
181 $contacts = array();
182 $sql = "SELECT $ufields, mc.blocked
183 FROM {user} u
184 JOIN {message_contacts} mc
185 ON u.id = mc.contactid
186 WHERE mc.userid = :userid
187 AND u.deleted = 0
188 AND u.confirmed = 1
189 AND " . $DB->sql_like($fullname, ':search', false) . "
190 AND u.id $exclude
191 ORDER BY " . $DB->sql_fullname();
192 if ($users = $DB->get_records_sql($sql, array('userid' => $userid, 'search' => '%' . $search . '%') +
193 $excludeparams, 0, $limitnum)) {
194 foreach ($users as $user) {
195 $contacts[] = \core_message\helper::create_contact($user);
199 // Now, let's get the courses.
200 $courses = array();
201 if ($arrcourses = \coursecat::search_courses(array('search' => $search), array('limit' => $limitnum))) {
202 foreach ($arrcourses as $course) {
203 $data = new \stdClass();
204 $data->id = $course->id;
205 $data->shortname = $course->shortname;
206 $data->fullname = $course->fullname;
207 $courses[] = $data;
211 // Let's get those non-contacts. Toast them gears boi.
212 // Note - you can only block contacts, so these users will not be blocked, so no need to get that
213 // extra detail from the database.
214 $noncontacts = array();
215 $sql = "SELECT $ufields
216 FROM {user} u
217 WHERE u.deleted = 0
218 AND u.confirmed = 1
219 AND " . $DB->sql_like($fullname, ':search', false) . "
220 AND u.id $exclude
221 AND u.id NOT IN (SELECT contactid
222 FROM {message_contacts}
223 WHERE userid = :userid)
224 ORDER BY " . $DB->sql_fullname();
225 if ($users = $DB->get_records_sql($sql, array('userid' => $userid, 'search' => '%' . $search . '%') +
226 $excludeparams, 0, $limitnum)) {
227 foreach ($users as $user) {
228 $noncontacts[] = \core_message\helper::create_contact($user);
232 return new \core_message\output\messagearea\people_search_results($contacts, $courses, $noncontacts);
236 * Returns the contacts and their conversation to display in the contacts area.
238 * @param int $userid The user id
239 * @param int $otheruserid The id of the user we have selected, 0 if none have been selected
240 * @param int $limitfrom
241 * @param int $limitnum
242 * @return \core_message\output\messagearea\contacts
244 public static function get_conversations($userid, $otheruserid = 0, $limitfrom = 0, $limitnum = 0) {
245 $arrcontacts = array();
246 if ($conversations = message_get_recent_conversations($userid, $limitfrom, $limitnum)) {
247 foreach ($conversations as $conversation) {
248 $arrcontacts[] = \core_message\helper::create_contact($conversation);
252 return new \core_message\output\messagearea\contacts($userid, $otheruserid, $arrcontacts);
256 * Returns the contacts to display in the contacts area.
258 * @param int $userid The user id
259 * @param int $limitfrom
260 * @param int $limitnum
261 * @return \core_message\output\messagearea\contacts
263 public static function get_contacts($userid, $limitfrom = 0, $limitnum = 0) {
264 global $DB;
266 $arrcontacts = array();
267 $sql = "SELECT u.*, mc.blocked
268 FROM {message_contacts} mc
269 JOIN {user} u
270 ON mc.contactid = u.id
271 WHERE mc.userid = :userid
272 AND u.deleted = 0
273 ORDER BY " . $DB->sql_fullname();
274 if ($contacts = $DB->get_records_sql($sql, array('userid' => $userid), $limitfrom, $limitnum)) {
275 foreach ($contacts as $contact) {
276 $arrcontacts[] = \core_message\helper::create_contact($contact);
280 return new \core_message\output\messagearea\contacts($userid, 0, $arrcontacts, false);
284 * Returns the messages to display in the message area.
286 * @param int $userid the current user
287 * @param int $otheruserid the other user
288 * @param int $limitfrom
289 * @param int $limitnum
290 * @param string $sort
291 * @return \core_message\output\messagearea\messages
293 public static function get_messages($userid, $otheruserid, $limitfrom = 0, $limitnum = 0, $sort = 'timecreated ASC') {
294 $arrmessages = array();
295 if ($messages = \core_message\helper::get_messages($userid, $otheruserid, 0, $limitfrom, $limitnum, $sort)) {
296 $arrmessages = \core_message\helper::create_messages($userid, $messages);
299 return new \core_message\output\messagearea\messages($userid, $otheruserid, $arrmessages);
303 * Returns the most recent message between two users.
305 * @param int $userid the current user
306 * @param int $otheruserid the other user
307 * @return \core_message\output\messagearea\message|null
309 public static function get_most_recent_message($userid, $otheruserid) {
310 // We want two messages here so we get an accurate 'blocktime' value.
311 if ($messages = \core_message\helper::get_messages($userid, $otheruserid, 0, 0, 2, 'timecreated DESC')) {
312 // Swap the order so we now have them in historical order.
313 $messages = array_reverse($messages);
314 $arrmessages = \core_message\helper::create_messages($userid, $messages);
315 return array_pop($arrmessages);
318 return null;
322 * Returns the profile information for a contact for a user.
324 * @param int $userid The user id
325 * @param int $otheruserid The id of the user whose profile we want to view.
326 * @return \core_message\output\messagearea\profile
328 public static function get_profile($userid, $otheruserid) {
329 global $CFG, $DB;
331 require_once($CFG->dirroot . '/user/lib.php');
333 if ($user = \core_user::get_user($otheruserid)) {
334 // Create the data we are going to pass to the renderable.
335 $userfields = user_get_user_details($user, null, array('city', 'country', 'email',
336 'profileimageurl', 'profileimageurlsmall', 'lastaccess'));
337 if ($userfields) {
338 $data = new \stdClass();
339 $data->userid = $userfields['id'];
340 $data->fullname = $userfields['fullname'];
341 $data->city = isset($userfields['city']) ? $userfields['city'] : '';
342 $data->country = isset($userfields['country']) ? $userfields['country'] : '';
343 $data->email = isset($userfields['email']) ? $userfields['email'] : '';
344 $data->profileimageurl = isset($userfields['profileimageurl']) ? $userfields['profileimageurl'] : '';
345 $data->profileimageurlsmall = isset($userfields['profileimageurlsmall']) ?
346 $userfields['profileimageurlsmall'] : '';
347 if (isset($userfields['lastaccess'])) {
348 $data->isonline = \core_message\helper::is_online($userfields['lastaccess']);
349 } else {
350 $data->isonline = 0;
352 } else {
353 // Technically the access checks in user_get_user_details are correct,
354 // but messaging has never obeyed them. In order to keep messaging working
355 // we at least need to return a minimal user record.
356 $data = new \stdClass();
357 $data->userid = $otheruserid;
358 $data->fullname = fullname($user);
359 $data->city = '';
360 $data->country = '';
361 $data->email = '';
362 $data->profileimageurl = '';
363 $data->profileimageurlsmall = '';
364 $data->isonline = 0;
366 // Check if the contact has been blocked.
367 $contact = $DB->get_record('message_contacts', array('userid' => $userid, 'contactid' => $otheruserid));
368 if ($contact) {
369 $data->isblocked = $contact->blocked;
370 $data->iscontact = true;
371 } else {
372 $data->isblocked = false;
373 $data->iscontact = false;
376 return new \core_message\output\messagearea\profile($userid, $data);
381 * Checks if a user can delete messages they have either received or sent.
383 * @param int $userid The user id of who we want to delete the messages for (this may be done by the admin
384 * but will still seem as if it was by the user)
385 * @return bool Returns true if a user can delete the message, false otherwise.
387 public static function can_delete_conversation($userid) {
388 global $USER;
390 $systemcontext = \context_system::instance();
392 // Let's check if the user is allowed to delete this message.
393 if (has_capability('moodle/site:deleteanymessage', $systemcontext) ||
394 ((has_capability('moodle/site:deleteownmessage', $systemcontext) &&
395 $USER->id == $userid))) {
396 return true;
399 return false;
403 * Deletes a conversation.
405 * This function does not verify any permissions.
407 * @param int $userid The user id of who we want to delete the messages for (this may be done by the admin
408 * but will still seem as if it was by the user)
409 * @param int $otheruserid The id of the other user in the conversation
410 * @return bool
412 public static function delete_conversation($userid, $otheruserid) {
413 global $DB, $USER;
415 // We need to update the tables to mark all messages as deleted from and to the other user. This seems worse than it
416 // is, that's because our DB structure splits messages into two tables (great idea, huh?) which causes code like this.
417 // This won't be a particularly heavily used function (at least I hope not), so let's hope MDL-36941 gets worked on
418 // soon for the sake of any developers' sanity when dealing with the messaging system.
419 $now = time();
420 $sql = "UPDATE {message}
421 SET timeuserfromdeleted = :time
422 WHERE useridfrom = :userid
423 AND useridto = :otheruserid
424 AND notification = 0";
425 $DB->execute($sql, array('time' => $now, 'userid' => $userid, 'otheruserid' => $otheruserid));
427 $sql = "UPDATE {message}
428 SET timeusertodeleted = :time
429 WHERE useridto = :userid
430 AND useridfrom = :otheruserid
431 AND notification = 0";
432 $DB->execute($sql, array('time' => $now, 'userid' => $userid, 'otheruserid' => $otheruserid));
434 $sql = "UPDATE {message_read}
435 SET timeuserfromdeleted = :time
436 WHERE useridfrom = :userid
437 AND useridto = :otheruserid
438 AND notification = 0";
439 $DB->execute($sql, array('time' => $now, 'userid' => $userid, 'otheruserid' => $otheruserid));
441 $sql = "UPDATE {message_read}
442 SET timeusertodeleted = :time
443 WHERE useridto = :userid
444 AND useridfrom = :otheruserid
445 AND notification = 0";
446 $DB->execute($sql, array('time' => $now, 'userid' => $userid, 'otheruserid' => $otheruserid));
448 // Now we need to trigger events for these.
449 if ($messages = \core_message\helper::get_messages($userid, $otheruserid, $now)) {
450 // Loop through and trigger a deleted event.
451 foreach ($messages as $message) {
452 $messagetable = 'message';
453 if (!empty($message->timeread)) {
454 $messagetable = 'message_read';
457 // Trigger event for deleting the message.
458 \core\event\message_deleted::create_from_ids($message->useridfrom, $message->useridto,
459 $USER->id, $messagetable, $message->id)->trigger();
463 return true;
467 * Returns the count of unread conversations (collection of messages from a single user) for
468 * the given user.
470 * @param \stdClass $user the user who's conversations should be counted
471 * @return int the count of the user's unread conversations
473 public static function count_unread_conversations($user = null) {
474 global $USER, $DB;
476 if (empty($user)) {
477 $user = $USER;
480 return $DB->count_records_select(
481 'message',
482 'useridto = ? AND timeusertodeleted = 0 AND notification = 0',
483 [$user->id],
484 "COUNT(DISTINCT(useridfrom))");
488 * Marks ALL messages being sent from $fromuserid to $touserid as read.
490 * Can be filtered by type.
492 * @param int $touserid the id of the message recipient
493 * @param int $fromuserid the id of the message sender
494 * @param string $type filter the messages by type, either MESSAGE_TYPE_NOTIFICATION, MESSAGE_TYPE_MESSAGE or '' for all.
495 * @return void
497 public static function mark_all_read_for_user($touserid, $fromuserid = 0, $type = '') {
498 global $DB;
500 $params = array();
502 if (!empty($touserid)) {
503 $params['useridto'] = $touserid;
506 if (!empty($fromuserid)) {
507 $params['useridfrom'] = $fromuserid;
510 if (!empty($type)) {
511 if (strtolower($type) == MESSAGE_TYPE_NOTIFICATION) {
512 $params['notification'] = 1;
513 } else if (strtolower($type) == MESSAGE_TYPE_MESSAGE) {
514 $params['notification'] = 0;
518 $sql = sprintf('SELECT m.* FROM {message} m WHERE m.%s = ?', implode('= ? AND m.', array_keys($params)));
519 $messages = $DB->get_recordset_sql($sql, array_values($params));
521 foreach ($messages as $message) {
522 message_mark_message_read($message, time());
525 $messages->close();
529 * Get popup notifications for the specified users.
531 * @param int $useridto the user id who received the notification
532 * @param string $status MESSAGE_READ for retrieving read notifications, MESSAGE_UNREAD for unread, empty for both
533 * @param bool $embeduserto embed the to user details in the notification response
534 * @param bool $embeduserfrom embed the from user details in the notification response
535 * @param string $sort the column name to order by including optionally direction
536 * @param int $limit limit the number of result returned
537 * @param int $offset offset the result set by this amount
538 * @return array notification records
539 * @throws \moodle_exception
540 * @since 3.2
542 public static function get_popup_notifications($useridto = 0, $status = '', $embeduserto = false, $embeduserfrom = false,
543 $sort = 'DESC', $limit = 0, $offset = 0) {
544 global $DB, $USER;
546 if (!empty($status) && $status != MESSAGE_READ && $status != MESSAGE_UNREAD) {
547 throw new \moodle_exception(sprintf('invalid parameter: status: must be "%s" or "%s"',
548 MESSAGE_READ, MESSAGE_UNREAD));
551 $sort = strtoupper($sort);
552 if ($sort != 'DESC' && $sort != 'ASC') {
553 throw new \moodle_exception('invalid parameter: sort: must be "DESC" or "ASC"');
556 if (empty($useridto)) {
557 $useridto = $USER->id;
560 $params = array();
562 $buildtablesql = function($table, $prefix, $additionalfields, $messagestatus)
563 use ($status, $useridto, $embeduserto, $embeduserfrom) {
565 $joinsql = '';
566 $fields = "concat('$prefix', $prefix.id) as uniqueid, $prefix.id, $prefix.useridfrom, $prefix.useridto,
567 $prefix.subject, $prefix.fullmessage, $prefix.fullmessageformat,
568 $prefix.fullmessagehtml, $prefix.smallmessage, $prefix.notification, $prefix.contexturl,
569 $prefix.contexturlname, $prefix.timecreated, $prefix.timeuserfromdeleted, $prefix.timeusertodeleted,
570 $prefix.component, $prefix.eventtype, $additionalfields";
571 $where = " AND $prefix.useridto = :{$prefix}useridto";
572 $params = ["{$prefix}useridto" => $useridto];
574 if ($embeduserto) {
575 $embedprefix = "{$prefix}ut";
576 $fields .= ", " . get_all_user_name_fields(true, $embedprefix, '', 'userto');
577 $joinsql .= " LEFT JOIN {user} $embedprefix ON $embedprefix.id = $prefix.useridto";
580 if ($embeduserfrom) {
581 $embedprefix = "{$prefix}uf";
582 $fields .= ", " . get_all_user_name_fields(true, $embedprefix, '', 'userfrom');
583 $joinsql .= " LEFT JOIN {user} $embedprefix ON $embedprefix.id = $prefix.useridfrom";
586 if ($messagestatus == MESSAGE_READ) {
587 $isread = '1';
588 } else {
589 $isread = '0';
592 return array(
593 sprintf(
594 "SELECT %s
595 FROM %s %s %s
596 WHERE %s.notification = 1
597 AND %s.id IN (SELECT messageid FROM {message_popup} WHERE isread = %s)
598 %s",
599 $fields, $table, $prefix, $joinsql, $prefix, $prefix, $isread, $where
601 $params
605 switch ($status) {
606 case MESSAGE_READ:
607 list($sql, $readparams) = $buildtablesql('{message_read}', 'r', 'r.timeread', MESSAGE_READ);
608 $params = array_merge($params, $readparams);
609 break;
610 case MESSAGE_UNREAD:
611 list($sql, $unreadparams) = $buildtablesql('{message}', 'u', '0 as timeread', MESSAGE_UNREAD);
612 $params = array_merge($params, $unreadparams);
613 break;
614 default:
615 list($readsql, $readparams) = $buildtablesql('{message_read}', 'r', 'r.timeread', MESSAGE_READ);
616 list($unreadsql, $unreadparams) = $buildtablesql('{message}', 'u', '0 as timeread', MESSAGE_UNREAD);
617 $sql = sprintf("SELECT * FROM (%s UNION %s) f", $readsql, $unreadsql);
618 $params = array_merge($params, $readparams, $unreadparams);
621 $sql .= " ORDER BY timecreated $sort, timeread $sort, id $sort";
623 return array_values($DB->get_records_sql($sql, $params, $offset, $limit));
627 * Count the unread notifications for a user.
629 * @param int $useridto the user id who received the notification
630 * @return int count of the unread notifications
631 * @since 3.2
633 public static function count_unread_popup_notifications($useridto = 0) {
634 global $USER, $DB;
636 if (empty($useridto)) {
637 $useridto = $USER->id;
640 return $DB->count_records_sql(
641 "SELECT count(id)
642 FROM {message}
643 WHERE id IN (SELECT messageid FROM {message_popup} WHERE isread = 0)
644 AND useridto = ?",
645 [$useridto]
650 * Returns message preferences.
652 * @param array $processors
653 * @param array $providers
654 * @param \stdClass $user
655 * @return \stdClass
656 * @since 3.2
658 public static function get_all_message_preferences($processors, $providers, $user) {
659 $preferences = helper::get_providers_preferences($providers, $user->id);
660 $preferences->userdefaultemail = $user->email; // May be displayed by the email processor.
662 // For every processors put its options on the form (need to get function from processor's lib.php).
663 foreach ($processors as $processor) {
664 $processor->object->load_data($preferences, $user->id);
667 // Load general messaging preferences.
668 $preferences->blocknoncontacts = get_user_preferences('message_blocknoncontacts', '', $user->id);
669 $preferences->mailformat = $user->mailformat;
670 $preferences->mailcharset = get_user_preferences('mailcharset', '', $user->id);
672 return $preferences;