aboutsummaryrefslogtreecommitdiffhomepage
path: root/templates/note.php
blob: 98581c8cfb8e5640394b3df2649bc1c0497e6b21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
use Digitigrade\Model\InteractionKind;
use Digitigrade\Model\NotePrivacyScope;
use Digitigrade\Model\UserAccount;

$user = UserAccount::findByCurrentSession();
$interKinds = [];
$actionsDisabled = $user == null;
if ($user != null) {
    $interactions = $note->getInteractionsWithAuthor($user->actor);
    $interKinds = array_map(fn($inter) => $inter->kind, $interactions);
}
?>
<article class="note <?= ($selected ?? false) ? 'selected' : '' ?>">

    <a href="/@/<?= $note->author->getFullHandle() ?>">
        <?php call_template('actor_avatar', ['actor' => $note->author]); ?>
    </a>

    <div>

        <div class="infoLine">
            <a class="authorName" href="/@/<?= $note->author->getFullHandle() ?>"><?= $note->author->displayName ?></a>
            <span class="authorHandle">@<?= $note->author->getFullHandle() ?></span>
            <a class="timestamp" href="/@/<?= $note->author->getFullHandle() ?>/note/<?= $note->id ?>">
                <?= // TODO: localise
                    $note->created->format('Y-m-d \a\t H:i')
                    . (isset($note->modified) && $note->modified != $note->created
                        ? ' (edited ' . $note->modified->format('Y-m-d \a\t H:i') . ')'
                        : ''
                    )
                    ?>
            </a>
            <span class="privacyScope inlineIcon material-symbols-outlined" title="<?= match ($note->privacy->scope) {
                NotePrivacyScope::NONE => __('note.privacy.scope.none'),
                NotePrivacyScope::MUTUALS => __('note.privacy.scope.mutuals'),
                NotePrivacyScope::FOLLOWERS => __('note.privacy.scope.followers'),
                NotePrivacyScope::PUBLIC => __('note.privacy.scope.public')
            } ?>"><?= match ($note->privacy->scope) {
                 NotePrivacyScope::NONE => 'lock',
                 NotePrivacyScope::MUTUALS => 'group',
                 NotePrivacyScope::FOLLOWERS => 'groups',
                 NotePrivacyScope::PUBLIC => 'public'
             } ?></span>
        </div>

        <?php if (isset($note->inReplyTo)): ?>
            <div class="replyInfo">
                <a href="/@/<?= $note->inReplyTo->author->getFullHandle() ?>/note/<?= $note->inReplyTo->id ?>">
                    <span class="material-symbols-outlined inlineIcon">reply</span>
                    <?= sprintf(__('note.info.replyTo'),
                        '<b>' . $note->inReplyTo->author->displayName) . '</b>' ?>
                </a>
            </div>
        <?php endif; ?>

        <div class="content">
            <?php if (isset($note->summary)): ?>
                <details>
                    <summary><?= htmlspecialchars($note->summary) ?></summary>
                <?php endif; ?>
                <?= $note->getFormattedContent('text/html') ?? htmlspecialchars($note->plainContent) ?>
                <?php if (isset($note->summary)): ?>
                </details>
            <?php endif; ?>
        </div>

        <div class="buttons">
            <?php foreach (['like', 'dislike', 'reshare'] as $action) {
                $kind = InteractionKind::from($action);
                call_template('interaction_button', [
                    'action' => $action,
                    'note' => $note,
                    'active' => in_array($kind, $interKinds),
                    'count' => $note->countInteractionsOfKind($kind),
                    'disabled' => $actionsDisabled
                ]);
            }
            call_template('reply_button', [
                'note' => $note,
                'count' => $note->countReplies(),
                'disabled' => $actionsDisabled
            ]);
            ?>
        </div>

        <?php call_template('reply_form', ['note' => $note]); ?>
    </div>
</article>