message_mark_messages_read($user1->id, $user2->id); if ($viewing == MESSAGE_VIEW_UNREAD_MESSAGES) { $viewingnewmessages = true; } } } $countunreadtotal = message_count_unread_messages($user1); if ($currentuser && $countunreadtotal == 0 && $viewing == MESSAGE_VIEW_UNREAD_MESSAGES && empty($user2)) { // If the user has no unread messages, show the search box. // We don't do this when a user is viewing another user's messages as search doesn't // handle user A searching user B's messages properly. $viewing = MESSAGE_VIEW_SEARCH; } $blockedusers = message_get_blocked_users($user1, $user2); $countblocked = count($blockedusers); list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts($user1, $user2); message_print_contact_selector($countunreadtotal, $viewing, $user1, $user2, $blockedusers, $onlinecontacts, $offlinecontacts, $strangers, $showactionlinks, $page); echo html_writer::start_tag('div', array('class' => 'messagearea mdl-align')); if (!empty($user2)) { echo html_writer::start_tag('div', array('class' => 'mdl-left messagehistory')); $visible = 'visible'; $hidden = 'hiddenelement'; //cant just use hidden as mform adds that class to its fieldset for something else $recentlinkclass = $recentlabelclass = $historylinkclass = $historylabelclass = $visible; if ($history == MESSAGE_HISTORY_ALL) { $displaycount = 0; $recentlabelclass = $historylinkclass = $hidden; } else { if ($viewingnewmessages) { //if user is viewing new messages only show them the new messages $displaycount = $countunread;
/** * Get contacts. * * @param array $userids array of user IDs. * @return external_description * @since Moodle 2.5 */ public static function get_contacts() { global $CFG, $PAGE; // Check if messaging is enabled. if (!$CFG->messaging) { throw new moodle_exception('disabled', 'message'); } require_once $CFG->dirroot . '/user/lib.php'; list($online, $offline, $strangers) = message_get_contacts(); $allcontacts = array('online' => $online, 'offline' => $offline, 'strangers' => $strangers); foreach ($allcontacts as $mode => $contacts) { foreach ($contacts as $key => $contact) { $newcontact = array('id' => $contact->id, 'fullname' => fullname($contact), 'unread' => $contact->messagecount); $userpicture = new user_picture($contact); $userpicture->size = 1; // Size f1. $newcontact['profileimageurl'] = $userpicture->get_url($PAGE)->out(false); $userpicture->size = 0; // Size f2. $newcontact['profileimageurlsmall'] = $userpicture->get_url($PAGE)->out(false); $allcontacts[$mode][$key] = $newcontact; } } return $allcontacts; }
/** * Get contacts. * * @param array $userids array of user IDs. * @return external_description * @since 2.5 */ public static function get_contacts() { global $CFG; require_once($CFG->dirroot . '/user/lib.php'); list($online, $offline, $strangers) = message_get_contacts(); $allcontacts = array('online' => $online, 'offline' => $offline, 'strangers' => $strangers); foreach ($allcontacts as $mode => $contacts) { foreach ($contacts as $key => $contact) { $newcontact = array( 'id' => $contact->id, 'fullname' => fullname($contact), 'unread' => $contact->messagecount ); // Try to get the user picture, but sometimes this method can return null. $userdetails = user_get_user_details($contact, null, array('profileimageurl', 'profileimageurlsmall')); if (!empty($userdetails)) { $newcontact['profileimageurl'] = $userdetails['profileimageurl']; $newcontact['profileimageurlsmall'] = $userdetails['profileimageurlsmall']; } $allcontacts[$mode][$key] = $newcontact; } } return $allcontacts; }
/** * Test message_get_contacts. */ public function test_message_get_contacts() { global $USER, $CFG; // Set this user as the admin. $this->setAdminUser(); $noreplyuser = core_user::get_noreply_user(); $supportuser = core_user::get_support_user(); // Create a user to add to the admin's contact list. $user1 = $this->getDataGenerator()->create_user(); $user2 = $this->getDataGenerator()->create_user(); $user3 = $this->getDataGenerator()->create_user(); // Stranger. // Add users to the admin's contact list. message_add_contact($user1->id); message_add_contact($user2->id); // Send some messages. $this->send_fake_message($user1, $USER); $this->send_fake_message($user2, $USER); $this->send_fake_message($user3, $USER); list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts(); $this->assertCount(0, $onlinecontacts); $this->assertCount(2, $offlinecontacts); $this->assertCount(1, $strangers); // Send message from noreply and support users. $this->send_fake_message($noreplyuser, $USER); $this->send_fake_message($supportuser, $USER); list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts(); $this->assertCount(0, $onlinecontacts); $this->assertCount(2, $offlinecontacts); $this->assertCount(3, $strangers); // Block 1 user. message_block_contact($user2->id); list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts(); $this->assertCount(0, $onlinecontacts); $this->assertCount(1, $offlinecontacts); $this->assertCount(3, $strangers); // Noreply user being valid user. core_user::reset_internal_users(); $CFG->noreplyuserid = $user3->id; $noreplyuser = core_user::get_noreply_user(); list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts(); $this->assertCount(0, $onlinecontacts); $this->assertCount(1, $offlinecontacts); $this->assertCount(2, $strangers); }
/** * Get contacts. * * @param array $userids array of user IDs. * @return external_description * @since Moodle 2.5 */ public static function get_contacts() { global $CFG; // Check if messaging is enabled. if (!$CFG->messaging) { throw new moodle_exception('disabled', 'message'); } require_once $CFG->dirroot . '/user/lib.php'; list($online, $offline, $strangers) = message_get_contacts(); $allcontacts = array('online' => $online, 'offline' => $offline, 'strangers' => $strangers); foreach ($allcontacts as $mode => $contacts) { foreach ($contacts as $key => $contact) { $newcontact = array('id' => $contact->id, 'fullname' => fullname($contact), 'unread' => $contact->messagecount); $usercontextid = context_user::instance($contact->id)->id; $newcontact['profileimageurl'] = moodle_url::make_webservice_pluginfile_url($usercontextid, 'user', 'icon', null, '/', 'f1')->out(false); $newcontact['profileimageurlsmall'] = moodle_url::make_webservice_pluginfile_url($usercontextid, 'user', 'icon', null, '/', 'f2')->out(false); $allcontacts[$mode][$key] = $newcontact; } } return $allcontacts; }