'classname' => 'core_message_external',
'methodname' => 'data_for_messagearea_conversations',
'classpath' => 'message/externallib.php',
- 'description' => 'Retrieve the template data for the conversation list',
+ 'description' => '** DEPRECATED ** Please do not call this function any more.
+ Retrieve the template data for the conversation list',
'type' => 'read',
'ajax' => true,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
}
return $members;
}
+
+ /**
+ * Backwards compatibility formatter, transforming the new output of get_conversations() into the old format.
+ *
+ * @param array $conversations the array of conversations, which must come from get_conversations().
+ * @return array the array of conversations, formatted in the legacy style.
+ */
+ public static function get_conversations_legacy_formatter(array $conversations) : array {
+ // Transform new data format back into the old format, just for BC during the deprecation life cycle.
+ $tmp = [];
+ foreach ($conversations as $id => $conv) {
+ $data = new \stdClass();
+ // The logic for the 'other user' is as follows:
+ // If a conversation is of type 'individual', the other user is always the member who is not the current user.
+ // If the conversation is of type 'group', the other user is always the sender of the most recent message.
+ // The get_conversations method already follows this logic, so we just need the first member.
+ $otheruser = reset($conv->members);
+ $data->userid = $otheruser->id;
+ $data->useridfrom = $conv->messages[0]->useridfrom ?? null;
+ $data->fullname = $conv->members[$otheruser->id]->fullname;
+ $data->profileimageurl = $conv->members[$otheruser->id]->profileimageurl;
+ $data->profileimageurlsmall = $conv->members[$otheruser->id]->profileimageurlsmall;
+ $data->ismessaging = isset($conv->messages[0]->text) ? true : false;
+ $data->lastmessage = $conv->messages[0]->text ?? null;
+ $data->messageid = $conv->messages[0]->id ?? null;
+ $data->isonline = $conv->members[$otheruser->id]->isonline ?? null;
+ $data->isblocked = $conv->members[$otheruser->id]->isblocked ?? null;
+ $data->isread = $conv->isread;
+ $data->unreadcount = $conv->unreadcount;
+ $tmp[$data->userid] = $data;
+ }
+ return $tmp;
+ }
}
/**
* The messagearea conversations parameters.
*
+ * @deprecated since 3.6
* @return external_function_parameters
* @since 3.2
*/
/**
* Get messagearea conversations.
*
+ * NOTE FOR FINAL DEPRECATION:
+ * When removing this method, please also consider removal of get_conversations_legacy_formatter()
+ * from the \core_message\helper class. This helper method was used solely to format the new get_conversations() return data
+ * into the old format used here, and in message/index.php. If we no longer need either of these, then that method can be
+ * removed.
+ *
+ * @deprecated since 3.6
* @param int $userid The id of the user who we are viewing conversations for
* @param int $limitfrom
* @param int $limitnum
}
$conversations = \core_message\api::get_conversations($userid, $limitfrom, $limitnum);
+
+ // Format the conversations in the legacy style, as the get_conversations method has since been changed.
+ $conversations = \core_message\helper::get_conversations_legacy_formatter($conversations);
+
$conversations = new \core_message\output\messagearea\contacts(null, $conversations);
$renderer = $PAGE->get_renderer('core_message');
/**
* The messagearea conversations return structure.
*
+ * @deprecated since 3.6
* @return external_single_structure
* @since 3.2
*/
);
}
+ /**
+ * Marking the method as deprecated.
+ *
+ * @return bool
+ */
+ public static function data_for_messagearea_conversations_is_deprecated() {
+ return true;
+ }
+
/**
* The messagearea contacts return parameters.
*
$conversations = \core_message\api::get_contacts($user1->id, 0, 20);
} else {
$conversations = \core_message\api::get_conversations($user1->id, 0, 20);
+
+ // Format the conversations in the legacy style, as the get_conversations method has since been changed.
+ $conversations = \core_message\helper::get_conversations_legacy_formatter($conversations);
}
$messages = [];
if (!$user2realuser) {
- core_message_external::delete_conversation(), please use core_message_external::delete_conversations_by_id() instead.
- core_message_external::core_message_mark_all_messages_as_read(), please use
core_message_external::core_message_mark_all_conversation_messages_as_read() instead.
+ - core_message_external::data_for_messagearea_conversations(), please use core_message_external::get_conversations()
+ instead
* The following function has been added for getting the privacy messaging preference:
- get_user_privacy_messaging_preference()