better system messages, display name relocation
This commit is contained in:
@@ -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),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user