Photo upload notification: only notify explicit friends of new explicit photo

face-detect
Noah Petherbridge 2023-05-07 13:16:22 -07:00
parent 7af6d82fc7
commit ba9e90b32a
3 changed files with 40 additions and 3 deletions

View File

@ -157,9 +157,15 @@ func notifyFriendsNewPhoto(photo *models.Photo, currentUser *models.User) {
friendIDs = models.PrivateGranteeUserIDs(currentUser.ID)
log.Info("Notify %d private grantees about the new photo by %s", len(friendIDs), currentUser.Username)
} else {
// Friends
friendIDs = models.FriendIDs(currentUser.ID)
log.Info("Notify %d friends about the new photo by %s", len(friendIDs), currentUser.Username)
// Get all our friend IDs. If this photo is Explicit, only select
// the friends who've opted-in for Explicit photo visibility.
if photo.Explicit {
friendIDs = models.FriendIDsAreExplicit(currentUser.ID)
log.Info("Notify %d EXPLICIT friends about the new photo by %s", len(friendIDs), currentUser.Username)
} else {
friendIDs = models.FriendIDs(currentUser.ID)
log.Info("Notify %d friends about the new photo by %s", len(friendIDs), currentUser.Username)
}
}
for _, fid := range friendIDs {

View File

@ -5,6 +5,7 @@ import (
"regexp"
"code.nonshy.com/nonshy/website/pkg/config"
"code.nonshy.com/nonshy/website/pkg/log"
"code.nonshy.com/nonshy/website/pkg/models"
"code.nonshy.com/nonshy/website/pkg/session"
"code.nonshy.com/nonshy/website/pkg/templates"
@ -114,6 +115,9 @@ func UserPhotos() http.HandlerFunc {
}
pager.ParsePage(r)
photos, err := models.PaginateUserPhotos(user.ID, visibility, explicit, pager)
if err != nil {
log.Error("PaginateUserPhotos(%s): %s", user.Username, err)
}
// Get the count of explicit photos if we are not viewing explicit photos.
var explicitCount int64

View File

@ -4,6 +4,7 @@ import (
"errors"
"time"
"code.nonshy.com/nonshy/website/pkg/log"
"gorm.io/gorm"
)
@ -104,6 +105,32 @@ func FriendIDs(userId uint64) []uint64 {
return userIDs
}
// FriendIDsAreExplicit returns friend IDs who have opted-in for Explicit content,
// e.g. to notify only them when you uploaded a new Explicit photo so that non-explicit
// users don't need to see that notification.
func FriendIDsAreExplicit(userId uint64) []uint64 {
var (
userIDs = []uint64{}
)
err := DB.Table(
"friends",
).Joins(
"JOIN users ON (users.id = friends.target_user_id)",
).Select(
"friends.target_user_id AS friend_id",
).Where(
"friends.source_user_id = ? AND friends.approved = ? AND users.explicit = ?",
userId, true, true,
).Scan(&userIDs)
if err.Error != nil {
log.Error("SQL error collecting explicit FriendIDs for %d: %s", userId, err)
}
return userIDs
}
// CountFriendRequests gets a count of pending requests for the user.
func CountFriendRequests(userID uint64) (int64, error) {
var count int64