Files
FamilyBook/templates/notifications/index.php
T

74 lines
3.3 KiB
PHP
Raw Normal View History

<?php
/**
* 通知消息(v30 第 5 条)。
*
* 用户原话:「引入通知模块,这个模块,不在导航显示,在个人头像点击那里显示,
* 放在个人设置前面,名字:通知消息。就是当有人在观影、旅程等地方
* 加我的时候,发一个通知。」
*
* 所以这一页**只有一条线**:谁、在什么时候、把"我"加进了哪件事 —— 点进去就是那件事。
*
* ⚠️ 进页面即全部标已读(在路由里做的)—— 消息中心的惯例:
* 打开看看就等于"看过了",不需要再让用户手动一条条点"已读"。
* 但**未读的才会被"撤销"**(被移出参与人时):已读的是历史,不删(见 Notification 头部)。
*
* @param array $items 我的通知(最新在前,含 actor_name / actor_nick / actor_avatar)
*/
$items = $items ?? [];
?>
<div class="page-head">
<h1>通知消息</h1>
<span class="sub">共 <?= count($items) ?> 条</span>
<div class="actions">
<?php if ($items): ?>
<form method="post" action="<?= e(url('notifications/clear')) ?>"
onsubmit="return confirm('清空全部通知?清掉就找不回来了。')" style="display:inline">
<?= csrf_field() ?>
<button class="btn btn-ghost btn-sm" type="submit">清空</button>
</form>
<?php endif; ?>
<a class="btn btn-ghost btn-sm" href="<?= e(url('home')) ?>">返回首页</a>
</div>
</div>
<div class="card card-pad">
<?php if (!$items): ?>
<p class="empty-hint">
还没有通知。别人在观影、旅程里把你加进去时,这里就会有消息。
</p>
<?php else: ?>
<ul class="ntf-list">
<?php foreach ($items as $n): ?>
<?php
// 谁发起的:优先用"我叫他什么"(与全站称呼口径一致)
$actorName = \App\Nickname::display(
(int)\App\Auth::personId(),
['name' => $n['actor_name'] ?? '', 'my_nickname' => $n['actor_nick'] ?? '']
);
if (trim((string)$actorName) === '') { $actorName = '有人'; }
$isUnread = empty($n['is_read']);
// 图标:按 kind 分(观影 = 胶片,旅程 = 脚印,其余 = 铃铛)
$kind = (string)($n['kind'] ?? '');
?>
<li class="ntf-row<?= $isUnread ? ' is-unread' : '' ?>">
<img class="ntf-av" src="<?= e(avatar_url($n['actor_avatar'] ?? null)) ?>" alt="">
<a class="ntf-main" href="<?= e(\App\Notification::href($n)) ?>">
<span class="ntf-title">
<b><?= e((string)$actorName) ?></b>
<?= e(preg_replace('/^有人/', '', (string)$n['title'])) ?>
</span>
<span class="ntf-time"><?= e(fb_time_ago((string)$n['created_at'])) ?></span>
</a>
<span class="ntf-kind ntf-kind-<?= e($kind) ?>" aria-hidden="true">
<?= $kind === 'movie' ? '🎬' : (strpos($kind, 'trip') === 0 ? '🧭' : '🔔') ?>
</span>
<form method="post" action="<?= e(url('notifications/del')) ?>" class="ntf-del">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$n['id'] ?>">
<button class="btn btn-ghost btn-sm" type="submit" title="删除这条">删除</button>
</form>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>