Skip to content

Commit

Permalink
add: show profile avatars in notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
trisuaso committed Nov 8, 2024
1 parent 477ffeb commit 6ae3e77
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 1 addition & 5 deletions crates/rainbeam/templates/components/notification.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<div class="card-nest w-full shadow" id="notif:{{ notif.id }}">
<div class="card flex flex-wrap justify-between gap-2">
<span
class="notif_title"
do="spam_notif_check"
data-id="{{ notif.id }}"
>
<span class="notif_title" do="notif_title" data-id="{{ notif.id }}">
{{ shared::ui::render_markdown(notif.title)|safe }}
</span>
<span class="notif_timestamp date">{{ notif.timestamp }}</span>
Expand Down
1 change: 0 additions & 1 deletion crates/rainbeam/templates/components/response_title.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
<a
title="Quote"
href="/intents/post?reply={{ response.id }}&title=Quote%20post"
target="_blank"
>
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
18 changes: 17 additions & 1 deletion crates/rainbeam/templates/notifications.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@
const spam = ["sent you a message"];

for (const element of Array.from(
document.querySelectorAll("[do=spam_notif_check]"),
document.querySelectorAll("[do=notif_title]"),
)) {
// check for spam
for (const spam_text of spam) {
if (element.innerText.includes(spam_text)) {
fetch(
Expand All @@ -144,6 +145,21 @@
);
}
}

// add user profile picture
if (element.innerText.startsWith("@")) {
const username = element.innerText.split(" ")[0].replace("@", "");
const anchor = element.children[0].children[0];

anchor.innerHTML = `<img
title="${username}'s avatar"
src="/api/v1/profiles/${username}/avatar"
alt="@${username}"
class="avatar"
loading="lazy"
style="--size: 20px; margin-right: 0.25rem"
/>${anchor.innerHTML}`;
}
}
</script>

Expand Down

0 comments on commit 6ae3e77

Please sign in to comment.