Skip to content
Permalink
Browse files

MDL-54701 message: add unread message count to messages

  • Loading branch information...
ryanwyllie authored and markn86 committed Aug 18, 2016
1 parent 52fa054 commit c33b7d89132bfd3c4990d39bcae202d57bae0e60
@@ -151,6 +151,7 @@ public static function create_contact($contact, $prefix = '') {
// Check if the user is online.
$data->isonline = \core_message\helper::is_online($userfields->lastaccess);
$data->isread = isset($contact->isread) ? $contact->isread : 0;
$data->unreadcount = isset($contact->unreadcount) ? $contact->unreadcount : null;
return new \core_message\output\messagearea\contact($data);
}
@@ -76,6 +76,7 @@ public function export_for_template(\renderer_base $output) {
}
$contact->isonline = $this->contact->isonline;
$contact->isread = $this->contact->isread;
$contact->unreadcount = $this->contact->unreadcount;
return $contact;
}
@@ -752,6 +752,7 @@ public static function data_for_messagearea_conversations_returns() {
'lastmessage' => new external_value(PARAM_RAW, 'The user\'s last message, null if none.'),
'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'),
'isread' => new external_value(PARAM_BOOL, 'If the user has read the message'),
'unreadcount' => new external_value(PARAM_INT, 'The number of unread messages in this conversation'),
)
)
)
@@ -411,6 +411,12 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) {
$sql = str_replace('1 as readtable', '0 as readtable', $sql);
$unread = $DB->get_records_sql($sql, $params, $limitfrom, $limitto);
$unreadcountssql = 'SELECT useridfrom, count(*) as count
FROM {message}
WHERE useridto = :userid
GROUP BY useridfrom';
$unreadcounts = $DB->get_records_sql($unreadcountssql, array('userid' => $user->id));
// Union the 2 result sets together looking for the message with the most
// recent timecreated for each other user.
// $conversation->id (the array key) is the other user's ID.
@@ -419,8 +425,9 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) {
foreach ($conversation_arrays as $conversation_array) {
foreach ($conversation_array as $conversation) {
// Only consider it unread if $user has unread messages.
if (!$conversation->readtable && $conversation->useridto == $user->id) {
if (isset($unreadcounts[$conversation->useridfrom])) {
$conversation->isread = 0;
$conversation->unreadcount = $unreadcounts[$conversation->useridfrom]->count;
} else {
$conversation->isread = 1;
}
@@ -429,6 +436,13 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) {
$conversations[$conversation->id] = $conversation;
} else {
$current = $conversations[$conversation->id];
// We need to maintain the isread and unreadcount values from existing
// parts of the conversation if we're replacing it.
$conversation->isread = ($conversation->isread && $current->isread);
if (isset($current->unreadcount) && !isset($conversation->unreadcount)) {
$conversation->unreadcount = $current->unreadcount;
}
if ($current->timecreated < $conversation->timecreated) {
$conversations[$conversation->id] = $conversation;
} else if ($current->timecreated == $conversation->timecreated) {
@@ -50,6 +50,9 @@
<h3>{{fullname}}</h3>
<p>{{lastmessage}}</p>
</div>
<div class="unread-count-container">
<span data-region="unread-count" class="badge badge-important">{{unreadcount}}</span>
</div>
</div>
{{#contexturl}}
</a>
@@ -637,6 +637,7 @@
height: 100%;
width: 20%;
display: inline-block;
text-align: center;

img {
height: 100%;
@@ -664,9 +665,23 @@
margin: 0;
}
}

.unread-count-container {
display: none;
}
}
&.unread {
background-color: #f1f1f1;

.content-item-body {
width: 65%;
}

.unread-count-container {
display: inline-block;
width: 10%;
text-align: center;
}
}
}
}
@@ -7848,6 +7848,7 @@ body.path-question-type .mform fieldset.hidden {
height: 100%;
width: 20%;
display: inline-block;
text-align: center;
}
.popover-region-messages.popover-region .popover-region-container .popover-region-content-container .popover-region-content .content-item-container .content-item .profile-image-container img {
height: 100%;
@@ -7871,9 +7872,20 @@ body.path-question-type .mform fieldset.hidden {
.popover-region-messages.popover-region .popover-region-container .popover-region-content-container .popover-region-content .content-item-container .content-item .content-item-body p {
margin: 0;
}
.popover-region-messages.popover-region .popover-region-container .popover-region-content-container .popover-region-content .content-item-container .content-item .unread-count-container {
display: none;
}
.popover-region-messages.popover-region .popover-region-container .popover-region-content-container .popover-region-content .content-item-container.unread {
background-color: #f1f1f1;
}
.popover-region-messages.popover-region .popover-region-container .popover-region-content-container .popover-region-content .content-item-container.unread .content-item-body {
width: 65%;
}
.popover-region-messages.popover-region .popover-region-container .popover-region-content-container .popover-region-content .content-item-container.unread .unread-count-container {
display: inline-block;
width: 10%;
text-align: center;
}
.popover-region-messages.popover-region .popover-region-container .popover-region-content-container.loading .popover-region-content .messages:empty + .empty-message {
display: none;
}

0 comments on commit c33b7d8

Please sign in to comment.
You can’t perform that action at this time.