better system messages, display name relocation
linter / quality (push) Failing after 1m6s
tests / ci (8.3) (push) Failing after 54s
tests / ci (8.4) (push) Failing after 1m8s
tests / ci (8.5) (push) Failing after 1m13s

This commit is contained in:
Daan Meijer
2026-06-17 11:00:35 +02:00
parent 0fee3c1972
commit c6d482e3de
22 changed files with 689 additions and 204 deletions
+18 -3
View File
@@ -52,20 +52,35 @@ class ActivityService
{
if ($entity instanceof Dynamic) {
$chatId = $entity->chat->id;
$dynamic = $entity;
} elseif ($entity instanceof Ledger) {
$chatId = $entity->dynamic->chat->id;
$dynamic = $entity->dynamic;
$chatId = $dynamic->chat->id;
} else {
return [];
}
$participants = $dynamic->participants()->withPivot('display_name')->get();
$participantsMap = $participants->reduce(function ($acc, $p) {
$acc[$p->id] = $p->pivot->display_name ?? $p->name;
return $acc;
}, []);
$messages = Message::where('chat_id', $chatId)
->with(['user', 'subject'])
->latest()
->get();
return $messages->map(function ($message) {
return $messages->map(function ($message) use ($participantsMap) {
$messageData = $message->toArray();
$messageData['url'] = $this->getUrlForMessage($message);
// Resolve <user:id> placeholders to actual names/display names
$messageData['content'] = preg_replace_callback('/<user:(\d+)>/', function ($matches) use ($participantsMap) {
$userId = $matches[1];
return $participantsMap[$userId] ?? "User #{$userId}";
}, $message->content);
return $messageData;
})->all();
}
@@ -116,7 +131,7 @@ class ActivityService
'url' => $url,
'unread_count' => count($unread),
'context_activities' => $context,
'new_activities' => $unread,
'new_activities' => array_reverse($unread),
];
}
}