···
···
func (h *Handler) HandleReaction(w http.ResponseWriter, r *http.Request) {
client, err := h.Oauth.AuthorizedClient(r)
-
log.Println("failed to get authorized client:", err)
htmx.HxRedirect(w, "/login")
user, err := bsky.GetUserWithBskyProfile(h.Oauth, r)
-
log.Println("failed to get logged-in user:", err)
htmx.HxRedirect(w, "/login")
···
if user.Did == session.Did {
-
log.Println("failed to react to study session, cannot react to your own study session")
htmx.HxError(w, http.StatusBadRequest, "You cannot react to your own study sessions.")
···
reaction, err := db.ReactionFromString(db.ReactionType(reactionId).String())
-
log.Printf("failed to get reaction types: %v", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to get global study session feed, try again later.")
reactionEvents, err := db.GetReactionsForSession(h.Db, subjectDid, subjectRkey)
-
log.Println("failed to get reactions for study session from db:", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to get global study session feed, try again later.")
···
reactionEvent, err := db.GetReactionEvent(h.Db, user.Did, session, reaction.ID)
-
log.Println("failed to get reaction event from db:", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to add reaction, try again later.")
if reactionEvent != nil {
-
log.Println("failed to add reaction, user already reacted")
htmx.HxError(w, http.StatusBadRequest, "You cannot react multiple times with the same reaction.")
···
-
log.Println("failed to create reaction record:", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to add reaction, try again later.")
···
Set("session_rkey", subjectRkey),
-
log.Println("failed to enqueue posthog event:", err)
···
reactionEvent, err := db.GetReactionEvent(h.Db, user.Did, session, reaction.ID)
-
log.Println("failed to get reaction event from db:", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to remove reaction, try again later.")
···
Rkey: reactionEvent.Rkey,
-
log.Println("failed to delete reaction record:", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to remove reaction, try again later.")
···
Set("session_rkey", subjectRkey),
-
log.Println("failed to enqueue posthog event:", err)
···
partials.NewReactions(partials.NewReactionsProps{
-
SessionRkey: subjectRkey,
-
SessionDid: subjectDid,
-
// Reactions: reactions,
ReactionEvents: reactionEvents,
}).Render(r.Context(), w)
···
···
func (h *Handler) HandleReaction(w http.ResponseWriter, r *http.Request) {
+
l := h.Logger.With("handler", "HandleReaction")
client, err := h.Oauth.AuthorizedClient(r)
+
l.Error("failed to get authorized client", "err", err)
htmx.HxRedirect(w, "/login")
user, err := bsky.GetUserWithBskyProfile(h.Oauth, r)
+
l.Error("failed to get logged-in user", "err", err)
htmx.HxRedirect(w, "/login")
···
if user.Did == session.Did {
+
l.Error("failed to react to study session, cannot react to your own study session")
htmx.HxError(w, http.StatusBadRequest, "You cannot react to your own study sessions.")
···
reaction, err := db.ReactionFromString(db.ReactionType(reactionId).String())
+
l.Error("failed to get reaction types", "err", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to get global study session feed, try again later.")
reactionEvents, err := db.GetReactionsForSession(h.Db, subjectDid, subjectRkey)
+
l.Error("failed to get reactions for study session from db", "err", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to get global study session feed, try again later.")
···
reactionEvent, err := db.GetReactionEvent(h.Db, user.Did, session, reaction.ID)
+
l.Error("failed to get reaction event from db", "err", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to add reaction, try again later.")
if reactionEvent != nil {
+
l.Error("failed to add reaction, user already reacted")
htmx.HxError(w, http.StatusBadRequest, "You cannot react multiple times with the same reaction.")
···
+
l.Error("failed to create reaction record", "err", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to add reaction, try again later.")
···
Set("session_rkey", subjectRkey),
+
l.Error("failed to enqueue posthog event", "err", err)
···
reactionEvent, err := db.GetReactionEvent(h.Db, user.Did, session, reaction.ID)
+
l.Error("failed to get reaction event from db", "err", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to remove reaction, try again later.")
···
Rkey: reactionEvent.Rkey,
+
l.Error("failed to delete reaction record", "err", err)
htmx.HxError(w, http.StatusInternalServerError, "Failed to remove reaction, try again later.")
···
Set("session_rkey", subjectRkey),
+
l.Error("failed to enqueue posthog event", "err", err)
···
partials.NewReactions(partials.NewReactionsProps{
+
SessionRkey: subjectRkey,
+
SessionDid: subjectDid,
ReactionEvents: reactionEvents,
}).Render(r.Context(), w)