diff --git a/lib/db/services.php b/lib/db/services.php index abc93f6d125..94f0c0d1701 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -1104,26 +1104,6 @@ $functions = array( 'ajax' => true, 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), ), - 'core_message_block_contacts' => array( - 'classname' => 'core_message_external', - 'methodname' => 'block_contacts', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Block contacts', - 'type' => 'write', - 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), - ), - 'core_message_create_contacts' => array( - 'classname' => 'core_message_external', - 'methodname' => 'create_contacts', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Add contacts to the contact list', - 'type' => 'write', - 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), - ), 'core_message_get_contact_requests' => array( 'classname' => 'core_message_external', 'methodname' => 'get_contact_requests', @@ -1178,17 +1158,6 @@ $functions = array( 'ajax' => true, 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), ), - 'core_message_delete_conversation' => array( - 'classname' => 'core_message_external', - 'methodname' => 'delete_conversation', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Deletes a conversation.', - 'type' => 'write', - 'capabilities' => 'moodle/site:deleteownmessage', - 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), - ), 'core_message_delete_conversations_by_id' => array( 'classname' => 'core_message_external', 'methodname' => 'delete_conversations_by_id', @@ -1226,24 +1195,6 @@ $functions = array( 'ajax' => true, 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), ), - 'core_message_data_for_messagearea_search_users' => array( - 'classname' => 'core_message_external', - 'methodname' => 'data_for_messagearea_search_users', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Retrieve the template data for searching for people', - 'type' => 'read', - 'ajax' => true, - ), - 'core_message_data_for_messagearea_search_users_in_course' => array( - 'classname' => 'core_message_external', - 'methodname' => 'data_for_messagearea_search_users_in_course', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Retrieve the template data for searching for people in a course', - 'type' => 'read', - 'ajax' => true, - ), 'core_message_message_search_users' => array( 'classname' => 'core_message_external', 'methodname' => 'message_search_users', @@ -1253,63 +1204,6 @@ $functions = array( 'ajax' => true, 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), ), - 'core_message_data_for_messagearea_conversations' => array( - 'classname' => 'core_message_external', - 'methodname' => 'data_for_messagearea_conversations', - 'classpath' => 'message/externallib.php', - '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), - ), - 'core_message_data_for_messagearea_contacts' => array( - 'classname' => 'core_message_external', - 'methodname' => 'data_for_messagearea_contacts', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Retrieve the template data for the contact list', - 'type' => 'read', - 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), - ), - 'core_message_data_for_messagearea_messages' => array( - 'classname' => 'core_message_external', - 'methodname' => 'data_for_messagearea_messages', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Retrieve the template data for the messages', - 'type' => 'read', - 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), - ), - 'core_message_data_for_messagearea_get_most_recent_message' => array( - 'classname' => 'core_message_external', - 'methodname' => 'data_for_messagearea_get_most_recent_message', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Retrieve the template data for the most recent message', - 'type' => 'read', - 'ajax' => true, - ), - 'core_message_data_for_messagearea_get_profile' => array( - 'classname' => 'core_message_external', - 'methodname' => 'data_for_messagearea_get_profile', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Retrieve the template data for the users\'s profile', - 'type' => 'read', - 'ajax' => true, - ), - 'core_message_get_contacts' => array( - 'classname' => 'core_message_external', - 'methodname' => 'get_contacts', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Retrieve the contact list', - 'type' => 'read', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), - ), 'core_message_get_user_contacts' => array( 'classname' => 'core_message_external', 'methodname' => 'get_user_contacts', @@ -1419,16 +1313,6 @@ $functions = array( 'ajax' => true, 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), ), - 'core_message_mark_all_messages_as_read' => array( - 'classname' => 'core_message_external', - 'methodname' => 'mark_all_messages_as_read', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Mark all messages as read for a given user', - 'type' => 'write', - 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), - ), 'core_message_mark_all_conversation_messages_as_read' => array( 'classname' => 'core_message_external', 'methodname' => 'mark_all_conversation_messages_as_read', @@ -1519,16 +1403,6 @@ $functions = array( 'ajax' => true, 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), ), - 'core_message_unblock_contacts' => array( - 'classname' => 'core_message_external', - 'methodname' => 'unblock_contacts', - 'classpath' => 'message/externallib.php', - 'description' => '** DEPRECATED ** Please do not call this function any more. - Unblock contacts', - 'type' => 'write', - 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), - ), 'core_message_get_user_notification_preferences' => array( 'classname' => 'core_message_external', 'methodname' => 'get_user_notification_preferences', diff --git a/message/amd/build/message_repository.min.js b/message/amd/build/message_repository.min.js index 12a1412952c..62651a7d5be 100644 --- a/message/amd/build/message_repository.min.js +++ b/message/amd/build/message_repository.min.js @@ -1,2 +1,2 @@ -define ("core_message/message_repository",["jquery","core/ajax","core/notification","core_message/message_drawer_view_conversation_constants"],function(a,b,c,d){var e=d.CONVERSATION_TYPES,f=function(a,c){var d=c.map(function(b){return{touserid:a,text:b}});return b.call([{methodname:"core_message_send_instant_messages",args:{messages:d}}])[0].then(function(a){var b=a.reduce(function(a,b){if(b.errormessage){a.push(b.errormessage)}return a},[]);if(b.length){throw new Error(b.join("\n"))}return a}).then(function(a){return a.map(function(a){return{id:a.msgid,text:a.text,timecreated:a.timecreated,useridfrom:a.useridfrom,conversationid:a.conversationid,candeletemessagesforallusers:a.candeletemessagesforallusers}})})},g=function(a,c){var d=c.map(function(a){return{text:a}});return b.call([{methodname:"core_message_send_messages_to_conversation",args:{conversationid:a,messages:d}}])[0]};return{query:function query(a){if("undefined"==typeof a.limit){a.limit=0}if("undefined"==typeof a.offset){a.offset=0}if("undefined"==typeof a.type){a.type=null}if("undefined"==typeof a.favouritesonly){a.favouritesonly=!1}a.limitfrom=a.offset;a.limitnum=a.limit;delete a.limit;delete a.offset;var d=b.call([{methodname:"core_message_data_for_messagearea_conversations",args:a}])[0];d.fail(c.exception);return d},countUnreadConversations:function countUnreadConversations(a){var d=b.call([{methodname:"core_message_get_unread_conversations_count",args:a}])[0];d.fail(c.exception);return d},markAllAsRead:function markAllAsRead(a){var d=b.call([{methodname:"core_message_mark_all_messages_as_read",args:a}])[0];d.fail(c.exception);return d},getContacts:function getContacts(a,c,d){var e={userid:a};if("undefined"!=typeof c){e.limitnum=c}if("undefined"!=typeof d){e.limitfrom=d}return b.call([{methodname:"core_message_get_user_contacts",args:e}])[0]},getProfile:function getProfile(a,c){return b.call([{methodname:"core_message_data_for_messagearea_get_profile",args:{currentuserid:a,otheruserid:c}}])[0]},blockUser:function blockUser(c,d){return a.when.apply(null,b.call([{methodname:"core_message_block_user",args:{userid:c,blockeduserid:d}},{methodname:"core_message_get_member_info",args:{referenceuserid:c,userids:[d],includecontactrequests:!0,includeprivacyinfo:!0}}])).then(function(a,b){return b.length?b[0]:{}})},unblockUser:function unblockUser(c,d){return a.when.apply(null,b.call([{methodname:"core_message_unblock_user",args:{userid:c,unblockeduserid:d}},{methodname:"core_message_get_member_info",args:{referenceuserid:c,userids:[d],includecontactrequests:!0,includeprivacyinfo:!0}}])).then(function(a,b){return b.length?b[0]:{}})},createContactRequest:function createContactRequest(a,c){return b.call([{methodname:"core_message_create_contact_request",args:{userid:a,requesteduserid:c}}])[0]},deleteContacts:function deleteContacts(c,d){return a.when.apply(null,b.call([{methodname:"core_message_delete_contacts",args:{userid:c,userids:d}},{methodname:"core_message_get_member_info",args:{referenceuserid:c,userids:d,includecontactrequests:!0,includeprivacyinfo:!0}}])).then(function(a,b){return b})},getMessages:function getMessages(a,c,d,e,f,g){var h={currentuserid:a,convid:c,newest:f?!0:!1};if("undefined"!=typeof d){h.limitnum=d}if("undefined"!=typeof e){h.limitfrom=e}if("undefined"!=typeof g){h.timefrom=g}return b.call([{methodname:"core_message_get_conversation_messages",args:h}])[0]},searchUsers:function searchUsers(a,c,d,e){var f={userid:a,search:c};if("undefined"!=typeof d){f.limitnum=d}if("undefined"!=typeof e){f.limitfrom=e}return b.call([{methodname:"core_message_message_search_users",args:f}])[0]},searchMessages:function searchMessages(a,c,d,e){var f={userid:a,search:c};if("undefined"!=typeof d){f.limitnum=d}if("undefined"!=typeof e){f.limitfrom=e}return b.call([{methodname:"core_message_data_for_messagearea_search_messages",args:f}])[0]},sendMessagesToUser:f,sendMessageToUser:function sendMessageToUser(a,b){return f(a,[b]).then(function(a){return a[0]})},sendMessagesToConversation:g,sendMessageToConversation:function sendMessageToConversation(a,b){return g(a,[b]).then(function(a){return a[0]})},savePreferences:function savePreferences(a,c){return b.call([{methodname:"core_user_update_user_preferences",args:{userid:a,preferences:c}}])[0]},getPreferences:function getPreferences(a){return b.call([{methodname:"core_user_get_user_preferences",args:{userid:a}}])[0]},deleteMessages:function deleteMessages(c,d){return a.when.apply(null,b.call(d.map(function(a){return{methodname:"core_message_delete_message",args:{messageid:a,userid:c}}})))},deleteMessagesForAllUsers:function deleteMessagesForAllUsers(c,d){return a.when.apply(null,b.call(d.map(function(a){return{methodname:"core_message_delete_message_for_all_users",args:{messageid:a,userid:c}}})))},deleteConversation:function deleteConversation(a,c){return b.call([{methodname:"core_message_delete_conversations_by_id",args:{userid:a,conversationids:[c]}}])[0]},getContactRequests:function getContactRequests(a){return b.call([{methodname:"core_message_get_contact_requests",args:{userid:a}}])[0]},acceptContactRequest:function acceptContactRequest(c,d){return a.when.apply(null,b.call([{methodname:"core_message_confirm_contact_request",args:{userid:c,requesteduserid:d}},{methodname:"core_message_get_member_info",args:{referenceuserid:d,userids:[c],includecontactrequests:!0,includeprivacyinfo:!0}}])).then(function(a,b){return b.length?b[0]:{}})},declineContactRequest:function declineContactRequest(c,d){return a.when.apply(null,b.call([{methodname:"core_message_decline_contact_request",args:{userid:c,requesteduserid:d}},{methodname:"core_message_get_member_info",args:{referenceuserid:d,userids:[c],includecontactrequests:!0,includeprivacyinfo:!0}}])).then(function(a,b){return b.length?b[0]:{}})},getConversation:function getConversation(a,c,d,e,f,g,h,i,j){var k={userid:a,conversationid:c};if("undefined"!=typeof d&&null!==d){k.includecontactrequests=d}if("undefined"!=typeof e&&null!==e){k.includeprivacyinfo=e}if("undefined"!=typeof f&&null!==f){k.memberlimit=f}if("undefined"!=typeof g&&null!==g){k.memberoffset=g}if("undefined"!=typeof h&&null!==h){k.messagelimit=h}if("undefined"!=typeof i&&null!==i){k.messageoffset=i}if("undefined"!=typeof j&&null!==j){k.newestmessagesfirst=j}return b.call([{methodname:"core_message_get_conversation",args:k}])[0]},getConversationBetweenUsers:function getConversationBetweenUsers(a,c,d,e,f,g,h,i,j){var k={userid:a,otheruserid:c};if("undefined"!=typeof d&&null!==d){k.includecontactrequests=d}if("undefined"!=typeof e&&null!==e){k.includeprivacyinfo=e}if("undefined"!=typeof f&&null!==f){k.memberlimit=f}if("undefined"!=typeof g&&null!==g){k.memberoffset=g}if("undefined"!=typeof h&&null!==h){k.messagelimit=h}if("undefined"!=typeof i&&null!==i){k.messageoffset=i}if("undefined"!=typeof j&&null!==j){k.newestmessagesfirst=j}return b.call([{methodname:"core_message_get_conversation_between_users",args:k}])[0]},getSelfConversation:function getSelfConversation(a,c,d,e){var f={userid:a};if("undefined"!=typeof c&&null!==c){f.messagelimit=c}if("undefined"!=typeof d&&null!==d){f.messageoffset=d}if("undefined"!=typeof e&&null!==e){f.newestmessagesfirst=e}return b.call([{methodname:"core_message_get_self_conversation",args:f}])[0]},getConversations:function getConversations(a,c,d,f,g,h){var i={userid:a,type:c};if("undefined"!=typeof d&&null!==d){i.limitnum=d}if("undefined"!=typeof f&&null!==f){i.limitfrom=f}if("undefined"!=typeof g&&null!==g){i.favourites=g}if("undefined"!=typeof h&&null!==h){i.mergeself=h}return b.call([{methodname:"core_message_get_conversations",args:i}])[0].then(function(a){if(a.conversations.length){a.conversations=a.conversations.map(function(a){if(a.type==e.PRIVATE||a.type==e.SELF){var b=a.members.length?a.members[0]:null;if(b){a.name=a.name?a.name:b.fullname;a.imageurl=a.imageurl?a.imageurl:b.profileimageurl}}return a})}return a})},getConversationMembers:function getConversationMembers(a,c,d,e,f){var g={userid:c,conversationid:a};if("undefined"!=typeof d&&null!==d){g.limitnum=d}if("undefined"!=typeof e&&null!==e){g.limitfrom=e}if("undefined"!=typeof f&&null!==f){g.includecontactrequests=f}return b.call([{methodname:"core_message_get_conversation_members",args:g}])[0]},setFavouriteConversations:function setFavouriteConversations(a,c){return b.call([{methodname:"core_message_set_favourite_conversations",args:{userid:a,conversations:c}}])[0]},setMutedConversations:function setMutedConversations(a,c){return b.call([{methodname:"core_message_mute_conversations",args:{userid:a,conversationids:c}}])[0]},unsetFavouriteConversations:function unsetFavouriteConversations(a,c){return b.call([{methodname:"core_message_unset_favourite_conversations",args:{userid:a,conversations:c}}])[0]},unsetMutedConversations:function unsetMutedConversations(a,c){return b.call([{methodname:"core_message_unmute_conversations",args:{userid:a,conversationids:c}}])[0]},getMemberInfo:function getMemberInfo(a,c,d,e){var f={referenceuserid:a,userids:c};if("undefined"!=typeof d){f.includecontactrequests=d}if("undefined"!=typeof e){f.includeprivacyinfo=e}return b.call([{methodname:"core_message_get_member_info",args:f}])[0]},markAllConversationMessagesAsRead:function markAllConversationMessagesAsRead(a,c){return b.call([{methodname:"core_message_mark_all_conversation_messages_as_read",args:{userid:a,conversationid:c}}])[0]},getUserMessagePreferences:function getUserMessagePreferences(a){return b.call([{methodname:"core_message_get_user_message_preferences",args:{userid:a}}])[0]},getTotalConversationCounts:function getTotalConversationCounts(a){return b.call([{methodname:"core_message_get_conversation_counts",args:{userid:a}}])[0]},getUnreadConversationCounts:function getUnreadConversationCounts(a){return b.call([{methodname:"core_message_get_unread_conversation_counts",args:{userid:a}}])[0]},getAllConversationCounts:function getAllConversationCounts(c){return a.when.apply(null,b.call([{methodname:"core_message_get_conversation_counts",args:{userid:c}},{methodname:"core_message_get_unread_conversation_counts",args:{userid:c}}])).then(function(a,b){return{total:a,unread:b}})}}}); +define ("core_message/message_repository",["jquery","core/ajax","core/notification","core_message/message_drawer_view_conversation_constants"],function(a,b,c,d){var e=d.CONVERSATION_TYPES,f=function(a,c){var d=c.map(function(b){return{touserid:a,text:b}});return b.call([{methodname:"core_message_send_instant_messages",args:{messages:d}}])[0].then(function(a){var b=a.reduce(function(a,b){if(b.errormessage){a.push(b.errormessage)}return a},[]);if(b.length){throw new Error(b.join("\n"))}return a}).then(function(a){return a.map(function(a){return{id:a.msgid,text:a.text,timecreated:a.timecreated,useridfrom:a.useridfrom,conversationid:a.conversationid,candeletemessagesforallusers:a.candeletemessagesforallusers}})})},g=function(a,c){var d=c.map(function(a){return{text:a}});return b.call([{methodname:"core_message_send_messages_to_conversation",args:{conversationid:a,messages:d}}])[0]};return{countUnreadConversations:function countUnreadConversations(a){var d=b.call([{methodname:"core_message_get_unread_conversations_count",args:a}])[0];d.fail(c.exception);return d},getContacts:function getContacts(a,c,d){var e={userid:a};if("undefined"!=typeof c){e.limitnum=c}if("undefined"!=typeof d){e.limitfrom=d}return b.call([{methodname:"core_message_get_user_contacts",args:e}])[0]},blockUser:function blockUser(c,d){return a.when.apply(null,b.call([{methodname:"core_message_block_user",args:{userid:c,blockeduserid:d}},{methodname:"core_message_get_member_info",args:{referenceuserid:c,userids:[d],includecontactrequests:!0,includeprivacyinfo:!0}}])).then(function(a,b){return b.length?b[0]:{}})},unblockUser:function unblockUser(c,d){return a.when.apply(null,b.call([{methodname:"core_message_unblock_user",args:{userid:c,unblockeduserid:d}},{methodname:"core_message_get_member_info",args:{referenceuserid:c,userids:[d],includecontactrequests:!0,includeprivacyinfo:!0}}])).then(function(a,b){return b.length?b[0]:{}})},createContactRequest:function createContactRequest(a,c){return b.call([{methodname:"core_message_create_contact_request",args:{userid:a,requesteduserid:c}}])[0]},deleteContacts:function deleteContacts(c,d){return a.when.apply(null,b.call([{methodname:"core_message_delete_contacts",args:{userid:c,userids:d}},{methodname:"core_message_get_member_info",args:{referenceuserid:c,userids:d,includecontactrequests:!0,includeprivacyinfo:!0}}])).then(function(a,b){return b})},getMessages:function getMessages(a,c,d,e,f,g){var h={currentuserid:a,convid:c,newest:f?!0:!1};if("undefined"!=typeof d){h.limitnum=d}if("undefined"!=typeof e){h.limitfrom=e}if("undefined"!=typeof g){h.timefrom=g}return b.call([{methodname:"core_message_get_conversation_messages",args:h}])[0]},searchUsers:function searchUsers(a,c,d,e){var f={userid:a,search:c};if("undefined"!=typeof d){f.limitnum=d}if("undefined"!=typeof e){f.limitfrom=e}return b.call([{methodname:"core_message_message_search_users",args:f}])[0]},searchMessages:function searchMessages(a,c,d,e){var f={userid:a,search:c};if("undefined"!=typeof d){f.limitnum=d}if("undefined"!=typeof e){f.limitfrom=e}return b.call([{methodname:"core_message_data_for_messagearea_search_messages",args:f}])[0]},sendMessagesToUser:f,sendMessageToUser:function sendMessageToUser(a,b){return f(a,[b]).then(function(a){return a[0]})},sendMessagesToConversation:g,sendMessageToConversation:function sendMessageToConversation(a,b){return g(a,[b]).then(function(a){return a[0]})},savePreferences:function savePreferences(a,c){return b.call([{methodname:"core_user_update_user_preferences",args:{userid:a,preferences:c}}])[0]},getPreferences:function getPreferences(a){return b.call([{methodname:"core_user_get_user_preferences",args:{userid:a}}])[0]},deleteMessages:function deleteMessages(c,d){return a.when.apply(null,b.call(d.map(function(a){return{methodname:"core_message_delete_message",args:{messageid:a,userid:c}}})))},deleteMessagesForAllUsers:function deleteMessagesForAllUsers(c,d){return a.when.apply(null,b.call(d.map(function(a){return{methodname:"core_message_delete_message_for_all_users",args:{messageid:a,userid:c}}})))},deleteConversation:function deleteConversation(a,c){return b.call([{methodname:"core_message_delete_conversations_by_id",args:{userid:a,conversationids:[c]}}])[0]},getContactRequests:function getContactRequests(a){return b.call([{methodname:"core_message_get_contact_requests",args:{userid:a}}])[0]},acceptContactRequest:function acceptContactRequest(c,d){return a.when.apply(null,b.call([{methodname:"core_message_confirm_contact_request",args:{userid:c,requesteduserid:d}},{methodname:"core_message_get_member_info",args:{referenceuserid:d,userids:[c],includecontactrequests:!0,includeprivacyinfo:!0}}])).then(function(a,b){return b.length?b[0]:{}})},declineContactRequest:function declineContactRequest(c,d){return a.when.apply(null,b.call([{methodname:"core_message_decline_contact_request",args:{userid:c,requesteduserid:d}},{methodname:"core_message_get_member_info",args:{referenceuserid:d,userids:[c],includecontactrequests:!0,includeprivacyinfo:!0}}])).then(function(a,b){return b.length?b[0]:{}})},getConversation:function getConversation(a,c,d,e,f,g,h,i,j){var k={userid:a,conversationid:c};if("undefined"!=typeof d&&null!==d){k.includecontactrequests=d}if("undefined"!=typeof e&&null!==e){k.includeprivacyinfo=e}if("undefined"!=typeof f&&null!==f){k.memberlimit=f}if("undefined"!=typeof g&&null!==g){k.memberoffset=g}if("undefined"!=typeof h&&null!==h){k.messagelimit=h}if("undefined"!=typeof i&&null!==i){k.messageoffset=i}if("undefined"!=typeof j&&null!==j){k.newestmessagesfirst=j}return b.call([{methodname:"core_message_get_conversation",args:k}])[0]},getConversationBetweenUsers:function getConversationBetweenUsers(a,c,d,e,f,g,h,i,j){var k={userid:a,otheruserid:c};if("undefined"!=typeof d&&null!==d){k.includecontactrequests=d}if("undefined"!=typeof e&&null!==e){k.includeprivacyinfo=e}if("undefined"!=typeof f&&null!==f){k.memberlimit=f}if("undefined"!=typeof g&&null!==g){k.memberoffset=g}if("undefined"!=typeof h&&null!==h){k.messagelimit=h}if("undefined"!=typeof i&&null!==i){k.messageoffset=i}if("undefined"!=typeof j&&null!==j){k.newestmessagesfirst=j}return b.call([{methodname:"core_message_get_conversation_between_users",args:k}])[0]},getSelfConversation:function getSelfConversation(a,c,d,e){var f={userid:a};if("undefined"!=typeof c&&null!==c){f.messagelimit=c}if("undefined"!=typeof d&&null!==d){f.messageoffset=d}if("undefined"!=typeof e&&null!==e){f.newestmessagesfirst=e}return b.call([{methodname:"core_message_get_self_conversation",args:f}])[0]},getConversations:function getConversations(a,c,d,f,g,h){var i={userid:a,type:c};if("undefined"!=typeof d&&null!==d){i.limitnum=d}if("undefined"!=typeof f&&null!==f){i.limitfrom=f}if("undefined"!=typeof g&&null!==g){i.favourites=g}if("undefined"!=typeof h&&null!==h){i.mergeself=h}return b.call([{methodname:"core_message_get_conversations",args:i}])[0].then(function(a){if(a.conversations.length){a.conversations=a.conversations.map(function(a){if(a.type==e.PRIVATE||a.type==e.SELF){var b=a.members.length?a.members[0]:null;if(b){a.name=a.name?a.name:b.fullname;a.imageurl=a.imageurl?a.imageurl:b.profileimageurl}}return a})}return a})},getConversationMembers:function getConversationMembers(a,c,d,e,f){var g={userid:c,conversationid:a};if("undefined"!=typeof d&&null!==d){g.limitnum=d}if("undefined"!=typeof e&&null!==e){g.limitfrom=e}if("undefined"!=typeof f&&null!==f){g.includecontactrequests=f}return b.call([{methodname:"core_message_get_conversation_members",args:g}])[0]},setFavouriteConversations:function setFavouriteConversations(a,c){return b.call([{methodname:"core_message_set_favourite_conversations",args:{userid:a,conversations:c}}])[0]},setMutedConversations:function setMutedConversations(a,c){return b.call([{methodname:"core_message_mute_conversations",args:{userid:a,conversationids:c}}])[0]},unsetFavouriteConversations:function unsetFavouriteConversations(a,c){return b.call([{methodname:"core_message_unset_favourite_conversations",args:{userid:a,conversations:c}}])[0]},unsetMutedConversations:function unsetMutedConversations(a,c){return b.call([{methodname:"core_message_unmute_conversations",args:{userid:a,conversationids:c}}])[0]},getMemberInfo:function getMemberInfo(a,c,d,e){var f={referenceuserid:a,userids:c};if("undefined"!=typeof d){f.includecontactrequests=d}if("undefined"!=typeof e){f.includeprivacyinfo=e}return b.call([{methodname:"core_message_get_member_info",args:f}])[0]},markAllConversationMessagesAsRead:function markAllConversationMessagesAsRead(a,c){return b.call([{methodname:"core_message_mark_all_conversation_messages_as_read",args:{userid:a,conversationid:c}}])[0]},getUserMessagePreferences:function getUserMessagePreferences(a){return b.call([{methodname:"core_message_get_user_message_preferences",args:{userid:a}}])[0]},getTotalConversationCounts:function getTotalConversationCounts(a){return b.call([{methodname:"core_message_get_conversation_counts",args:{userid:a}}])[0]},getUnreadConversationCounts:function getUnreadConversationCounts(a){return b.call([{methodname:"core_message_get_unread_conversation_counts",args:{userid:a}}])[0]},getAllConversationCounts:function getAllConversationCounts(c){return a.when.apply(null,b.call([{methodname:"core_message_get_conversation_counts",args:{userid:c}},{methodname:"core_message_get_unread_conversation_counts",args:{userid:c}}])).then(function(a,b){return{total:a,unread:b}})}}}); //# sourceMappingURL=message_repository.min.js.map diff --git a/message/amd/build/message_repository.min.js.map b/message/amd/build/message_repository.min.js.map index f2f971001db..053d670f04d 100644 --- a/message/amd/build/message_repository.min.js.map +++ b/message/amd/build/message_repository.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/message_repository.js"],"names":["define","$","Ajax","Notification","Constants","CONVERSATION_TYPES","sendMessagesToUser","toUserId","messages","formattedMessages","map","message","touserid","text","call","methodname","args","then","results","errors","reduce","carry","result","errormessage","push","length","Error","join","id","msgid","timecreated","useridfrom","conversationid","candeletemessagesforallusers","sendMessagesToConversation","conversationId","query","limit","offset","type","favouritesonly","limitfrom","limitnum","promise","fail","exception","countUnreadConversations","markAllAsRead","getContacts","userId","userid","getProfile","profileUserId","currentuserid","otheruserid","blockUser","blockedUserId","when","apply","blockeduserid","referenceuserid","userids","includecontactrequests","includeprivacyinfo","reponse1","profiles","unblockUser","unblockedUserId","unblockeduserid","createContactRequest","requestUserIds","requesteduserid","deleteContacts","contactUserIds","response1","getMessages","currentUserId","newestFirst","timeFrom","convid","newest","timefrom","searchUsers","searchString","search","searchMessages","sendMessageToUser","sendMessageToConversation","savePreferences","preferences","getPreferences","deleteMessages","messageIds","messageId","messageid","deleteMessagesForAllUsers","deleteConversation","conversationids","getContactRequests","acceptContactRequest","sendingUserId","recipientUserId","declineContactRequest","getConversation","loggedInUserId","includeContactRequests","includePrivacyInfo","memberLimit","memberOffset","messageLimit","messageOffset","newestMessagesFirst","memberlimit","memberoffset","messagelimit","messageoffset","newestmessagesfirst","getConversationBetweenUsers","otherUserId","getSelfConversation","getConversations","favourites","mergeself","conversations","conversation","PRIVATE","SELF","otherUser","members","name","fullname","imageurl","profileimageurl","getConversationMembers","setFavouriteConversations","conversationIds","setMutedConversations","unsetFavouriteConversations","unsetMutedConversations","getMemberInfo","referenceUserId","userIds","markAllConversationMessagesAsRead","getUserMessagePreferences","getTotalConversationCounts","getUnreadConversationCounts","getAllConversationCounts","total","unread"],"mappings":"AAwBAA,OAAM,mCACN,CACI,QADJ,CAEI,WAFJ,CAGI,mBAHJ,CAII,yDAJJ,CADM,CAMH,SACCC,CADD,CAECC,CAFD,CAGCC,CAHD,CAICC,CAJD,CAIY,IAEPC,CAAAA,CAAkB,CAAGD,CAAS,CAACC,kBAFxB,CAyWPC,CAAkB,CAAG,SAASC,CAAT,CAAmBC,CAAnB,CAA6B,IAC9CC,CAAAA,CAAiB,CAAGD,CAAQ,CAACE,GAAT,CAAa,SAASC,CAAT,CAAkB,CACnD,MAAO,CACHC,QAAQ,CAAEL,CADP,CAEHM,IAAI,CAAEF,CAFH,CAIV,CALuB,CAD0B,CAclD,MAAOT,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,CAFV,CAPW,CAcW,CAAnB,EAAwChC,IAAxC,CAA6C,SAASkI,CAAT,CAAgBC,CAAhB,CAAwB,CACxE,MAAO,CACHD,KAAK,CAAEA,CADJ,CAEHC,MAAM,CAAEA,CAFL,CAIV,CALM,CAMV,CAEM,CAyCV,CAroCK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Retrieves messages from the server.\n *\n * @module core_message/message_repository\n * @class message_repository\n * @package message\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n[\n 'jquery',\n 'core/ajax',\n 'core/notification',\n 'core_message/message_drawer_view_conversation_constants'\n], function(\n $,\n Ajax,\n Notification,\n Constants) {\n\n var CONVERSATION_TYPES = Constants.CONVERSATION_TYPES;\n\n /**\n * Retrieve a list of messages from the server.\n *\n * @param {object} args The request arguments:\n * @return {object} jQuery promise\n */\n var query = function(args) {\n // Normalise the arguments to use limit/offset rather than limitnum/limitfrom.\n if (typeof args.limit === 'undefined') {\n args.limit = 0;\n }\n\n if (typeof args.offset === 'undefined') {\n args.offset = 0;\n }\n\n if (typeof args.type === 'undefined') {\n args.type = null;\n }\n\n if (typeof args.favouritesonly === 'undefined') {\n args.favouritesonly = false;\n }\n\n args.limitfrom = args.offset;\n args.limitnum = args.limit;\n\n delete args.limit;\n delete args.offset;\n\n var request = {\n methodname: 'core_message_data_for_messagearea_conversations',\n args: args\n };\n\n var promise = Ajax.call([request])[0];\n\n promise.fail(Notification.exception);\n\n return promise;\n };\n\n /**\n * Count the number of unread conversations (one or more messages from a user)\n * for a given user.\n *\n * @param {object} args The request arguments:\n * @return {object} jQuery promise\n */\n var countUnreadConversations = function(args) {\n var request = {\n methodname: 'core_message_get_unread_conversations_count',\n args: args\n };\n\n var promise = Ajax.call([request])[0];\n\n promise.fail(Notification.exception);\n\n return promise;\n };\n\n /**\n * Mark all of unread messages for a user as read.\n *\n * @param {object} args The request arguments:\n * @return {object} jQuery promise\n */\n var markAllAsRead = function(args) {\n var request = {\n methodname: 'core_message_mark_all_messages_as_read',\n args: args\n };\n\n var promise = Ajax.call([request])[0];\n\n promise.fail(Notification.exception);\n\n return promise;\n };\n\n /**\n * Get contacts for given user.\n *\n * @param {int} userId The user id\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @return {object} jQuery promise\n */\n var getContacts = function(userId, limit, offset) {\n var args = {\n userid: userId\n };\n\n if (typeof limit !== 'undefined') {\n args.limitnum = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.limitfrom = offset;\n }\n\n var request = {\n methodname: 'core_message_get_user_contacts',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Request profile information as a user for a given user.\n *\n * @param {int} userId The requesting user\n * @param {int} profileUserId The id of the user who's profile is being requested\n * @return {object} jQuery promise\n */\n var getProfile = function(userId, profileUserId) {\n var request = {\n methodname: 'core_message_data_for_messagearea_get_profile',\n args: {\n currentuserid: userId,\n otheruserid: profileUserId\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Block a user.\n *\n * @param {int} userId The requesting user\n * @param {int} blockedUserId Id of user to block\n * @return {object} jQuery promise\n */\n var blockUser = function(userId, blockedUserId) {\n var requests = [\n {\n methodname: 'core_message_block_user',\n args: {\n userid: userId,\n blockeduserid: blockedUserId\n }\n },\n {\n methodname: 'core_message_get_member_info',\n args: {\n referenceuserid: userId,\n userids: [blockedUserId],\n includecontactrequests: true,\n includeprivacyinfo: true\n }\n }\n ];\n\n // Wrap both requests in a single promise so that we can catch an error\n // from either request.\n return $.when.apply(null, Ajax.call(requests)).then(function(reponse1, profiles) {\n // Only return the profile.\n return profiles.length ? profiles[0] : {};\n });\n };\n\n /**\n * Unblock a user.\n *\n * @param {int} userId The requesting user\n * @param {int} unblockedUserId Id of user to unblock\n * @return {object} jQuery promise\n */\n var unblockUser = function(userId, unblockedUserId) {\n var requests = [\n {\n methodname: 'core_message_unblock_user',\n args: {\n userid: userId,\n unblockeduserid: unblockedUserId\n }\n },\n {\n methodname: 'core_message_get_member_info',\n args: {\n referenceuserid: userId,\n userids: [unblockedUserId],\n includecontactrequests: true,\n includeprivacyinfo: true\n }\n }\n ];\n\n // Wrap both requests in a single promise so that we can catch an error\n // from either request.\n return $.when.apply(null, Ajax.call(requests)).then(function(reponse1, profiles) {\n // Only return the profile.\n return profiles.length ? profiles[0] : {};\n });\n };\n\n /**\n * Create a request to add a user as a contact.\n *\n * @param {int} userId The requesting user\n * @param {int[]} requestUserIds List of user ids to add\n * @return {object} jQuery promise\n */\n var createContactRequest = function(userId, requestUserIds) {\n var request = {\n methodname: 'core_message_create_contact_request',\n args: {\n userid: userId,\n requesteduserid: requestUserIds\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Remove a list of users as contacts.\n *\n * @param {int} userId The requesting user\n * @param {int[]} contactUserIds List of user ids to add\n * @return {object} jQuery promise\n */\n var deleteContacts = function(userId, contactUserIds) {\n var requests = [\n {\n methodname: 'core_message_delete_contacts',\n args: {\n userid: userId,\n userids: contactUserIds\n }\n },\n {\n methodname: 'core_message_get_member_info',\n args: {\n referenceuserid: userId,\n userids: contactUserIds,\n includecontactrequests: true,\n includeprivacyinfo: true\n }\n }\n ];\n\n return $.when.apply(null, Ajax.call(requests)).then(function(response1, profiles) {\n // Return all of the profiles as an array.\n return profiles;\n });\n };\n\n /**\n * Get messages between two users.\n *\n * @param {int} currentUserId The requesting user\n * @param {int} conversationId Other user in the conversation\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @param {bool} newestFirst Order results by newest first\n * @param {int} timeFrom Only return messages after this timestamp\n * @return {object} jQuery promise\n */\n var getMessages = function(currentUserId, conversationId, limit, offset, newestFirst, timeFrom) {\n var args = {\n currentuserid: currentUserId,\n convid: conversationId,\n newest: newestFirst ? true : false\n };\n\n if (typeof limit !== 'undefined') {\n args.limitnum = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.limitfrom = offset;\n }\n\n if (typeof timeFrom !== 'undefined') {\n args.timefrom = timeFrom;\n }\n\n var request = {\n methodname: 'core_message_get_conversation_messages',\n args: args\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Search for users.\n *\n * @param {int} userId The requesting user\n * @param {string} searchString Search string\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @return {object} jQuery promise\n */\n var searchUsers = function(userId, searchString, limit, offset) {\n var args = {\n userid: userId,\n search: searchString\n };\n\n if (typeof limit !== 'undefined') {\n args.limitnum = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.limitfrom = offset;\n }\n\n var request = {\n methodname: 'core_message_message_search_users',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Search for messages.\n *\n * @param {int} userId The requesting user\n * @param {string} searchString Search string\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @return {object} jQuery promise\n */\n var searchMessages = function(userId, searchString, limit, offset) {\n var args = {\n userid: userId,\n search: searchString\n };\n\n if (typeof limit !== 'undefined') {\n args.limitnum = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.limitfrom = offset;\n }\n\n var request = {\n methodname: 'core_message_data_for_messagearea_search_messages',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Send a list of messages to a user.\n *\n * @param {int} toUserId The recipient user id\n * @param {string[]} messages List of messages to send\n * @return {object} jQuery promise\n */\n var sendMessagesToUser = function(toUserId, messages) {\n var formattedMessages = messages.map(function(message) {\n return {\n touserid: toUserId,\n text: message\n };\n });\n var request = {\n methodname: 'core_message_send_instant_messages',\n args: {\n messages: formattedMessages\n }\n };\n\n return Ajax.call([request])[0]\n .then(function(results) {\n // Error handling for the weird way the old function works.\n var errors = results.reduce(function(carry, result) {\n if (result.errormessage) {\n carry.push(result.errormessage);\n }\n\n return carry;\n }, []);\n if (errors.length) {\n throw new Error(errors.join(\"\\n\"));\n }\n\n return results;\n })\n .then(function(results) {\n // Format the results to match the other send message function.\n return results.map(function(result) {\n return {\n id: result.msgid,\n text: result.text,\n timecreated: result.timecreated,\n useridfrom: result.useridfrom,\n conversationid: result.conversationid,\n candeletemessagesforallusers: result.candeletemessagesforallusers\n };\n });\n });\n };\n\n /**\n * Send a single message to a user.\n *\n * @param {int} toUserId The recipient user id\n * @param {string} text The message text\n * @return {object} jQuery promise\n */\n var sendMessageToUser = function(toUserId, text) {\n return sendMessagesToUser(toUserId, [text])\n .then(function(results) {\n return results[0];\n });\n };\n\n /**\n * Send messages to a conversation.\n *\n * @param {int} conversationId The conversation id\n * @param {string[]} messages List of messages to send\n * @return {object} jQuery promise\n */\n var sendMessagesToConversation = function(conversationId, messages) {\n var formattedMessages = messages.map(function(message) {\n return {\n text: message\n };\n });\n var request = {\n methodname: 'core_message_send_messages_to_conversation',\n args: {\n conversationid: conversationId,\n messages: formattedMessages\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Send a message to a conversation.\n *\n * @param {int} conversationId The conversation id\n * @param {string} text The message text\n * @return {object} jQuery promise\n */\n var sendMessageToConversation = function(conversationId, text) {\n return sendMessagesToConversation(conversationId, [text])\n .then(function(result) {\n return result[0];\n });\n };\n\n /**\n * Save message preferences.\n *\n * @param {int} userId The owner of the preferences\n * @param {object[]} preferences New preferences values\n * @return {object} jQuery promise\n */\n var savePreferences = function(userId, preferences) {\n var request = {\n methodname: 'core_user_update_user_preferences',\n args: {\n userid: userId,\n preferences: preferences\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get the user's preferences.\n *\n * @param {int} userId The target user\n * @return {object} jQuery promise\n */\n var getPreferences = function(userId) {\n var request = {\n methodname: 'core_user_get_user_preferences',\n args: {\n userid: userId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Delete a list of messages.\n *\n * @param {int} userId The user to delete messages for\n * @param {int[]} messageIds List of message ids to delete\n * @return {object} jQuery promise\n */\n var deleteMessages = function(userId, messageIds) {\n return $.when.apply(null, Ajax.call(messageIds.map(function(messageId) {\n return {\n methodname: 'core_message_delete_message',\n args: {\n messageid: messageId,\n userid: userId\n }\n };\n })));\n };\n\n /**\n * Delete a list of messages for all users.\n *\n * @param {int} userId The user to delete messages for\n * @param {int[]} messageIds List of message ids to delete\n * @return {object} jQuery promise\n */\n var deleteMessagesForAllUsers = function(userId, messageIds) {\n return $.when.apply(null, Ajax.call(messageIds.map(function(messageId) {\n return {\n methodname: 'core_message_delete_message_for_all_users',\n args: {\n messageid: messageId,\n userid: userId\n }\n };\n })));\n };\n\n /**\n * Delete a conversation between two users.\n *\n * @param {int} userId The user to delete messages for\n * @param {int} conversationId The id of the conversation\n * @return {object} jQuery promise\n */\n var deleteConversation = function(userId, conversationId) {\n var request = {\n methodname: 'core_message_delete_conversations_by_id',\n args: {\n userid: userId,\n conversationids: [conversationId]\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get the list of contact requests for a user.\n *\n * @param {int} userId The user id\n * @return {object} jQuery promise\n */\n var getContactRequests = function(userId) {\n var request = {\n methodname: 'core_message_get_contact_requests',\n args: {\n userid: userId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Accept a contact request.\n *\n * @param {int} sendingUserId The user that sent the request\n * @param {int} recipientUserId The user that received the request\n * @return {object} jQuery promise\n */\n var acceptContactRequest = function(sendingUserId, recipientUserId) {\n var requests = [\n {\n methodname: 'core_message_confirm_contact_request',\n args: {\n userid: sendingUserId,\n requesteduserid: recipientUserId\n }\n },\n {\n methodname: 'core_message_get_member_info',\n args: {\n referenceuserid: recipientUserId,\n userids: [sendingUserId],\n includecontactrequests: true,\n includeprivacyinfo: true\n }\n }\n ];\n\n // Wrap both requests in a single promise so that we can catch an error\n // from either request.\n return $.when.apply(null, Ajax.call(requests)).then(function(reponse1, profiles) {\n // Only return the profile.\n return profiles.length ? profiles[0] : {};\n });\n };\n\n /**\n * Decline a contact request.\n *\n * @param {int} sendingUserId The user that sent the request\n * @param {int} recipientUserId The user that received the request\n * @return {object} jQuery promise\n */\n var declineContactRequest = function(sendingUserId, recipientUserId) {\n var requests = [\n {\n methodname: 'core_message_decline_contact_request',\n args: {\n userid: sendingUserId,\n requesteduserid: recipientUserId\n }\n },\n {\n methodname: 'core_message_get_member_info',\n args: {\n referenceuserid: recipientUserId,\n userids: [sendingUserId],\n includecontactrequests: true,\n includeprivacyinfo: true\n }\n }\n ];\n\n // Wrap both requests in a single promise so that we can catch an error\n // from either request.\n return $.when.apply(null, Ajax.call(requests)).then(function(reponse1, profiles) {\n // Only return the profile.\n return profiles.length ? profiles[0] : {};\n });\n };\n\n /**\n * Get a conversation.\n *\n * @param {int} loggedInUserId The logged in user\n * @param {int} conversationId The conversation id\n * @param {bool} includeContactRequests Incldue contact requests between members\n * @param {bool} includePrivacyInfo Include privacy info for members\n * @param {int} memberLimit Limit for members\n * @param {int} memberOffset Offset for members\n * @param {int} messageLimit Limit for messages\n * @param {int} messageOffset Offset for messages\n * @param {bool} newestMessagesFirst Order the messages by newest first\n * @return {object} jQuery promise\n */\n var getConversation = function(\n loggedInUserId,\n conversationId,\n includeContactRequests,\n includePrivacyInfo,\n memberLimit,\n memberOffset,\n messageLimit,\n messageOffset,\n newestMessagesFirst\n ) {\n var args = {\n userid: loggedInUserId,\n conversationid: conversationId\n };\n\n if (typeof includeContactRequests != 'undefined' && includeContactRequests !== null) {\n args.includecontactrequests = includeContactRequests;\n }\n\n if (typeof includePrivacyInfo != 'undefined' && includePrivacyInfo !== null) {\n args.includeprivacyinfo = includePrivacyInfo;\n }\n\n if (typeof memberLimit != 'undefined' && memberLimit !== null) {\n args.memberlimit = memberLimit;\n }\n\n if (typeof memberOffset != 'undefined' && memberOffset !== null) {\n args.memberoffset = memberOffset;\n }\n\n if (typeof messageLimit != 'undefined' && messageLimit !== null) {\n args.messagelimit = messageLimit;\n }\n\n if (typeof messageOffset != 'undefined' && messageOffset !== null) {\n args.messageoffset = messageOffset;\n }\n\n if (typeof newestMessagesFirst != 'undefined' && newestMessagesFirst !== null) {\n args.newestmessagesfirst = newestMessagesFirst;\n }\n\n var request = {\n methodname: 'core_message_get_conversation',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get a conversation between users.\n *\n * @param {int} loggedInUserId The logged in user\n * @param {int} otherUserId The other user id\n * @param {bool} includeContactRequests Incldue contact requests between members\n * @param {bool} includePrivacyInfo Include privacy info for members\n * @param {int} memberLimit Limit for members\n * @param {int} memberOffset Offset for members\n * @param {int} messageLimit Limit for messages\n * @param {int} messageOffset Offset for messages\n * @param {bool} newestMessagesFirst Order the messages by newest first\n * @return {object} jQuery promise\n */\n var getConversationBetweenUsers = function(\n loggedInUserId,\n otherUserId,\n includeContactRequests,\n includePrivacyInfo,\n memberLimit,\n memberOffset,\n messageLimit,\n messageOffset,\n newestMessagesFirst\n ) {\n var args = {\n userid: loggedInUserId,\n otheruserid: otherUserId\n };\n\n if (typeof includeContactRequests != 'undefined' && includeContactRequests !== null) {\n args.includecontactrequests = includeContactRequests;\n }\n\n if (typeof includePrivacyInfo != 'undefined' && includePrivacyInfo !== null) {\n args.includeprivacyinfo = includePrivacyInfo;\n }\n\n if (typeof memberLimit != 'undefined' && memberLimit !== null) {\n args.memberlimit = memberLimit;\n }\n\n if (typeof memberOffset != 'undefined' && memberOffset !== null) {\n args.memberoffset = memberOffset;\n }\n\n if (typeof messageLimit != 'undefined' && messageLimit !== null) {\n args.messagelimit = messageLimit;\n }\n\n if (typeof messageOffset != 'undefined' && messageOffset !== null) {\n args.messageoffset = messageOffset;\n }\n\n if (typeof newestMessagesFirst != 'undefined' && newestMessagesFirst !== null) {\n args.newestmessagesfirst = newestMessagesFirst;\n }\n\n var request = {\n methodname: 'core_message_get_conversation_between_users',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get a self-conversation.\n *\n * @param {int} loggedInUserId The logged in user\n * @param {int} messageLimit Limit for messages\n * @param {int} messageOffset Offset for messages\n * @param {bool} newestMessagesFirst Order the messages by newest first\n * @return {object} jQuery promise\n */\n var getSelfConversation = function(\n loggedInUserId,\n messageLimit,\n messageOffset,\n newestMessagesFirst\n ) {\n var args = {\n userid: loggedInUserId\n };\n\n if (typeof messageLimit != 'undefined' && messageLimit !== null) {\n args.messagelimit = messageLimit;\n }\n\n if (typeof messageOffset != 'undefined' && messageOffset !== null) {\n args.messageoffset = messageOffset;\n }\n\n if (typeof newestMessagesFirst != 'undefined' && newestMessagesFirst !== null) {\n args.newestmessagesfirst = newestMessagesFirst;\n }\n\n var request = {\n methodname: 'core_message_get_self_conversation',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get the conversations for a user.\n *\n * @param {int} userId The logged in user\n * @param {int|null} type The type of conversation to get\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @param {bool|null} favourites If favourites should be included or not\n * @return {object} jQuery promise\n */\n var getConversations = function(\n userId,\n type,\n limit,\n offset,\n favourites,\n mergeself\n ) {\n var args = {\n userid: userId,\n type: type\n };\n\n if (typeof limit != 'undefined' && limit !== null) {\n args.limitnum = limit;\n }\n\n if (typeof offset != 'undefined' && offset !== null) {\n args.limitfrom = offset;\n }\n\n if (typeof favourites != 'undefined' && favourites !== null) {\n args.favourites = favourites;\n }\n\n if (typeof mergeself != 'undefined' && mergeself !== null) {\n args.mergeself = mergeself;\n }\n\n var request = {\n methodname: 'core_message_get_conversations',\n args: args\n };\n\n return Ajax.call([request])[0]\n .then(function(result) {\n if (result.conversations.length) {\n result.conversations = result.conversations.map(function(conversation) {\n if (conversation.type == CONVERSATION_TYPES.PRIVATE || conversation.type == CONVERSATION_TYPES.SELF) {\n var otherUser = conversation.members.length ? conversation.members[0] : null;\n\n if (otherUser) {\n conversation.name = conversation.name ? conversation.name : otherUser.fullname;\n conversation.imageurl = conversation.imageurl ? conversation.imageurl : otherUser.profileimageurl;\n }\n }\n\n return conversation;\n });\n }\n\n return result;\n });\n };\n\n /**\n * Get the conversations for a user.\n *\n * @param {int} conversationId The conversation id\n * @param {int} loggedInUserId The logged in user\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @param {bool} includeContactRequests If contact requests should be included in result\n * @return {object} jQuery promise\n */\n var getConversationMembers = function(conversationId, loggedInUserId, limit, offset, includeContactRequests) {\n var args = {\n userid: loggedInUserId,\n conversationid: conversationId\n };\n\n if (typeof limit != 'undefined' && limit !== null) {\n args.limitnum = limit;\n }\n\n if (typeof offset != 'undefined' && offset !== null) {\n args.limitfrom = offset;\n }\n\n if (typeof includeContactRequests != 'undefined' && includeContactRequests !== null) {\n args.includecontactrequests = includeContactRequests;\n }\n\n var request = {\n methodname: 'core_message_get_conversation_members',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Set a list of conversations to set as favourites for the given user.\n *\n * @param {int} userId The user id\n * @param {array} conversationIds List of conversation ids to set as favourite\n * @return {object} jQuery promise\n */\n var setFavouriteConversations = function(userId, conversationIds) {\n\n var request = {\n methodname: 'core_message_set_favourite_conversations',\n args: {\n userid: userId,\n conversations: conversationIds\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Set a list of conversations to unset as favourites for the given user.\n *\n * @param {int} userId The user id\n * @param {array} conversationIds List of conversation ids to unset as favourite\n * @return {object} jQuery promise\n */\n var unsetFavouriteConversations = function(userId, conversationIds) {\n\n var request = {\n methodname: 'core_message_unset_favourite_conversations',\n args: {\n userid: userId,\n conversations: conversationIds\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Set a list of conversations to set as muted for the given user.\n *\n * @param {int} userId The user id\n * @param {array} conversationIds List of conversation ids to set as favourite\n * @return {object} jQuery promise\n */\n var setMutedConversations = function(userId, conversationIds) {\n var request = {\n methodname: 'core_message_mute_conversations',\n args: {\n userid: userId,\n conversationids: conversationIds\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Set a list of conversations to unset as muted for the given user.\n *\n * @param {int} userId The user id\n * @param {array} conversationIds List of conversation ids to unset as favourite\n * @return {object} jQuery promise\n */\n var unsetMutedConversations = function(userId, conversationIds) {\n var request = {\n methodname: 'core_message_unmute_conversations',\n args: {\n userid: userId,\n conversationids: conversationIds\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get a list of user's member info.\n *\n * @param {int} referenceUserId The user id\n * @param {array} userIds List of user ids to get\n * @param {bool} includeContactRequests Include contact requests between users in response\n * @param {bool} includePrivacyInfo Include privacy info for reference user in response\n * @return {object} jQuery promise\n */\n var getMemberInfo = function(referenceUserId, userIds, includeContactRequests, includePrivacyInfo) {\n var args = {\n referenceuserid: referenceUserId,\n userids: userIds\n };\n\n if (typeof includeContactRequests != 'undefined') {\n args.includecontactrequests = includeContactRequests;\n }\n\n if (typeof includePrivacyInfo != 'undefined') {\n args.includeprivacyinfo = includePrivacyInfo;\n }\n\n var request = {\n methodname: 'core_message_get_member_info',\n args: args\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get a list of user's member info.\n *\n * @param {int} userId The user id to mark as read for\n * @param {int} conversationId The conversation to mark as read\n * @return {object} jQuery promise\n */\n var markAllConversationMessagesAsRead = function(userId, conversationId) {\n\n var request = {\n methodname: 'core_message_mark_all_conversation_messages_as_read',\n args: {\n userid: userId,\n conversationid: conversationId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get the user's message preferences.\n *\n * @param {int} userId The user id to load preferences for\n * @return {object} jQuery promise\n */\n var getUserMessagePreferences = function(userId) {\n var request = {\n methodname: 'core_message_get_user_message_preferences',\n args: {\n userid: userId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * The the count of the user's conversations grouped by type.\n *\n * @param {Number} userId The user's id.\n * @return {Object} jQuery promise.\n */\n var getTotalConversationCounts = function(userId) {\n var request = {\n methodname: 'core_message_get_conversation_counts',\n args: {\n userid: userId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * The the count of the user's unread conversations grouped by type.\n *\n * @param {Number} userId The user's id.\n * @return {Object} jQuery promise.\n */\n var getUnreadConversationCounts = function(userId) {\n var request = {\n methodname: 'core_message_get_unread_conversation_counts',\n args: {\n userid: userId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get both the unread and total conversation counts in a single request.\n *\n * @param {Number} userId The user's id.\n * @return {Object} jQuery promise.\n */\n var getAllConversationCounts = function(userId) {\n var requests = [\n {\n methodname: 'core_message_get_conversation_counts',\n args: {\n userid: userId\n }\n },\n {\n methodname: 'core_message_get_unread_conversation_counts',\n args: {\n userid: userId\n }\n },\n ];\n return $.when.apply(null, Ajax.call(requests)).then(function(total, unread) {\n return {\n total: total,\n unread: unread\n };\n });\n };\n\n return {\n query: query,\n countUnreadConversations: countUnreadConversations,\n markAllAsRead: markAllAsRead,\n getContacts: getContacts,\n getProfile: getProfile,\n blockUser: blockUser,\n unblockUser: unblockUser,\n createContactRequest: createContactRequest,\n deleteContacts: deleteContacts,\n getMessages: getMessages,\n searchUsers: searchUsers,\n searchMessages: searchMessages,\n sendMessagesToUser: sendMessagesToUser,\n sendMessageToUser: sendMessageToUser,\n sendMessagesToConversation: sendMessagesToConversation,\n sendMessageToConversation: sendMessageToConversation,\n savePreferences: savePreferences,\n getPreferences: getPreferences,\n deleteMessages: deleteMessages,\n deleteMessagesForAllUsers: deleteMessagesForAllUsers,\n deleteConversation: deleteConversation,\n getContactRequests: getContactRequests,\n acceptContactRequest: acceptContactRequest,\n declineContactRequest: declineContactRequest,\n getConversation: getConversation,\n getConversationBetweenUsers: getConversationBetweenUsers,\n getSelfConversation: getSelfConversation,\n getConversations: getConversations,\n getConversationMembers: getConversationMembers,\n setFavouriteConversations: setFavouriteConversations,\n setMutedConversations: setMutedConversations,\n unsetFavouriteConversations: unsetFavouriteConversations,\n unsetMutedConversations: unsetMutedConversations,\n getMemberInfo: getMemberInfo,\n markAllConversationMessagesAsRead: markAllConversationMessagesAsRead,\n getUserMessagePreferences: getUserMessagePreferences,\n getTotalConversationCounts: getTotalConversationCounts,\n getUnreadConversationCounts: getUnreadConversationCounts,\n getAllConversationCounts: getAllConversationCounts\n };\n});\n"],"file":"message_repository.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/message_repository.js"],"names":["define","$","Ajax","Notification","Constants","CONVERSATION_TYPES","sendMessagesToUser","toUserId","messages","formattedMessages","map","message","touserid","text","call","methodname","args","then","results","errors","reduce","carry","result","errormessage","push","length","Error","join","id","msgid","timecreated","useridfrom","conversationid","candeletemessagesforallusers","sendMessagesToConversation","conversationId","countUnreadConversations","promise","fail","exception","getContacts","userId","limit","offset","userid","limitnum","limitfrom","blockUser","blockedUserId","when","apply","blockeduserid","referenceuserid","userids","includecontactrequests","includeprivacyinfo","reponse1","profiles","unblockUser","unblockedUserId","unblockeduserid","createContactRequest","requestUserIds","requesteduserid","deleteContacts","contactUserIds","response1","getMessages","currentUserId","newestFirst","timeFrom","currentuserid","convid","newest","timefrom","searchUsers","searchString","search","searchMessages","sendMessageToUser","sendMessageToConversation","savePreferences","preferences","getPreferences","deleteMessages","messageIds","messageId","messageid","deleteMessagesForAllUsers","deleteConversation","conversationids","getContactRequests","acceptContactRequest","sendingUserId","recipientUserId","declineContactRequest","getConversation","loggedInUserId","includeContactRequests","includePrivacyInfo","memberLimit","memberOffset","messageLimit","messageOffset","newestMessagesFirst","memberlimit","memberoffset","messagelimit","messageoffset","newestmessagesfirst","getConversationBetweenUsers","otherUserId","otheruserid","getSelfConversation","getConversations","type","favourites","mergeself","conversations","conversation","PRIVATE","SELF","otherUser","members","name","fullname","imageurl","profileimageurl","getConversationMembers","setFavouriteConversations","conversationIds","setMutedConversations","unsetFavouriteConversations","unsetMutedConversations","getMemberInfo","referenceUserId","userIds","markAllConversationMessagesAsRead","getUserMessagePreferences","getTotalConversationCounts","getUnreadConversationCounts","getAllConversationCounts","total","unread"],"mappings":"AAwBAA,OAAM,mCACN,CACI,QADJ,CAEI,WAFJ,CAGI,mBAHJ,CAII,yDAJJ,CADM,CAMH,SACCC,CADD,CAECC,CAFD,CAGCC,CAHD,CAICC,CAJD,CAIY,IAEPC,CAAAA,CAAkB,CAAGD,CAAS,CAACC,kBAFxB,CAyRPC,CAAkB,CAAG,SAASC,CAAT,CAAmBC,CAAnB,CAA6B,IAC9CC,CAAAA,CAAiB,CAAGD,CAAQ,CAACE,GAAT,CAAa,SAASC,CAAT,CAAkB,CACnD,MAAO,CACHC,QAAQ,CAAEL,CADP,CAEHM,IAAI,CAAEF,CAFH,CAIV,CALuB,CAD0B,CAclD,MAAOT,CAAAA,CAAI,CAACY,IAAL,CAAU,CAPH,CACVC,UAAU,CAAE,oCADF,CAEVC,IAAI,CAAE,CACFR,QAAQ,CAAEC,CADR,CAFI,CAOG,CAAV,EAAqB,CAArB,EACFQ,IADE,CACG,SAASC,CAAT,CAAkB,CAEpB,GAAIC,CAAAA,CAAM,CAAGD,CAAO,CAACE,MAAR,CAAe,SAASC,CAAT,CAAgBC,CAAhB,CAAwB,CAChD,GAAIA,CAAM,CAACC,YAAX,CAAyB,CACrBF,CAAK,CAACG,IAAN,CAAWF,CAAM,CAACC,YAAlB,CACH,CAED,MAAOF,CAAAA,CACV,CANY,CAMV,EANU,CAAb,CAOA,GAAIF,CAAM,CAACM,MAAX,CAAmB,CACf,KAAM,IAAIC,CAAAA,KAAJ,CAAUP,CAAM,CAACQ,IAAP,CAAY,IAAZ,CAAV,CACT,CAED,MAAOT,CAAAA,CACV,CAfE,EAgBFD,IAhBE,CAgBG,SAASC,CAAT,CAAkB,CAEpB,MAAOA,CAAAA,CAAO,CAACR,GAAR,CAAY,SAASY,CAAT,CAAiB,CAChC,MAAO,CACHM,EAAE,CAAEN,CAAM,CAACO,KADR,CAEHhB,IAAI,CAAES,CAAM,CAACT,IAFV,CAGHiB,WAAW,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CAe5C,MAAOxC,CAAAA,CAAC,CAACgD,IAAF,CAAOC,KAAP,CAAa,IAAb,CAAmBhD,CAAI,CAACY,IAAL,CAdX,CACX,CACIC,UAAU,CAAE,sCADhB,CAEIC,IAAI,CAAE,CACF4B,MAAM,CAAEH,CADN,CAFV,CADW,CAOX,CACI1B,UAAU,CAAE,6CADhB,CAEIC,IAAI,CAAE,CACF4B,MAAM,CAAEH,CADN,CAFV,CAPW,CAcW,CAAnB,EAAwCxB,IAAxC,CAA6C,SAAS6H,CAAT,CAAgBC,CAAhB,CAAwB,CACxE,MAAO,CACHD,KAAK,CAAEA,CADJ,CAEHC,MAAM,CAAEA,CAFL,CAIV,CALM,CAMV,CAEM,CAsCV,CAljCK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Retrieves messages from the server.\n *\n * @module core_message/message_repository\n * @class message_repository\n * @package message\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n[\n 'jquery',\n 'core/ajax',\n 'core/notification',\n 'core_message/message_drawer_view_conversation_constants'\n], function(\n $,\n Ajax,\n Notification,\n Constants) {\n\n var CONVERSATION_TYPES = Constants.CONVERSATION_TYPES;\n\n /**\n * Count the number of unread conversations (one or more messages from a user)\n * for a given user.\n *\n * @param {object} args The request arguments:\n * @return {object} jQuery promise\n */\n var countUnreadConversations = function(args) {\n var request = {\n methodname: 'core_message_get_unread_conversations_count',\n args: args\n };\n\n var promise = Ajax.call([request])[0];\n\n promise.fail(Notification.exception);\n\n return promise;\n };\n\n /**\n * Get contacts for given user.\n *\n * @param {int} userId The user id\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @return {object} jQuery promise\n */\n var getContacts = function(userId, limit, offset) {\n var args = {\n userid: userId\n };\n\n if (typeof limit !== 'undefined') {\n args.limitnum = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.limitfrom = offset;\n }\n\n var request = {\n methodname: 'core_message_get_user_contacts',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Block a user.\n *\n * @param {int} userId The requesting user\n * @param {int} blockedUserId Id of user to block\n * @return {object} jQuery promise\n */\n var blockUser = function(userId, blockedUserId) {\n var requests = [\n {\n methodname: 'core_message_block_user',\n args: {\n userid: userId,\n blockeduserid: blockedUserId\n }\n },\n {\n methodname: 'core_message_get_member_info',\n args: {\n referenceuserid: userId,\n userids: [blockedUserId],\n includecontactrequests: true,\n includeprivacyinfo: true\n }\n }\n ];\n\n // Wrap both requests in a single promise so that we can catch an error\n // from either request.\n return $.when.apply(null, Ajax.call(requests)).then(function(reponse1, profiles) {\n // Only return the profile.\n return profiles.length ? profiles[0] : {};\n });\n };\n\n /**\n * Unblock a user.\n *\n * @param {int} userId The requesting user\n * @param {int} unblockedUserId Id of user to unblock\n * @return {object} jQuery promise\n */\n var unblockUser = function(userId, unblockedUserId) {\n var requests = [\n {\n methodname: 'core_message_unblock_user',\n args: {\n userid: userId,\n unblockeduserid: unblockedUserId\n }\n },\n {\n methodname: 'core_message_get_member_info',\n args: {\n referenceuserid: userId,\n userids: [unblockedUserId],\n includecontactrequests: true,\n includeprivacyinfo: true\n }\n }\n ];\n\n // Wrap both requests in a single promise so that we can catch an error\n // from either request.\n return $.when.apply(null, Ajax.call(requests)).then(function(reponse1, profiles) {\n // Only return the profile.\n return profiles.length ? profiles[0] : {};\n });\n };\n\n /**\n * Create a request to add a user as a contact.\n *\n * @param {int} userId The requesting user\n * @param {int[]} requestUserIds List of user ids to add\n * @return {object} jQuery promise\n */\n var createContactRequest = function(userId, requestUserIds) {\n var request = {\n methodname: 'core_message_create_contact_request',\n args: {\n userid: userId,\n requesteduserid: requestUserIds\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Remove a list of users as contacts.\n *\n * @param {int} userId The requesting user\n * @param {int[]} contactUserIds List of user ids to add\n * @return {object} jQuery promise\n */\n var deleteContacts = function(userId, contactUserIds) {\n var requests = [\n {\n methodname: 'core_message_delete_contacts',\n args: {\n userid: userId,\n userids: contactUserIds\n }\n },\n {\n methodname: 'core_message_get_member_info',\n args: {\n referenceuserid: userId,\n userids: contactUserIds,\n includecontactrequests: true,\n includeprivacyinfo: true\n }\n }\n ];\n\n return $.when.apply(null, Ajax.call(requests)).then(function(response1, profiles) {\n // Return all of the profiles as an array.\n return profiles;\n });\n };\n\n /**\n * Get messages between two users.\n *\n * @param {int} currentUserId The requesting user\n * @param {int} conversationId Other user in the conversation\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @param {bool} newestFirst Order results by newest first\n * @param {int} timeFrom Only return messages after this timestamp\n * @return {object} jQuery promise\n */\n var getMessages = function(currentUserId, conversationId, limit, offset, newestFirst, timeFrom) {\n var args = {\n currentuserid: currentUserId,\n convid: conversationId,\n newest: newestFirst ? true : false\n };\n\n if (typeof limit !== 'undefined') {\n args.limitnum = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.limitfrom = offset;\n }\n\n if (typeof timeFrom !== 'undefined') {\n args.timefrom = timeFrom;\n }\n\n var request = {\n methodname: 'core_message_get_conversation_messages',\n args: args\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Search for users.\n *\n * @param {int} userId The requesting user\n * @param {string} searchString Search string\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @return {object} jQuery promise\n */\n var searchUsers = function(userId, searchString, limit, offset) {\n var args = {\n userid: userId,\n search: searchString\n };\n\n if (typeof limit !== 'undefined') {\n args.limitnum = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.limitfrom = offset;\n }\n\n var request = {\n methodname: 'core_message_message_search_users',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Search for messages.\n *\n * @param {int} userId The requesting user\n * @param {string} searchString Search string\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @return {object} jQuery promise\n */\n var searchMessages = function(userId, searchString, limit, offset) {\n var args = {\n userid: userId,\n search: searchString\n };\n\n if (typeof limit !== 'undefined') {\n args.limitnum = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.limitfrom = offset;\n }\n\n var request = {\n methodname: 'core_message_data_for_messagearea_search_messages',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Send a list of messages to a user.\n *\n * @param {int} toUserId The recipient user id\n * @param {string[]} messages List of messages to send\n * @return {object} jQuery promise\n */\n var sendMessagesToUser = function(toUserId, messages) {\n var formattedMessages = messages.map(function(message) {\n return {\n touserid: toUserId,\n text: message\n };\n });\n var request = {\n methodname: 'core_message_send_instant_messages',\n args: {\n messages: formattedMessages\n }\n };\n\n return Ajax.call([request])[0]\n .then(function(results) {\n // Error handling for the weird way the old function works.\n var errors = results.reduce(function(carry, result) {\n if (result.errormessage) {\n carry.push(result.errormessage);\n }\n\n return carry;\n }, []);\n if (errors.length) {\n throw new Error(errors.join(\"\\n\"));\n }\n\n return results;\n })\n .then(function(results) {\n // Format the results to match the other send message function.\n return results.map(function(result) {\n return {\n id: result.msgid,\n text: result.text,\n timecreated: result.timecreated,\n useridfrom: result.useridfrom,\n conversationid: result.conversationid,\n candeletemessagesforallusers: result.candeletemessagesforallusers\n };\n });\n });\n };\n\n /**\n * Send a single message to a user.\n *\n * @param {int} toUserId The recipient user id\n * @param {string} text The message text\n * @return {object} jQuery promise\n */\n var sendMessageToUser = function(toUserId, text) {\n return sendMessagesToUser(toUserId, [text])\n .then(function(results) {\n return results[0];\n });\n };\n\n /**\n * Send messages to a conversation.\n *\n * @param {int} conversationId The conversation id\n * @param {string[]} messages List of messages to send\n * @return {object} jQuery promise\n */\n var sendMessagesToConversation = function(conversationId, messages) {\n var formattedMessages = messages.map(function(message) {\n return {\n text: message\n };\n });\n var request = {\n methodname: 'core_message_send_messages_to_conversation',\n args: {\n conversationid: conversationId,\n messages: formattedMessages\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Send a message to a conversation.\n *\n * @param {int} conversationId The conversation id\n * @param {string} text The message text\n * @return {object} jQuery promise\n */\n var sendMessageToConversation = function(conversationId, text) {\n return sendMessagesToConversation(conversationId, [text])\n .then(function(result) {\n return result[0];\n });\n };\n\n /**\n * Save message preferences.\n *\n * @param {int} userId The owner of the preferences\n * @param {object[]} preferences New preferences values\n * @return {object} jQuery promise\n */\n var savePreferences = function(userId, preferences) {\n var request = {\n methodname: 'core_user_update_user_preferences',\n args: {\n userid: userId,\n preferences: preferences\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get the user's preferences.\n *\n * @param {int} userId The target user\n * @return {object} jQuery promise\n */\n var getPreferences = function(userId) {\n var request = {\n methodname: 'core_user_get_user_preferences',\n args: {\n userid: userId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Delete a list of messages.\n *\n * @param {int} userId The user to delete messages for\n * @param {int[]} messageIds List of message ids to delete\n * @return {object} jQuery promise\n */\n var deleteMessages = function(userId, messageIds) {\n return $.when.apply(null, Ajax.call(messageIds.map(function(messageId) {\n return {\n methodname: 'core_message_delete_message',\n args: {\n messageid: messageId,\n userid: userId\n }\n };\n })));\n };\n\n /**\n * Delete a list of messages for all users.\n *\n * @param {int} userId The user to delete messages for\n * @param {int[]} messageIds List of message ids to delete\n * @return {object} jQuery promise\n */\n var deleteMessagesForAllUsers = function(userId, messageIds) {\n return $.when.apply(null, Ajax.call(messageIds.map(function(messageId) {\n return {\n methodname: 'core_message_delete_message_for_all_users',\n args: {\n messageid: messageId,\n userid: userId\n }\n };\n })));\n };\n\n /**\n * Delete a conversation between two users.\n *\n * @param {int} userId The user to delete messages for\n * @param {int} conversationId The id of the conversation\n * @return {object} jQuery promise\n */\n var deleteConversation = function(userId, conversationId) {\n var request = {\n methodname: 'core_message_delete_conversations_by_id',\n args: {\n userid: userId,\n conversationids: [conversationId]\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get the list of contact requests for a user.\n *\n * @param {int} userId The user id\n * @return {object} jQuery promise\n */\n var getContactRequests = function(userId) {\n var request = {\n methodname: 'core_message_get_contact_requests',\n args: {\n userid: userId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Accept a contact request.\n *\n * @param {int} sendingUserId The user that sent the request\n * @param {int} recipientUserId The user that received the request\n * @return {object} jQuery promise\n */\n var acceptContactRequest = function(sendingUserId, recipientUserId) {\n var requests = [\n {\n methodname: 'core_message_confirm_contact_request',\n args: {\n userid: sendingUserId,\n requesteduserid: recipientUserId\n }\n },\n {\n methodname: 'core_message_get_member_info',\n args: {\n referenceuserid: recipientUserId,\n userids: [sendingUserId],\n includecontactrequests: true,\n includeprivacyinfo: true\n }\n }\n ];\n\n // Wrap both requests in a single promise so that we can catch an error\n // from either request.\n return $.when.apply(null, Ajax.call(requests)).then(function(reponse1, profiles) {\n // Only return the profile.\n return profiles.length ? profiles[0] : {};\n });\n };\n\n /**\n * Decline a contact request.\n *\n * @param {int} sendingUserId The user that sent the request\n * @param {int} recipientUserId The user that received the request\n * @return {object} jQuery promise\n */\n var declineContactRequest = function(sendingUserId, recipientUserId) {\n var requests = [\n {\n methodname: 'core_message_decline_contact_request',\n args: {\n userid: sendingUserId,\n requesteduserid: recipientUserId\n }\n },\n {\n methodname: 'core_message_get_member_info',\n args: {\n referenceuserid: recipientUserId,\n userids: [sendingUserId],\n includecontactrequests: true,\n includeprivacyinfo: true\n }\n }\n ];\n\n // Wrap both requests in a single promise so that we can catch an error\n // from either request.\n return $.when.apply(null, Ajax.call(requests)).then(function(reponse1, profiles) {\n // Only return the profile.\n return profiles.length ? profiles[0] : {};\n });\n };\n\n /**\n * Get a conversation.\n *\n * @param {int} loggedInUserId The logged in user\n * @param {int} conversationId The conversation id\n * @param {bool} includeContactRequests Incldue contact requests between members\n * @param {bool} includePrivacyInfo Include privacy info for members\n * @param {int} memberLimit Limit for members\n * @param {int} memberOffset Offset for members\n * @param {int} messageLimit Limit for messages\n * @param {int} messageOffset Offset for messages\n * @param {bool} newestMessagesFirst Order the messages by newest first\n * @return {object} jQuery promise\n */\n var getConversation = function(\n loggedInUserId,\n conversationId,\n includeContactRequests,\n includePrivacyInfo,\n memberLimit,\n memberOffset,\n messageLimit,\n messageOffset,\n newestMessagesFirst\n ) {\n var args = {\n userid: loggedInUserId,\n conversationid: conversationId\n };\n\n if (typeof includeContactRequests != 'undefined' && includeContactRequests !== null) {\n args.includecontactrequests = includeContactRequests;\n }\n\n if (typeof includePrivacyInfo != 'undefined' && includePrivacyInfo !== null) {\n args.includeprivacyinfo = includePrivacyInfo;\n }\n\n if (typeof memberLimit != 'undefined' && memberLimit !== null) {\n args.memberlimit = memberLimit;\n }\n\n if (typeof memberOffset != 'undefined' && memberOffset !== null) {\n args.memberoffset = memberOffset;\n }\n\n if (typeof messageLimit != 'undefined' && messageLimit !== null) {\n args.messagelimit = messageLimit;\n }\n\n if (typeof messageOffset != 'undefined' && messageOffset !== null) {\n args.messageoffset = messageOffset;\n }\n\n if (typeof newestMessagesFirst != 'undefined' && newestMessagesFirst !== null) {\n args.newestmessagesfirst = newestMessagesFirst;\n }\n\n var request = {\n methodname: 'core_message_get_conversation',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get a conversation between users.\n *\n * @param {int} loggedInUserId The logged in user\n * @param {int} otherUserId The other user id\n * @param {bool} includeContactRequests Incldue contact requests between members\n * @param {bool} includePrivacyInfo Include privacy info for members\n * @param {int} memberLimit Limit for members\n * @param {int} memberOffset Offset for members\n * @param {int} messageLimit Limit for messages\n * @param {int} messageOffset Offset for messages\n * @param {bool} newestMessagesFirst Order the messages by newest first\n * @return {object} jQuery promise\n */\n var getConversationBetweenUsers = function(\n loggedInUserId,\n otherUserId,\n includeContactRequests,\n includePrivacyInfo,\n memberLimit,\n memberOffset,\n messageLimit,\n messageOffset,\n newestMessagesFirst\n ) {\n var args = {\n userid: loggedInUserId,\n otheruserid: otherUserId\n };\n\n if (typeof includeContactRequests != 'undefined' && includeContactRequests !== null) {\n args.includecontactrequests = includeContactRequests;\n }\n\n if (typeof includePrivacyInfo != 'undefined' && includePrivacyInfo !== null) {\n args.includeprivacyinfo = includePrivacyInfo;\n }\n\n if (typeof memberLimit != 'undefined' && memberLimit !== null) {\n args.memberlimit = memberLimit;\n }\n\n if (typeof memberOffset != 'undefined' && memberOffset !== null) {\n args.memberoffset = memberOffset;\n }\n\n if (typeof messageLimit != 'undefined' && messageLimit !== null) {\n args.messagelimit = messageLimit;\n }\n\n if (typeof messageOffset != 'undefined' && messageOffset !== null) {\n args.messageoffset = messageOffset;\n }\n\n if (typeof newestMessagesFirst != 'undefined' && newestMessagesFirst !== null) {\n args.newestmessagesfirst = newestMessagesFirst;\n }\n\n var request = {\n methodname: 'core_message_get_conversation_between_users',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get a self-conversation.\n *\n * @param {int} loggedInUserId The logged in user\n * @param {int} messageLimit Limit for messages\n * @param {int} messageOffset Offset for messages\n * @param {bool} newestMessagesFirst Order the messages by newest first\n * @return {object} jQuery promise\n */\n var getSelfConversation = function(\n loggedInUserId,\n messageLimit,\n messageOffset,\n newestMessagesFirst\n ) {\n var args = {\n userid: loggedInUserId\n };\n\n if (typeof messageLimit != 'undefined' && messageLimit !== null) {\n args.messagelimit = messageLimit;\n }\n\n if (typeof messageOffset != 'undefined' && messageOffset !== null) {\n args.messageoffset = messageOffset;\n }\n\n if (typeof newestMessagesFirst != 'undefined' && newestMessagesFirst !== null) {\n args.newestmessagesfirst = newestMessagesFirst;\n }\n\n var request = {\n methodname: 'core_message_get_self_conversation',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get the conversations for a user.\n *\n * @param {int} userId The logged in user\n * @param {int|null} type The type of conversation to get\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @param {bool|null} favourites If favourites should be included or not\n * @return {object} jQuery promise\n */\n var getConversations = function(\n userId,\n type,\n limit,\n offset,\n favourites,\n mergeself\n ) {\n var args = {\n userid: userId,\n type: type\n };\n\n if (typeof limit != 'undefined' && limit !== null) {\n args.limitnum = limit;\n }\n\n if (typeof offset != 'undefined' && offset !== null) {\n args.limitfrom = offset;\n }\n\n if (typeof favourites != 'undefined' && favourites !== null) {\n args.favourites = favourites;\n }\n\n if (typeof mergeself != 'undefined' && mergeself !== null) {\n args.mergeself = mergeself;\n }\n\n var request = {\n methodname: 'core_message_get_conversations',\n args: args\n };\n\n return Ajax.call([request])[0]\n .then(function(result) {\n if (result.conversations.length) {\n result.conversations = result.conversations.map(function(conversation) {\n if (conversation.type == CONVERSATION_TYPES.PRIVATE || conversation.type == CONVERSATION_TYPES.SELF) {\n var otherUser = conversation.members.length ? conversation.members[0] : null;\n\n if (otherUser) {\n conversation.name = conversation.name ? conversation.name : otherUser.fullname;\n conversation.imageurl = conversation.imageurl ? conversation.imageurl : otherUser.profileimageurl;\n }\n }\n\n return conversation;\n });\n }\n\n return result;\n });\n };\n\n /**\n * Get the conversations for a user.\n *\n * @param {int} conversationId The conversation id\n * @param {int} loggedInUserId The logged in user\n * @param {int} limit Limit for results\n * @param {int} offset Offset for results\n * @param {bool} includeContactRequests If contact requests should be included in result\n * @return {object} jQuery promise\n */\n var getConversationMembers = function(conversationId, loggedInUserId, limit, offset, includeContactRequests) {\n var args = {\n userid: loggedInUserId,\n conversationid: conversationId\n };\n\n if (typeof limit != 'undefined' && limit !== null) {\n args.limitnum = limit;\n }\n\n if (typeof offset != 'undefined' && offset !== null) {\n args.limitfrom = offset;\n }\n\n if (typeof includeContactRequests != 'undefined' && includeContactRequests !== null) {\n args.includecontactrequests = includeContactRequests;\n }\n\n var request = {\n methodname: 'core_message_get_conversation_members',\n args: args\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Set a list of conversations to set as favourites for the given user.\n *\n * @param {int} userId The user id\n * @param {array} conversationIds List of conversation ids to set as favourite\n * @return {object} jQuery promise\n */\n var setFavouriteConversations = function(userId, conversationIds) {\n\n var request = {\n methodname: 'core_message_set_favourite_conversations',\n args: {\n userid: userId,\n conversations: conversationIds\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Set a list of conversations to unset as favourites for the given user.\n *\n * @param {int} userId The user id\n * @param {array} conversationIds List of conversation ids to unset as favourite\n * @return {object} jQuery promise\n */\n var unsetFavouriteConversations = function(userId, conversationIds) {\n\n var request = {\n methodname: 'core_message_unset_favourite_conversations',\n args: {\n userid: userId,\n conversations: conversationIds\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Set a list of conversations to set as muted for the given user.\n *\n * @param {int} userId The user id\n * @param {array} conversationIds List of conversation ids to set as favourite\n * @return {object} jQuery promise\n */\n var setMutedConversations = function(userId, conversationIds) {\n var request = {\n methodname: 'core_message_mute_conversations',\n args: {\n userid: userId,\n conversationids: conversationIds\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Set a list of conversations to unset as muted for the given user.\n *\n * @param {int} userId The user id\n * @param {array} conversationIds List of conversation ids to unset as favourite\n * @return {object} jQuery promise\n */\n var unsetMutedConversations = function(userId, conversationIds) {\n var request = {\n methodname: 'core_message_unmute_conversations',\n args: {\n userid: userId,\n conversationids: conversationIds\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get a list of user's member info.\n *\n * @param {int} referenceUserId The user id\n * @param {array} userIds List of user ids to get\n * @param {bool} includeContactRequests Include contact requests between users in response\n * @param {bool} includePrivacyInfo Include privacy info for reference user in response\n * @return {object} jQuery promise\n */\n var getMemberInfo = function(referenceUserId, userIds, includeContactRequests, includePrivacyInfo) {\n var args = {\n referenceuserid: referenceUserId,\n userids: userIds\n };\n\n if (typeof includeContactRequests != 'undefined') {\n args.includecontactrequests = includeContactRequests;\n }\n\n if (typeof includePrivacyInfo != 'undefined') {\n args.includeprivacyinfo = includePrivacyInfo;\n }\n\n var request = {\n methodname: 'core_message_get_member_info',\n args: args\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get a list of user's member info.\n *\n * @param {int} userId The user id to mark as read for\n * @param {int} conversationId The conversation to mark as read\n * @return {object} jQuery promise\n */\n var markAllConversationMessagesAsRead = function(userId, conversationId) {\n\n var request = {\n methodname: 'core_message_mark_all_conversation_messages_as_read',\n args: {\n userid: userId,\n conversationid: conversationId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get the user's message preferences.\n *\n * @param {int} userId The user id to load preferences for\n * @return {object} jQuery promise\n */\n var getUserMessagePreferences = function(userId) {\n var request = {\n methodname: 'core_message_get_user_message_preferences',\n args: {\n userid: userId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * The the count of the user's conversations grouped by type.\n *\n * @param {Number} userId The user's id.\n * @return {Object} jQuery promise.\n */\n var getTotalConversationCounts = function(userId) {\n var request = {\n methodname: 'core_message_get_conversation_counts',\n args: {\n userid: userId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * The the count of the user's unread conversations grouped by type.\n *\n * @param {Number} userId The user's id.\n * @return {Object} jQuery promise.\n */\n var getUnreadConversationCounts = function(userId) {\n var request = {\n methodname: 'core_message_get_unread_conversation_counts',\n args: {\n userid: userId\n }\n };\n return Ajax.call([request])[0];\n };\n\n /**\n * Get both the unread and total conversation counts in a single request.\n *\n * @param {Number} userId The user's id.\n * @return {Object} jQuery promise.\n */\n var getAllConversationCounts = function(userId) {\n var requests = [\n {\n methodname: 'core_message_get_conversation_counts',\n args: {\n userid: userId\n }\n },\n {\n methodname: 'core_message_get_unread_conversation_counts',\n args: {\n userid: userId\n }\n },\n ];\n return $.when.apply(null, Ajax.call(requests)).then(function(total, unread) {\n return {\n total: total,\n unread: unread\n };\n });\n };\n\n return {\n countUnreadConversations: countUnreadConversations,\n getContacts: getContacts,\n blockUser: blockUser,\n unblockUser: unblockUser,\n createContactRequest: createContactRequest,\n deleteContacts: deleteContacts,\n getMessages: getMessages,\n searchUsers: searchUsers,\n searchMessages: searchMessages,\n sendMessagesToUser: sendMessagesToUser,\n sendMessageToUser: sendMessageToUser,\n sendMessagesToConversation: sendMessagesToConversation,\n sendMessageToConversation: sendMessageToConversation,\n savePreferences: savePreferences,\n getPreferences: getPreferences,\n deleteMessages: deleteMessages,\n deleteMessagesForAllUsers: deleteMessagesForAllUsers,\n deleteConversation: deleteConversation,\n getContactRequests: getContactRequests,\n acceptContactRequest: acceptContactRequest,\n declineContactRequest: declineContactRequest,\n getConversation: getConversation,\n getConversationBetweenUsers: getConversationBetweenUsers,\n getSelfConversation: getSelfConversation,\n getConversations: getConversations,\n getConversationMembers: getConversationMembers,\n setFavouriteConversations: setFavouriteConversations,\n setMutedConversations: setMutedConversations,\n unsetFavouriteConversations: unsetFavouriteConversations,\n unsetMutedConversations: unsetMutedConversations,\n getMemberInfo: getMemberInfo,\n markAllConversationMessagesAsRead: markAllConversationMessagesAsRead,\n getUserMessagePreferences: getUserMessagePreferences,\n getTotalConversationCounts: getTotalConversationCounts,\n getUnreadConversationCounts: getUnreadConversationCounts,\n getAllConversationCounts: getAllConversationCounts\n };\n});\n"],"file":"message_repository.min.js"} \ No newline at end of file diff --git a/message/amd/build/toggle_contact_button.min.js b/message/amd/build/toggle_contact_button.min.js index ebfd3cd6964..1294576905a 100644 --- a/message/amd/build/toggle_contact_button.min.js +++ b/message/amd/build/toggle_contact_button.min.js @@ -1,2 +1,2 @@ -define ("core_message/toggle_contact_button",["jquery","core/ajax","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e){var f=function(a){return"1"==a.attr("data-is-contact")},g=function(a){a.attr("data-is-contact","1")},h=function(a){a.attr("data-is-contact","0")},i=function(a){return a.attr("data-userid")},j=function(a){return a.hasClass("loading")||a.attr("disabled")},k=function(c,e){if(j(c)){return a.Deferred()}c.addClass("loading");c.attr("disabled","disabled");return b.call([e])[0].fail(d.exception).always(function(){c.removeClass("loading");c.removeAttr("disabled")})},l=function(a){if(j(a)){return}var b={methodname:"core_message_create_contacts",args:{userids:[i(a)]}};k(a,b).done(function(){g(a);c.render("message/remove_contact_button",{}).done(function(b,d){c.replaceNodeContents(a,b,d)})})},m=function(a){if(j(a)){return}var b={methodname:"core_message_delete_contacts",args:{userids:[i(a)]}};k(a,b).done(function(){h(a);c.render("message/add_contact_button",{}).done(function(b,d){c.replaceNodeContents(a,b,d)})})};return{enhance:function enhance(b){b=a(b);if(!b.children(".loading-icon").length){c.render("core/loading",{}).done(function(a,c){b.append(a,c)})}e.define(b,[e.events.activate]);b.on(e.events.activate,function(a,c){if(f(b)){m(b)}else{l(b)}a.preventDefault();c.originalEvent.preventDefault()})}}}); +define ("core_message/toggle_contact_button",["jquery","core/ajax","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e){var f=function(a){return"1"==a.attr("data-is-contact")},g=function(a){a.attr("data-is-contact","1")},h=function(a){a.attr("data-is-contact","0")},i=function(a){return a.attr("data-userid")},j=function(a){return a.attr("data-currentuserid")},k=function(a){return a.hasClass("loading")||a.attr("disabled")},l=function(c,e){if(k(c)){return a.Deferred()}c.addClass("loading");c.attr("disabled","disabled");return b.call([e])[0].fail(d.exception).always(function(){c.removeClass("loading");c.removeAttr("disabled")})},m=function(a){if(k(a)){return}var b={methodname:"core_message_create_contact_request",args:{userid:j(a),requesteduserid:i(a)}};l(a,b).done(function(){g(a);c.render("message/remove_contact_button",{}).done(function(b,d){c.replaceNodeContents(a,b,d)})})},n=function(a){if(k(a)){return}var b={methodname:"core_message_delete_contacts",args:{userids:[i(a)]}};l(a,b).done(function(){h(a);c.render("message/add_contact_button",{}).done(function(b,d){c.replaceNodeContents(a,b,d)})})};return{enhance:function enhance(b){b=a(b);if(!b.children(".loading-icon").length){c.render("core/loading",{}).done(function(a,c){b.append(a,c)})}e.define(b,[e.events.activate]);b.on(e.events.activate,function(a,c){if(f(b)){n(b)}else{m(b)}a.preventDefault();c.originalEvent.preventDefault()})}}}); //# sourceMappingURL=toggle_contact_button.min.js.map diff --git a/message/amd/build/toggle_contact_button.min.js.map b/message/amd/build/toggle_contact_button.min.js.map index 0466155c7af..6f2d7efc8cf 100644 --- a/message/amd/build/toggle_contact_button.min.js.map +++ b/message/amd/build/toggle_contact_button.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/toggle_contact_button.js"],"names":["define","$","Ajax","Templates","Notification","CustomEvents","isContact","element","attr","setContact","setNotContact","getUserId","isLoading","hasClass","sendRequest","request","Deferred","addClass","call","fail","exception","always","removeClass","removeAttr","addContact","methodname","args","userids","done","render","html","js","replaceNodeContents","removeContact","enhance","children","length","append","events","activate","on","e","data","preventDefault","originalEvent"],"mappings":"AAwBAA,OAAM,sCAAC,CAAC,QAAD,CAAW,WAAX,CAAwB,gBAAxB,CAA0C,mBAA1C,CAA+D,gCAA/D,CAAD,CACE,SAASC,CAAT,CAAYC,CAAZ,CAAkBC,CAAlB,CAA6BC,CAA7B,CAA2CC,CAA3C,CAAyD,IASzDC,CAAAA,CAAS,CAAG,SAASC,CAAT,CAAkB,CAC9B,MAA0C,GAAnC,EAAAA,CAAO,CAACC,IAAR,CAAa,iBAAb,CACV,CAX4D,CAmBzDC,CAAU,CAAG,SAASF,CAAT,CAAkB,CAC/BA,CAAO,CAACC,IAAR,CAAa,iBAAb,CAAgC,GAAhC,CACH,CArB4D,CA6BzDE,CAAa,CAAG,SAASH,CAAT,CAAkB,CAClCA,CAAO,CAACC,IAAR,CAAa,iBAAb,CAAgC,GAAhC,CACH,CA/B4D,CAwCzDG,CAAS,CAAG,SAASJ,CAAT,CAAkB,CAC9B,MAAOA,CAAAA,CAAO,CAACC,IAAR,CAAa,aAAb,CACV,CA1C4D,CAmDzDI,CAAS,CAAG,SAASL,CAAT,CAAkB,CAC9B,MAAOA,CAAAA,CAAO,CAACM,QAAR,CAAiB,SAAjB,GAA+BN,CAAO,CAACC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yD,CAG7D,CAzKK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Module to add/remove contact using ajax.\n *\n * @module core_message/toggle_contact_button\n * @class toggle_contact_button\n * @package message\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/custom_interaction_events'],\n function($, Ajax, Templates, Notification, CustomEvents) {\n\n /**\n * Check the state of the element, if the current user is a contact or not.\n *\n * @method isContact\n * @param {object} element jQuery object for the button\n * @return {bool}\n */\n var isContact = function(element) {\n return element.attr('data-is-contact') == '1';\n };\n\n /**\n * Record that the user is a contact.\n *\n * @method setContact\n * @param {object} element jQuery object for the button\n */\n var setContact = function(element) {\n element.attr('data-is-contact', '1');\n };\n\n /**\n * Record that the user is not a contact.\n *\n * @method setNotContact\n * @param {object} element jQuery object for the button\n */\n var setNotContact = function(element) {\n element.attr('data-is-contact', '0');\n };\n\n /**\n * Get the id for the user being viewed.\n *\n * @method getUserId\n * @param {object} element jQuery object for the button\n * @return {int}\n */\n var getUserId = function(element) {\n return element.attr('data-userid');\n };\n\n /**\n * Check if this element is currently loading.\n *\n * @method isLoading\n * @param {object} element jQuery object for the button\n * @return {bool}\n */\n var isLoading = function(element) {\n return element.hasClass('loading') || element.attr('disabled');\n };\n\n /**\n * Sends an ajax request to the server and handles the element state\n * while the request is being performed.\n *\n * @method sendRequest\n * @param {object} element jQuery object for the button\n * @param {object} request Request hash to send\n * @return {object} jQuery promise\n */\n var sendRequest = function(element, request) {\n if (isLoading(element)) {\n return $.Deferred();\n }\n\n element.addClass('loading');\n element.attr('disabled', 'disabled');\n\n return Ajax.call([request])[0]\n .fail(Notification.exception)\n .always(function() {\n element.removeClass('loading');\n element.removeAttr('disabled');\n });\n };\n\n /**\n * Send a request to the server to add the current user as\n * a contact. The contents of the button are changed to the\n * remove contact button upon success.\n *\n * @method addContact\n * @param {object} element jQuery object for the button\n */\n var addContact = function(element) {\n if (isLoading(element)) {\n return;\n }\n\n var request = {\n methodname: 'core_message_create_contacts',\n args: {\n userids: [getUserId(element)],\n }\n };\n sendRequest(element, request).done(function() {\n setContact(element);\n Templates.render('message/remove_contact_button', {}).done(function(html, js) {\n Templates.replaceNodeContents(element, html, js);\n });\n });\n };\n\n /**\n * Send a request to the server to remove the current user as\n * a contact. The contents of the button are changed to the\n * add contact button upon success.\n *\n * @method removeContact\n * @param {object} element jQuery object for the button\n */\n var removeContact = function(element) {\n if (isLoading(element)) {\n return;\n }\n\n var request = {\n methodname: 'core_message_delete_contacts',\n args: {\n userids: [getUserId(element)],\n }\n };\n\n sendRequest(element, request).done(function() {\n setNotContact(element);\n Templates.render('message/add_contact_button', {}).done(function(html, js) {\n Templates.replaceNodeContents(element, html, js);\n });\n });\n };\n\n /**\n * Enhances the given element with a loading gif and event handles to make\n * ajax requests to add or remove a contact where appropriate.\n *\n * @method enhance\n * @param {object} element jQuery object for the button\n */\n var enhance = function(element) {\n element = $(element);\n\n if (!element.children('.loading-icon').length) {\n // Add the loading gif if it isn't already there.\n Templates.render('core/loading', {}).done(function(html, js) {\n element.append(html, js);\n });\n }\n\n CustomEvents.define(element, [CustomEvents.events.activate]);\n\n element.on(CustomEvents.events.activate, function(e, data) {\n if (isContact(element)) {\n removeContact(element);\n } else {\n addContact(element);\n }\n e.preventDefault();\n data.originalEvent.preventDefault();\n });\n };\n\n return /** @alias module:message/toggle_contact_button */ {\n enhance: enhance\n };\n});\n"],"file":"toggle_contact_button.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/toggle_contact_button.js"],"names":["define","$","Ajax","Templates","Notification","CustomEvents","isContact","element","attr","setContact","setNotContact","getUserId","getCurrentUserId","isLoading","hasClass","sendRequest","request","Deferred","addClass","call","fail","exception","always","removeClass","removeAttr","addContact","methodname","args","userid","requesteduserid","done","render","html","js","replaceNodeContents","removeContact","userids","enhance","children","length","append","events","activate","on","e","data","preventDefault","originalEvent"],"mappings":"AAwBAA,OAAM,sCAAC,CAAC,QAAD,CAAW,WAAX,CAAwB,gBAAxB,CAA0C,mBAA1C,CAA+D,gCAA/D,CAAD,CACE,SAASC,CAAT,CAAYC,CAAZ,CAAkBC,CAAlB,CAA6BC,CAA7B,CAA2CC,CAA3C,CAAyD,IASzDC,CAAAA,CAAS,CAAG,SAASC,CAAT,CAAkB,CAC9B,MAA0C,GAAnC,EAAAA,CAAO,CAACC,IAAR,CAAa,iBAAb,CACV,CAX4D,CAmBzDC,CAAU,CAAG,SAASF,CAAT,CAAkB,CAC/BA,CAAO,CAACC,IAAR,CAAa,iBAAb,CAAgC,GAAhC,CACH,CArB4D,CA6BzDE,CAAa,CAAG,SAASH,CAAT,CAAkB,CAClCA,CAAO,CAACC,IAAR,CAAa,iBAAb,CAAgC,GAAhC,CACH,CA/B4D,CAwCzDG,CAAS,CAAG,SAASJ,CAAT,CAAkB,CAC9B,MAAOA,CAAAA,CAAO,CAACC,IAAR,CAAa,aAAb,CACV,CA1C4D,CAmDzDI,CAAgB,CAAG,SAASL,CAAT,CAAkB,CACrC,MAAOA,CAAAA,CAAO,CAACC,IAAR,CAAa,oBAAb,CACV,CArD4D,CA8DzDK,CAAS,CAAG,SAASN,CAAT,CAAkB,CAC9B,MAAOA,CAAAA,CAAO,CAACO,QAAR,CAAiB,SAAjB,GAA+BP,CAAO,CAACC,IAAR,CAAa,UAAb,CACzC,CAhE4D,CA2EzDO,CAAW,CAAG,SAASR,CAAT,CAAkBS,CAAlB,CAA2B,CACzC,GAAIH,CAAS,CAACN,C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,CADP,CAFI,CAAd,CAOAQ,CAAW,CAACR,CAAD,CAAUS,CAAV,CAAX,CAA8Bc,IAA9B,CAAmC,UAAW,CAC1CpB,CAAa,CAACH,CAAD,CAAb,CACAJ,CAAS,CAAC4B,MAAV,CAAiB,4BAAjB,CAA+C,EAA/C,EAAmDD,IAAnD,CAAwD,SAASE,CAAT,CAAeC,CAAf,CAAmB,CACvE9B,CAAS,CAAC+B,mBAAV,CAA8B3B,CAA9B,CAAuCyB,CAAvC,CAA6CC,CAA7C,CACH,CAFD,CAGH,CALD,CAMH,CAjJ4D,CAiL7D,MAA0D,CACtDI,OAAO,CAxBG,QAAVA,CAAAA,OAAU,CAAS9B,CAAT,CAAkB,CAC5BA,CAAO,CAAGN,CAAC,CAACM,CAAD,CAAX,CAEA,GAAI,CAACA,CAAO,CAAC+B,QAAR,CAAiB,eAAjB,EAAkCC,MAAvC,CAA+C,CAE3CpC,CAAS,CAAC4B,MAAV,CAAiB,cAAjB,CAAiC,EAAjC,EAAqCD,IAArC,CAA0C,SAASE,CAAT,CAAeC,CAAf,CAAmB,CACzD1B,CAAO,CAACiC,MAAR,CAAeR,CAAf,CAAqBC,CAArB,CACH,CAFD,CAGH,CAED5B,CAAY,CAACL,MAAb,CAAoBO,CAApB,CAA6B,CAACF,CAAY,CAACoC,MAAb,CAAoBC,QAArB,CAA7B,EAEAnC,CAAO,CAACoC,EAAR,CAAWtC,CAAY,CAACoC,MAAb,CAAoBC,QAA/B,CAAyC,SAASE,CAAT,CAAYC,CAAZ,CAAkB,CACvD,GAAIvC,CAAS,CAACC,CAAD,CAAb,CAAwB,CACpB4B,CAAa,CAAC5B,CAAD,CAChB,CAFD,IAEO,CACHkB,CAAU,CAAClB,CAAD,CACb,CACDqC,CAAC,CAACE,cAAF,GACAD,CAAI,CAACE,aAAL,CAAmBD,cAAnB,EACH,CARD,CASH,CAEyD,CAG7D,CArLK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Module to add/remove contact using ajax.\n *\n * @module core_message/toggle_contact_button\n * @class toggle_contact_button\n * @package message\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/custom_interaction_events'],\n function($, Ajax, Templates, Notification, CustomEvents) {\n\n /**\n * Check the state of the element, if the current user is a contact or not.\n *\n * @method isContact\n * @param {object} element jQuery object for the button\n * @return {bool}\n */\n var isContact = function(element) {\n return element.attr('data-is-contact') == '1';\n };\n\n /**\n * Record that the user is a contact.\n *\n * @method setContact\n * @param {object} element jQuery object for the button\n */\n var setContact = function(element) {\n element.attr('data-is-contact', '1');\n };\n\n /**\n * Record that the user is not a contact.\n *\n * @method setNotContact\n * @param {object} element jQuery object for the button\n */\n var setNotContact = function(element) {\n element.attr('data-is-contact', '0');\n };\n\n /**\n * Get the id for the user being viewed.\n *\n * @method getUserId\n * @param {object} element jQuery object for the button\n * @return {int}\n */\n var getUserId = function(element) {\n return element.attr('data-userid');\n };\n\n /**\n * Get the id for the logged in user.\n *\n * @method getUserId\n * @param {object} element jQuery object for the button\n * @return {int}\n */\n var getCurrentUserId = function(element) {\n return element.attr('data-currentuserid');\n };\n\n /**\n * Check if this element is currently loading.\n *\n * @method isLoading\n * @param {object} element jQuery object for the button\n * @return {bool}\n */\n var isLoading = function(element) {\n return element.hasClass('loading') || element.attr('disabled');\n };\n\n /**\n * Sends an ajax request to the server and handles the element state\n * while the request is being performed.\n *\n * @method sendRequest\n * @param {object} element jQuery object for the button\n * @param {object} request Request hash to send\n * @return {object} jQuery promise\n */\n var sendRequest = function(element, request) {\n if (isLoading(element)) {\n return $.Deferred();\n }\n\n element.addClass('loading');\n element.attr('disabled', 'disabled');\n\n return Ajax.call([request])[0]\n .fail(Notification.exception)\n .always(function() {\n element.removeClass('loading');\n element.removeAttr('disabled');\n });\n };\n\n /**\n * Send a request to the server to add the current user as\n * a contact. The contents of the button are changed to the\n * remove contact button upon success.\n *\n * @method addContact\n * @param {object} element jQuery object for the button\n */\n var addContact = function(element) {\n if (isLoading(element)) {\n return;\n }\n\n var request = {\n methodname: 'core_message_create_contact_request',\n args: {\n userid: getCurrentUserId(element),\n requesteduserid: getUserId(element),\n }\n };\n sendRequest(element, request).done(function() {\n setContact(element);\n Templates.render('message/remove_contact_button', {}).done(function(html, js) {\n Templates.replaceNodeContents(element, html, js);\n });\n });\n };\n\n /**\n * Send a request to the server to remove the current user as\n * a contact. The contents of the button are changed to the\n * add contact button upon success.\n *\n * @method removeContact\n * @param {object} element jQuery object for the button\n */\n var removeContact = function(element) {\n if (isLoading(element)) {\n return;\n }\n\n var request = {\n methodname: 'core_message_delete_contacts',\n args: {\n userids: [getUserId(element)],\n }\n };\n\n sendRequest(element, request).done(function() {\n setNotContact(element);\n Templates.render('message/add_contact_button', {}).done(function(html, js) {\n Templates.replaceNodeContents(element, html, js);\n });\n });\n };\n\n /**\n * Enhances the given element with a loading gif and event handles to make\n * ajax requests to add or remove a contact where appropriate.\n *\n * @method enhance\n * @param {object} element jQuery object for the button\n */\n var enhance = function(element) {\n element = $(element);\n\n if (!element.children('.loading-icon').length) {\n // Add the loading gif if it isn't already there.\n Templates.render('core/loading', {}).done(function(html, js) {\n element.append(html, js);\n });\n }\n\n CustomEvents.define(element, [CustomEvents.events.activate]);\n\n element.on(CustomEvents.events.activate, function(e, data) {\n if (isContact(element)) {\n removeContact(element);\n } else {\n addContact(element);\n }\n e.preventDefault();\n data.originalEvent.preventDefault();\n });\n };\n\n return /** @alias module:message/toggle_contact_button */ {\n enhance: enhance\n };\n});\n"],"file":"toggle_contact_button.min.js"} \ No newline at end of file diff --git a/message/amd/src/message_repository.js b/message/amd/src/message_repository.js index 56b592516a9..d034a70860a 100644 --- a/message/amd/src/message_repository.js +++ b/message/amd/src/message_repository.js @@ -36,48 +36,6 @@ define( var CONVERSATION_TYPES = Constants.CONVERSATION_TYPES; - /** - * Retrieve a list of messages from the server. - * - * @param {object} args The request arguments: - * @return {object} jQuery promise - */ - var query = function(args) { - // Normalise the arguments to use limit/offset rather than limitnum/limitfrom. - if (typeof args.limit === 'undefined') { - args.limit = 0; - } - - if (typeof args.offset === 'undefined') { - args.offset = 0; - } - - if (typeof args.type === 'undefined') { - args.type = null; - } - - if (typeof args.favouritesonly === 'undefined') { - args.favouritesonly = false; - } - - args.limitfrom = args.offset; - args.limitnum = args.limit; - - delete args.limit; - delete args.offset; - - var request = { - methodname: 'core_message_data_for_messagearea_conversations', - args: args - }; - - var promise = Ajax.call([request])[0]; - - promise.fail(Notification.exception); - - return promise; - }; - /** * Count the number of unread conversations (one or more messages from a user) * for a given user. @@ -98,25 +56,6 @@ define( return promise; }; - /** - * Mark all of unread messages for a user as read. - * - * @param {object} args The request arguments: - * @return {object} jQuery promise - */ - var markAllAsRead = function(args) { - var request = { - methodname: 'core_message_mark_all_messages_as_read', - args: args - }; - - var promise = Ajax.call([request])[0]; - - promise.fail(Notification.exception); - - return promise; - }; - /** * Get contacts for given user. * @@ -146,25 +85,6 @@ define( return Ajax.call([request])[0]; }; - /** - * Request profile information as a user for a given user. - * - * @param {int} userId The requesting user - * @param {int} profileUserId The id of the user who's profile is being requested - * @return {object} jQuery promise - */ - var getProfile = function(userId, profileUserId) { - var request = { - methodname: 'core_message_data_for_messagearea_get_profile', - args: { - currentuserid: userId, - otheruserid: profileUserId - } - }; - - return Ajax.call([request])[0]; - }; - /** * Block a user. * @@ -1139,11 +1059,8 @@ define( }; return { - query: query, countUnreadConversations: countUnreadConversations, - markAllAsRead: markAllAsRead, getContacts: getContacts, - getProfile: getProfile, blockUser: blockUser, unblockUser: unblockUser, createContactRequest: createContactRequest, diff --git a/message/amd/src/toggle_contact_button.js b/message/amd/src/toggle_contact_button.js index aa22a420405..bf5349f4a3a 100644 --- a/message/amd/src/toggle_contact_button.js +++ b/message/amd/src/toggle_contact_button.js @@ -67,6 +67,17 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust return element.attr('data-userid'); }; + /** + * Get the id for the logged in user. + * + * @method getUserId + * @param {object} element jQuery object for the button + * @return {int} + */ + var getCurrentUserId = function(element) { + return element.attr('data-currentuserid'); + }; + /** * Check if this element is currently loading. * @@ -117,9 +128,10 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust } var request = { - methodname: 'core_message_create_contacts', + methodname: 'core_message_create_contact_request', args: { - userids: [getUserId(element)], + userid: getCurrentUserId(element), + requesteduserid: getUserId(element), } }; sendRequest(element, request).done(function() { diff --git a/message/classes/api.php b/message/classes/api.php index 86708bca857..4d758b1b5b1 100644 --- a/message/classes/api.php +++ b/message/classes/api.php @@ -167,138 +167,17 @@ class api { } /** - * Handles searching for user in a particular course in the message area. - * - * TODO: This function should be removed once the related web service goes through final deprecation. - * The related web service is data_for_messagearea_search_users_in_course. - * Followup: MDL-63261 - * - * @param int $userid The user id doing the searching - * @param int $courseid The id of the course we are searching in - * @param string $search The string the user is searching - * @param int $limitfrom - * @param int $limitnum - * @return array + * @deprecated since 3.6 */ - public static function search_users_in_course($userid, $courseid, $search, $limitfrom = 0, $limitnum = 0) { - global $DB; - - // Get all the users in the course. - list($esql, $params) = get_enrolled_sql(\context_course::instance($courseid), '', 0, true); - $sql = "SELECT u.*, mub.id as isblocked - FROM {user} u - JOIN ($esql) je - ON je.id = u.id - LEFT JOIN {message_users_blocked} mub - ON (mub.blockeduserid = u.id AND mub.userid = :userid) - WHERE u.deleted = 0"; - // Add more conditions. - $fullname = $DB->sql_fullname(); - $sql .= " AND u.id != :userid2 - AND " . $DB->sql_like($fullname, ':search', false) . " - ORDER BY " . $DB->sql_fullname(); - $params = array_merge(array('userid' => $userid, 'userid2' => $userid, 'search' => '%' . $search . '%'), $params); - - // Convert all the user records into contacts. - $contacts = array(); - if ($users = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum)) { - foreach ($users as $user) { - $user->blocked = $user->isblocked ? 1 : 0; - $contacts[] = helper::create_contact($user); - } - } - - return $contacts; + public static function search_users_in_course() { + throw new \coding_exception('\core_message\api::search_users_in_course has been removed.'); } /** - * Handles searching for user in the message area. - * - * TODO: This function should be removed once the related web service goes through final deprecation. - * The related web service is data_for_messagearea_search_users. - * Followup: MDL-63261 - * - * @param int $userid The user id doing the searching - * @param string $search The string the user is searching - * @param int $limitnum - * @return array + * @deprecated since 3.6 */ - public static function search_users($userid, $search, $limitnum = 0) { - global $CFG, $DB; - - // Used to search for contacts. - $fullname = $DB->sql_fullname(); - $ufields = \user_picture::fields('u', array('lastaccess')); - - // Users not to include. - $excludeusers = array($userid, $CFG->siteguest); - list($exclude, $excludeparams) = $DB->get_in_or_equal($excludeusers, SQL_PARAMS_NAMED, 'param', false); - - // Ok, let's search for contacts first. - $contacts = array(); - $sql = "SELECT $ufields, mub.id as isuserblocked - FROM {user} u - JOIN {message_contacts} mc - ON u.id = mc.contactid - LEFT JOIN {message_users_blocked} mub - ON (mub.userid = :userid2 AND mub.blockeduserid = u.id) - WHERE mc.userid = :userid - AND u.deleted = 0 - AND u.confirmed = 1 - AND " . $DB->sql_like($fullname, ':search', false) . " - AND u.id $exclude - ORDER BY " . $DB->sql_fullname(); - if ($users = $DB->get_records_sql($sql, array('userid' => $userid, 'userid2' => $userid, - 'search' => '%' . $search . '%') + $excludeparams, 0, $limitnum)) { - foreach ($users as $user) { - $user->blocked = $user->isuserblocked ? 1 : 0; - $contacts[] = helper::create_contact($user); - } - } - - // Now, let's get the courses. - // Make sure to limit searches to enrolled courses. - $enrolledcourses = enrol_get_my_courses(array('id', 'cacherev')); - $courses = array(); - // Really we want the user to be able to view the participants if they have the capability - // 'moodle/course:viewparticipants' or 'moodle/course:enrolreview', but since the search_courses function - // only takes required parameters we can't. However, the chance of a user having 'moodle/course:enrolreview' but - // *not* 'moodle/course:viewparticipants' are pretty much zero, so it is not worth addressing. - if ($arrcourses = \core_course_category::search_courses(array('search' => $search), array('limit' => $limitnum), - array('moodle/course:viewparticipants'))) { - foreach ($arrcourses as $course) { - if (isset($enrolledcourses[$course->id])) { - $data = new \stdClass(); - $data->id = $course->id; - $data->shortname = $course->shortname; - $data->fullname = $course->fullname; - $courses[] = $data; - } - } - } - - // Let's get those non-contacts. Toast them gears boi. - // Note - you can only block contacts, so these users will not be blocked, so no need to get that - // extra detail from the database. - $noncontacts = array(); - $sql = "SELECT $ufields - FROM {user} u - WHERE u.deleted = 0 - AND u.confirmed = 1 - AND " . $DB->sql_like($fullname, ':search', false) . " - AND u.id $exclude - AND u.id NOT IN (SELECT contactid - FROM {message_contacts} - WHERE userid = :userid) - ORDER BY " . $DB->sql_fullname(); - if ($users = $DB->get_records_sql($sql, array('userid' => $userid, 'search' => '%' . $search . '%') + $excludeparams, - 0, $limitnum)) { - foreach ($users as $user) { - $noncontacts[] = helper::create_contact($user); - } - } - - return array($contacts, $courses, $noncontacts); + public static function search_users() { + throw new \coding_exception('\core_message\api::search_users has been removed.'); } /** @@ -1070,55 +949,10 @@ class api { } /** - * Returns the contacts to display in the contacts area. - * - * TODO: This function should be removed once the related web service goes through final deprecation. - * The related web service is data_for_messagearea_contacts. - * Followup: MDL-63261 - * - * @param int $userid The user id - * @param int $limitfrom - * @param int $limitnum - * @return array + * @deprecated since 3.6 */ - public static function get_contacts($userid, $limitfrom = 0, $limitnum = 0) { - global $DB; - - $contactids = []; - $sql = "SELECT mc.* - FROM {message_contacts} mc - WHERE mc.userid = ? OR mc.contactid = ? - ORDER BY timecreated DESC"; - if ($contacts = $DB->get_records_sql($sql, [$userid, $userid], $limitfrom, $limitnum)) { - foreach ($contacts as $contact) { - if ($userid == $contact->userid) { - $contactids[] = $contact->contactid; - } else { - $contactids[] = $contact->userid; - } - } - } - - if (!empty($contactids)) { - list($insql, $inparams) = $DB->get_in_or_equal($contactids); - - $sql = "SELECT u.*, mub.id as isblocked - FROM {user} u - LEFT JOIN {message_users_blocked} mub - ON u.id = mub.blockeduserid - WHERE u.id $insql"; - if ($contacts = $DB->get_records_sql($sql, $inparams)) { - $arrcontacts = []; - foreach ($contacts as $contact) { - $contact->blocked = $contact->isblocked ? 1 : 0; - $arrcontacts[] = helper::create_contact($contact); - } - - return $arrcontacts; - } - } - - return []; + public static function get_contacts() { + throw new \coding_exception('\core_message\api::get_contacts has been removed.'); } /** @@ -1170,6 +1004,8 @@ class api { * Returns the an array of the users the given user is in a conversation * with who are a contact and the number of unread messages. * + * @deprecated since 3.10 + * TODO: MDL-69643 * @param int $userid The user id * @param int $limitfrom * @param int $limitnum @@ -1178,6 +1014,9 @@ class api { public static function get_contacts_with_unread_message_count($userid, $limitfrom = 0, $limitnum = 0) { global $DB; + debugging('\core_message\api::get_contacts_with_unread_message_count is deprecated and no longer used', + DEBUG_DEVELOPER); + $userfields = \user_picture::fields('u', array('lastaccess')); $unreadcountssql = "SELECT $userfields, count(m.id) as messagecount FROM {message_contacts} mc @@ -1206,6 +1045,8 @@ class api { * Returns the an array of the users the given user is in a conversation * with who are not a contact and the number of unread messages. * + * @deprecated since 3.10 + * TODO: MDL-69643 * @param int $userid The user id * @param int $limitfrom * @param int $limitnum @@ -1214,6 +1055,9 @@ class api { public static function get_non_contacts_with_unread_message_count($userid, $limitfrom = 0, $limitnum = 0) { global $DB; + debugging('\core_message\api::get_non_contacts_with_unread_message_count is deprecated and no longer used', + DEBUG_DEVELOPER); + $userfields = \user_picture::fields('u', array('lastaccess')); $unreadcountssql = "SELECT $userfields, count(m.id) as messagecount FROM {user} u @@ -1240,52 +1084,10 @@ class api { } /** - * Returns the messages to display in the message area. - * - * TODO: This function should be removed once the related web service goes through final deprecation. - * The related web service is data_for_messagearea_messages. - * Followup: MDL-63261 - * - * @param int $userid the current user - * @param int $otheruserid the other user - * @param int $limitfrom - * @param int $limitnum - * @param string $sort - * @param int $timefrom the time from the message being sent - * @param int $timeto the time up until the message being sent - * @return array + * @deprecated since 3.6 */ - public static function get_messages($userid, $otheruserid, $limitfrom = 0, $limitnum = 0, - $sort = 'timecreated ASC', $timefrom = 0, $timeto = 0) { - - if (!empty($timefrom)) { - // Get the conversation between userid and otheruserid. - $userids = [$userid, $otheruserid]; - if (!$conversationid = self::get_conversation_between_users($userids)) { - // This method was always used for individual conversations. - $conversation = self::create_conversation(self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $userids); - $conversationid = $conversation->id; - } - - // Check the cache to see if we even need to do a DB query. - $cache = \cache::make('core', 'message_time_last_message_between_users'); - $key = helper::get_last_message_time_created_cache_key($conversationid); - $lastcreated = $cache->get($key); - - // The last known message time is earlier than the one being requested so we can - // just return an empty result set rather than having to query the DB. - if ($lastcreated && $lastcreated < $timefrom) { - return []; - } - } - - $arrmessages = array(); - if ($messages = helper::get_messages($userid, $otheruserid, 0, $limitfrom, $limitnum, - $sort, $timefrom, $timeto)) { - $arrmessages = helper::create_messages($userid, $messages); - } - - return $arrmessages; + public static function get_messages() { + throw new \coding_exception('\core_message\api::get_messages has been removed.'); } /** @@ -1321,26 +1123,10 @@ class api { } /** - * Returns the most recent message between two users. - * - * TODO: This function should be removed once the related web service goes through final deprecation. - * The related web service is data_for_messagearea_get_most_recent_message. - * Followup: MDL-63261 - * - * @param int $userid the current user - * @param int $otheruserid the other user - * @return \stdClass|null + * @deprecated since 3.6 */ - public static function get_most_recent_message($userid, $otheruserid) { - // We want two messages here so we get an accurate 'blocktime' value. - if ($messages = helper::get_messages($userid, $otheruserid, 0, 0, 2, 'timecreated DESC')) { - // Swap the order so we now have them in historical order. - $messages = array_reverse($messages); - $arrmessages = helper::create_messages($userid, $messages); - return array_pop($arrmessages); - } - - return null; + public static function get_most_recent_message() { + throw new \coding_exception('\core_message\api::get_most_recent_message has been removed.'); } /** @@ -1366,58 +1152,10 @@ class api { } /** - * Returns the profile information for a contact for a user. - * - * TODO: This function should be removed once the related web service goes through final deprecation. - * The related web service is data_for_messagearea_get_profile. - * Followup: MDL-63261 - * - * @param int $userid The user id - * @param int $otheruserid The id of the user whose profile we want to view. - * @return \stdClass + * @deprecated since 3.6 */ - public static function get_profile($userid, $otheruserid) { - global $CFG, $PAGE; - - require_once($CFG->dirroot . '/user/lib.php'); - - $user = \core_user::get_user($otheruserid, '*', MUST_EXIST); - - // Create the data we are going to pass to the renderable. - $data = new \stdClass(); - $data->userid = $otheruserid; - $data->fullname = fullname($user); - $data->city = ''; - $data->country = ''; - $data->email = ''; - $data->isonline = null; - // Get the user picture data - messaging has always shown these to the user. - $userpicture = new \user_picture($user); - $userpicture->size = 1; // Size f1. - $data->profileimageurl = $userpicture->get_url($PAGE)->out(false); - $userpicture->size = 0; // Size f2. - $data->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false); - - $userfields = user_get_user_details($user, null, array('city', 'country', 'email', 'lastaccess')); - if ($userfields) { - if (isset($userfields['city'])) { - $data->city = $userfields['city']; - } - if (isset($userfields['country'])) { - $data->country = $userfields['country']; - } - if (isset($userfields['email'])) { - $data->email = $userfields['email']; - } - if (isset($userfields['lastaccess'])) { - $data->isonline = helper::is_online($userfields['lastaccess']); - } - } - - $data->isblocked = self::is_blocked($userid, $otheruserid); - $data->iscontact = self::is_contact($userid, $otheruserid); - - return $data; + public static function get_profile() { + throw new \coding_exception('\core_message\api::get_profile has been removed.'); } /** @@ -1456,30 +1194,11 @@ class api { } /** - * Deletes a conversation. - * - * This function does not verify any permissions. - * * @deprecated since 3.6 - * @param int $userid The user id of who we want to delete the messages for (this may be done by the admin - * but will still seem as if it was by the user) - * @param int $otheruserid The id of the other user in the conversation - * @return bool */ - public static function delete_conversation($userid, $otheruserid) { - debugging('\core_message\api::delete_conversation() is deprecated, please use ' . - '\core_message\api::delete_conversation_by_id() instead.', DEBUG_DEVELOPER); - - $conversationid = self::get_conversation_between_users([$userid, $otheruserid]); - - // If there is no conversation, there is nothing to do. - if (!$conversationid) { - return true; - } - - self::delete_conversation_by_id($userid, $conversationid); - - return true; + public static function delete_conversation() { + throw new \coding_exception('\core_message\api::delete_conversation() is deprecated, please use ' . + '\core_message\api::delete_conversation_by_id() instead.'); } /** @@ -2028,80 +1747,17 @@ class api { } /** - * Checks if the recipient is allowing messages from users that aren't a - * contact. If not then it checks to make sure the sender is in the - * recipient's contacts. - * * @deprecated since 3.6 - * @param \stdClass $recipient The user object. - * @param \stdClass|null $sender The user object. - * @return bool true if $sender is blocked, false otherwise. */ - public static function is_user_non_contact_blocked($recipient, $sender = null) { - debugging('\core_message\api::is_user_non_contact_blocked() is deprecated', DEBUG_DEVELOPER); - - global $USER, $CFG; - - if (is_null($sender)) { - // The message is from the logged in user, unless otherwise specified. - $sender = $USER; - } - - $privacypreference = self::get_user_privacy_messaging_preference($recipient->id); - switch ($privacypreference) { - case self::MESSAGE_PRIVACY_SITE: - if (!empty($CFG->messagingallusers)) { - // Users can be messaged without being contacts or members of the same course. - break; - } - // When the $CFG->messagingallusers privacy setting is disabled, continue with the next - // case, because MESSAGE_PRIVACY_SITE is replaced to MESSAGE_PRIVACY_COURSEMEMBER. - case self::MESSAGE_PRIVACY_COURSEMEMBER: - // Confirm the sender and the recipient are both members of the same course. - if (enrol_sharing_course($recipient, $sender)) { - // All good, the recipient and the sender are members of the same course. - return false; - } - case self::MESSAGE_PRIVACY_ONLYCONTACTS: - // True if they aren't contacts (they can't send a message because of the privacy settings), false otherwise. - return !self::is_contact($sender->id, $recipient->id); - } - - return false; + public static function is_user_non_contact_blocked() { + throw new \coding_exception('\core_message\api::is_user_non_contact_blocked() is deprecated'); } /** - * Checks if the recipient has specifically blocked the sending user. - * - * Note: This function will always return false if the sender has the - * readallmessages capability at the system context level. - * * @deprecated since 3.6 - * @param int $recipientid User ID of the recipient. - * @param int $senderid User ID of the sender. - * @return bool true if $sender is blocked, false otherwise. */ - public static function is_user_blocked($recipientid, $senderid = null) { - debugging('\core_message\api::is_user_blocked is deprecated and should not be used.', - DEBUG_DEVELOPER); - - global $USER; - - if (is_null($senderid)) { - // The message is from the logged in user, unless otherwise specified. - $senderid = $USER->id; - } - - $systemcontext = \context_system::instance(); - if (has_capability('moodle/site:readallmessages', $systemcontext, $senderid)) { - return false; - } - - if (self::is_blocked($recipientid, $senderid)) { - return true; - } - - return false; + public static function is_user_blocked() { + throw new \coding_exception('\core_message\api::is_user_blocked is deprecated and should not be used.'); } /** @@ -2465,20 +2121,11 @@ class api { } /** - * Creates a conversation between two users. - * * @deprecated since 3.6 - * @param array $userids - * @return int The id of the conversation */ - public static function create_conversation_between_users(array $userids) { - debugging('\core_message\api::create_conversation_between_users is deprecated, please use ' . - '\core_message\api::create_conversation instead.', DEBUG_DEVELOPER); - - // This method was always used for individual conversations. - $conversation = self::create_conversation(self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $userids); - - return $conversation->id; + public static function create_conversation_between_users() { + throw new \coding_exception('\core_message\api::create_conversation_between_users is deprecated, please use ' . + '\core_message\api::create_conversation instead.'); } /** diff --git a/message/classes/helper.php b/message/classes/helper.php index c6472a4de8b..286b36c3113 100644 --- a/message/classes/helper.php +++ b/message/classes/helper.php @@ -37,82 +37,10 @@ require_once($CFG->dirroot . '/message/lib.php'); class helper { /** - * Helper function to retrieve the messages between two users - * - * TODO: This function should be removed once the related web services go through final deprecation. - * The related web services are data_for_messagearea_messages AND data_for_messagearea_get_most_recent_message. - * Followup: MDL-63261 - * - * @param int $userid the current user - * @param int $otheruserid the other user - * @param int $timedeleted the time the message was deleted - * @param int $limitfrom - * @param int $limitnum - * @param string $sort - * @param int $timefrom the time from the message being sent - * @param int $timeto the time up until the message being sent - * @return array of messages + * @deprecated since 3.6 */ - public static function get_messages($userid, $otheruserid, $timedeleted = 0, $limitfrom = 0, $limitnum = 0, - $sort = 'timecreated ASC', $timefrom = 0, $timeto = 0) { - global $DB; - - $hash = self::get_conversation_hash([$userid, $otheruserid]); - - $sql = "SELECT m.id, m.useridfrom, m.subject, m.fullmessage, m.fullmessagehtml, - m.fullmessageformat, m.fullmessagetrust, m.smallmessage, m.timecreated, - mc.contextid, muaread.timecreated AS timeread - FROM {message_conversations} mc - INNER JOIN {messages} m - ON m.conversationid = mc.id - LEFT JOIN {message_user_actions} muaread - ON (muaread.messageid = m.id - AND muaread.userid = :userid1 - AND muaread.action = :readaction)"; - $params = ['userid1' => $userid, 'readaction' => api::MESSAGE_ACTION_READ, 'convhash' => $hash]; - - if (empty($timedeleted)) { - $sql .= " LEFT JOIN {message_user_actions} mua - ON (mua.messageid = m.id - AND mua.userid = :userid2 - AND mua.action = :deleteaction - AND mua.timecreated is NOT NULL)"; - } else { - $sql .= " INNER JOIN {message_user_actions} mua - ON (mua.messageid = m.id - AND mua.userid = :userid2 - AND mua.action = :deleteaction - AND mua.timecreated = :timedeleted)"; - $params['timedeleted'] = $timedeleted; - } - - $params['userid2'] = $userid; - $params['deleteaction'] = api::MESSAGE_ACTION_DELETED; - - $sql .= " WHERE mc.convhash = :convhash"; - - if (!empty($timefrom)) { - $sql .= " AND m.timecreated >= :timefrom"; - $params['timefrom'] = $timefrom; - } - - if (!empty($timeto)) { - $sql .= " AND m.timecreated <= :timeto"; - $params['timeto'] = $timeto; - } - - if (empty($timedeleted)) { - $sql .= " AND mua.id is NULL"; - } - - $sql .= " ORDER BY m.$sort"; - - $messages = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum); - foreach ($messages as &$message) { - $message->useridto = ($message->useridfrom == $userid) ? $otheruserid : $userid; - } - - return $messages; + public static function get_messages() { + throw new \coding_exception('\core_message\helper::get_messages has been removed.'); } /** @@ -234,55 +162,10 @@ class helper { } /** - * Helper function to return an array of messages. - * - * TODO: This function should be removed once the related web services go through final deprecation. - * The related web services are data_for_messagearea_messages AND data_for_messagearea_get_most_recent_message. - * Followup: MDL-63261 - * - * @param int $userid - * @param array $messages - * @return array + * @deprecated since 3.6 */ - public static function create_messages($userid, $messages) { - // Store the messages. - $arrmessages = array(); - - // We always view messages from oldest to newest, ensure we have it in that order. - $lastmessage = end($messages); - $firstmessage = reset($messages); - if ($lastmessage->timecreated < $firstmessage->timecreated) { - $messages = array_reverse($messages); - } - - // Keeps track of the last day, month and year combo we were viewing. - $day = ''; - $month = ''; - $year = ''; - foreach ($messages as $message) { - // Check if we are now viewing a different block period. - $displayblocktime = false; - $date = usergetdate($message->timecreated); - if ($day != $date['mday'] || $month != $date['month'] || $year != $date['year']) { - $day = $date['mday']; - $month = $date['month']; - $year = $date['year']; - $displayblocktime = true; - } - // Store the message to pass to the renderable. - $msg = new \stdClass(); - $msg->id = $message->id; - $msg->text = message_format_message_text($message); - $msg->currentuserid = $userid; - $msg->useridfrom = $message->useridfrom; - $msg->useridto = $message->useridto; - $msg->displayblocktime = $displayblocktime; - $msg->timecreated = $message->timecreated; - $msg->timeread = $message->timeread; - $arrmessages[] = $msg; - } - - return $arrmessages; + public static function create_messages() { + throw new \coding_exception('\core_message\helper::create_messages has been removed.'); } /** @@ -428,7 +311,9 @@ class helper { * @return array */ public static function togglecontact_link_params($user, $iscontact = false) { + global $USER; $params = array( + 'data-currentuserid' => $USER->id, 'data-userid' => $user->id, 'data-is-contact' => $iscontact, 'id' => 'toggle-contact-button', @@ -639,47 +524,11 @@ class helper { return $members; } - /** - * Backwards compatibility formatter, transforming the new output of get_conversations() into the old format. - * - * TODO: This function should be removed once the related web services go through final deprecation. - * The related web services are data_for_messagearea_conversations. - * Followup: MDL-63261 - * - * @param array $conversations the array of conversations, which must come from get_conversations(). - * @return array the array of conversations, formatted in the legacy style. + * @deprecated since 3.6 */ - 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) { - // Only individual conversations were supported in legacy messaging. - if ($conv->type != \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) { - continue; - } - $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 ? clean_param($conv->messages[0]->text, PARAM_NOTAGS) : null; - $data->lastmessagedate = $conv->messages[0]->timecreated ?? 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; + public static function get_conversations_legacy_formatter() { + throw new \coding_exception('\core_message\helper::get_conversations_legacy_formatter has been removed.'); } /** diff --git a/message/classes/output/messagearea/contact.php b/message/classes/output/messagearea/contact.php deleted file mode 100644 index ab012378cc5..00000000000 --- a/message/classes/output/messagearea/contact.php +++ /dev/null @@ -1,168 +0,0 @@ -. - -/** - * Contains class used to prepare a contact for display. - * - * TODO: This file should be removed once the related web services go through final deprecation. - * Followup: MDL-63261 - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace core_message\output\messagearea; - -defined('MOODLE_INTERNAL') || die(); - -use renderable; -use templatable; - -/** - * Class to prepare a contact for display. - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class contact implements templatable, renderable { - - /** - * @var int Maximum length of message to show in panel. - */ - const MAX_MSG_LENGTH = 60; - - /** - * @var int The userid. - */ - public $userid; - - /** - * @var int The id of the user who sent the last message. - */ - public $useridfrom; - - /** - * @var string The fullname. - */ - public $fullname; - - /** - * @var string The profile image url. - */ - public $profileimageurl; - - /** - * @var string The small profile image url. - */ - public $profileimageurlsmall; - - /** - * @var int The message id. - */ - public $messageid; - - /** - * @var bool Are we messaging the user? - */ - public $ismessaging; - - /** - * @var string The last message sent. - */ - public $lastmessage; - - /** - * @var int The last message sent timestamp. - */ - public $lastmessagedate; - - /** - * @var bool Is the user online? - */ - public $isonline; - - /** - * @var bool Is the user blocked? - */ - public $isblocked; - - /** - * @var bool Is the message read? - */ - public $isread; - - /** - * @var int The number of unread messages. - */ - public $unreadcount; - - /** - * @var int The id of the conversation to which to message belongs. - */ - public $conversationid; - - /** - * Constructor. - * - * @param \stdClass $contact - */ - public function __construct($contact) { - $this->userid = $contact->userid; - $this->useridfrom = $contact->useridfrom; - $this->fullname = $contact->fullname; - $this->profileimageurl = $contact->profileimageurl; - $this->profileimageurlsmall = $contact->profileimageurlsmall; - $this->messageid = $contact->messageid; - $this->ismessaging = $contact->ismessaging; - $this->lastmessage = $contact->lastmessage; - $this->lastmessagedate = $contact->lastmessagedate; - $this->isonline = $contact->isonline; - $this->isblocked = $contact->isblocked; - $this->isread = $contact->isread; - $this->unreadcount = $contact->unreadcount; - $this->conversationid = $contact->conversationid ?? null; - } - - public function export_for_template(\renderer_base $output) { - $contact = new \stdClass(); - $contact->userid = $this->userid; - $contact->fullname = $this->fullname; - $contact->profileimageurl = $this->profileimageurl; - $contact->profileimageurlsmall = $this->profileimageurlsmall; - $contact->messageid = $this->messageid; - $contact->ismessaging = $this->ismessaging; - $contact->sentfromcurrentuser = false; - if ($this->lastmessage) { - if ($this->userid !== $this->useridfrom) { - $contact->sentfromcurrentuser = true; - } - $contact->lastmessage = shorten_text($this->lastmessage, self::MAX_MSG_LENGTH); - } else { - $contact->lastmessage = null; - } - $contact->lastmessagedate = $this->lastmessagedate; - $contact->showonlinestatus = is_null($this->isonline) ? false : true; - $contact->isonline = $this->isonline; - $contact->isblocked = $this->isblocked; - $contact->isread = $this->isread; - $contact->unreadcount = $this->unreadcount; - $contact->conversationid = $this->conversationid; - - return $contact; - } -} diff --git a/message/classes/output/messagearea/contacts.php b/message/classes/output/messagearea/contacts.php deleted file mode 100644 index 785d9a9941d..00000000000 --- a/message/classes/output/messagearea/contacts.php +++ /dev/null @@ -1,96 +0,0 @@ -. - -/** - * Contains class used to prepare the contacts for display. - * - * TODO: This file should be removed once the related web services go through final deprecation. - * Followup: MDL-63261 - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace core_message\output\messagearea; - -defined('MOODLE_INTERNAL') || die(); - -use renderable; -use templatable; - -/** - * Class to prepare the contacts for display. - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class contacts implements templatable, renderable { - - /** - * @var int The id of the user that has been selected. - */ - public $contactuserid; - - /** - * @var array The contacts. - */ - public $contacts; - - /** - * Constructor. - * - * @param int|null $contactuserid The id of the user that has been selected - * @param array $contacts - */ - public function __construct($contactuserid, $contacts) { - $this->contactuserid = $contactuserid; - $this->contacts = $contacts; - } - - public function export_for_template(\renderer_base $output) { - $data = new \stdClass(); - $data->contacts = array(); - $userids = array(); - foreach ($this->contacts as $contact) { - $contact = new contact($contact); - $contactdata = $contact->export_for_template($output); - $userids[$contactdata->userid] = $contactdata->userid; - // Check if the contact was selected. - if ($this->contactuserid == $contactdata->userid) { - $contactdata->selected = true; - } - $data->contacts[] = $contactdata; - } - // Check if the other user is not part of the contacts. We may be sending a message to someone - // we have not had a conversation with, so we want to add a new item to the contacts array. - if ($this->contactuserid && !isset($userids[$this->contactuserid])) { - $user = \core_user::get_user($this->contactuserid); - // Set an empty message so that we know we are messaging the user, and not viewing their profile. - $user->smallmessage = ''; - $user->useridfrom = $user->id; - $contact = \core_message\helper::create_contact($user); - $contact = new contact($contact); - $contactdata = $contact->export_for_template($output); - $contactdata->selected = true; - // Put the contact at the front. - array_unshift($data->contacts, $contactdata); - } - - return $data; - } -} diff --git a/message/classes/output/messagearea/message.php b/message/classes/output/messagearea/message.php deleted file mode 100644 index 93177e050c8..00000000000 --- a/message/classes/output/messagearea/message.php +++ /dev/null @@ -1,118 +0,0 @@ -. - -/** - * Contains class used to prepare a message for display. - * - * TODO: This file should be removed once the related web services go through final deprecation. - * Followup: MDL-63261 - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace core_message\output\messagearea; - -defined('MOODLE_INTERNAL') || die(); - -use renderable; -use templatable; - -/** - * Class to prepare a message for display. - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class message implements templatable, renderable { - - /** - * @var int The message id. - */ - public $id; - - /** - * @var int The current userid. - */ - public $currentuserid; - - /** - * @var int The userid to. - */ - public $useridto; - - /** - * @var int The userid from. - */ - public $useridfrom; - - /** - * @var string The message text. - */ - public $text; - - /** - * @var bool Are we displaying the time? - */ - public $displayblocktime; - - /** - * @var int The time created of the message. - */ - public $timecreated; - - /** - * @var int The time the message was read. - */ - public $timeread; - - /** - * Constructor. - * - * @param \stdClass $message - */ - public function __construct($message) { - $this->id = $message->id; - $this->currentuserid = $message->currentuserid; - $this->useridto = $message->useridto; - $this->useridfrom = $message->useridfrom; - $this->text = $message->text; - $this->displayblocktime = $message->displayblocktime; - $this->timecreated = $message->timecreated; - $this->timeread = $message->timeread; - } - - public function export_for_template(\renderer_base $output) { - $message = new \stdClass(); - $message->id = $this->id; - $message->useridto = $this->useridto; - $message->useridfrom = $this->useridfrom; - $message->text = $this->text; - $message->displayblocktime = $this->displayblocktime; - $message->blocktime = userdate($this->timecreated, get_string('strftimedaydate')); - $message->position = 'left'; - if ($this->currentuserid == $this->useridfrom) { - $message->position = 'right'; - } - $message->timesent = userdate($this->timecreated, get_string('strftimetime')); - $message->timecreated = $this->timecreated; - $message->isread = !empty($this->timeread) ? 1 : 0; - - return $message; - } -} diff --git a/message/classes/output/messagearea/message_area.php b/message/classes/output/messagearea/message_area.php deleted file mode 100644 index 9d2e05d72e6..00000000000 --- a/message/classes/output/messagearea/message_area.php +++ /dev/null @@ -1,137 +0,0 @@ -. - -/** - * Contains class used to prepare the message area for display. - * - * TODO: This file should be removed once the related web services go through final deprecation. - * Followup: MDL-63261 - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace core_message\output\messagearea; - -defined('MOODLE_INTERNAL') || die(); - -use renderable; -use templatable; - -/** - * Class to prepare the message area for display. - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class message_area implements templatable, renderable { - - /** - * @var int The user id. - */ - public $userid; - - /** - * @var int The other user id. - */ - public $otheruserid; - - /** - * @var array The contacts for the users. - */ - public $contacts; - - /** - * @var array The messages for the user. - */ - public $messages; - - /** - * @var bool Was a specific conversation requested. - */ - public $requestedconversation; - - /** - * @var int The minimum time to poll for messages. - */ - public $pollmin; - - /** - * @var int The maximum time to poll for messages. - */ - public $pollmax; - - /** - * @var int The time used once we have reached the maximum polling time. - */ - public $polltimeout; - - /** - * @var bool Are we creating a new message and show the contacts section first? - */ - public $contactsfirst; - - /** - * Constructor. - * - * @param int $userid The ID of the user whose contacts and messages we are viewing - * @param int|null $otheruserid The id of the user we are viewing, null if none - * @param array $contacts - * @param array|null $messages - * @param bool $requestedconversation - * @param bool $contactsfirst Whether we are viewing the contacts first. - * @param int $pollmin - * @param int $pollmax - * @param int $polltimeout - */ - public function __construct($userid, $otheruserid, $contacts, $messages, $requestedconversation, $contactsfirst, $pollmin, - $pollmax, $polltimeout) { - $this->userid = $userid; - // Setting the other user to null when showing contacts will remove any contact from being selected. - $this->otheruserid = (!$contactsfirst) ? $otheruserid : null; - $this->contacts = $contacts; - $this->messages = $messages; - $this->requestedconversation = $requestedconversation; - $this->pollmin = $pollmin; - $this->pollmax = $pollmax; - $this->polltimeout = $polltimeout; - $this->contactsfirst = $contactsfirst; - } - - public function export_for_template(\renderer_base $output) { - $data = new \stdClass(); - $data->userid = $this->userid; - $contacts = new contacts($this->otheruserid, $this->contacts); - $data->contacts = $contacts->export_for_template($output); - if ($this->contactsfirst) { - // Don't show any messages if we are creating a new message. - $messages = new messages($this->userid, null, array()); - } else { - $messages = new messages($this->userid, $this->otheruserid, $this->messages); - } - $data->messages = $messages->export_for_template($output); - $data->isconversation = ($this->contactsfirst) ? false : true; - $data->requestedconversation = $this->requestedconversation; - $data->pollmin = $this->pollmin; - $data->pollmax = $this->pollmax; - $data->polltimeout = $this->polltimeout; - $data->contactsfirst = $this->contactsfirst; - - return $data; - } -} diff --git a/message/classes/output/messagearea/messages.php b/message/classes/output/messagearea/messages.php deleted file mode 100644 index ce8e75ccbf9..00000000000 --- a/message/classes/output/messagearea/messages.php +++ /dev/null @@ -1,112 +0,0 @@ -. - -/** - * Contains class used to prepare the messages for display. - * - * TODO: This file should be removed once the related web services go through final deprecation. - * Followup: MDL-63261 - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace core_message\output\messagearea; - -defined('MOODLE_INTERNAL') || die(); - -use core_message\api; -use renderable; -use templatable; - -/** - * Class to prepare the messages for display. - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class messages implements templatable, renderable { - - /** - * @var array The messages. - */ - public $messages; - - /** - * @var int The current user id. - */ - public $currentuserid; - - /** - * @var int The other user id. - */ - public $otheruserid; - - /** - * @var \stdClass The other user. - */ - public $otheruser; - - /** - * Constructor. - * - * @param int $currentuserid The current user we are wanting to view messages for - * @param int $otheruserid The other user we are wanting to view messages for - * @param array $messages - */ - public function __construct($currentuserid, $otheruserid, $messages) { - $ufields = 'id, ' . get_all_user_name_fields(true) . ', lastaccess'; - - $this->currentuserid = $currentuserid; - if ($otheruserid) { - $this->otheruserid = $otheruserid; - $this->otheruser = \core_user::get_user($otheruserid, $ufields, MUST_EXIST); - } - $this->messages = $messages; - } - - public function export_for_template(\renderer_base $output) { - global $USER; - - $data = new \stdClass(); - $data->iscurrentuser = $USER->id == $this->currentuserid; - $data->currentuserid = $this->currentuserid; - if ($this->otheruserid) { - $data->otheruserid = $this->otheruserid; - $data->otheruserfullname = fullname($this->otheruser); - } - $data->isonline = null; - if ($this->otheruserid) { - if (\core_message\helper::show_online_status($this->otheruser)) { - $data->isonline = \core_message\helper::is_online($this->otheruser->lastaccess); - } - } - $data->showonlinestatus = is_null($data->isonline) ? false : true; - - $data->messages = array(); - foreach ($this->messages as $message) { - $message = new message($message); - $data->messages[] = $message->export_for_template($output); - } - - $blockeduserid = $this->otheruserid ?? $USER->id; - $data->isblocked = api::is_blocked($this->currentuserid, $blockeduserid); - - return $data; - } -} diff --git a/message/classes/output/messagearea/profile.php b/message/classes/output/messagearea/profile.php deleted file mode 100644 index 151bba1488b..00000000000 --- a/message/classes/output/messagearea/profile.php +++ /dev/null @@ -1,132 +0,0 @@ -. - -/** - * Contains class used to prepare a profile for display. - * - * TODO: This file should be removed once the related web services go through final deprecation. - * Followup: MDL-63261 - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace core_message\output\messagearea; - -defined('MOODLE_INTERNAL') || die(); - -use renderable; -use templatable; - -/** - * Class to prepare a profile for display. - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class profile implements templatable, renderable { - - /** - * @var int The id of the user we are going to view. - */ - public $userid; - - /** - * @var string The fullname. - */ - public $fullname; - - /** - * @var string The city. - */ - public $city; - - /** - * @var string The country. - */ - public $country; - - /** - * @var string The email. - */ - public $email; - - /** - * @var string The profile image url. - */ - public $profileimageurl; - - /** - * @var string The small profile image url. - */ - public $profileimageurlsmall; - - /** - * @var bool Is the user online? - */ - public $isonline; - - /** - * @var bool Is the user blocked? - */ - public $isblocked; - - /** - * @var bool Is the user a contact? - */ - public $iscontact; - - /** - * Constructor. - * - * @param \stdClass $profile - */ - public function __construct($profile) { - $this->userid = $profile->userid; - $this->fullname = $profile->fullname; - $this->isonline = $profile->isonline; - $this->email = $profile->email; - $this->country = $profile->country; - $this->city = $profile->city; - $this->profileimageurl = $profile->profileimageurl; - $this->profileimageurlsmall = $profile->profileimageurlsmall; - $this->isblocked = $profile->isblocked; - $this->iscontact = $profile->iscontact; - } - - public function export_for_template(\renderer_base $output) { - $data = new \stdClass(); - $data->userid = $this->userid; - $data->fullname = $this->fullname; - $data->showonlinestatus = is_null($this->isonline) ? false : true; - $data->isonline = $this->isonline; - $data->email = $this->email; - if (!empty($this->country)) { - $data->country = get_string($this->country, 'countries'); - } else { - $data->country = ''; - } - $data->city = $this->city; - $data->profileimageurl = $this->profileimageurl; - $data->profileimageurlsmall = $this->profileimageurlsmall; - $data->isblocked = $this->isblocked; - $data->iscontact = $this->iscontact; - - return $data; - } -} diff --git a/message/classes/output/messagearea/user_search_results.php b/message/classes/output/messagearea/user_search_results.php deleted file mode 100644 index ac6635880d3..00000000000 --- a/message/classes/output/messagearea/user_search_results.php +++ /dev/null @@ -1,114 +0,0 @@ -. - -/** - * Contains class used to display user search results. - * - * TODO: This file should be removed once the related web services go through final deprecation. - * Followup: MDL-63261 - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace core_message\output\messagearea; - -defined('MOODLE_INTERNAL') || die(); - -use renderable; -use templatable; - -/** - * Class used to display user search results. - * - * @package core_message - * @copyright 2016 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class user_search_results implements templatable, renderable { - - /** - * @var array The list of contacts. - */ - public $contacts; - - /** - * @var array The list of courses. - */ - public $courses; - - /** - * @var array The list of non-contacts. - */ - public $noncontacts; - - /** - * Constructor. - * - * @param array $contacts list of contacts. - * @param array $courses list of courses. - * @param array $noncontacts list of nonconcat users. - */ - public function __construct($contacts, $courses = array(), $noncontacts = array()) { - $this->contacts = $contacts; - $this->courses = $courses; - $this->noncontacts = $noncontacts; - } - - public function export_for_template(\renderer_base $output) { - // Set the defaults for the data we are going to export. - $data = new \stdClass(); - $data->hascontacts = false; - $data->contacts = array(); - $data->hascourses = false; - $data->courses = array(); - $data->hasnoncontacts = false; - $data->noncontacts = array(); - - // Check if there are any contacts. - if (!empty($this->contacts)) { - $data->hascontacts = true; - foreach ($this->contacts as $contact) { - $contact = new contact($contact); - $data->contacts[] = $contact->export_for_template($output); - } - } - - // Check if there are any courses. - if (!empty($this->courses)) { - $data->hascourses = true; - $data->courses = []; - foreach ($this->courses as $course) { - $coursecontext = \context_course::instance($course->id); - $course->shortname = external_format_string($course->shortname, $coursecontext->id, true); - $course->fullname = external_format_string($course->fullname, $coursecontext->id, true); - $data->courses[] = $course; - } - } - - // Check if there are any non-contacts. - if (!empty($this->noncontacts)) { - $data->hasnoncontacts = true; - foreach ($this->noncontacts as $noncontact) { - $noncontact = new contact($noncontact); - $data->noncontacts[] = $noncontact->export_for_template($output); - } - } - - return $data; - } -} \ No newline at end of file diff --git a/message/externallib.php b/message/externallib.php index d9428212cf3..0358c402ec8 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -268,94 +268,6 @@ class core_message_external extends external_api { ); } - /** - * Create contacts parameters description. - * - * @deprecated since Moodle 3.6 - * @return external_function_parameters - * @since Moodle 2.5 - */ - public static function create_contacts_parameters() { - return new external_function_parameters( - array( - 'userids' => new external_multiple_structure( - new external_value(PARAM_INT, 'User ID'), - 'List of user IDs' - ), - 'userid' => new external_value(PARAM_INT, 'The id of the user we are creating the contacts for, 0 for the - current user', VALUE_DEFAULT, 0) - ) - ); - } - - /** - * Create contacts. - * - * @deprecated since Moodle 3.6 - * TODO: MDL-63261 - * @param array $userids array of user IDs. - * @param int $userid The id of the user we are creating the contacts for - * @return external_description - * @since Moodle 2.5 - */ - public static function create_contacts($userids, $userid = 0) { - global $CFG, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - if (empty($userid)) { - $userid = $USER->id; - } - - // Validate context. - $context = context_system::instance(); - self::validate_context($context); - - $params = array('userids' => $userids, 'userid' => $userid); - $params = self::validate_parameters(self::create_contacts_parameters(), $params); - - $capability = 'moodle/site:manageallmessaging'; - if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { - throw new required_capability_exception($context, $capability, 'nopermissions', ''); - } - - $warnings = array(); - foreach ($params['userids'] as $id) { - if (!\core_message\api::create_contact_request($params['userid'], $id)) { - $warnings[] = array( - 'item' => 'user', - 'itemid' => $id, - 'warningcode' => 'contactnotcreated', - 'message' => 'The contact could not be created' - ); - } - } - return $warnings; - } - - /** - * Create contacts return description. - * - * @deprecated since Moodle 3.6 - * @return external_description - * @since Moodle 2.5 - */ - public static function create_contacts_returns() { - return new external_warnings(); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function create_contacts_is_deprecated() { - return true; - } - /** * Delete contacts parameters description. * @@ -659,173 +571,6 @@ class core_message_external extends external_api { return new external_warnings(); } - /** - * Block contacts parameters description. - * - * @deprecated since Moodle 3.6 - * @return external_function_parameters - * @since Moodle 2.5 - */ - public static function block_contacts_parameters() { - return new external_function_parameters( - array( - 'userids' => new external_multiple_structure( - new external_value(PARAM_INT, 'User ID'), - 'List of user IDs' - ), - 'userid' => new external_value(PARAM_INT, 'The id of the user we are blocking the contacts for, 0 for the - current user', VALUE_DEFAULT, 0) - ) - ); - } - - /** - * Block contacts. - * - * @deprecated since Moodle 3.6 - * TODO: MDL-63261 - * @param array $userids array of user IDs. - * @param int $userid The id of the user we are blocking the contacts for - * @return external_description - * @since Moodle 2.5 - */ - public static function block_contacts($userids, $userid = 0) { - global $CFG, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - if (empty($userid)) { - $userid = $USER->id; - } - - // Validate context. - $context = context_system::instance(); - self::validate_context($context); - - $params = array('userids' => $userids, 'userid' => $userid); - $params = self::validate_parameters(self::block_contacts_parameters(), $params); - - $capability = 'moodle/site:manageallmessaging'; - if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { - throw new required_capability_exception($context, $capability, 'nopermissions', ''); - } - - $warnings = array(); - foreach ($params['userids'] as $id) { - if (!\core_message\api::block_user($params['userid'], $id)) { - $warnings[] = array( - 'item' => 'user', - 'itemid' => $id, - 'warningcode' => 'contactnotblocked', - 'message' => 'The contact could not be blocked' - ); - } - } - return $warnings; - } - - /** - * Block contacts return description. - * - * @deprecated since Moodle 3.6 - * @return external_description - * @since Moodle 2.5 - */ - public static function block_contacts_returns() { - return new external_warnings(); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function block_contacts_is_deprecated() { - return true; - } - - /** - * Unblock contacts parameters description. - * - * @deprecated since Moodle 3.6 - * @return external_function_parameters - * @since Moodle 2.5 - */ - public static function unblock_contacts_parameters() { - return new external_function_parameters( - array( - 'userids' => new external_multiple_structure( - new external_value(PARAM_INT, 'User ID'), - 'List of user IDs' - ), - 'userid' => new external_value(PARAM_INT, 'The id of the user we are unblocking the contacts for, 0 for the - current user', VALUE_DEFAULT, 0) - ) - ); - } - - /** - * Unblock contacts. - * - * @param array $userids array of user IDs. - * @param int $userid The id of the user we are unblocking the contacts for - * @return null - * @since Moodle 2.5 - */ - public static function unblock_contacts($userids, $userid = 0) { - global $CFG, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - if (empty($userid)) { - $userid = $USER->id; - } - - // Validate context. - $context = context_system::instance(); - self::validate_context($context); - - $params = array('userids' => $userids, 'userid' => $userid); - $params = self::validate_parameters(self::unblock_contacts_parameters(), $params); - - $capability = 'moodle/site:manageallmessaging'; - if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { - throw new required_capability_exception($context, $capability, 'nopermissions', ''); - } - - foreach ($params['userids'] as $id) { - core_message\api::unblock_user($params['userid'], $id); - } - - return null; - } - - /** - * Unblock contacts return description. - * - * @deprecated since Moodle 3.6 - * @return external_description - * @since Moodle 2.5 - */ - public static function unblock_contacts_returns() { - return null; - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function unblock_contacts_is_deprecated() { - return true; - } - /** * Returns contact requests parameters description. * @@ -1346,231 +1091,6 @@ class core_message_external extends external_api { ); } - /** - * Return the structure of a message area message. - * - * @return external_single_structure - * @since Moodle 3.2 - */ - private static function get_messagearea_message_structure() { - return new external_single_structure( - array( - 'id' => new external_value(PARAM_INT, 'The id of the message'), - 'useridfrom' => new external_value(PARAM_INT, 'The id of the user who sent the message'), - 'useridto' => new external_value(PARAM_INT, 'The id of the user who received the message'), - 'text' => new external_value(PARAM_RAW, 'The text of the message'), - 'displayblocktime' => new external_value(PARAM_BOOL, 'Should we display the block time?'), - 'blocktime' => new external_value(PARAM_NOTAGS, 'The time to display above the message'), - 'position' => new external_value(PARAM_ALPHA, 'The position of the text'), - 'timesent' => new external_value(PARAM_NOTAGS, 'The time the message was sent'), - 'timecreated' => new external_value(PARAM_INT, 'The timecreated timestamp for the message'), - 'isread' => new external_value(PARAM_INT, 'Determines if the message was read or not'), - ) - ); - } - - /** - * Get messagearea search users in course parameters. - * - * @deprecated since 3.6 - * - * @return external_function_parameters - * @since 3.2 - */ - public static function data_for_messagearea_search_users_in_course_parameters() { - return new external_function_parameters( - array( - 'userid' => new external_value(PARAM_INT, 'The id of the user who is performing the search'), - 'courseid' => new external_value(PARAM_INT, 'The id of the course'), - 'search' => new external_value(PARAM_RAW, 'The string being searched'), - 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), - 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) - ) - ); - } - - /** - * Get messagearea search users in course results. - * - * @deprecated since 3.6 - * - * @param int $userid The id of the user who is performing the search - * @param int $courseid The id of the course - * @param string $search The string being searched - * @param int $limitfrom - * @param int $limitnum - * @return stdClass - * @throws moodle_exception - * @since 3.2 - */ - public static function data_for_messagearea_search_users_in_course($userid, $courseid, $search, $limitfrom = 0, - $limitnum = 0) { - global $CFG, $PAGE, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - $systemcontext = context_system::instance(); - - $params = array( - 'userid' => $userid, - 'courseid' => $courseid, - 'search' => $search, - 'limitfrom' => $limitfrom, - 'limitnum' => $limitnum - ); - $params = self::validate_parameters(self::data_for_messagearea_search_users_in_course_parameters(), $params); - self::validate_context($systemcontext); - - if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { - throw new moodle_exception('You do not have permission to perform this action.'); - } - - $users = \core_message\api::search_users_in_course( - $params['userid'], - $params['courseid'], - $params['search'], - $params['limitfrom'], - $params['limitnum'] - ); - $results = new \core_message\output\messagearea\user_search_results($users); - - $renderer = $PAGE->get_renderer('core_message'); - return $results->export_for_template($renderer); - } - - /** - * Get messagearea search users in course returns. - * - * @deprecated since 3.6 - * - * @return external_single_structure - * @since 3.2 - */ - public static function data_for_messagearea_search_users_in_course_returns() { - return new external_single_structure( - array( - 'contacts' => new external_multiple_structure( - self::get_messagearea_contact_structure() - ), - ) - ); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function data_for_messagearea_search_users_in_course_is_deprecated() { - return true; - } - - /** - * Get messagearea search users parameters. - * - * @deprecated since 3.6 - * - * @return external_function_parameters - * @since 3.2 - */ - public static function data_for_messagearea_search_users_parameters() { - return new external_function_parameters( - array( - 'userid' => new external_value(PARAM_INT, 'The id of the user who is performing the search'), - 'search' => new external_value(PARAM_RAW, 'The string being searched'), - 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) - ) - ); - } - - /** - * Get messagearea search users results. - * - * @deprecated since 3.6 - * - * @param int $userid The id of the user who is performing the search - * @param string $search The string being searched - * @param int $limitnum - * @return stdClass - * @throws moodle_exception - * @since 3.2 - */ - public static function data_for_messagearea_search_users($userid, $search, $limitnum = 0) { - global $CFG, $PAGE, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - $systemcontext = context_system::instance(); - - $params = array( - 'userid' => $userid, - 'search' => $search, - 'limitnum' => $limitnum - ); - $params = self::validate_parameters(self::data_for_messagearea_search_users_parameters(), $params); - self::validate_context($systemcontext); - - if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { - throw new moodle_exception('You do not have permission to perform this action.'); - } - - list($contacts, $courses, $noncontacts) = \core_message\api::search_users( - $params['userid'], - $params['search'], - $params['limitnum'] - ); - - $search = new \core_message\output\messagearea\user_search_results($contacts, $courses, $noncontacts); - - $renderer = $PAGE->get_renderer('core_message'); - return $search->export_for_template($renderer); - } - - /** - * Get messagearea search users returns. - * - * @deprecated since 3.6 - * - * @return external_single_structure - * @since 3.2 - */ - public static function data_for_messagearea_search_users_returns() { - return new external_single_structure( - array( - 'contacts' => new external_multiple_structure( - self::get_messagearea_contact_structure() - ), - 'courses' => new external_multiple_structure( - new external_single_structure( - array( - 'id' => new external_value(PARAM_INT, 'The course id'), - 'shortname' => new external_value(PARAM_TEXT, 'The course shortname'), - 'fullname' => new external_value(PARAM_TEXT, 'The course fullname'), - ) - ) - ), - 'noncontacts' => new external_multiple_structure( - self::get_messagearea_contact_structure() - ) - ) - ); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function data_for_messagearea_search_users_is_deprecated() { - return true; - } - /** * Get messagearea message search users parameters. * @@ -2134,298 +1654,6 @@ class core_message_external extends external_api { return self::get_conversation_structure(); } - /** - * The messagearea conversations parameters. - * - * @deprecated since 3.6 - * @return external_function_parameters - * @since 3.2 - */ - public static function data_for_messagearea_conversations_parameters() { - return new external_function_parameters( - array( - 'userid' => new external_value(PARAM_INT, 'The id of the user who we are viewing conversations for'), - 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), - 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) - ) - ); - } - - /** - * 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 - * @return stdClass - * @throws moodle_exception - * @since 3.2 - */ - public static function data_for_messagearea_conversations($userid, $limitfrom = 0, $limitnum = 0) { - global $CFG, $PAGE, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - $systemcontext = context_system::instance(); - - $params = array( - 'userid' => $userid, - 'limitfrom' => $limitfrom, - 'limitnum' => $limitnum - ); - $params = self::validate_parameters(self::data_for_messagearea_conversations_parameters(), $params); - self::validate_context($systemcontext); - - if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { - throw new moodle_exception('You do not have permission to perform this action.'); - } - - $conversations = \core_message\api::get_conversations($params['userid'], $params['limitfrom'], $params['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'); - return $conversations->export_for_template($renderer); - } - - /** - * The messagearea conversations return structure. - * - * @deprecated since 3.6 - * @return external_single_structure - * @since 3.2 - */ - public static function data_for_messagearea_conversations_returns() { - return new external_single_structure( - array( - 'contacts' => new external_multiple_structure( - self::get_messagearea_contact_structure() - ) - ) - ); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function data_for_messagearea_conversations_is_deprecated() { - return true; - } - - /** - * The messagearea contacts return parameters. - * - * @deprecated since 3.6 - * @return external_function_parameters - * @since 3.2 - */ - public static function data_for_messagearea_contacts_parameters() { - return self::data_for_messagearea_conversations_parameters(); - } - - /** - * Get messagearea contacts parameters. - * - * @deprecated since 3.6 - * @param int $userid The id of the user who we are viewing conversations for - * @param int $limitfrom - * @param int $limitnum - * @return stdClass - * @throws moodle_exception - * @since 3.2 - */ - public static function data_for_messagearea_contacts($userid, $limitfrom = 0, $limitnum = 0) { - global $CFG, $PAGE, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - $systemcontext = context_system::instance(); - - $params = array( - 'userid' => $userid, - 'limitfrom' => $limitfrom, - 'limitnum' => $limitnum - ); - $params = self::validate_parameters(self::data_for_messagearea_contacts_parameters(), $params); - self::validate_context($systemcontext); - - if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { - throw new moodle_exception('You do not have permission to perform this action.'); - } - - $contacts = \core_message\api::get_contacts($params['userid'], $params['limitfrom'], $params['limitnum']); - $contacts = new \core_message\output\messagearea\contacts(null, $contacts); - - $renderer = $PAGE->get_renderer('core_message'); - return $contacts->export_for_template($renderer); - } - - /** - * The messagearea contacts return structure. - * - * @deprecated since 3.6 - * @return external_single_structure - * @since 3.2 - */ - public static function data_for_messagearea_contacts_returns() { - return self::data_for_messagearea_conversations_returns(); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function data_for_messagearea_contacts_is_deprecated() { - return true; - } - - /** - * The messagearea messages parameters. - * - * @deprecated since 3.6 - * @return external_function_parameters - * @since 3.2 - */ - public static function data_for_messagearea_messages_parameters() { - return new external_function_parameters( - array( - 'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'), - 'otheruserid' => new external_value(PARAM_INT, 'The other user\'s id'), - 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), - 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0), - 'newest' => new external_value(PARAM_BOOL, 'Newest first?', VALUE_DEFAULT, false), - 'timefrom' => new external_value(PARAM_INT, - 'The timestamp from which the messages were created', VALUE_DEFAULT, 0), - ) - ); - } - - /** - * Get messagearea messages. - * - * @deprecated since 3.6 - * @param int $currentuserid The current user's id - * @param int $otheruserid The other user's id - * @param int $limitfrom - * @param int $limitnum - * @param boolean $newest - * @return stdClass - * @throws moodle_exception - * @since 3.2 - */ - public static function data_for_messagearea_messages($currentuserid, $otheruserid, $limitfrom = 0, $limitnum = 0, - $newest = false, $timefrom = 0) { - global $CFG, $PAGE, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - $systemcontext = context_system::instance(); - - $params = array( - 'currentuserid' => $currentuserid, - 'otheruserid' => $otheruserid, - 'limitfrom' => $limitfrom, - 'limitnum' => $limitnum, - 'newest' => $newest, - 'timefrom' => $timefrom, - ); - $params = self::validate_parameters(self::data_for_messagearea_messages_parameters(), $params); - self::validate_context($systemcontext); - - if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { - throw new moodle_exception('You do not have permission to perform this action.'); - } - - if ($params['newest']) { - $sort = 'timecreated DESC'; - } else { - $sort = 'timecreated ASC'; - } - - // We need to enforce a one second delay on messages to avoid race conditions of current - // messages still being sent. - // - // There is a chance that we could request messages before the current time's - // second has elapsed and while other messages are being sent in that same second. In which - // case those messages will be lost. - // - // Instead we ignore the current time in the result set to ensure that second is allowed to finish. - if (!empty($params['timefrom'])) { - $timeto = time() - 1; - } else { - $timeto = 0; - } - - // No requesting messages from the current time, as stated above. - if ($params['timefrom'] == time()) { - $messages = []; - } else { - $messages = \core_message\api::get_messages($params['currentuserid'], $params['otheruserid'], $params['limitfrom'], - $params['limitnum'], $sort, $params['timefrom'], $timeto); - } - - $messages = new \core_message\output\messagearea\messages($params['currentuserid'], $params['otheruserid'], $messages); - - $renderer = $PAGE->get_renderer('core_message'); - return $messages->export_for_template($renderer); - } - - /** - * The messagearea messages return structure. - * - * @deprecated since 3.6 - * @return external_single_structure - * @since 3.2 - */ - public static function data_for_messagearea_messages_returns() { - return new external_single_structure( - array( - 'iscurrentuser' => new external_value(PARAM_BOOL, 'Is the currently logged in user the user we are viewing - the messages on behalf of?'), - 'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'), - 'otheruserid' => new external_value(PARAM_INT, 'The other user\'s id'), - 'otheruserfullname' => new external_value(PARAM_NOTAGS, 'The other user\'s fullname'), - 'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'), - 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'), - 'messages' => new external_multiple_structure( - self::get_messagearea_message_structure() - ), - 'isblocked' => new external_value(PARAM_BOOL, 'Is this user blocked by the current user?', VALUE_DEFAULT, false), - ) - ); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function data_for_messagearea_messages_is_deprecated() { - return true; - } - /** * The conversation messages parameters. * @@ -2599,320 +1827,6 @@ class core_message_external extends external_api { ); } - /** - * The get most recent message return parameters. - * - * @deprecated since 3.6 - * @return external_function_parameters - * @since 3.2 - */ - public static function data_for_messagearea_get_most_recent_message_parameters() { - return new external_function_parameters( - array( - 'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'), - 'otheruserid' => new external_value(PARAM_INT, 'The other user\'s id'), - ) - ); - } - - /** - * Get the most recent message in a conversation. - * - * @deprecated since 3.6 - * @param int $currentuserid The current user's id - * @param int $otheruserid The other user's id - * @return stdClass - * @throws moodle_exception - * @since 3.2 - */ - public static function data_for_messagearea_get_most_recent_message($currentuserid, $otheruserid) { - global $CFG, $PAGE, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - $systemcontext = context_system::instance(); - - $params = array( - 'currentuserid' => $currentuserid, - 'otheruserid' => $otheruserid - ); - $params = self::validate_parameters(self::data_for_messagearea_get_most_recent_message_parameters(), $params); - self::validate_context($systemcontext); - - if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { - throw new moodle_exception('You do not have permission to perform this action.'); - } - - $message = \core_message\api::get_most_recent_message($params['currentuserid'], $params['otheruserid']); - $message = new \core_message\output\messagearea\message($message); - - $renderer = $PAGE->get_renderer('core_message'); - return $message->export_for_template($renderer); - } - - /** - * The get most recent message return structure. - * - * @deprecated since 3.6 - * @return external_single_structure - * @since 3.2 - */ - public static function data_for_messagearea_get_most_recent_message_returns() { - return self::get_messagearea_message_structure(); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function data_for_messagearea_get_most_recent_message_is_deprecated() { - return true; - } - - /** - * The get profile parameters. - * - * @deprecated since 3.6 - * @return external_function_parameters - * @since 3.2 - */ - public static function data_for_messagearea_get_profile_parameters() { - return new external_function_parameters( - array( - 'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'), - 'otheruserid' => new external_value(PARAM_INT, 'The id of the user whose profile we want to view'), - ) - ); - } - - /** - * Get the profile information for a contact. - * - * @deprecated since 3.6 - * @param int $currentuserid The current user's id - * @param int $otheruserid The id of the user whose profile we are viewing - * @return stdClass - * @throws moodle_exception - * @since 3.2 - */ - public static function data_for_messagearea_get_profile($currentuserid, $otheruserid) { - global $CFG, $PAGE, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - $systemcontext = context_system::instance(); - - $params = array( - 'currentuserid' => $currentuserid, - 'otheruserid' => $otheruserid - ); - $params = self::validate_parameters(self::data_for_messagearea_get_profile_parameters(), $params); - self::validate_context($systemcontext); - - if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { - throw new moodle_exception('You do not have permission to perform this action.'); - } - - $profile = \core_message\api::get_profile($params['currentuserid'], $params['otheruserid']); - $profile = new \core_message\output\messagearea\profile($profile); - - $renderer = $PAGE->get_renderer('core_message'); - return $profile->export_for_template($renderer); - } - - /** - * The get profile return structure. - * - * @deprecated since 3.6 - * @return external_single_structure - * @since 3.2 - */ - public static function data_for_messagearea_get_profile_returns() { - return new external_single_structure( - array( - 'userid' => new external_value(PARAM_INT, 'The id of the user whose profile we are viewing'), - 'email' => new external_value(core_user::get_property_type('email'), 'An email address'), - 'country' => new external_value(PARAM_TEXT, 'Home country of the user'), - 'city' => new external_value(core_user::get_property_type('city'), 'Home city of the user'), - 'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'), - 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'), - 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'), - 'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'), - 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'), - 'isblocked' => new external_value(PARAM_BOOL, 'Is the user blocked?'), - 'iscontact' => new external_value(PARAM_BOOL, 'Is the user a contact?') - ) - ); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function data_for_messagearea_get_profile_is_deprecated() { - return true; - } - - /** - * Get contacts parameters description. - * - * @deprecated since 3.6 - * @return external_function_parameters - * @since Moodle 2.5 - */ - public static function get_contacts_parameters() { - return new external_function_parameters(array()); - } - - /** - * Get contacts. - * - * @deprecated since 3.6 - * @return external_description - * @since Moodle 2.5 - */ - public static function get_contacts() { - global $CFG, $PAGE, $USER; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - require_once($CFG->dirroot . '/user/lib.php'); - - $allcontacts = array('online' => [], 'offline' => [], 'strangers' => []); - $contacts = \core_message\api::get_contacts_with_unread_message_count($USER->id); - foreach ($contacts as $contact) { - // Set the mode. - $mode = 'offline'; - if (\core_message\helper::is_online($contact->lastaccess)) { - $mode = 'online'; - } - - $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][$contact->id] = $newcontact; - } - - $strangers = \core_message\api::get_non_contacts_with_unread_message_count($USER->id); - foreach ($strangers as $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['strangers'][$contact->id] = $newcontact; - } - - // Add noreply user and support user to the list, if they don't exist. - $supportuser = core_user::get_support_user(); - if (!isset($strangers[$supportuser->id]) && !$supportuser->deleted) { - $supportuser->messagecount = message_count_unread_messages($USER, $supportuser); - if ($supportuser->messagecount > 0) { - $supportuser->fullname = fullname($supportuser); - $supportuser->unread = $supportuser->messagecount; - $allcontacts['strangers'][$supportuser->id] = $supportuser; - } - } - - $noreplyuser = core_user::get_noreply_user(); - if (!isset($strangers[$noreplyuser->id]) && !$noreplyuser->deleted) { - $noreplyuser->messagecount = message_count_unread_messages($USER, $noreplyuser); - if ($noreplyuser->messagecount > 0) { - $noreplyuser->fullname = fullname($noreplyuser); - $noreplyuser->unread = $noreplyuser->messagecount; - $allcontacts['strangers'][$noreplyuser->id] = $noreplyuser; - } - } - - return $allcontacts; - } - - /** - * Get contacts return description. - * - * @deprecated since 3.6 - * @return external_description - * @since Moodle 2.5 - */ - public static function get_contacts_returns() { - return new external_single_structure( - array( - 'online' => new external_multiple_structure( - new external_single_structure( - array( - 'id' => new external_value(PARAM_INT, 'User ID'), - 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), - 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), - 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL), - 'unread' => new external_value(PARAM_INT, 'Unread message count') - ) - ), - 'List of online contacts' - ), - 'offline' => new external_multiple_structure( - new external_single_structure( - array( - 'id' => new external_value(PARAM_INT, 'User ID'), - 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), - 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), - 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL), - 'unread' => new external_value(PARAM_INT, 'Unread message count') - ) - ), - 'List of offline contacts' - ), - 'strangers' => new external_multiple_structure( - new external_single_structure( - array( - 'id' => new external_value(PARAM_INT, 'User ID'), - 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), - 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), - 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL), - 'unread' => new external_value(PARAM_INT, 'Unread message count') - ) - ), - 'List of users that are not in the user\'s contact list but have sent a message' - ) - ) - ); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function get_contacts_is_deprecated() { - return true; - } - /** * Search contacts parameters description. * @@ -3679,108 +2593,6 @@ class core_message_external extends external_api { ); } - /** - * Mark all messages as read parameters description. - * - * @deprecated since 3.6 - * @return external_function_parameters - * @since 3.2 - */ - public static function mark_all_messages_as_read_parameters() { - return new external_function_parameters( - array( - 'useridto' => new external_value(PARAM_INT, 'the user id who received the message, 0 for any user', VALUE_REQUIRED), - 'useridfrom' => new external_value( - PARAM_INT, 'the user id who send the message, 0 for any user. -10 or -20 for no-reply or support user', - VALUE_DEFAULT, 0), - ) - ); - } - - /** - * Mark all messages as read function. - * - * @deprecated since 3.6 - * @throws invalid_parameter_exception - * @throws moodle_exception - * @param int $useridto the user id who received the message - * @param int $useridfrom the user id who send the message. -10 or -20 for no-reply or support user - * @return external_description - * @since 3.2 - */ - public static function mark_all_messages_as_read($useridto, $useridfrom) { - global $USER, $CFG; - - // Check if messaging is enabled. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - $params = self::validate_parameters( - self::mark_all_messages_as_read_parameters(), - array( - 'useridto' => $useridto, - 'useridfrom' => $useridfrom, - ) - ); - - $context = context_system::instance(); - self::validate_context($context); - - $useridto = $params['useridto']; - $useridfrom = $params['useridfrom']; - - if (!empty($useridto)) { - if (core_user::is_real_user($useridto)) { - $userto = core_user::get_user($useridto, '*', MUST_EXIST); - } else { - throw new moodle_exception('invaliduser'); - } - } - - if (!empty($useridfrom)) { - // We use get_user here because the from user can be the noreply or support user. - $userfrom = core_user::get_user($useridfrom, '*', MUST_EXIST); - } - - // Check if the current user is the sender/receiver or just a privileged user. - if ($useridto != $USER->id and $useridfrom != $USER->id and - // The deleteanymessage cap seems more reasonable here than readallmessages. - !has_capability('moodle/site:deleteanymessage', $context)) { - throw new moodle_exception('accessdenied', 'admin'); - } - - if ($useridfrom) { - if ($conversationid = \core_message\api::get_conversation_between_users([$useridto, $useridfrom])) { - \core_message\api::mark_all_messages_as_read($useridto, $conversationid); - } - } else { - \core_message\api::mark_all_messages_as_read($useridto); - } - - return true; - } - - /** - * Mark all messages as read return description. - * - * @deprecated since 3.6 - * @return external_single_structure - * @since 3.2 - */ - public static function mark_all_messages_as_read_returns() { - return new external_value(PARAM_BOOL, 'True if the messages were marked read, false otherwise'); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function mark_all_messages_as_read_is_deprecated() { - return true; - } - /** * Mark all conversation messages as read parameters description. * @@ -3841,101 +2653,6 @@ class core_message_external extends external_api { return null; } - /** - * Returns description of method parameters. - * - * @deprecated since 3.6 - * @return external_function_parameters - * @since 3.2 - */ - public static function delete_conversation_parameters() { - return new external_function_parameters( - array( - 'userid' => new external_value(PARAM_INT, 'The user id of who we want to delete the conversation for'), - 'otheruserid' => new external_value(PARAM_INT, 'The user id of the other user in the conversation'), - ) - ); - } - - /** - * Deletes a conversation. - * - * @deprecated since 3.6 - * @param int $userid The user id of who we want to delete the conversation for - * @param int $otheruserid The user id of the other user in the conversation - * @return array - * @throws moodle_exception - * @since 3.2 - */ - public static function delete_conversation($userid, $otheruserid) { - global $CFG; - - // Check if private messaging between users is allowed. - if (empty($CFG->messaging)) { - throw new moodle_exception('disabled', 'message'); - } - - // Warnings array, it can be empty at the end but is mandatory. - $warnings = array(); - - // Validate params. - $params = array( - 'userid' => $userid, - 'otheruserid' => $otheruserid, - ); - $params = self::validate_parameters(self::delete_conversation_parameters(), $params); - - // Validate context. - $context = context_system::instance(); - self::validate_context($context); - - $user = core_user::get_user($params['userid'], '*', MUST_EXIST); - core_user::require_active_user($user); - - if (!$conversationid = \core_message\api::get_conversation_between_users([$params['userid'], $params['otheruserid']])) { - return []; - } - - if (\core_message\api::can_delete_conversation($user->id, $conversationid)) { - \core_message\api::delete_conversation_by_id($user->id, $conversationid); - $status = true; - } else { - throw new moodle_exception('You do not have permission to delete messages'); - } - - $results = array( - 'status' => $status, - 'warnings' => $warnings - ); - - return $results; - } - - /** - * Returns description of method result value. - * - * @deprecated since 3.6 - * @return external_description - * @since 3.2 - */ - public static function delete_conversation_returns() { - return new external_single_structure( - array( - 'status' => new external_value(PARAM_BOOL, 'True if the conversation was deleted, false otherwise'), - 'warnings' => new external_warnings() - ) - ); - } - - /** - * Marking the method as deprecated. - * - * @return bool - */ - public static function delete_conversation_is_deprecated() { - return true; - } - /** * Returns description of method parameters. * diff --git a/message/lib.php b/message/lib.php index b3cb81d7785..406465c78b9 100644 --- a/message/lib.php +++ b/message/lib.php @@ -65,6 +65,8 @@ define('MESSAGE_DEFAULT_TIMEOUT_POLL_IN_SECONDS', 5 * MINSECS); /** * Returns the count of unread messages for user. Either from a specific user or from all users. * + * @deprecated since 3.10 + * TODO: MDL-69643 * @param object $user1 the first user. Defaults to $USER * @param object $user2 the second user. If null this function will count all of user 1's unread messages. * @return int the count of $user1's unread messages @@ -72,6 +74,9 @@ define('MESSAGE_DEFAULT_TIMEOUT_POLL_IN_SECONDS', 5 * MINSECS); function message_count_unread_messages($user1=null, $user2=null) { global $USER, $DB; + debugging('message_count_unread_messages is deprecated and no longer used', + DEBUG_DEVELOPER); + if (empty($user1)) { $user1 = $USER; } diff --git a/message/tests/api_test.php b/message/tests/api_test.php index bbcdd433623..917ab4e3c0c 100644 --- a/message/tests/api_test.php +++ b/message/tests/api_test.php @@ -54,7 +54,9 @@ class core_message_api_testcase extends core_message_messagelib_testcase { \core_message\api::mark_all_notifications_as_read($recipient->id); \core_message\api::mark_all_messages_as_read($recipient->id); + $this->assertEquals(message_count_unread_messages($recipient), 0); + $this->assertDebuggingCalled(); } public function test_mark_all_read_for_user_touser_with_fromuser() { @@ -80,6 +82,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { \core_message\api::mark_all_messages_as_read($recipient->id, $conversationid); $this->assertEquals(message_count_unread_messages($recipient), 3); + $this->assertDebuggingCalled(); } public function test_mark_all_read_for_user_touser_with_type() { @@ -95,9 +98,11 @@ class core_message_api_testcase extends core_message_messagelib_testcase { \core_message\api::mark_all_notifications_as_read($recipient->id); $this->assertEquals(message_count_unread_messages($recipient), 3); + $this->assertDebuggingCalled(); \core_message\api::mark_all_messages_as_read($recipient->id); $this->assertEquals(message_count_unread_messages($recipient), 0); + $this->assertDebuggingCalled(); } /** @@ -122,190 +127,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { $this->assertEquals(1, \core_message\api::count_blocked_users()); } - /** - * Tests searching users in a course. - */ - public function test_search_users_in_course() { - // Create some users. - $user1 = new stdClass(); - $user1->firstname = 'User'; - $user1->lastname = 'One'; - $user1 = self::getDataGenerator()->create_user($user1); - - // The person doing the search. - $this->setUser($user1); - - // Second user is going to have their last access set to now, so they are online. - $user2 = new stdClass(); - $user2->firstname = 'User'; - $user2->lastname = 'Two'; - $user2->lastaccess = time(); - $user2 = self::getDataGenerator()->create_user($user2); - - // Block the second user. - \core_message\api::block_user($user1->id, $user2->id); - - $user3 = new stdClass(); - $user3->firstname = 'User'; - $user3->lastname = 'Three'; - $user3 = self::getDataGenerator()->create_user($user3); - - // Create a course. - $course1 = new stdClass(); - $course1->fullname = 'Course'; - $course1->shortname = 'One'; - $course1 = $this->getDataGenerator()->create_course($course1); - - // Enrol the searcher and one user in the course. - $this->getDataGenerator()->enrol_user($user1->id, $course1->id); - $this->getDataGenerator()->enrol_user($user2->id, $course1->id); - - // Perform a search. - $results = \core_message\api::search_users_in_course($user1->id, $course1->id, 'User'); - - $this->assertEquals(1, count($results)); - - $user = $results[0]; - $this->assertEquals($user2->id, $user->userid); - $this->assertEquals(fullname($user2), $user->fullname); - $this->assertFalse($user->ismessaging); - $this->assertNull($user->lastmessage); - $this->assertNull($user->messageid); - $this->assertNull($user->isonline); - $this->assertFalse($user->isread); - $this->assertTrue($user->isblocked); - $this->assertNull($user->unreadcount); - } - - /** - * Tests searching users. - */ - public function test_search_users() { - global $DB; - - // Create some users. - $user1 = new stdClass(); - $user1->firstname = 'User'; - $user1->lastname = 'One'; - $user1 = self::getDataGenerator()->create_user($user1); - - // Set as the user performing the search. - $this->setUser($user1); - - $user2 = new stdClass(); - $user2->firstname = 'User search'; - $user2->lastname = 'Two'; - $user2 = self::getDataGenerator()->create_user($user2); - - $user3 = new stdClass(); - $user3->firstname = 'User search'; - $user3->lastname = 'Three'; - $user3 = self::getDataGenerator()->create_user($user3); - - $user4 = new stdClass(); - $user4->firstname = 'User'; - $user4->lastname = 'Four'; - $user4 = self::getDataGenerator()->create_user($user4); - - $user5 = new stdClass(); - $user5->firstname = 'User search'; - $user5->lastname = 'Five'; - $user5 = self::getDataGenerator()->create_user($user5); - - $user6 = new stdClass(); - $user6->firstname = 'User'; - $user6->lastname = 'Six'; - $user6 = self::getDataGenerator()->create_user($user6); - - // Create some courses. - $course1 = new stdClass(); - $course1->fullname = 'Course search'; - $course1->shortname = 'One'; - $course1 = $this->getDataGenerator()->create_course($course1); - - $course2 = new stdClass(); - $course2->fullname = 'Course'; - $course2->shortname = 'Two'; - $course2 = $this->getDataGenerator()->create_course($course2); - - $course3 = new stdClass(); - $course3->fullname = 'Course'; - $course3->shortname = 'Three search'; - $course3 = $this->getDataGenerator()->create_course($course3); - - $course4 = new stdClass(); - $course4->fullname = 'Course Four'; - $course4->shortname = 'CF100'; - $course4 = $this->getDataGenerator()->create_course($course4); - - $course5 = new stdClass(); - $course5->fullname = 'Course'; - $course5->shortname = 'Five search'; - $course5 = $this->getDataGenerator()->create_course($course5); - - $role = $DB->get_record('role', ['shortname' => 'student']); - $this->getDataGenerator()->enrol_user($user1->id, $course1->id, $role->id); - $this->getDataGenerator()->enrol_user($user1->id, $course2->id, $role->id); - $this->getDataGenerator()->enrol_user($user1->id, $course3->id, $role->id); - $this->getDataGenerator()->enrol_user($user1->id, $course5->id, $role->id); - - // Add some users as contacts. - \core_message\api::add_contact($user1->id, $user2->id); - \core_message\api::add_contact($user1->id, $user3->id); - \core_message\api::add_contact($user1->id, $user4->id); - - // Remove the viewparticipants capability from one of the courses. - $course5context = context_course::instance($course5->id); - assign_capability('moodle/course:viewparticipants', CAP_PROHIBIT, $role->id, $course5context->id); - - // Perform a search $CFG->messagingallusers setting enabled. - set_config('messagingallusers', 1); - list($contacts, $courses, $noncontacts) = \core_message\api::search_users($user1->id, 'search'); - - // Check that we retrieved the correct contacts. - $this->assertEquals(2, count($contacts)); - $this->assertEquals($user3->id, $contacts[0]->userid); - $this->assertEquals($user2->id, $contacts[1]->userid); - - // Check that we retrieved the correct courses. - $this->assertEquals(2, count($courses)); - $this->assertEquals($course3->id, $courses[0]->id); - $this->assertEquals($course1->id, $courses[1]->id); - - // Check that we retrieved the correct non-contacts. - $this->assertEquals(1, count($noncontacts)); - $this->assertEquals($user5->id, $noncontacts[0]->userid); - } - - /** - * Tests searching users with empty result. - */ - public function test_search_users_with_empty_result() { - - // Create some users. - $user1 = new stdClass(); - $user1->firstname = 'User'; - $user1->lastname = 'One'; - $user1 = self::getDataGenerator()->create_user($user1); - - // Set as the user performing the search. - $this->setUser($user1); - - $user2 = new stdClass(); - $user2->firstname = 'User'; - $user2->lastname = 'Two'; - $user2 = self::getDataGenerator()->create_user($user2); - - // Perform a search $CFG->messagingallusers setting enabled. - set_config('messagingallusers', 1); - list($contacts, $courses, $noncontacts) = \core_message\api::search_users($user1->id, 'search'); - - // Check results are empty. - $this->assertEquals(0, count($contacts)); - $this->assertEquals(0, count($courses)); - $this->assertEquals(0, count($noncontacts)); - } - /** * Tests searching for users when site-wide messaging is disabled. * @@ -2350,83 +2171,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { } } - /** - * Tests retrieving contacts. - */ - public function test_get_contacts() { - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - - // Set as the user. - $this->setUser($user1); - - $user2 = new stdClass(); - $user2->firstname = 'User'; - $user2->lastname = 'A'; - $user2 = self::getDataGenerator()->create_user($user2); - - $user3 = new stdClass(); - $user3->firstname = 'User'; - $user3->lastname = 'B'; - $user3 = self::getDataGenerator()->create_user($user3); - - $user4 = new stdClass(); - $user4->firstname = 'User'; - $user4->lastname = 'C'; - $user4 = self::getDataGenerator()->create_user($user4); - - $user5 = new stdClass(); - $user5->firstname = 'User'; - $user5->lastname = 'D'; - $user5 = self::getDataGenerator()->create_user($user5); - - // Add some users as contacts. - \core_message\api::add_contact($user1->id, $user2->id); - \core_message\api::add_contact($user1->id, $user3->id); - \core_message\api::add_contact($user1->id, $user4->id); - - // Retrieve the contacts. - $contacts = \core_message\api::get_contacts($user1->id); - - // Confirm the data is correct. - $this->assertEquals(3, count($contacts)); - usort($contacts, ['static', 'sort_contacts']); - - $contact1 = $contacts[0]; - $contact2 = $contacts[1]; - $contact3 = $contacts[2]; - - $this->assertEquals($user2->id, $contact1->userid); - $this->assertEmpty($contact1->useridfrom); - $this->assertFalse($contact1->ismessaging); - $this->assertNull($contact1->lastmessage); - $this->assertNull($contact1->messageid); - $this->assertNull($contact1->isonline); - $this->assertFalse($contact1->isread); - $this->assertFalse($contact1->isblocked); - $this->assertNull($contact1->unreadcount); - - $this->assertEquals($user3->id, $contact2->userid); - $this->assertEmpty($contact2->useridfrom); - $this->assertFalse($contact2->ismessaging); - $this->assertNull($contact2->lastmessage); - $this->assertNull($contact2->messageid); - $this->assertNull($contact2->isonline); - $this->assertFalse($contact2->isread); - $this->assertFalse($contact2->isblocked); - $this->assertNull($contact2->unreadcount); - - $this->assertEquals($user4->id, $contact3->userid); - $this->assertEmpty($contact3->useridfrom); - $this->assertFalse($contact3->ismessaging); - $this->assertNull($contact3->lastmessage); - $this->assertNull($contact3->messageid); - $this->assertNull($contact3->isonline); - $this->assertFalse($contact3->isread); - $this->assertFalse($contact3->isblocked); - $this->assertNull($contact3->unreadcount); - } - /** * Tests retrieving user contacts. */ @@ -2487,56 +2231,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { $this->assertTrue($contact3->iscontact); } - /** - * Tests retrieving messages. - */ - public function test_get_messages() { - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person doing the search. - $this->setUser($user1); - - // Send some messages back and forth. - $time = 1; - $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1); - $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2); - $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3); - $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4); - - // Retrieve the messages. - $messages = \core_message\api::get_messages($user1->id, $user2->id); - - // Confirm the message data is correct. - $this->assertEquals(4, count($messages)); - - $message1 = $messages[0]; - $message2 = $messages[1]; - $message3 = $messages[2]; - $message4 = $messages[3]; - - $this->assertEquals($user1->id, $message1->useridfrom); - $this->assertEquals($user2->id, $message1->useridto); - $this->assertTrue($message1->displayblocktime); - $this->assertContains('Yo!', $message1->text); - - $this->assertEquals($user2->id, $message2->useridfrom); - $this->assertEquals($user1->id, $message2->useridto); - $this->assertFalse($message2->displayblocktime); - $this->assertContains('Sup mang?', $message2->text); - - $this->assertEquals($user1->id, $message3->useridfrom); - $this->assertEquals($user2->id, $message3->useridto); - $this->assertFalse($message3->displayblocktime); - $this->assertContains('Writing PHPUnit tests!', $message3->text); - - $this->assertEquals($user2->id, $message4->useridfrom); - $this->assertEquals($user1->id, $message4->useridto); - $this->assertFalse($message4->displayblocktime); - $this->assertContains('Word.', $message4->text); - } - /** * Tests retrieving conversation messages. */ @@ -3009,33 +2703,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { $this->assertEquals(1, count($members)); } - /** - * Tests retrieving most recent message. - */ - public function test_get_most_recent_message() { - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person doing the search. - $this->setUser($user1); - - // Send some messages back and forth. - $time = 1; - $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1); - $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2); - $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3); - $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4); - - // Retrieve the most recent messages. - $message = \core_message\api::get_most_recent_message($user1->id, $user2->id); - - // Check the results are correct. - $this->assertEquals($user2->id, $message->useridfrom); - $this->assertEquals($user1->id, $message->useridto); - $this->assertContains('Word.', $message->text); - } - /** * Tests retrieving most recent conversation message. */ @@ -3069,62 +2736,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { $this->assertContains('Word.', $message->text); } - /** - * Tests retrieving a user's profile. - */ - public function test_get_profile() { - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - - $user2 = new stdClass(); - $user2->country = 'AU'; - $user2->city = 'Perth'; - $user2 = self::getDataGenerator()->create_user($user2); - - // The person doing the search. - $this->setUser($user1); - - // Get the profile. - $profile = \core_message\api::get_profile($user1->id, $user2->id); - - $this->assertEquals($user2->id, $profile->userid); - $this->assertEmpty($profile->email); - $this->assertEmpty($profile->country); - $this->assertEmpty($profile->city); - $this->assertEquals(fullname($user2), $profile->fullname); - $this->assertNull($profile->isonline); - $this->assertFalse($profile->isblocked); - $this->assertFalse($profile->iscontact); - } - - /** - * Tests retrieving a user's profile. - */ - public function test_get_profile_as_admin() { - // The person doing the search. - $this->setAdminUser(); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - - $user2 = new stdClass(); - $user2->country = 'AU'; - $user2->city = 'Perth'; - $user2 = self::getDataGenerator()->create_user($user2); - - // Get the profile. - $profile = \core_message\api::get_profile($user1->id, $user2->id); - - $this->assertEquals($user2->id, $profile->userid); - $this->assertEquals($user2->email, $profile->email); - $this->assertEquals($user2->country, $profile->country); - $this->assertEquals($user2->city, $profile->city); - $this->assertEquals(fullname($user2), $profile->fullname); - $this->assertFalse($profile->isonline); - $this->assertFalse($profile->isblocked); - $this->assertFalse($profile->iscontact); - } - /** * Tests checking if a user can mark all messages as read. */ @@ -3195,57 +2806,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { $this->assertFalse(\core_message\api::can_delete_conversation($user2->id, $conversationid)); } - /** - * Tests deleting a conversation. - */ - public function test_delete_conversation() { - global $DB; - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person doing the search. - $this->setUser($user1); - - // Send some messages back and forth. - $time = 1; - $m1id = $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1); - $m2id = $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2); - $m3id = $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3); - $m4id = $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4); - - // Delete the conversation as user 1. - \core_message\api::delete_conversation($user1->id, $user2->id); - $this->assertDebuggingCalled(); - - $muas = $DB->get_records('message_user_actions', array(), 'timecreated ASC'); - $this->assertCount(4, $muas); - // Sort by id. - ksort($muas); - - $mua1 = array_shift($muas); - $mua2 = array_shift($muas); - $mua3 = array_shift($muas); - $mua4 = array_shift($muas); - - $this->assertEquals($user1->id, $mua1->userid); - $this->assertEquals($m1id, $mua1->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua1->action); - - $this->assertEquals($user1->id, $mua2->userid); - $this->assertEquals($m2id, $mua2->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua2->action); - - $this->assertEquals($user1->id, $mua3->userid); - $this->assertEquals($m3id, $mua3->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua3->action); - - $this->assertEquals($user1->id, $mua4->userid); - $this->assertEquals($m4id, $mua4->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua4->action); - } - /** * Tests deleting a conversation by conversation id. */ @@ -4157,99 +3717,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { ); } - /** - * Tests that when blocking messages from non-contacts is enabled that - * non-contacts trying to send a message return false. - */ - public function test_is_user_non_contact_blocked() { - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // Set as the first user. - $this->setUser($user1); - - // By default, user only can be messaged by contacts and members of any of his/her courses. - $this->assertTrue(\core_message\api::is_user_non_contact_blocked($user2)); - $this->assertDebuggingCalled(); - - // Enable all users privacy messaging and check now the default user's preference has been set to allow receiving - // messages from everybody. - set_config('messagingallusers', true); - // Check that the return result is now false because any site user can contact him/her. - $this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2)); - $this->assertDebuggingCalled(); - - // Set the second user's preference to not receive messages from non-contacts. - set_user_preference('message_blocknoncontacts', \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS, $user2->id); - // Check that the return result is still true (because is even more restricted). - $this->assertTrue(\core_message\api::is_user_non_contact_blocked($user2)); - $this->assertDebuggingCalled(); - - // Add the first user as a contact for the second user. - \core_message\api::add_contact($user2->id, $user1->id); - - // Check that the return result is now false. - $this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2)); - $this->assertDebuggingCalled(); - - // Set the second user's preference to receive messages from course members. - set_user_preference('message_blocknoncontacts', \core_message\api::MESSAGE_PRIVACY_COURSEMEMBER, $user2->id); - // Check that the return result is still false (because $user1 is still his/her contact). - $this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2)); - $this->assertDebuggingCalled(); - } - - /** - * Tests that we return true when a user is blocked, or false - * if they are not blocked. - */ - public function test_is_user_blocked() { - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // Set the user. - $this->setUser($user1); - - // User shouldn't be blocked. - $this->assertFalse(\core_message\api::is_user_blocked($user1->id, $user2->id)); - $this->assertDebuggingCalled(); - - // Block the user. - \core_message\api::block_user($user1->id, $user2->id); - - // User should be blocked. - $this->assertTrue(\core_message\api::is_user_blocked($user1->id, $user2->id)); - $this->assertDebuggingCalled(); - - // Unblock the user. - \core_message\api::unblock_user($user1->id, $user2->id); - $this->assertFalse(\core_message\api::is_user_blocked($user1->id, $user2->id)); - $this->assertDebuggingCalled(); - } - - /** - * Tests that the admin is not blocked even if someone has chosen to block them. - */ - public function test_is_user_blocked_as_admin() { - // Create a user. - $user1 = self::getDataGenerator()->create_user(); - - // Set the user. - $this->setUser($user1); - - // Block the admin user. - \core_message\api::block_user($user1->id, 2); - - // Now change to the admin user. - $this->setAdminUser(); - - // As the admin you should still be able to send messages to the user. - $this->assertFalse(\core_message\api::is_user_blocked($user1->id)); - $this->assertDebuggingCalled(); - } - /* * Tes get_message_processor api. */ @@ -4339,131 +3806,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { $this->assertEquals(1, $status); } - /** - * Test retrieving messages by providing a minimum timecreated value. - */ - public function test_get_messages_time_from_only() { - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person doing the search. - $this->setUser($user1); - - // Send some messages back and forth. - $time = 1; - $this->send_fake_message($user1, $user2, 'Message 1', 0, $time + 1); - $this->send_fake_message($user2, $user1, 'Message 2', 0, $time + 2); - $this->send_fake_message($user1, $user2, 'Message 3', 0, $time + 3); - $this->send_fake_message($user2, $user1, 'Message 4', 0, $time + 4); - - // Retrieve the messages from $time, which should be all of them. - $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 0, 'timecreated ASC', $time); - - // Confirm the message data is correct. - $this->assertEquals(4, count($messages)); - - $message1 = $messages[0]; - $message2 = $messages[1]; - $message3 = $messages[2]; - $message4 = $messages[3]; - - $this->assertContains('Message 1', $message1->text); - $this->assertContains('Message 2', $message2->text); - $this->assertContains('Message 3', $message3->text); - $this->assertContains('Message 4', $message4->text); - - // Retrieve the messages from $time + 3, which should only be the 2 last messages. - $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 0, 'timecreated ASC', $time + 3); - - // Confirm the message data is correct. - $this->assertEquals(2, count($messages)); - - $message1 = $messages[0]; - $message2 = $messages[1]; - - $this->assertContains('Message 3', $message1->text); - $this->assertContains('Message 4', $message2->text); - } - - /** - * Test retrieving messages by providing a maximum timecreated value. - */ - public function test_get_messages_time_to_only() { - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person doing the search. - $this->setUser($user1); - - // Send some messages back and forth. - $time = 1; - $this->send_fake_message($user1, $user2, 'Message 1', 0, $time + 1); - $this->send_fake_message($user2, $user1, 'Message 2', 0, $time + 2); - $this->send_fake_message($user1, $user2, 'Message 3', 0, $time + 3); - $this->send_fake_message($user2, $user1, 'Message 4', 0, $time + 4); - - // Retrieve the messages up until $time + 4, which should be all of them. - $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 0, 'timecreated ASC', 0, $time + 4); - - // Confirm the message data is correct. - $this->assertEquals(4, count($messages)); - - $message1 = $messages[0]; - $message2 = $messages[1]; - $message3 = $messages[2]; - $message4 = $messages[3]; - - $this->assertContains('Message 1', $message1->text); - $this->assertContains('Message 2', $message2->text); - $this->assertContains('Message 3', $message3->text); - $this->assertContains('Message 4', $message4->text); - - // Retrieve the messages up until $time + 2, which should be the first two. - $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 0, 'timecreated ASC', 0, $time + 2); - - // Confirm the message data is correct. - $this->assertEquals(2, count($messages)); - - $message1 = $messages[0]; - $message2 = $messages[1]; - - $this->assertContains('Message 1', $message1->text); - $this->assertContains('Message 2', $message2->text); - } - - /** - * Test retrieving messages by providing a minimum and maximum timecreated value. - */ - public function test_get_messages_time_from_and_to() { - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person doing the search. - $this->setUser($user1); - - // Send some messages back and forth. - $time = 1; - $this->send_fake_message($user1, $user2, 'Message 1', 0, $time + 1); - $this->send_fake_message($user2, $user1, 'Message 2', 0, $time + 2); - $this->send_fake_message($user1, $user2, 'Message 3', 0, $time + 3); - $this->send_fake_message($user2, $user1, 'Message 4', 0, $time + 4); - - // Retrieve the messages from $time + 2 up until $time + 3, which should be 2nd and 3rd message. - $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 0, 'timecreated ASC', $time + 2, $time + 3); - - // Confirm the message data is correct. - $this->assertEquals(2, count($messages)); - - $message1 = $messages[0]; - $message2 = $messages[1]; - - $this->assertContains('Message 2', $message1->text); - $this->assertContains('Message 3', $message2->text); - } - /** * Test returning blocked users. */ @@ -4493,6 +3835,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { /** * Test returning contacts with unread message count. + * MDL-69643 */ public function test_get_contacts_with_unread_message_count() { global $DB; @@ -4522,6 +3865,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { // Get the contacts and the unread message count. $messages = \core_message\api::get_contacts_with_unread_message_count($user2->id); + $this->assertDebuggingCalled(); // Confirm the size is correct. $this->assertCount(2, $messages); @@ -4543,6 +3887,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { // Get the contacts and the unread message count. $messages = \core_message\api::get_contacts_with_unread_message_count($user2->id); + $this->assertDebuggingCalled(); // Confirm the size is correct. $this->assertCount(2, $messages); @@ -4566,6 +3911,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { // Get the contacts and the unread message count. $messages = \core_message\api::get_contacts_with_unread_message_count($user1->id); + $this->assertDebuggingCalled(); // Confirm the size is correct. $this->assertCount(1, $messages); @@ -4578,6 +3924,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { \core_message\api::mark_message_as_read($user1->id, $m); $messages = \core_message\api::get_contacts_with_unread_message_count($user1->id); + $this->assertDebuggingCalled(); // Confirm the size is correct. $this->assertCount(1, $messages); @@ -4600,6 +3947,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { // Check we get the correct message count. $messages = \core_message\api::get_contacts_with_unread_message_count($user2->id); + $this->assertDebuggingCalled(); // Confirm the size is correct. $this->assertCount(1, $messages); @@ -4612,6 +3960,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { /** * Test returning non-contacts with unread message count. + * MDL-69643 */ public function test_get_non_contacts_with_unread_message_count() { global $DB; @@ -4639,8 +3988,10 @@ class core_message_api_testcase extends core_message_messagelib_testcase { // Send a message that should never be included as the user is a contact. $this->send_fake_message($user4, $user2); + // Get the non-contacts and the unread message count. $messages = \core_message\api::get_non_contacts_with_unread_message_count($user2->id); + $this->assertDebuggingCalled(); // Check we get the correct message count. ksort($messages); @@ -4660,6 +4011,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { // Get the non-contacts and the unread message count. $messages = \core_message\api::get_non_contacts_with_unread_message_count($user2->id); + $this->assertDebuggingCalled(); // Check the marked message is not returned in the message count. ksort($messages); @@ -4681,6 +4033,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { // Get the non-contacts and the unread message count. $messages = \core_message\api::get_non_contacts_with_unread_message_count($user1->id); + $this->assertDebuggingCalled(); // Confirm the size is correct. $this->assertCount(1, $messages); @@ -4694,6 +4047,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase { // Get the non-contacts and the unread message count. $messages = \core_message\api::get_non_contacts_with_unread_message_count($user1->id); + $this->assertDebuggingCalled(); // Check the marked message is not returned in the message count. $this->assertCount(1, $messages); @@ -4781,20 +4135,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { $this->assertFalse(\core_message\api::get_conversation_between_users([$user1->id, $user2->id])); } - /** - * Test we can return a conversation that exists between users. - */ - public function test_get_conversation_between_users_with_existing_conversation() { - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - $conversationid = \core_message\api::create_conversation_between_users([$user1->id, $user2->id]); - $this->assertDebuggingCalled(); - - $this->assertEquals($conversationid, - \core_message\api::get_conversation_between_users([$user1->id, $user2->id])); - } - /** * Test count_conversation_members for non existing conversation. */ diff --git a/message/tests/events_test.php b/message/tests/events_test.php index 8960bed680b..00a6b19fae2 100644 --- a/message/tests/events_test.php +++ b/message/tests/events_test.php @@ -458,8 +458,8 @@ class core_message_events_testcase extends core_message_messagelib_testcase { // Trigger and capture the event. $sink = $this->redirectEvents(); - \core_message\api::delete_conversation($user1->id, $user2->id); - $this->assertDebuggingCalled(); + $conversationid = \core_message\api::get_conversation_between_users([$user1->id, $user2->id]); + \core_message\api::delete_conversation_by_id($user1->id, $conversationid); $events = $sink->get_events(); // Get the user actions for the messages deleted by that user. diff --git a/message/tests/externallib_test.php b/message/tests/externallib_test.php index 9a614448c1b..35f315011d9 100644 --- a/message/tests/externallib_test.php +++ b/message/tests/externallib_test.php @@ -338,39 +338,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase { core_message_external::send_instant_messages($messages); } - /** - * Test create_contacts. - * - * TODO: MDL-63261 - */ - public function test_create_contacts() { - $this->resetAfterTest(true); - - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - $user3 = self::getDataGenerator()->create_user(); - $user4 = self::getDataGenerator()->create_user(); - $user5 = self::getDataGenerator()->create_user(); - $this->setUser($user1); - - // Adding a contact who is already a contact. - $return = core_message_external::create_contacts(array($user2->id)); - $return = external_api::clean_returnvalue(core_message_external::create_contacts_returns(), $return); - $this->assertEquals(array(), $return); - - // Adding multiple contacts. - $return = core_message_external::create_contacts(array($user3->id, $user4->id)); - $return = external_api::clean_returnvalue(core_message_external::create_contacts_returns(), $return); - $this->assertEquals(array(), $return); - - // Note: We should add real user checks in api L:2656. - - // Try to add a contact to another user, should throw an exception. - // All assertions must be added before this point. - $this->expectException('required_capability_exception'); - core_message_external::create_contacts(array($user2->id), $user3->id); - } - /** * Test delete_contacts. */ @@ -416,110 +383,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase { core_message_external::delete_contacts(array($user2->id), $user3->id); } - /** - * Test block_contacts. - */ - public function test_block_contacts() { - $this->resetAfterTest(true); - - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - $user3 = self::getDataGenerator()->create_user(); - $user4 = self::getDataGenerator()->create_user(); - $user5 = self::getDataGenerator()->create_user(); - $this->setUser($user1); - - \core_message\api::add_contact($user1->id, $user3->id); - \core_message\api::add_contact($user1->id, $user4->id); - \core_message\api::add_contact($user1->id, $user5->id); - - // Blocking a contact who is already a contact. - $return = core_message_external::block_contacts(array($user2->id)); - $return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return); - $this->assertEquals(array(array( - 'item' => 'user', - 'itemid' => $user2->id, - 'warningcode' => 'contactnotblocked', - 'message' => 'The contact could not be blocked' - )), $return); - - // Blocking multiple contacts. - $return = core_message_external::block_contacts(array($user3->id, $user4->id)); - $return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return); - $this->assertEquals(array( - array( - 'item' => 'user', - 'itemid' => $user3->id, - 'warningcode' => 'contactnotblocked', - 'message' => 'The contact could not be blocked' - ), - array( - 'item' => 'user', - 'itemid' => $user4->id, - 'warningcode' => 'contactnotblocked', - 'message' => 'The contact could not be blocked' - ) - ), $return); - - // Blocking a non-existing user. - $return = core_message_external::block_contacts(array(99999)); - $return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return); - $this->assertCount(1, $return); - $return = array_pop($return); - $this->assertEquals($return['warningcode'], 'contactnotblocked'); - $this->assertEquals($return['itemid'], 99999); - - // Try to block a contact of another user contact list, should throw an exception. - // All assertions must be added before this point. - $this->expectException('required_capability_exception'); - core_message_external::block_contacts(array($user2->id), $user3->id); - } - - /** - * Test unblock_contacts. - */ - public function test_unblock_contacts() { - $this->resetAfterTest(true); - - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - $user3 = self::getDataGenerator()->create_user(); - $user4 = self::getDataGenerator()->create_user(); - $user5 = self::getDataGenerator()->create_user(); - $user6 = self::getDataGenerator()->create_user(); - $this->setUser($user1); - - \core_message\api::add_contact($user1->id, $user3->id); - \core_message\api::add_contact($user1->id, $user4->id); - \core_message\api::add_contact($user1->id, $user5->id); - \core_message\api::add_contact($user1->id, $user6->id); - - // Removing a non-contact. - $return = core_message_external::unblock_contacts(array($user2->id)); - $this->assertNull($return); - - // Removing one contact. - $return = core_message_external::unblock_contacts(array($user3->id)); - $this->assertNull($return); - - // Removing multiple contacts. - $return = core_message_external::unblock_contacts(array($user4->id, $user5->id)); - $this->assertNull($return); - - // Removing contact from unexisting user. - $return = core_message_external::unblock_contacts(array(99999)); - $this->assertNull($return); - - // Removing mixed valid and invalid data. - $return = core_message_external::unblock_contacts(array($user6->id, 99999)); - $this->assertNull($return); - - // Try to unblock a contact of another user contact list, should throw an exception. - // All assertions must be added before this point. - $this->expectException('required_capability_exception'); - core_message_external::unblock_contacts(array($user2->id), $user3->id); - } - /** * Test getting contact requests. */ @@ -1323,70 +1186,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase { core_message_external::unblock_user($user1->id, $user2->id); } - /** - * Test get_contacts. - */ - public function test_get_contacts() { - $this->resetAfterTest(true); - - $user1 = self::getDataGenerator()->create_user(); - $user_stranger = self::getDataGenerator()->create_user(); - $user_offline1 = self::getDataGenerator()->create_user(); - $user_offline2 = self::getDataGenerator()->create_user(); - $user_offline3 = self::getDataGenerator()->create_user(); - $user_online = new stdClass(); - $user_online->lastaccess = time(); - $user_online = self::getDataGenerator()->create_user($user_online); - $user_blocked = self::getDataGenerator()->create_user(); - $noreplyuser = core_user::get_user(core_user::NOREPLY_USER); - - // Login as user1. - $this->setUser($user1); - \core_message\api::add_contact($user1->id, $user_offline1->id); - \core_message\api::add_contact($user1->id, $user_offline2->id); - \core_message\api::add_contact($user1->id, $user_offline3->id); - \core_message\api::add_contact($user1->id, $user_online->id); - - // User_stranger sends a couple of messages to user1. - $this->send_message($user_stranger, $user1, 'Hello there!'); - $this->send_message($user_stranger, $user1, 'How you goin?'); - $this->send_message($user_stranger, $user1, 'Cya!'); - $this->send_message($noreplyuser, $user1, 'I am not a real user'); - - // User_blocked sends a message to user1. - $this->send_message($user_blocked, $user1, 'Here, have some spam.'); - - // Retrieve the contacts of the user. - $this->setUser($user1); - $contacts = core_message_external::get_contacts(); - $contacts = external_api::clean_returnvalue(core_message_external::get_contacts_returns(), $contacts); - $this->assertCount(3, $contacts['offline']); - $this->assertCount(1, $contacts['online']); - $this->assertCount(3, $contacts['strangers']); - core_message_external::block_contacts(array($user_blocked->id)); - $contacts = core_message_external::get_contacts(); - $contacts = external_api::clean_returnvalue(core_message_external::get_contacts_returns(), $contacts); - $this->assertCount(3, $contacts['offline']); - $this->assertCount(1, $contacts['online']); - $this->assertCount(2, $contacts['strangers']); - - // Checking some of the fields returned. - $stranger = array_pop($contacts['strangers']); - - $this->assertEquals(core_user::NOREPLY_USER, $stranger['id']); - $this->assertEquals(1, $stranger['unread']); - - // Check that deleted users are not returned. - delete_user($user_offline1); - delete_user($user_stranger); - delete_user($user_online); - $contacts = core_message_external::get_contacts(); - $contacts = external_api::clean_returnvalue(core_message_external::get_contacts_returns(), $contacts); - $this->assertCount(2, $contacts['offline']); - $this->assertCount(0, $contacts['online']); - $this->assertCount(1, $contacts['strangers']); - } - /** * Test search_contacts. * @expectedException moodle_exception @@ -1792,7 +1591,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase { $this->assertCount(0, $blockedusers['users']); // Block the $userblocked and retrieve again the list. - core_message_external::block_contacts(array($userblocked->id)); + \core_message\api::block_user($user1->id, $userblocked->id); $blockedusers = core_message_external::get_blocked_users($user1->id); $blockedusers = external_api::clean_returnvalue(core_message_external::get_blocked_users_returns(), $blockedusers); $this->assertCount(1, $blockedusers['users']); @@ -2184,402 +1983,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase { $prefs = core_message_external::get_user_notification_preferences($otheruser->id); } - /** - * Tests searching users in a course. - */ - public function test_data_for_messagearea_search_users_in_course() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = new stdClass(); - $user1->firstname = 'User'; - $user1->lastname = 'One'; - $user1 = self::getDataGenerator()->create_user($user1); - - // The person doing the search. - $this->setUser($user1); - - // Set the second user's status to online by setting their last access to now. - $user2 = new stdClass(); - $user2->firstname = 'User'; - $user2->lastname = 'Two'; - $user2->lastaccess = time(); - $user2 = self::getDataGenerator()->create_user($user2); - - // Block the second user. - \core_message\api::block_user($user1->id, $user2->id); - - $user3 = new stdClass(); - $user3->firstname = 'User'; - $user3->lastname = 'Three'; - $user3 = self::getDataGenerator()->create_user($user3); - - // Create a course. - $course1 = new stdClass(); - $course1->fullname = 'Course'; - $course1->shortname = 'One'; - $course1 = $this->getDataGenerator()->create_course(); - - // Enrol the user we are doing the search for and one user in the course. - $this->getDataGenerator()->enrol_user($user1->id, $course1->id); - $this->getDataGenerator()->enrol_user($user2->id, $course1->id); - - // Perform a search. - $result = core_message_external::data_for_messagearea_search_users_in_course($user1->id, $course1->id, 'User'); - - // We need to execute the return values cleaning process to simulate the web service. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_users_in_course_returns(), - $result); - - // Check that we only retrieved a user that was enrolled, and that the user performing the search was not returned. - $users = $result['contacts']; - $this->assertCount(1, $users); - - $user = $users[0]; - $this->assertEquals($user2->id, $user['userid']); - $this->assertEquals(fullname($user2), $user['fullname']); - $this->assertFalse($user['ismessaging']); - $this->assertFalse($user['sentfromcurrentuser']); - $this->assertNull($user['lastmessage']); - $this->assertNull($user['messageid']); - $this->assertNull($user['isonline']); - $this->assertFalse($user['isread']); - $this->assertTrue($user['isblocked']); - $this->assertNull($user['unreadcount']); - } - - /** - * Tests searching users in course as another user. - */ - public function test_data_for_messagearea_search_users_in_course_as_other_user() { - $this->resetAfterTest(true); - - // The person doing the search for another user. - $this->setAdminUser(); - - // Create some users. - $user1 = new stdClass(); - $user1->firstname = 'User'; - $user1->lastname = 'One'; - $user1 = self::getDataGenerator()->create_user($user1); - - $user2 = new stdClass(); - $user2->firstname = 'User'; - $user2->lastname = 'Two'; - $user2 = self::getDataGenerator()->create_user($user2); - - $user3 = new stdClass(); - $user3->firstname = 'User'; - $user3->lastname = 'Three'; - $user3 = self::getDataGenerator()->create_user($user3); - - // Create a course. - $course1 = new stdClass(); - $course1->fullname = 'Course'; - $course1->shortname = 'One'; - $course1 = $this->getDataGenerator()->create_course(); - - // Enrol the user we are doing the search for and one user in the course. - $this->getDataGenerator()->enrol_user($user1->id, $course1->id); - $this->getDataGenerator()->enrol_user($user2->id, $course1->id); - - // Perform a search. - $result = core_message_external::data_for_messagearea_search_users_in_course($user1->id, $course1->id, 'User'); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_users_in_course_returns(), - $result); - - // Check that we got the user enrolled, and that the user we are performing the search on behalf of was not returned. - $users = $result['contacts']; - $this->assertCount(1, $users); - - $user = $users[0]; - $this->assertEquals($user2->id, $user['userid']); - $this->assertEquals(fullname($user2), $user['fullname']); - $this->assertFalse($user['ismessaging']); - $this->assertFalse($user['sentfromcurrentuser']); - $this->assertNull($user['lastmessage']); - $this->assertNull($user['messageid']); - $this->assertFalse($user['isonline']); - $this->assertFalse($user['isread']); - $this->assertFalse($user['isblocked']); - $this->assertNull($user['unreadcount']); - } - - /** - * Tests searching users in course as another user without the proper capabilities. - */ - public function test_data_for_messagearea_search_users_in_course_as_other_user_without_cap() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person doing the search for another user. - $this->setUser($user1); - - // Create a course. - $course = $this->getDataGenerator()->create_course(); - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_search_users_in_course($user2->id, $course->id, 'User'); - $this->assertDebuggingCalled(); - } - - /** - * Tests searching users in course with messaging disabled. - */ - public function test_data_for_messagearea_search_users_in_course_messaging_disabled() { - global $CFG; - - $this->resetAfterTest(true); - - // Create some skeleton data just so we can call the WS.. - $user = self::getDataGenerator()->create_user(); - $course = $this->getDataGenerator()->create_course(); - - // The person doing the search for another user. - $this->setUser($user); - - // Disable messaging. - $CFG->messaging = 0; - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_search_users_in_course($user->id, $course->id, 'User'); - $this->assertDebuggingCalled(); - } - - /** - * Tests searching users. - */ - public function test_data_for_messagearea_search_users() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = new stdClass(); - $user1->firstname = 'User'; - $user1->lastname = 'One'; - $user1 = self::getDataGenerator()->create_user($user1); - - // Set as the user performing the search. - $this->setUser($user1); - - $user2 = new stdClass(); - $user2->firstname = 'User search'; - $user2->lastname = 'Two'; - $user2 = self::getDataGenerator()->create_user($user2); - - $user3 = new stdClass(); - $user3->firstname = 'User search'; - $user3->lastname = 'Three'; - $user3 = self::getDataGenerator()->create_user($user3); - - $user4 = new stdClass(); - $user4->firstname = 'User'; - $user4->lastname = 'Four'; - $user4 = self::getDataGenerator()->create_user($user4); - - $user5 = new stdClass(); - $user5->firstname = 'User search'; - $user5->lastname = 'Five'; - $user5 = self::getDataGenerator()->create_user($user5); - - $user6 = new stdClass(); - $user6->firstname = 'User'; - $user6->lastname = 'Six'; - $user6 = self::getDataGenerator()->create_user($user6); - - // Create some courses. - $course1 = new stdClass(); - $course1->fullname = 'Course search'; - $course1->shortname = 'One'; - $course1 = $this->getDataGenerator()->create_course($course1); - - $course2 = new stdClass(); - $course2->fullname = 'Course'; - $course2->shortname = 'Two'; - $course2 = $this->getDataGenerator()->create_course($course2); - - $course3 = new stdClass(); - $course3->fullname = 'Course'; - $course3->shortname = 'Three search'; - $course3 = $this->getDataGenerator()->create_course($course3); - - $course4 = new stdClass(); - $course4->fullname = 'Course Four'; - $course4->shortname = 'CF100'; - $course4 = $this->getDataGenerator()->create_course($course4); - - $this->getDataGenerator()->enrol_user($user1->id, $course1->id, 'student'); - $this->getDataGenerator()->enrol_user($user1->id, $course2->id, 'student'); - $this->getDataGenerator()->enrol_user($user1->id, $course3->id, 'student'); - - // Add some users as contacts. - \core_message\api::add_contact($user1->id, $user2->id); - \core_message\api::add_contact($user1->id, $user3->id); - \core_message\api::add_contact($user1->id, $user4->id); - - // Perform a search $CFG->messagingallusers setting enabled. - set_config('messagingallusers', 1); - $result = core_message_external::data_for_messagearea_search_users($user1->id, 'search'); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_users_returns(), - $result); - - // Confirm that we returns contacts, courses and non-contacts. - $contacts = $result['contacts']; - $courses = $result['courses']; - $noncontacts = $result['noncontacts']; - - // Check that we retrieved the correct contacts. - $this->assertCount(2, $contacts); - $this->assertEquals($user3->id, $contacts[0]['userid']); - $this->assertEquals($user2->id, $contacts[1]['userid']); - - // Check that we retrieved the correct courses. - $this->assertCount(2, $courses); - $this->assertEquals($course3->id, $courses[0]['id']); - $this->assertEquals($course1->id, $courses[1]['id']); - - // Check that we retrieved the correct non-contacts. - $this->assertCount(1, $noncontacts); - $this->assertEquals($user5->id, $noncontacts[0]['userid']); - } - - /** - * Tests searching users as another user. - */ - public function test_data_for_messagearea_search_users_as_other_user() { - $this->resetAfterTest(true); - - // The person doing the search. - $this->setAdminUser(); - - // Create some users. - $user1 = new stdClass(); - $user1->firstname = 'User'; - $user1->lastname = 'One'; - $user1 = self::getDataGenerator()->create_user($user1); - - $user2 = new stdClass(); - $user2->firstname = 'User search'; - $user2->lastname = 'Two'; - $user2 = self::getDataGenerator()->create_user($user2); - - $user3 = new stdClass(); - $user3->firstname = 'User search'; - $user3->lastname = 'Three'; - $user3 = self::getDataGenerator()->create_user($user3); - - $user4 = new stdClass(); - $user4->firstname = 'User'; - $user4->lastname = 'Four'; - $user4 = self::getDataGenerator()->create_user($user4); - - $user5 = new stdClass(); - $user5->firstname = 'User search'; - $user5->lastname = 'Five'; - $user5 = self::getDataGenerator()->create_user($user5); - - $user6 = new stdClass(); - $user6->firstname = 'User'; - $user6->lastname = 'Six'; - $user6 = self::getDataGenerator()->create_user($user6); - - // Create some courses. - $course1 = new stdClass(); - $course1->fullname = 'Course search'; - $course1->shortname = 'One'; - $course1 = $this->getDataGenerator()->create_course($course1); - - $course2 = new stdClass(); - $course2->fullname = 'Course'; - $course2->shortname = 'Two'; - $course2 = $this->getDataGenerator()->create_course($course2); - - $course3 = new stdClass(); - $course3->fullname = 'Course'; - $course3->shortname = 'Three search'; - $course3 = $this->getDataGenerator()->create_course($course3); - - // Add some users as contacts. - \core_message\api::add_contact($user1->id, $user2->id); - \core_message\api::add_contact($user1->id, $user3->id); - \core_message\api::add_contact($user1->id, $user4->id); - - // Perform a search $CFG->messagingallusers setting enabled. - set_config('messagingallusers', 1); - $result = core_message_external::data_for_messagearea_search_users($user1->id, 'search'); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_users_returns(), - $result); - - // Confirm that we returns contacts, courses and non-contacts. - $contacts = $result['contacts']; - $courses = $result['courses']; - $noncontacts = $result['noncontacts']; - - // Check that we retrieved the correct contacts. - $this->assertCount(2, $contacts); - $this->assertEquals($user3->id, $contacts[0]['userid']); - $this->assertEquals($user2->id, $contacts[1]['userid']); - - // Check that we retrieved the correct courses. - $this->assertCount(0, $courses); - - // Check that we retrieved the correct non-contacts. - $this->assertCount(1, $noncontacts); - $this->assertEquals($user5->id, $noncontacts[0]['userid']); - } - - /** - * Tests searching users as another user without the proper capabilities. - */ - public function test_data_for_messagearea_search_users_as_other_user_without_cap() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person doing the search for another user. - $this->setUser($user1); - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_search_users($user2->id, 'User'); - $this->assertDebuggingCalled(); - } - - /** - * Tests searching users with messaging disabled. - */ - public function test_data_for_messagearea_search_users_messaging_disabled() { - global $CFG; - - $this->resetAfterTest(true); - - // Create some skeleton data just so we can call the WS. - $user = self::getDataGenerator()->create_user(); - - // The person doing the search. - $this->setUser($user); - - // Disable messaging. - $CFG->messaging = 0; - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_search_users($user->id, 'User'); - $this->assertDebuggingCalled(); - } - /** * Tests searching for users when site-wide messaging is disabled. * @@ -3160,407 +2563,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase { core_message_external::data_for_messagearea_search_messages($user->id, 'Search'); } - /** - * Tests retrieving conversations. - */ - public function test_messagearea_conversations() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - $user3 = self::getDataGenerator()->create_user(); - $user4 = self::getDataGenerator()->create_user(); - - // The person retrieving the conversations. - $this->setUser($user1); - - // Send some messages back and forth, have some different conversations with different users. - $time = time(); - $this->send_message($user1, $user2, 'Yo!', 0, $time); - $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1); - $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2); - $messageid1 = $this->send_message($user2, $user1, 'Word.', 0, $time + 3); - - $this->send_message($user1, $user3, 'Booyah', 0, $time + 4); - $this->send_message($user3, $user1, 'Whaaat?', 0, $time + 5); - $this->send_message($user1, $user3, 'Nothing.', 0, $time + 6); - $messageid2 = $this->send_message($user3, $user1, 'Cool.', 0, $time + 7); - - $this->send_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?', 0, $time + 8); - $this->send_message($user4, $user1, 'Yah brah, it\'s pretty rad.', 0, $time + 9); - $messageid3 = $this->send_message($user1, $user4, 'Dope.', 0, $time + 10); - - // Retrieve the conversations. - $result = core_message_external::data_for_messagearea_conversations($user1->id); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_conversations_returns(), - $result); - - // Confirm the data is correct. - $messages = $result['contacts']; - $this->assertCount(3, $messages); - - $message1 = $messages[0]; - $message2 = $messages[1]; - $message3 = $messages[2]; - - $this->assertEquals($user4->id, $message1['userid']); - $this->assertTrue($message1['ismessaging']); - $this->assertTrue($message1['sentfromcurrentuser']); - $this->assertEquals('Dope.', $message1['lastmessage']); - $this->assertEquals($messageid3, $message1['messageid']); - $this->assertNull($message1['isonline']); - $this->assertFalse($message1['isread']); - $this->assertFalse($message1['isblocked']); - $this->assertEquals(1, $message1['unreadcount']); - - $this->assertEquals($user3->id, $message2['userid']); - $this->assertTrue($message2['ismessaging']); - $this->assertFalse($message2['sentfromcurrentuser']); - $this->assertEquals('Cool.', $message2['lastmessage']); - $this->assertEquals($messageid2, $message2['messageid']); - $this->assertNull($message2['isonline']); - $this->assertFalse($message2['isread']); - $this->assertFalse($message2['isblocked']); - $this->assertEquals(2, $message2['unreadcount']); - - $this->assertEquals($user2->id, $message3['userid']); - $this->assertTrue($message3['ismessaging']); - $this->assertFalse($message3['sentfromcurrentuser']); - $this->assertEquals('Word.', $message3['lastmessage']); - $this->assertEquals($messageid1, $message3['messageid']); - $this->assertNull($message3['isonline']); - $this->assertFalse($message3['isread']); - $this->assertFalse($message3['isblocked']); - $this->assertEquals(2, $message3['unreadcount']); - } - - /** - * Tests retrieving conversations as another user. - */ - public function test_messagearea_conversations_as_other_user() { - $this->resetAfterTest(true); - - // Set as admin. - $this->setAdminUser(); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - $user3 = self::getDataGenerator()->create_user(); - $user4 = self::getDataGenerator()->create_user(); - - // Send some messages back and forth, have some different conversations with different users. - $time = time(); - $this->send_message($user1, $user2, 'Yo!', 0, $time); - $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1); - $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2); - $messageid1 = $this->send_message($user2, $user1, 'Word.', 0, $time + 3); - - $this->send_message($user1, $user3, 'Booyah', 0, $time + 4); - $this->send_message($user3, $user1, 'Whaaat?', 0, $time + 5); - $this->send_message($user1, $user3, 'Nothing.', 0, $time + 6); - $messageid2 = $this->send_message($user3, $user1, 'Cool.', 0, $time + 7); - - $this->send_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?', 0, $time + 8); - $this->send_message($user4, $user1, 'Yah brah, it\'s pretty rad.', 0, $time + 9); - $messageid3 = $this->send_message($user1, $user4, 'Dope.', 0, $time + 10); - - // Retrieve the conversations. - $result = core_message_external::data_for_messagearea_conversations($user1->id); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_conversations_returns(), - $result); - - // Confirm the data is correct. - $messages = $result['contacts']; - $this->assertCount(3, $messages); - - $message1 = $messages[0]; - $message2 = $messages[1]; - $message3 = $messages[2]; - - $this->assertEquals($user4->id, $message1['userid']); - $this->assertTrue($message1['ismessaging']); - $this->assertTrue($message1['sentfromcurrentuser']); - $this->assertEquals('Dope.', $message1['lastmessage']); - $this->assertEquals($messageid3, $message1['messageid']); - $this->assertFalse($message1['isonline']); - $this->assertFalse($message1['isread']); - $this->assertFalse($message1['isblocked']); - $this->assertEquals(1, $message1['unreadcount']); - - $this->assertEquals($user3->id, $message2['userid']); - $this->assertTrue($message2['ismessaging']); - $this->assertFalse($message2['sentfromcurrentuser']); - $this->assertEquals('Cool.', $message2['lastmessage']); - $this->assertEquals($messageid2, $message2['messageid']); - $this->assertFalse($message2['isonline']); - $this->assertFalse($message2['isread']); - $this->assertFalse($message2['isblocked']); - $this->assertEquals(2, $message2['unreadcount']); - - $this->assertEquals($user2->id, $message3['userid']); - $this->assertTrue($message3['ismessaging']); - $this->assertFalse($message3['sentfromcurrentuser']); - $this->assertEquals('Word.', $message3['lastmessage']); - $this->assertEquals($messageid1, $message3['messageid']); - $this->assertFalse($message3['isonline']); - $this->assertFalse($message3['isread']); - $this->assertFalse($message3['isblocked']); - $this->assertEquals(2, $message3['unreadcount']); - } - - /** - * Tests retrieving conversations as another user without the proper capabilities. - */ - public function test_messagearea_conversations_as_other_user_without_cap() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person retrieving the conversations for another user. - $this->setUser($user1); - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_conversations($user2->id); - } - - /** - * Tests retrieving conversations with messaging disabled. - */ - public function test_messagearea_conversations_messaging_disabled() { - global $CFG; - - $this->resetAfterTest(true); - - // Create some skeleton data just so we can call the WS. - $user = self::getDataGenerator()->create_user(); - - // The person retrieving the conversations. - $this->setUser($user); - - // Disable messaging. - $CFG->messaging = 0; - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_conversations($user->id); - } - - /** - * Tests retrieving contacts. - */ - public function test_messagearea_contacts() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - - // Set as the user. - $this->setUser($user1); - - $user2 = new stdClass(); - $user2->firstname = 'User'; - $user2->lastname = 'A'; - $user2 = self::getDataGenerator()->create_user($user2); - - $user3 = new stdClass(); - $user3->firstname = 'User'; - $user3->lastname = 'B'; - $user3 = self::getDataGenerator()->create_user($user3); - - $user4 = new stdClass(); - $user4->firstname = 'User'; - $user4->lastname = 'C'; - $user4 = self::getDataGenerator()->create_user($user4); - - $user5 = new stdClass(); - $user5->firstname = 'User'; - $user5->lastname = 'D'; - $user5 = self::getDataGenerator()->create_user($user5); - - // Add some users as contacts. - \core_message\api::add_contact($user1->id, $user2->id); - \core_message\api::add_contact($user1->id, $user3->id); - \core_message\api::add_contact($user1->id, $user4->id); - - // Retrieve the contacts. - $result = core_message_external::data_for_messagearea_contacts($user1->id); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_contacts_returns(), - $result); - - // Confirm the data is correct. - $contacts = $result['contacts']; - usort($contacts, ['static', 'sort_contacts']); - $this->assertCount(3, $contacts); - - $contact1 = $contacts[0]; - $contact2 = $contacts[1]; - $contact3 = $contacts[2]; - - $this->assertEquals($user2->id, $contact1['userid']); - $this->assertFalse($contact1['ismessaging']); - $this->assertFalse($contact1['sentfromcurrentuser']); - $this->assertNull($contact1['lastmessage']); - $this->assertNull($contact1['messageid']); - $this->assertNull($contact1['isonline']); - $this->assertFalse($contact1['isread']); - $this->assertFalse($contact1['isblocked']); - $this->assertNull($contact1['unreadcount']); - - $this->assertEquals($user3->id, $contact2['userid']); - $this->assertFalse($contact2['ismessaging']); - $this->assertFalse($contact2['sentfromcurrentuser']); - $this->assertNull($contact2['lastmessage']); - $this->assertNull($contact2['messageid']); - $this->assertNull($contact2['isonline']); - $this->assertFalse($contact2['isread']); - $this->assertFalse($contact2['isblocked']); - $this->assertNull($contact2['unreadcount']); - - $this->assertEquals($user4->id, $contact3['userid']); - $this->assertFalse($contact3['ismessaging']); - $this->assertFalse($contact3['sentfromcurrentuser']); - $this->assertNull($contact3['lastmessage']); - $this->assertNull($contact3['messageid']); - $this->assertNull($contact3['isonline']); - $this->assertFalse($contact3['isread']); - $this->assertFalse($contact3['isblocked']); - $this->assertNull($contact3['unreadcount']); - } - - /** - * Tests retrieving contacts as another user. - */ - public function test_messagearea_contacts_as_other_user() { - $this->resetAfterTest(true); - - $this->setAdminUser(); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - - $user2 = new stdClass(); - $user2->firstname = 'User'; - $user2->lastname = 'A'; - $user2 = self::getDataGenerator()->create_user($user2); - - $user3 = new stdClass(); - $user3->firstname = 'User'; - $user3->lastname = 'B'; - $user3 = self::getDataGenerator()->create_user($user3); - - $user4 = new stdClass(); - $user4->firstname = 'User'; - $user4->lastname = 'C'; - $user4 = self::getDataGenerator()->create_user($user4); - - $user5 = new stdClass(); - $user5->firstname = 'User'; - $user5->lastname = 'D'; - $user5 = self::getDataGenerator()->create_user($user5); - - // Add some users as contacts. - \core_message\api::add_contact($user1->id, $user2->id); - \core_message\api::add_contact($user1->id, $user3->id); - \core_message\api::add_contact($user1->id, $user4->id); - - // Retrieve the contacts. - $result = core_message_external::data_for_messagearea_contacts($user1->id); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_contacts_returns(), - $result); - - // Confirm the data is correct. - $contacts = $result['contacts']; - usort($contacts, ['static', 'sort_contacts']); - $this->assertCount(3, $contacts); - - $contact1 = $contacts[0]; - $contact2 = $contacts[1]; - $contact3 = $contacts[2]; - - $this->assertEquals($user2->id, $contact1['userid']); - $this->assertFalse($contact1['ismessaging']); - $this->assertFalse($contact1['sentfromcurrentuser']); - $this->assertNull($contact1['lastmessage']); - $this->assertNull($contact1['messageid']); - $this->assertFalse($contact1['isonline']); - $this->assertFalse($contact1['isread']); - $this->assertFalse($contact1['isblocked']); - $this->assertNull($contact1['unreadcount']); - - $this->assertEquals($user3->id, $contact2['userid']); - $this->assertFalse($contact2['ismessaging']); - $this->assertFalse($contact2['sentfromcurrentuser']); - $this->assertNull($contact2['lastmessage']); - $this->assertNull($contact2['messageid']); - $this->assertFalse($contact2['isonline']); - $this->assertFalse($contact2['isread']); - $this->assertFalse($contact2['isblocked']); - $this->assertNull($contact2['unreadcount']); - - $this->assertEquals($user4->id, $contact3['userid']); - $this->assertFalse($contact3['ismessaging']); - $this->assertFalse($contact3['sentfromcurrentuser']); - $this->assertNull($contact3['lastmessage']); - $this->assertNull($contact3['messageid']); - $this->assertFalse($contact3['isonline']); - $this->assertFalse($contact3['isread']); - $this->assertFalse($contact3['isblocked']); - $this->assertNull($contact3['unreadcount']); - } - - /** - * Tests retrieving contacts as another user without the proper capabilities. - */ - public function test_messagearea_contacts_as_other_user_without_cap() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person retrieving the contacts for another user. - $this->setUser($user1); - - // Perform the WS call and ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_contacts($user2->id); - } - - /** - * Tests retrieving contacts with messaging disabled. - */ - public function test_messagearea_contacts_messaging_disabled() { - global $CFG; - - $this->resetAfterTest(true); - - // Create some skeleton data just so we can call the WS. - $user = self::getDataGenerator()->create_user(); - - // The person retrieving the contacts. - $this->setUser($user); - - // Disable messaging. - $CFG->messaging = 0; - - // Perform the WS call and ensure we are shown that it is disabled. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_contacts($user->id); - } - /** * Tests retrieving contacts. */ @@ -3748,216 +2750,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase { $this->assertEmpty($requests); } - /** - * Tests retrieving messages. - */ - public function test_messagearea_messages() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person asking for the messages. - $this->setUser($user1); - - // Send some messages back and forth. - $time = time(); - $this->send_message($user1, $user2, 'Yo!', 0, $time); - $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1); - $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2); - $this->send_message($user2, $user1, 'Word.', 0, $time + 3); - - // Retrieve the messages. - $result = core_message_external::data_for_messagearea_messages($user1->id, $user2->id); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_messages_returns(), - $result); - - // Check the results are correct. - $this->assertTrue($result['iscurrentuser']); - $this->assertEquals($user1->id, $result['currentuserid']); - $this->assertEquals($user2->id, $result['otheruserid']); - $this->assertEquals(fullname($user2), $result['otheruserfullname']); - $this->assertNull($result['isonline']); - - // Confirm the message data is correct. - $messages = $result['messages']; - $this->assertCount(4, $messages); - - $message1 = $messages[0]; - $message2 = $messages[1]; - $message3 = $messages[2]; - $message4 = $messages[3]; - - $this->assertEquals($user1->id, $message1['useridfrom']); - $this->assertEquals($user2->id, $message1['useridto']); - $this->assertTrue($message1['displayblocktime']); - $this->assertContains('Yo!', $message1['text']); - - $this->assertEquals($user2->id, $message2['useridfrom']); - $this->assertEquals($user1->id, $message2['useridto']); - $this->assertFalse($message2['displayblocktime']); - $this->assertContains('Sup mang?', $message2['text']); - - $this->assertEquals($user1->id, $message3['useridfrom']); - $this->assertEquals($user2->id, $message3['useridto']); - $this->assertFalse($message3['displayblocktime']); - $this->assertContains('Writing PHPUnit tests!', $message3['text']); - - $this->assertEquals($user2->id, $message4['useridfrom']); - $this->assertEquals($user1->id, $message4['useridto']); - $this->assertFalse($message4['displayblocktime']); - $this->assertContains('Word.', $message4['text']); - } - - /** - * Tests retrieving messages. - */ - public function test_messagearea_messages_timefrom() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person asking for the messages. - $this->setUser($user1); - - // Send some messages back and forth. - $time = time(); - $this->send_message($user1, $user2, 'Message 1', 0, $time - 4); - $this->send_message($user2, $user1, 'Message 2', 0, $time - 3); - $this->send_message($user1, $user2, 'Message 3', 0, $time - 2); - $this->send_message($user2, $user1, 'Message 4', 0, $time - 1); - - // Retrieve the messages from $time - 3, which should be the 3 most recent messages. - $result = core_message_external::data_for_messagearea_messages($user1->id, $user2->id, 0, 0, false, $time - 3); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_messages_returns(), - $result); - - // Confirm the message data is correct. We shouldn't get 'Message 1' back. - $messages = $result['messages']; - $this->assertCount(3, $messages); - - $message1 = $messages[0]; - $message2 = $messages[1]; - $message3 = $messages[2]; - - $this->assertContains('Message 2', $message1['text']); - $this->assertContains('Message 3', $message2['text']); - $this->assertContains('Message 4', $message3['text']); - } - - /** - * Tests retrieving messages as another user. - */ - public function test_messagearea_messages_as_other_user() { - $this->resetAfterTest(true); - - // Set as admin. - $this->setAdminUser(); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // Send some messages back and forth. - $time = time(); - $this->send_message($user1, $user2, 'Yo!', 0, $time); - $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1); - $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2); - $this->send_message($user2, $user1, 'Word.', 0, $time + 3); - - // Retrieve the messages. - $result = core_message_external::data_for_messagearea_messages($user1->id, $user2->id); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_messages_returns(), - $result); - - // Check the results are correct. - $this->assertFalse($result['iscurrentuser']); - $this->assertEquals($user1->id, $result['currentuserid']); - $this->assertEquals($user2->id, $result['otheruserid']); - $this->assertEquals(fullname($user2), $result['otheruserfullname']); - $this->assertFalse($result['isonline']); - - // Confirm the message data is correct. - $messages = $result['messages']; - $this->assertCount(4, $messages); - - $message1 = $messages[0]; - $message2 = $messages[1]; - $message3 = $messages[2]; - $message4 = $messages[3]; - - $this->assertEquals($user1->id, $message1['useridfrom']); - $this->assertEquals($user2->id, $message1['useridto']); - $this->assertTrue($message1['displayblocktime']); - $this->assertContains('Yo!', $message1['text']); - - $this->assertEquals($user2->id, $message2['useridfrom']); - $this->assertEquals($user1->id, $message2['useridto']); - $this->assertFalse($message2['displayblocktime']); - $this->assertContains('Sup mang?', $message2['text']); - - $this->assertEquals($user1->id, $message3['useridfrom']); - $this->assertEquals($user2->id, $message3['useridto']); - $this->assertFalse($message3['displayblocktime']); - $this->assertContains('Writing PHPUnit tests!', $message3['text']); - - $this->assertEquals($user2->id, $message4['useridfrom']); - $this->assertEquals($user1->id, $message4['useridto']); - $this->assertFalse($message4['displayblocktime']); - $this->assertContains('Word.', $message4['text']); - } - - /** - * Tests retrieving messages as another user without the proper capabilities. - */ - public function test_messagearea_messages_as_other_user_without_cap() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - $user3 = self::getDataGenerator()->create_user(); - - // The person asking for the messages for another user. - $this->setUser($user1); - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_messages($user2->id, $user3->id); - } - - /** - * Tests retrieving messages with messaging disabled. - */ - public function test_messagearea_messages_messaging_disabled() { - global $CFG; - - $this->resetAfterTest(true); - - // Create some skeleton data just so we can call the WS. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person asking for the messages for another user. - $this->setUser($user1); - - // Disable messaging. - $CFG->messaging = 0; - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_messages($user1->id, $user2->id); - } - /** * Tests get_conversation_messages for retrieving messages. */ @@ -4236,286 +3028,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase { core_message_external::get_conversation_messages($user1->id, $conversation->id); } - /** - * Tests retrieving most recent message. - */ - public function test_messagearea_get_most_recent_message() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person doing the search. - $this->setUser($user1); - - // Send some messages back and forth. - $time = time(); - $this->send_message($user1, $user2, 'Yo!', 0, $time); - $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1); - $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2); - $this->send_message($user2, $user1, 'Word.', 0, $time + 3); - - // Get the most recent message. - $result = core_message_external::data_for_messagearea_get_most_recent_message($user1->id, $user2->id); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_get_most_recent_message_returns(), - $result); - - // Check the results are correct. - $this->assertEquals($user2->id, $result['useridfrom']); - $this->assertEquals($user1->id, $result['useridto']); - $this->assertContains('Word.', $result['text']); - } - - /** - * Tests retrieving most recent message as another user. - */ - public function test_messagearea_get_most_recent_message_as_other_user() { - $this->resetAfterTest(true); - - // The person doing the search. - $this->setAdminUser(); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // Send some messages back and forth. - $time = time(); - $this->send_message($user1, $user2, 'Yo!', 0, $time); - $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1); - $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2); - $this->send_message($user2, $user1, 'Word.', 0, $time + 3); - - // Get the most recent message. - $result = core_message_external::data_for_messagearea_get_most_recent_message($user1->id, $user2->id); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_get_most_recent_message_returns(), - $result); - - // Check the results are correct. - $this->assertEquals($user2->id, $result['useridfrom']); - $this->assertEquals($user1->id, $result['useridto']); - $this->assertContains('Word.', $result['text']); - } - - /** - * Tests retrieving most recent message as another user without the proper capabilities. - */ - public function test_messagearea_get_most_recent_message_as_other_user_without_cap() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - $user3 = self::getDataGenerator()->create_user(); - - // The person asking for the most recent message for another user. - $this->setUser($user1); - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_get_most_recent_message($user2->id, $user3->id); - } - - /** - * Tests retrieving most recent message with messaging disabled. - */ - public function test_messagearea_get_most_recent_message_messaging_disabled() { - global $CFG; - - $this->resetAfterTest(true); - - // Create some skeleton data just so we can call the WS. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person asking for the most recent message. - $this->setUser($user1); - - // Disable messaging. - $CFG->messaging = 0; - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_get_most_recent_message($user1->id, $user2->id); - } - - /** - * Tests retrieving a user's profile. - */ - public function test_messagearea_get_profile() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person asking for the profile information. - $this->setUser($user1); - - // Get the profile. - $result = core_message_external::data_for_messagearea_get_profile($user1->id, $user2->id); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_get_profile_returns(), - $result); - - $this->assertEquals($user2->id, $result['userid']); - $this->assertEmpty($result['email']); - $this->assertEmpty($result['country']); - $this->assertEmpty($result['city']); - $this->assertEquals(fullname($user2), $result['fullname']); - $this->assertNull($result['isonline']); - $this->assertFalse($result['isblocked']); - $this->assertFalse($result['iscontact']); - } - - /** - * Tests retrieving a user's profile as another user. - */ - public function test_messagearea_profile_as_other_user() { - $this->resetAfterTest(true); - - // The person asking for the profile information. - $this->setAdminUser(); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - - $user2 = new stdClass(); - $user2->country = 'AU'; - $user2->city = 'Perth'; - $user2 = self::getDataGenerator()->create_user($user2); - - // Get the profile. - $result = core_message_external::data_for_messagearea_get_profile($user1->id, $user2->id); - - // We need to execute the return values cleaning process to simulate the web service server. - $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_get_profile_returns(), - $result); - - $this->assertEquals($user2->id, $result['userid']); - $this->assertEquals($user2->email, $result['email']); - $this->assertEquals(get_string($user2->country, 'countries'), $result['country']); - $this->assertEquals($user2->city, $result['city']); - $this->assertEquals(fullname($user2), $result['fullname']); - $this->assertFalse($result['isonline']); - $this->assertFalse($result['isblocked']); - $this->assertFalse($result['iscontact']); - } - - /** - * Tests retrieving a user's profile as another user without the proper capabilities. - */ - public function test_messagearea_profile_as_other_user_without_cap() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - $user3 = self::getDataGenerator()->create_user(); - - // The person asking for the profile information for another user. - $this->setUser($user1); - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_get_profile($user2->id, $user3->id); - } - - /** - * Tests retrieving a user's profile with messaging disabled. - */ - public function test_messagearea_profile_messaging_disabled() { - global $CFG; - - $this->resetAfterTest(true); - - // Create some skeleton data just so we can call the WS. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person asking for the profile information. - $this->setUser($user1); - - // Disable messaging. - $CFG->messaging = 0; - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::data_for_messagearea_get_profile($user1->id, $user2->id); - } - - /** - * Test marking all message as read with an invalid user. - */ - public function test_mark_all_messages_as_read_invalid_user_exception() { - $this->resetAfterTest(true); - - $this->expectException('moodle_exception'); - core_message_external::mark_all_messages_as_read(-2132131, 0); - } - - /** - * Test marking all message as read without proper access. - */ - public function test_mark_all_messages_as_read_access_denied_exception() { - $this->resetAfterTest(true); - - $sender = $this->getDataGenerator()->create_user(); - $user = $this->getDataGenerator()->create_user(); - - $this->setUser($user); - $this->expectException('moodle_exception'); - core_message_external::mark_all_messages_as_read($sender->id, 0); - } - - /** - * Test marking all message as read with missing from user. - */ - public function test_mark_all_messages_as_read_missing_from_user_exception() { - $this->resetAfterTest(true); - - $sender = $this->getDataGenerator()->create_user(); - - $this->setUser($sender); - $this->expectException('moodle_exception'); - core_message_external::mark_all_messages_as_read($sender->id, 99999); - } - - /** - * Test marking all message as read. - */ - public function test_mark_all_messages_as_read() { - global $DB; - - $this->resetAfterTest(true); - - $sender1 = $this->getDataGenerator()->create_user(); - $sender2 = $this->getDataGenerator()->create_user(); - $sender3 = $this->getDataGenerator()->create_user(); - $recipient = $this->getDataGenerator()->create_user(); - - $this->setUser($recipient); - - $this->send_message($sender1, $recipient, 'Message'); - $this->send_message($sender1, $recipient, 'Message'); - $this->send_message($sender2, $recipient, 'Message'); - $this->send_message($sender2, $recipient, 'Message'); - $this->send_message($sender3, $recipient, 'Message'); - $this->send_message($sender3, $recipient, 'Message'); - - core_message_external::mark_all_messages_as_read($recipient->id, $sender1->id); - $this->assertEquals(2, $DB->count_records('message_user_actions')); - - core_message_external::mark_all_messages_as_read($recipient->id, 0); - $this->assertEquals(6, $DB->count_records('message_user_actions')); - } - /** * Test marking all conversation messages as read with an invalid user. */ @@ -4736,158 +3248,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase { core_message_external::get_unread_conversations_count($user2->id); } - /** - * Test deleting conversation. - */ - public function test_delete_conversation() { - global $DB; - - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person wanting to delete the conversation. - $this->setUser($user1); - - // Send some messages back and forth. - $time = time(); - $m1id = $this->send_message($user1, $user2, 'Yo!', 0, $time); - $m2id = $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1); - $m3id = $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2); - $m4id = $this->send_message($user2, $user1, 'Word.', 0, $time + 3); - - // Delete the conversation. - core_message_external::delete_conversation($user1->id, $user2->id); - - $muas = $DB->get_records('message_user_actions', array(), 'timecreated ASC'); - $this->assertCount(4, $muas); - // Sort by id. - ksort($muas); - - $mua1 = array_shift($muas); - $mua2 = array_shift($muas); - $mua3 = array_shift($muas); - $mua4 = array_shift($muas); - - $this->assertEquals($user1->id, $mua1->userid); - $this->assertEquals($m1id, $mua1->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua1->action); - - $this->assertEquals($user1->id, $mua2->userid); - $this->assertEquals($m2id, $mua2->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua2->action); - - $this->assertEquals($user1->id, $mua3->userid); - $this->assertEquals($m3id, $mua3->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua3->action); - - $this->assertEquals($user1->id, $mua4->userid); - $this->assertEquals($m4id, $mua4->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua4->action); - } - - /** - * Test deleting conversation as other user. - */ - public function test_delete_conversation_as_other_user() { - global $DB; - - $this->resetAfterTest(true); - - $this->setAdminUser(); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // Send some messages back and forth. - $time = time(); - $m1id = $this->send_message($user1, $user2, 'Yo!', 0, $time); - $m2id = $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1); - $m3id = $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2); - $m4id = $this->send_message($user2, $user1, 'Word.', 0, $time + 3); - - // Delete the conversation. - core_message_external::delete_conversation($user1->id, $user2->id); - - $muas = $DB->get_records('message_user_actions', array(), 'timecreated ASC'); - $this->assertCount(4, $muas); - // Sort by id. - ksort($muas); - - $mua1 = array_shift($muas); - $mua2 = array_shift($muas); - $mua3 = array_shift($muas); - $mua4 = array_shift($muas); - - $this->assertEquals($user1->id, $mua1->userid); - $this->assertEquals($m1id, $mua1->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua1->action); - - $this->assertEquals($user1->id, $mua2->userid); - $this->assertEquals($m2id, $mua2->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua2->action); - - $this->assertEquals($user1->id, $mua3->userid); - $this->assertEquals($m3id, $mua3->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua3->action); - - $this->assertEquals($user1->id, $mua4->userid); - $this->assertEquals($m4id, $mua4->messageid); - $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua4->action); - } - - /** - * Test deleting conversation as other user without proper capability. - */ - public function test_delete_conversation_as_other_user_without_cap() { - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - $user3 = self::getDataGenerator()->create_user(); - - // Send some messages back and forth. - $time = time(); - $this->send_message($user1, $user2, 'Yo!', 0, $time); - $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1); - $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2); - $this->send_message($user2, $user1, 'Word.', 0, $time + 3); - - // The person wanting to delete the conversation. - $this->setUser($user3); - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::delete_conversation($user1->id, $user2->id); - } - - /** - * Test deleting conversation with messaging disabled. - */ - public function test_delete_conversation_messaging_disabled() { - global $CFG; - - $this->resetAfterTest(true); - - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // The person wanting to delete the conversation. - $this->setUser($user1); - - // Disable messaging. - $CFG->messaging = 0; - - // Ensure an exception is thrown. - $this->expectException('moodle_exception'); - core_message_external::delete_conversation($user1->id, $user2->id); - } - /** * Test deleting conversations. */ diff --git a/message/tests/messagelib_test.php b/message/tests/messagelib_test.php index c02a6100f11..5a75739fffd 100644 --- a/message/tests/messagelib_test.php +++ b/message/tests/messagelib_test.php @@ -143,6 +143,7 @@ class core_message_messagelib_testcase extends advanced_testcase { /** * Test message_count_unread_messages. + * TODO: MDL-69643 */ public function test_message_count_unread_messages() { // Create users to send and receive message. @@ -151,13 +152,17 @@ class core_message_messagelib_testcase extends advanced_testcase { $userto = $this->getDataGenerator()->create_user(); $this->assertEquals(0, message_count_unread_messages($userto)); + $this->assertDebuggingCalled(); // Send fake messages. $this->send_fake_message($userfrom1, $userto); $this->send_fake_message($userfrom2, $userto); $this->assertEquals(2, message_count_unread_messages($userto)); + $this->assertDebuggingCalled(); + $this->assertEquals(1, message_count_unread_messages($userto, $userfrom1)); + $this->assertDebuggingCalled(); } /** @@ -183,7 +188,10 @@ class core_message_messagelib_testcase extends advanced_testcase { // Should only count the messages that weren't read by the current user. $this->assertEquals(1, message_count_unread_messages($userto)); + $this->assertDebuggingCalledCount(2); + $this->assertEquals(0, message_count_unread_messages($userto, $userfrom1)); + $this->assertDebuggingCalled(); } /** @@ -198,6 +206,7 @@ class core_message_messagelib_testcase extends advanced_testcase { $userto = $this->getDataGenerator()->create_user(); $this->assertEquals(0, message_count_unread_messages($userto)); + $this->assertDebuggingCalled(); // Send fake messages. $messageid = $this->send_fake_message($userfrom1, $userto); @@ -208,7 +217,9 @@ class core_message_messagelib_testcase extends advanced_testcase { // Should only count the messages that weren't deleted by the current user. $this->assertEquals(1, message_count_unread_messages($userto)); + $this->assertDebuggingCalled(); $this->assertEquals(0, message_count_unread_messages($userto, $userfrom1)); + $this->assertDebuggingCalled(); } /** @@ -220,7 +231,9 @@ class core_message_messagelib_testcase extends advanced_testcase { $this->send_fake_message($userfrom, $userto); + // Ensure an exception is thrown. $this->assertEquals(0, message_count_unread_messages($userfrom)); + $this->assertDebuggingCalled(); } /** diff --git a/message/upgrade.txt b/message/upgrade.txt index be6da940d4a..a989150feab 100644 --- a/message/upgrade.txt +++ b/message/upgrade.txt @@ -1,6 +1,38 @@ This files describes API changes in /message/ messaging system, information provided here is intended especially for developers. +=== 3.10 === + +* The following methods have been deprecated and should not be used any more: + * message_count_unread_messages() + * get_non_contacts_with_unread_message_count() + * get_contacts_with_unread_message_count() + +* The following functions have been finally deprecated and can not be used anymore:: + * search_users_in_course() + * search_users() + * get_contacts() + * get_messages() + * get_most_recent_message() + * get_profile() + * get_messages() + * create_messages() + * get_conversations_legacy_formatter() + * create_contacts() + * block_contacts() + * unblock_contacts() + * data_for_messagearea_search_users_in_course() + * data_for_messagearea_search_users() + * message_search_users() + * data_for_messagearea_conversations() + * data_for_messagearea_contacts() + * data_for_messagearea_messages() + * get_conversation_messages() + * data_for_messagearea_get_most_recent_message() + * data_for_messagearea_get_profile() + * mark_all_messages_as_read() + * delete_conversation() + === 3.9 === * Removed the following deprecated functions: - message_move_userfrom_unread2read diff --git a/version.php b/version.php index 83decada253..6255179d8c4 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2020090300.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2020090300.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '3.10dev (Build: 20200903)';// Human-friendly version name