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 ...@@ -40,6 +40,7 @@ class BlubberThreadsWidget extends SidebarWidget
'avatar' => $thread->getAvatar(), 'avatar' => $thread->getAvatar(),
'name' => $thread->getName(), 'name' => $thread->getName(),
'timestamp' => (int) $thread->getLatestActivity(), 'timestamp' => (int) $thread->getLatestActivity(),
'mkdate' => (int) $thread->mkdate,
'unseen_comments' => $unseen_comments, 'unseen_comments' => $unseen_comments,
'notifications' => $thread->id === 'global' || ($thread->context_type === 'course' && !$GLOBALS['perm']->have_perm('admin')), 'notifications' => $thread->id === 'global' || ($thread->context_type === 'course' && !$GLOBALS['perm']->have_perm('admin')),
'followed' => $thread->isFollowedByUser(), 'followed' => $thread->isFollowedByUser(),
......
...@@ -279,7 +279,7 @@ class BlubberThread extends SimpleORMap implements PrivacyObject ...@@ -279,7 +279,7 @@ class BlubberThread extends SimpleORMap implements PrivacyObject
['olderthan' => $olderthan] ['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); $query->limit($limit);
$threads = $query->fetchAll(static::class); $threads = $query->fetchAll(static::class);
...@@ -291,7 +291,7 @@ class BlubberThread extends SimpleORMap implements PrivacyObject ...@@ -291,7 +291,7 @@ class BlubberThread extends SimpleORMap implements PrivacyObject
$since = 0; $since = 0;
$olderthan = time(); $olderthan = time();
foreach ($upgraded_threads as $thread) { foreach ($upgraded_threads as $thread) {
$active_time = $thread->getLatestActivity(); $active_time = $thread->getLatestActivity(true);
$since = max($since, $active_time); $since = max($since, $active_time);
$olderthan = min($olderthan, $active_time); $olderthan = min($olderthan, $active_time);
} }
...@@ -581,10 +581,13 @@ class BlubberThread extends SimpleORMap implements PrivacyObject ...@@ -581,10 +581,13 @@ class BlubberThread extends SimpleORMap implements PrivacyObject
return OpenGraph::extract($this['content']); 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()]); $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() public function getURL()
......
...@@ -104,7 +104,11 @@ ...@@ -104,7 +104,11 @@
}, },
computed: { computed: {
sortedThreads () { 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.
Finish editing this message first!
Please register or to comment