Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix JSON error when comment has no reactions
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed May 9, 2022
commit 4e0595fb0f8413832865975748898445bc4117c4
28 changes: 17 additions & 11 deletions lib/private/Comments/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,24 @@ protected function normalizeDatabaseData(array $data) {
$data['children_count'] = (int)$data['children_count'];
$data['reference_id'] = $data['reference_id'] ?? null;
if ($this->supportReactions()) {
$list = json_decode($data['reactions'], true);
// Ordering does not work on the database with group concat and Oracle,
// So we simply sort on the output.
if (is_array($list)) {
uasort($list, static function ($a, $b) {
if ($a === $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
});
if ($data['reactions'] !== null) {
$list = json_decode($data['reactions'], true);
// Ordering does not work on the database with group concat and Oracle,
// So we simply sort on the output.
if (is_array($list)) {
uasort($list, static function ($a, $b) {
if ($a === $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
});
$data['reactions'] = $list;
} else {
$data['reactions'] = [];
}
} else {
$data['reactions'] = [];
}
$data['reactions'] = $list;
}
return $data;
}
Expand Down