Bugfixes on user profile pages
This commit is contained in:
parent
c701dd831f
commit
0143fd752f
|
@ -16,7 +16,7 @@ func Likes() http.HandlerFunc {
|
||||||
// Request JSON schema.
|
// Request JSON schema.
|
||||||
type Request struct {
|
type Request struct {
|
||||||
TableName string `json:"name"`
|
TableName string `json:"name"`
|
||||||
TableID uint64 `json:"id"`
|
TableID string `json:"id"`
|
||||||
Unlike bool `json:"unlike,omitempty"`
|
Unlike bool `json:"unlike,omitempty"`
|
||||||
Referrer string `json:"page"`
|
Referrer string `json:"page"`
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,29 @@ func Likes() http.HandlerFunc {
|
||||||
req.Referrer = ""
|
req.Referrer = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Is the ID an integer?
|
||||||
|
var tableID uint64
|
||||||
|
if v, err := strconv.Atoi(req.TableID); err != nil {
|
||||||
|
// Non-integer must be usernames?
|
||||||
|
if req.TableName == "users" {
|
||||||
|
user, err := models.FindUser(req.TableID)
|
||||||
|
if err != nil {
|
||||||
|
SendJSON(w, http.StatusBadRequest, Response{
|
||||||
|
Error: "User not found.",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tableID = user.ID
|
||||||
|
} else {
|
||||||
|
SendJSON(w, http.StatusBadRequest, Response{
|
||||||
|
Error: "Invalid ID.",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tableID = uint64(v)
|
||||||
|
}
|
||||||
|
|
||||||
// Who do we notify about this like?
|
// Who do we notify about this like?
|
||||||
var (
|
var (
|
||||||
targetUser *models.User
|
targetUser *models.User
|
||||||
|
@ -68,7 +91,7 @@ func Likes() http.HandlerFunc {
|
||||||
)
|
)
|
||||||
switch req.TableName {
|
switch req.TableName {
|
||||||
case "photos":
|
case "photos":
|
||||||
if photo, err := models.GetPhoto(req.TableID); err == nil {
|
if photo, err := models.GetPhoto(tableID); err == nil {
|
||||||
if user, err := models.GetUser(photo.UserID); err == nil {
|
if user, err := models.GetUser(photo.UserID); err == nil {
|
||||||
// Admin safety check: in case the admin clicked 'Like' on a friends-only or private
|
// Admin safety check: in case the admin clicked 'Like' on a friends-only or private
|
||||||
// picture they shouldn't have been expected to see, do not log a like.
|
// picture they shouldn't have been expected to see, do not log a like.
|
||||||
|
@ -92,11 +115,11 @@ func Likes() http.HandlerFunc {
|
||||||
targetUser = user
|
targetUser = user
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Error("For like on photos table: didn't find photo %d: %s", req.TableID, err)
|
log.Error("For like on photos table: didn't find photo %d: %s", tableID, err)
|
||||||
}
|
}
|
||||||
case "users":
|
case "users":
|
||||||
log.Error("subject is users, find %d", req.TableID)
|
log.Error("subject is users, find %d", tableID)
|
||||||
if user, err := models.GetUser(req.TableID); err == nil {
|
if user, err := models.GetUser(tableID); err == nil {
|
||||||
targetUser = user
|
targetUser = user
|
||||||
log.Warn("found user %s", targetUser.Username)
|
log.Warn("found user %s", targetUser.Username)
|
||||||
|
|
||||||
|
@ -108,11 +131,11 @@ func Likes() http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Error("For like on users table: didn't find user %d: %s", req.TableID, err)
|
log.Error("For like on users table: didn't find user %d: %s", tableID, err)
|
||||||
}
|
}
|
||||||
case "comments":
|
case "comments":
|
||||||
log.Error("subject is comments, find %d", req.TableID)
|
log.Error("subject is comments, find %d", tableID)
|
||||||
if comment, err := models.GetComment(req.TableID); err == nil {
|
if comment, err := models.GetComment(tableID); err == nil {
|
||||||
targetUser = &comment.User
|
targetUser = &comment.User
|
||||||
notificationMessage = comment.Message
|
notificationMessage = comment.Message
|
||||||
log.Warn("found user %s", targetUser.Username)
|
log.Warn("found user %s", targetUser.Username)
|
||||||
|
@ -125,7 +148,7 @@ func Likes() http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Error("For like on users table: didn't find user %d: %s", req.TableID, err)
|
log.Error("For like on users table: didn't find user %d: %s", tableID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +162,7 @@ func Likes() http.HandlerFunc {
|
||||||
|
|
||||||
// Put in a like.
|
// Put in a like.
|
||||||
if req.Unlike {
|
if req.Unlike {
|
||||||
if err := models.Unlike(currentUser, req.TableName, req.TableID); err != nil {
|
if err := models.Unlike(currentUser, req.TableName, tableID); err != nil {
|
||||||
SendJSON(w, http.StatusBadRequest, Response{
|
SendJSON(w, http.StatusBadRequest, Response{
|
||||||
Error: fmt.Sprintf("Error unliking: %s", err),
|
Error: fmt.Sprintf("Error unliking: %s", err),
|
||||||
})
|
})
|
||||||
|
@ -147,9 +170,9 @@ func Likes() http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the target's notification about this like.
|
// Remove the target's notification about this like.
|
||||||
models.RemoveSpecificNotification(targetUser.ID, models.NotificationLike, req.TableName, req.TableID)
|
models.RemoveSpecificNotification(targetUser.ID, models.NotificationLike, req.TableName, tableID)
|
||||||
} else {
|
} else {
|
||||||
if err := models.AddLike(currentUser, req.TableName, req.TableID); err != nil {
|
if err := models.AddLike(currentUser, req.TableName, tableID); err != nil {
|
||||||
SendJSON(w, http.StatusBadRequest, Response{
|
SendJSON(w, http.StatusBadRequest, Response{
|
||||||
Error: fmt.Sprintf("Error liking: %s", err),
|
Error: fmt.Sprintf("Error liking: %s", err),
|
||||||
})
|
})
|
||||||
|
@ -157,14 +180,14 @@ func Likes() http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the recipient of the like.
|
// Notify the recipient of the like.
|
||||||
log.Info("Added like on %s:%d, notifying owner %+v", req.TableName, req.TableID, targetUser)
|
log.Info("Added like on %s:%d, notifying owner %+v", req.TableName, tableID, targetUser)
|
||||||
if targetUser != nil {
|
if targetUser != nil {
|
||||||
notif := &models.Notification{
|
notif := &models.Notification{
|
||||||
UserID: targetUser.ID,
|
UserID: targetUser.ID,
|
||||||
AboutUser: *currentUser,
|
AboutUser: *currentUser,
|
||||||
Type: models.NotificationLike,
|
Type: models.NotificationLike,
|
||||||
TableName: req.TableName,
|
TableName: req.TableName,
|
||||||
TableID: req.TableID,
|
TableID: tableID,
|
||||||
Message: notificationMessage,
|
Message: notificationMessage,
|
||||||
Link: req.Referrer,
|
Link: req.Referrer,
|
||||||
}
|
}
|
||||||
|
@ -177,7 +200,7 @@ func Likes() http.HandlerFunc {
|
||||||
// Send success response.
|
// Send success response.
|
||||||
SendJSON(w, http.StatusOK, Response{
|
SendJSON(w, http.StatusOK, Response{
|
||||||
OK: true,
|
OK: true,
|
||||||
Likes: models.CountLikes(req.TableName, req.TableID),
|
Likes: models.CountLikes(req.TableName, tableID),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,13 @@ func Contact() http.HandlerFunc {
|
||||||
)
|
)
|
||||||
|
|
||||||
// For report intents: ID of the user, photo, message, etc.
|
// For report intents: ID of the user, photo, message, etc.
|
||||||
tableID, _ = strconv.Atoi(r.FormValue("id"))
|
tableID, err := strconv.Atoi(r.FormValue("id"))
|
||||||
|
if err != nil {
|
||||||
|
// The tableID is not an int - was it a username?
|
||||||
|
if user, err := models.FindUser(r.FormValue("id")); err == nil {
|
||||||
|
tableID = int(user.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
if tableID > 0 {
|
if tableID > 0 {
|
||||||
messageRequired = false
|
messageRequired = false
|
||||||
}
|
}
|
||||||
|
@ -195,7 +201,7 @@ func Contact() http.HandlerFunc {
|
||||||
|
|
||||||
var vars = map[string]interface{}{
|
var vars = map[string]interface{}{
|
||||||
"Intent": intent,
|
"Intent": intent,
|
||||||
"TableID": tableID,
|
"TableID": r.FormValue("id"),
|
||||||
"TableLabel": tableLabel,
|
"TableLabel": tableLabel,
|
||||||
"Subject": subject,
|
"Subject": subject,
|
||||||
"PageTitle": title,
|
"PageTitle": title,
|
||||||
|
|
|
@ -35,7 +35,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"name": tableName, // TODO
|
"name": tableName, // TODO
|
||||||
"id": parseInt(tableID),
|
"id": ""+tableID,
|
||||||
"unlike": !liking,
|
"unlike": !liking,
|
||||||
"page": window.location.pathname + window.location.search + window.location.hash,
|
"page": window.location.pathname + window.location.search + window.location.hash,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
<div class="field block">
|
<div class="field block">
|
||||||
<label class="label" for="dob">Date of birth:</label>
|
<label class="label" for="dob">Date of birth:</label>
|
||||||
<input type="date" class="input"
|
<input type="date" class="input"
|
||||||
placeholder="password"
|
|
||||||
name="dob"
|
name="dob"
|
||||||
id="dob"
|
id="dob"
|
||||||
required>
|
required>
|
||||||
|
|
|
@ -205,7 +205,7 @@
|
||||||
{{$Like := .LikeMap.Get .User.ID}}
|
{{$Like := .LikeMap.Get .User.ID}}
|
||||||
<div class="column is-narrow has-text-centered">
|
<div class="column is-narrow has-text-centered">
|
||||||
<button type="button" class="button is-fullwidth nonshy-like-button"
|
<button type="button" class="button is-fullwidth nonshy-like-button"
|
||||||
data-table-name="users" data-table-id="{{.User.ID}}"
|
data-table-name="users" data-table-id="{{.User.Username}}"
|
||||||
title="Like this profile">
|
title="Like this profile">
|
||||||
<span class="icon{{if $Like.UserLikes}} has-text-danger{{end}}"><i class="fa fa-heart"></i></span>
|
<span class="icon{{if $Like.UserLikes}} has-text-danger{{end}}"><i class="fa fa-heart"></i></span>
|
||||||
<span class="nonshy-likes">
|
<span class="nonshy-likes">
|
||||||
|
@ -236,7 +236,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="column is-narrow has-text-centered">
|
<div class="column is-narrow has-text-centered">
|
||||||
<a href="/contact?intent=report&subject=report.user&id={{.User.ID}}" class="button is-fullwidth">
|
<a href="/contact?intent=report&subject=report.user&id={{.User.Username}}" class="button is-fullwidth">
|
||||||
<span class="icon-text">
|
<span class="icon-text">
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
<i class="fa fa-flag"></i>
|
<i class="fa fa-flag"></i>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user