Minor bugfixes

- Revoke photo notifications if visibility moving to inner circle
- No longer show usernames in chat on the landing page
face-detect
Noah Petherbridge 2023-09-14 17:40:12 -07:00
parent fdc6c5c0a7
commit a70e1c2b73
3 changed files with 15 additions and 35 deletions

View File

@ -59,8 +59,9 @@ func Edit() http.HandlerFunc {
setProfilePic = r.FormValue("intent") == "profile-pic"
crop = pphoto.ParseCropCoords(r.FormValue("crop"))
// Are we GOING private?
// Are we GOING private or changing to Inner Circle?
goingPrivate = visibility == models.PhotoPrivate && visibility != photo.Visibility
goingCircle = visibility == models.PhotoInnerCircle && visibility != photo.Visibility
)
photo.Caption = caption
@ -113,8 +114,8 @@ func Edit() http.HandlerFunc {
session.Flash(w, r, "Photo settings updated!")
// If this picture has moved to Private, revoke any notification we gave about it before.
if goingPrivate {
log.Info("The picture is GOING PRIVATE, revoke any notifications about it")
if goingPrivate || goingCircle {
log.Info("The picture is GOING PRIVATE (to %s), revoke any notifications about it", photo.Visibility)
models.RemoveNotification("photos", photo.ID)
}

View File

@ -14,7 +14,7 @@ import (
// ChatStatistics is the json result of the BareRTC /api/statistics endpoint.
type ChatStatistics struct {
UserCount int
Usernames []string
Usernames []string `json:",omitempty"`
Cameras struct {
Blue int
Red int
@ -41,6 +41,14 @@ func SetChatStatistics(stats *ChatStatistics) {
cachedChatStatistics = stats
}
// Privatized returns a copy of ChatStatistics with the usernames list scrubbed.
func (cs ChatStatistics) Privatized() ChatStatistics {
return ChatStatistics{
UserCount: cs.UserCount,
Cameras: cs.Cameras,
}
}
// IsOnline returns whether the username is currently logged-in to chat.
func (cs ChatStatistics) IsOnline(username string) bool {
for _, user := range cs.Usernames {

View File

@ -44,8 +44,6 @@
<div class="notification is-success is-light" id="chatStatsBanner" style="display: none">
<span id="usersOnline"></span>
<a id="whoLink" href="#" style="visibility: hidden">Who?</a>
<span id="whoList" style="display: none"></span>
<!-- Camera stats if active -->
<div id="cameraStats" style="display: none" class="mt-2">
@ -159,8 +157,6 @@
<script>
function showWhoBanner(chatStatistics) {
const $banner = document.querySelector("#chatStatsBanner"),
$whoLink = document.querySelector("#whoLink"),
$whoList = document.querySelector("#whoList"),
$usersOnline = document.querySelector("#usersOnline")
$cameraStats = document.querySelector("#cameraStats")
$cameraCount = document.querySelector("#cameraCount")
@ -171,16 +167,7 @@ function showWhoBanner(chatStatistics) {
let people = chatStatistics.UserCount === 1 ? 'person' : 'people';
let isAre = chatStatistics.UserCount === 1 ? 'is' : 'are';
$usersOnline.innerHTML = `There ${isAre} currently <strong>${chatStatistics.UserCount}</strong> ${people}</span> in the chat room`;
$whoList.innerHTML = chatStatistics.Usernames.join(", ");
// Show the "Who?" link if there's anybody.
if (chatStatistics.UserCount > 0) {
$usersOnline.innerHTML += ":";
$whoLink.style.visibility = "visible";
} else {
$usersOnline.innerHTML += ".";
}
$usersOnline.innerHTML = `There ${isAre} currently <strong>${chatStatistics.UserCount}</strong> ${people}</span> in the chat room.`;
// Camera stats too?
if (chatStatistics.Cameras.Blue + chatStatistics.Cameras.Red > 0) {
@ -192,30 +179,14 @@ function showWhoBanner(chatStatistics) {
}
}
window.addEventListener("DOMContentLoaded", () => {
let url = "{{.ChatAPI}}",
ChatStatistics = {{.ChatStatistics}},
let ChatStatistics = {{.ChatStatistics.Privatized}},
$banner = document.querySelector("#chatStatsBanner"),
$whoLink = document.querySelector("#whoLink"),
$whoList = document.querySelector("#whoList"),
$usersOnline = document.querySelector("#usersOnline");
// If we already know people are online, show the banner immediately while we refresh from live data
if (ChatStatistics.UserCount > 0) {
showWhoBanner(ChatStatistics);
}
$whoLink.addEventListener("click", (e) => {
e.preventDefault();
$whoLink.style.display = "none";
$whoList.style.display = "";
});
fetch(url, {
mode: 'cors',
cache: 'no-cache',
}).then(resp => resp.json()).then(result => {
showWhoBanner(result);
}).catch(console.error);
});
</script>
{{end}}