Commit 2fc51498 authored by Matthias Larisch's avatar Matthias Larisch Committed by Matthias Larisch

calculate avatar urls for forum post in frontend

parent b04ecd66
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<script> <script>
import { AVATAR_DEFAULT } from '@/consts' import { AVATAR_DEFAULT } from '@/consts'
import { img } from '@/script'
export default { export default {
props: { props: {
...@@ -29,7 +30,7 @@ export default { ...@@ -29,7 +30,7 @@ export default {
return { return {
width: `${this.size}px`, width: `${this.size}px`,
height: `${this.size}px`, height: `${this.size}px`,
backgroundImage: `url(${this.url ? this.url : AVATAR_DEFAULT})` backgroundImage: `url(${this.url ? img(this.url, '130') : AVATAR_DEFAULT})`
} }
} }
} }
......
...@@ -49,10 +49,10 @@ class ForumRestController extends AbstractFOSRestController ...@@ -49,10 +49,10 @@ class ForumRestController extends AbstractFOSRestController
if (isset($thread['post_time'])) { if (isset($thread['post_time'])) {
$res['lastPost']['createdAt'] = str_replace(' ', 'T', $thread['post_time']); $res['lastPost']['createdAt'] = str_replace(' ', 'T', $thread['post_time']);
$res['lastPost']['body'] = $this->sanitizerService->markdownToHtml($thread['post_body']); $res['lastPost']['body'] = $this->sanitizerService->markdownToHtml($thread['post_body']);
$res['lastPost']['author'] = RestNormalization::normalizeFoodsaver($thread, 'foodsaver_', '130_q_'); $res['lastPost']['author'] = RestNormalization::normalizeFoodsaver($thread, 'foodsaver_');
} }
if (isset($thread['creator_name'])) { if (isset($thread['creator_name'])) {
$res['creator'] = RestNormalization::normalizeFoodsaver($thread, 'creator_', '130_q_'); $res['creator'] = RestNormalization::normalizeFoodsaver($thread, 'creator_');
} }
return $res; return $res;
...@@ -64,7 +64,7 @@ class ForumRestController extends AbstractFOSRestController ...@@ -64,7 +64,7 @@ class ForumRestController extends AbstractFOSRestController
'id' => $post['id'], 'id' => $post['id'],
'body' => $this->sanitizerService->markdownToHtml($post['body']), 'body' => $this->sanitizerService->markdownToHtml($post['body']),
'createdAt' => str_replace(' ', 'T', $post['time']), 'createdAt' => str_replace(' ', 'T', $post['time']),
'author' => RestNormalization::normalizeFoodsaver($post, 'author_', '130_q_'), 'author' => RestNormalization::normalizeFoodsaver($post, 'author_'),
'reactions' => $post['reactions'] ?: new \ArrayObject(), 'reactions' => $post['reactions'] ?: new \ArrayObject(),
'mayDelete' => $this->forumPermissions->mayDeletePost($post) 'mayDelete' => $this->forumPermissions->mayDeletePost($post)
]; ];
......
...@@ -18,7 +18,7 @@ class RestNormalization ...@@ -18,7 +18,7 @@ class RestNormalization
* *
* @return array * @return array
*/ */
public static function normalizeFoodsaver($data, $prefix = '', $photoVersion = ''): array public static function normalizeFoodsaver($data, $prefix = ''): array
{ {
//sleep_status is used with and without prefix //sleep_status is used with and without prefix
if (isset($data[$prefix . 'sleep_status'])) { if (isset($data[$prefix . 'sleep_status'])) {
...@@ -32,7 +32,7 @@ class RestNormalization ...@@ -32,7 +32,7 @@ class RestNormalization
return [ return [
'id' => (int)$data[$prefix . 'id'], 'id' => (int)$data[$prefix . 'id'],
'name' => $data[$prefix . 'name'], 'name' => $data[$prefix . 'name'],
'avatar' => $data[$prefix . 'photo'] ? ('/images/' . $photoVersion . $data[$prefix . 'photo']) : null, 'avatar' => $data[$prefix . 'photo'] ?? null,
'sleepStatus' => $sleepStatus, 'sleepStatus' => $sleepStatus,
]; ];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment