Skip to content

Commit

Permalink
Merge pull request #35245 from nextcloud/backport/32288/stable24
Browse files Browse the repository at this point in the history
[stable24] Fix JSON error when comment has no reactions
  • Loading branch information
nickvergessen authored Nov 19, 2022
2 parents 77dccd3 + 3f1865b commit 9f8b6e9
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/private/Comments/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,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

0 comments on commit 9f8b6e9

Please sign in to comment.