Skip to content
Snippets Groups Projects
Commit 0214dea9 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Jan-Hendrik Willms
Browse files

fix ordering of blubber threads, fixes #319

parent 95e631f8
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@ class BlubberThreadsWidget extends SidebarWidget
'avatar' => $thread->getAvatar(),
'name' => $thread->getName(),
'timestamp' => (int) $thread->getLatestActivity(),
'mkdate' => (int) $thread->mkdate,
'unseen_comments' => $unseen_comments,
'notifications' => $thread->id === 'global' || ($thread->context_type === 'course' && !$GLOBALS['perm']->have_perm('admin')),
'followed' => $thread->isFollowedByUser(),
......
......@@ -279,7 +279,7 @@ class BlubberThread extends SimpleORMap implements PrivacyObject
['olderthan' => $olderthan]
);
}
$query->orderBy("IFNULL(MAX(blubber_comments.mkdate), blubber_threads.mkdate) DESC");
$query->orderBy("MAX(blubber_comments.mkdate) DESC, blubber_threads.mkdate DESC");
$query->limit($limit);
$threads = $query->fetchAll(static::class);
......@@ -291,7 +291,7 @@ class BlubberThread extends SimpleORMap implements PrivacyObject
$since = 0;
$olderthan = time();
foreach ($upgraded_threads as $thread) {
$active_time = $thread->getLatestActivity();
$active_time = $thread->getLatestActivity(true);
$since = max($since, $active_time);
$olderthan = min($olderthan, $active_time);
}
......@@ -581,10 +581,13 @@ class BlubberThread extends SimpleORMap implements PrivacyObject
return OpenGraph::extract($this['content']);
}
public function getLatestActivity()
public function getLatestActivity(bool $include_mkdate = false)
{
$newest_comment = BlubberComment::findOneBySQL("thread_id = ? ORDER BY mkdate DESC", [$this->getId()]);
return $newest_comment ? $newest_comment['mkdate'] : $this['mkdate'];
if ($newest_comment) {
return $newest_comment->mkdate;
}
return $include_mkdate ? $this->mkdate : null;
}
public function getURL()
......
......@@ -104,7 +104,11 @@
},
computed: {
sortedThreads () {
return this.threads.sort((a, b) => b.timestamp - a.timestamp);
return this.threads.sort((a, b) => {
return b.timestamp - a.timestamp
|| b.mkdate - a.mkdate
|| b.name.localeCompare(a.name);
});
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment