MDL-64017 core_message: can specify conversation to view on index page
authorMark Nelson <markn@moodle.com>
Fri, 5 Apr 2019 06:48:26 +0000 (14:48 +0800)
committerMark Nelson <markn@moodle.com>
Thu, 18 Apr 2019 06:28:09 +0000 (14:28 +0800)
message/amd/build/message_drawer.min.js
message/amd/src/message_drawer.js
message/classes/helper.php
message/index.php

index 453da2f..867cb43 100644 (file)
Binary files a/message/amd/build/message_drawer.min.js and b/message/amd/build/message_drawer.min.js differ
index 8823ac0..ef6bc0b 100644 (file)
@@ -267,12 +267,16 @@ function(
         registerEventListeners(uniqueId, root, alwaysVisible);
         if (alwaysVisible) {
             show(uniqueId, root);
+            // Are we sending to a specific user?
             if (sendToUser) {
+                // Check if a conversation already exists, if not, create one.
                 if (conversationId) {
                     Router.go(uniqueId, Routes.VIEW_CONVERSATION, conversationId);
                 } else {
                     Router.go(uniqueId, Routes.VIEW_CONVERSATION, null, 'create', sendToUser);
                 }
+            } else if (conversationId) { // We aren't sending to a specific user, but to a group conversation.
+                Router.go(uniqueId, Routes.VIEW_CONVERSATION, conversationId);
             }
         }
     };
index a1099b9..5e61e63 100644 (file)
@@ -763,6 +763,9 @@ class helper {
 
         if ($sendtouser) {
             $templatecontext['sendtouser'] = $sendtouser;
+        }
+
+        if ($conversationid) {
             $templatecontext['conversationid'] = $conversationid;
         }
 
index 5883633..e396bf6 100644 (file)
@@ -40,10 +40,20 @@ $id = optional_param('id', 0, PARAM_INT);
 // We no longer support viewing another user's messaging area (that can be achieved
 // via the 'Log-in as' feature). The 'user2' value takes preference over 'id'.
 $userid = optional_param('user2', $id, PARAM_INT);
+$conversationid = optional_param('convid', null, PARAM_INT);
 
 if (!core_user::is_real_user($userid)) {
     $userid = null;
 }
+// You can specify either a user, or a conversation, not both.
+if ($userid) {
+    $conversationid = \core_message\api::get_conversation_between_users([$USER->id, $userid]);
+} else if ($conversationid) {
+    // Check that the user belongs to the conversation.
+    if (!\core_message\api::is_user_in_conversation($USER->id, $conversationid)) {
+        $conversationid = null;
+    }
+}
 
 if ($userid) {
     $recipient = new stdClass();
@@ -73,12 +83,6 @@ $usernode->remove();
 $settings = $PAGE->settingsnav->find('messages', null);
 $settings->make_active();
 
-// Check if there is an existing conversation with the supplied user (if there is one).
-$conversationid = null;
-if ($userid) {
-    $conversationid = \core_message\api::get_conversation_between_users([$USER->id, $userid]);
-}
-
 echo $OUTPUT->header();
 // Display a message if the messages have not been migrated yet.
 if (!get_user_preferences('core_message_migrate_data', false)) {