Skip to content

Commit

Permalink
MDL-66244 message: Include group sender images in payload
Browse files Browse the repository at this point in the history
Android 9 notifications now displays two image icons in conversations.
The group and the sender.
  • Loading branch information
jleyva committed Aug 28, 2019
1 parent 9e4178a commit 47138d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 deletions message/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1983,10 +1983,15 @@ public static function send_message_to_conversation(int $userid, int $conversati
],
];

$userpicture = new \user_picture($eventdata->userfrom);
$userpicture->size = 1; // Use f1 size.
$userpicture = $userpicture->get_url($PAGE)->out(false);

$conv = $DB->get_record('message_conversations', ['id' => $conversationid]);
if ($conv->type == self::MESSAGE_CONVERSATION_TYPE_GROUP) {
$convextrafields = self::get_linked_conversation_extra_fields([$conv]);
// Conversation image.
// Conversation images.
$customdata['notificationsendericonurl'] = $userpicture;
$imageurl = isset($convextrafields[$conv->id]) ? $convextrafields[$conv->id]['imageurl'] : null;
if ($imageurl) {
$customdata['notificationiconurl'] = $imageurl;
Expand All @@ -1999,8 +2004,7 @@ public static function send_message_to_conversation(int $userid, int $conversati
}
$customdata['conversationname'] = format_string($conv->name, true, ['context' => $convcontext]);
} else if ($conv->type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
$userpicture = new \user_picture($eventdata->userfrom);
$customdata['notificationiconurl'] = $userpicture->get_url($PAGE)->out(false);
$customdata['notificationiconurl'] = $userpicture;
}
$eventdata->customdata = $customdata;

Expand Down
7 changes: 5 additions & 2 deletions message/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6298,7 +6298,7 @@ public function test_send_message_to_conversation_group_conversation() {
* Test verifying that messages can be sent to existing linked group conversations.
*/
public function test_send_message_to_conversation_linked_group_conversation() {
global $CFG;
global $CFG, $PAGE;

// Create some users.
$user1 = self::getDataGenerator()->create_user();
Expand Down Expand Up @@ -6349,9 +6349,12 @@ public function test_send_message_to_conversation_linked_group_conversation() {
// Test customdata.
$customdata = json_decode($messages[0]->customdata);
$this->assertObjectHasAttribute('notificationiconurl', $customdata);
$this->assertObjectHasAttribute('notificationsendericonurl', $customdata);
$this->assertEquals($groupimageurl, $customdata->notificationiconurl);
$this->assertEquals($group->name, $customdata->conversationname);

$userpicture = new \user_picture($user1);
$userpicture->size = 1; // Use f1 size.
$this->assertEquals($userpicture->get_url($PAGE)->out(false), $customdata->notificationsendericonurl);
}

/**
Expand Down

0 comments on commit 47138d9

Please sign in to comment.