Noah Petherbridge
bb08ec56ce
Finish implementing the basic forum features: * Pinned threads (admin or board owner only) * Edit Thread settings when you edit the top-most comment. * NoReply threads remove all the reply buttons. * Explicit forums and threads are filtered out unless opted-in (admins always see them). * Count the unique members who participated in each forum. * Get the most recently updated thread to show on forum list page. * Contact/Report page: handle receiving a comment ID to report on. Implement Likes & Notifications * Like buttons added to Photos and Profile Pages. Implemented via simple vanilla JS (likes.js) to make ajax requests to back-end to like/unlike. * Notifications: for your photo or profile being liked. If you unlike, the existing notifications about the like are revoked. * The notifications appear as an alert number in the nav bar and are read on the User Dashboard. Click to mark a notification as "read" or click the "mark all as read" button. Update DeleteUser to scrub likes, notifications, threads, and comments.
77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.kirsle.net/apps/gosocial/pkg/models"
|
|
"git.kirsle.net/apps/gosocial/pkg/session"
|
|
)
|
|
|
|
// ReadNotification API to mark a notif ID as "read."
|
|
func ReadNotification() http.HandlerFunc {
|
|
// Request JSON schema.
|
|
type Request struct {
|
|
ID uint64 `json:"id"`
|
|
}
|
|
|
|
// Response JSON schema.
|
|
type Response struct {
|
|
OK bool `json:"OK"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodPost {
|
|
SendJSON(w, http.StatusNotAcceptable, Response{
|
|
Error: "POST method only",
|
|
})
|
|
return
|
|
}
|
|
|
|
// Get the current user.
|
|
currentUser, err := session.CurrentUser(r)
|
|
if err != nil {
|
|
SendJSON(w, http.StatusBadRequest, Response{
|
|
Error: "Couldn't get current user!",
|
|
})
|
|
return
|
|
}
|
|
|
|
// Parse request payload.
|
|
var req Request
|
|
if err := ParseJSON(r, &req); err != nil {
|
|
SendJSON(w, http.StatusBadRequest, Response{
|
|
Error: fmt.Sprintf("Error with request payload: %s", err),
|
|
})
|
|
return
|
|
}
|
|
|
|
// Get this notification.
|
|
notif, err := models.GetNotification(req.ID)
|
|
if err != nil {
|
|
SendJSON(w, http.StatusInternalServerError, Response{
|
|
Error: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
// Ensure it's ours to read.
|
|
if notif.UserID != currentUser.ID {
|
|
SendJSON(w, http.StatusForbidden, Response{
|
|
Error: "That is not your notification.",
|
|
})
|
|
return
|
|
}
|
|
|
|
// Mark it read.
|
|
notif.Read = true
|
|
notif.Save()
|
|
|
|
// Send success response.
|
|
SendJSON(w, http.StatusOK, Response{
|
|
OK: true,
|
|
})
|
|
})
|
|
}
|