Remove from inner circle when deleting all your pictures

This commit is contained in:
Noah Petherbridge 2024-04-13 10:44:09 -07:00
parent 6866bec972
commit 32b054cacf
6 changed files with 62 additions and 5 deletions

View File

@ -163,14 +163,14 @@ func DisconnectUserNow(user *models.User, message string) (int, error) {
} }
// EraseChatHistory tells the chat room to clear DMs history for this user. // EraseChatHistory tells the chat room to clear DMs history for this user.
func EraseChatHistory(user *models.User) (int, error) { func EraseChatHistory(username string) (int, error) {
// API request struct for BareRTC /api/message/clear endpoint. // API request struct for BareRTC /api/message/clear endpoint.
var request = struct { var request = struct {
APIKey string APIKey string
Username string Username string
}{ }{
APIKey: config.Current.CronAPIKey, APIKey: config.Current.CronAPIKey,
Username: user.Username, Username: username,
} }
type response struct { type response struct {

View File

@ -339,6 +339,18 @@ func Settings() http.HandlerFunc {
return return
} }
// Clear their history on the chat room.
go func(username string) {
log.Error("Change of username, clear chat history for old name %s", username)
i, err := chat.EraseChatHistory(username)
if err != nil {
log.Error("EraseChatHistory(%s): %s", username, err)
return
}
session.Flash(w, r, "Notice: due to your recent change in username, your direct message history on the Chat Room has been reset. %d message(s) had been removed.", i)
}(user.Username)
// Set their name. // Set their name.
origUsername := user.Username origUsername := user.Username
user.Username = changeUsername user.Username = changeUsername

View File

@ -238,6 +238,13 @@ func Delete() http.HandlerFunc {
} }
} }
// Inner circle warning: if this deletion would drop them below the 5 public picture
// threshold, warn them they will be removed from the circle if they continue.
var innerCircleWarning bool
if currentUser.IsInnerCircle() && photo.Visibility == models.PhotoPublic && models.CountPublicPhotos(currentUser.ID) <= 5 {
innerCircleWarning = true
}
// Confirm deletion? // Confirm deletion?
if r.Method == http.MethodPost { if r.Method == http.MethodPost {
confirm := r.PostFormValue("confirm") == "true" confirm := r.PostFormValue("confirm") == "true"
@ -281,6 +288,15 @@ func Delete() http.HandlerFunc {
// Log the change. // Log the change.
models.LogDeleted(currentUser, requestUser, "photos", photo.ID, "Deleted the photo.", photo) models.LogDeleted(currentUser, requestUser, "photos", photo.ID, "Deleted the photo.", photo)
// Remove them from the inner circle?
if innerCircleWarning {
if err := models.RemoveFromInnerCircle(currentUser); err != nil {
session.FlashError(w, r, "Couldn't remove from the inner circle: %s", err)
} else {
session.Flash(w, r, "You have been removed from the inner circle because your count of public photos has dropped below 5.")
}
}
session.Flash(w, r, "Photo deleted!") session.Flash(w, r, "Photo deleted!")
// Maybe kick them from chat if this deletion makes them into a Shy Account. // Maybe kick them from chat if this deletion makes them into a Shy Account.
@ -294,7 +310,8 @@ func Delete() http.HandlerFunc {
} }
var vars = map[string]interface{}{ var vars = map[string]interface{}{
"Photo": photo, "Photo": photo,
"InnerCircleWarning": innerCircleWarning,
} }
if err := tmpl.Execute(w, r, vars); err != nil { if err := tmpl.Execute(w, r, vars); err != nil {

View File

@ -15,7 +15,7 @@ func DeleteUser(user *models.User) error {
// Clear their history on the chat room. // Clear their history on the chat room.
go func() { go func() {
i, err := chat.EraseChatHistory(user) i, err := chat.EraseChatHistory(user.Username)
if err != nil { if err != nil {
log.Error("EraseChatHistory(%s): %s", user.Username, err) log.Error("EraseChatHistory(%s): %s", user.Username, err)
return return

View File

@ -14,7 +14,11 @@
} }
.has-background-warning-light, .has-background-warning { .has-background-warning-light, .has-background-warning {
background-color: rgb(100, 90, 41) !important; background-color: rgb(44, 40, 18) !important;
}
.has-background-danger-light, .has-background-danger {
background-color: rgb(31, 13, 13) !important;
} }
.has-background-link-light { .has-background-link-light {

View File

@ -40,6 +40,30 @@
<div class="block"> <div class="block">
Are you sure you want to delete this photo? Are you sure you want to delete this photo?
</div> </div>
{{if .InnerCircleWarning}}
<div class="notification has-background-danger-light">
<strong class="has-text-danger">
<i class="fa fa-exclamation-triangle mr-1"></i>
Important
{{PrettyCircle}}
<img src="/static/img/circle-10.png" alt="Inner circle icon">
Information
</strong>
<div class="mt-2">
When you delete this photo, your count of <strong>public</strong> photos will drop below 5 (five)
and you will be immediately <strong>removed from the inner circle.</strong>
</div>
<div class="mt-2">
If you wish to avoid this, please upload a new <strong>public</strong> photo
before deleting this one. {{PrettyCircle}} members are expected to maintain at
least 5 nudes with face on their public gallery &mdash; it's what qualified you
to be invited to the inner circle in the first place!
<a href="/inner-circle" target="_blank">Learn more <i class="fa fa-external-link"></i></a>
</div>
</div>
{{end}}
<div class="block has-text-center"> <div class="block has-text-center">
<button type="submit" class="button is-danger">Delete Photo</button> <button type="submit" class="button is-danger">Delete Photo</button>
<button type="button" class="button" onclick="history.back()">Cancel</button> <button type="button" class="button" onclick="history.back()">Cancel</button>