**Major Features Added:** - **Inline Reply System**: Replace compose screen with inline reply boxes - **Thread Navigation**: Parent/child navigation with jump functionality - **Chain Flow UI**: Reply counts, expand/collapse animations, visual hierarchy - **Enhanced Animations**: Smooth transitions, hover effects, micro-interactions **Frontend Changes:** - **ThreadedCommentWidget**: Complete rewrite with animations and navigation - **ThreadNode Model**: Added parent references and descendant counting - **ThreadedConversationScreen**: Integrated navigation handlers - **PostDetailScreen**: Replaced with threaded conversation view - **ComposeScreen**: Added reply indicators and context - **PostActions**: Fixed visibility checks for chain buttons **Backend Changes:** - **API Route**: Added /posts/:id/thread endpoint - **Post Repository**: Include allow_chain and visibility fields in feed - **Thread Handler**: Support for fetching post chains **UI/UX Improvements:** - **Reply Context**: Clear indication when replying to specific posts - **Character Counting**: 500 character limit with live counter - **Visual Hierarchy**: Depth-based indentation and styling - **Smooth Animations**: SizeTransition, FadeTransition, hover states - **Chain Navigation**: Parent/child buttons with visual feedback **Technical Enhancements:** - **Animation Controllers**: Proper lifecycle management - **State Management**: Clean separation of concerns - **Navigation Callbacks**: Reusable navigation system - **Error Handling**: Graceful fallbacks and user feedback This creates a Reddit-style threaded conversation experience with smooth animations, inline replies, and intuitive navigation between posts in a chain.
142 lines
4.1 KiB
Go
142 lines
4.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
"github.com/patbritton/sojorn-backend/internal/models"
|
|
"github.com/patbritton/sojorn-backend/internal/repository"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type SettingsHandler struct {
|
|
userRepo *repository.UserRepository
|
|
notifRepo *repository.NotificationRepository
|
|
}
|
|
|
|
func NewSettingsHandler(userRepo *repository.UserRepository, notifRepo *repository.NotificationRepository) *SettingsHandler {
|
|
return &SettingsHandler{userRepo: userRepo, notifRepo: notifRepo}
|
|
}
|
|
|
|
func (h *SettingsHandler) GetPrivacySettings(c *gin.Context) {
|
|
userIdStr, exists := c.Get("user_id")
|
|
if !exists {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
|
|
return
|
|
}
|
|
|
|
settings, err := h.userRepo.GetPrivacySettings(c.Request.Context(), userIdStr.(string))
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get settings"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, settings)
|
|
}
|
|
|
|
func (h *SettingsHandler) UpdatePrivacySettings(c *gin.Context) {
|
|
userIdStr, _ := c.Get("user_id")
|
|
userID, _ := uuid.Parse(userIdStr.(string))
|
|
|
|
var ps models.PrivacySettings
|
|
if err := c.ShouldBindJSON(&ps); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
|
|
return
|
|
}
|
|
ps.UserID = userID // Ensure ID matches authenticated user
|
|
|
|
if err := h.userRepo.UpdatePrivacySettings(c.Request.Context(), &ps); err != nil {
|
|
log.Error().Err(err).Msg("Failed to update privacy settings")
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update settings", "details": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, ps)
|
|
}
|
|
|
|
func (h *SettingsHandler) GetUserSettings(c *gin.Context) {
|
|
userIdStr, exists := c.Get("user_id")
|
|
if !exists {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
|
|
return
|
|
}
|
|
|
|
settings, err := h.userRepo.GetUserSettings(c.Request.Context(), userIdStr.(string))
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get settings"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, settings)
|
|
}
|
|
|
|
func (h *SettingsHandler) UpdateUserSettings(c *gin.Context) {
|
|
userIdStr, _ := c.Get("user_id")
|
|
userID, _ := uuid.Parse(userIdStr.(string))
|
|
|
|
var us models.UserSettings
|
|
if err := c.ShouldBindJSON(&us); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
|
|
return
|
|
}
|
|
us.UserID = userID
|
|
|
|
if err := h.userRepo.UpdateUserSettings(c.Request.Context(), &us); err != nil {
|
|
log.Error().Err(err).Msg("Failed to update user settings")
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update settings", "details": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, us)
|
|
}
|
|
|
|
func (h *SettingsHandler) RegisterDevice(c *gin.Context) {
|
|
userIdStr, exists := c.Get("user_id")
|
|
if !exists {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
|
|
return
|
|
}
|
|
userID, _ := uuid.Parse(userIdStr.(string))
|
|
|
|
var req models.UserFCMToken
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
|
|
return
|
|
}
|
|
req.UserID = userID
|
|
|
|
if err := h.notifRepo.UpsertFCMToken(c.Request.Context(), &req); err != nil {
|
|
log.Error().Err(err).Msg("Failed to register device")
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to register device", "details": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": "Device registered"})
|
|
}
|
|
|
|
func (h *SettingsHandler) UnregisterDevice(c *gin.Context) {
|
|
userIdStr, exists := c.Get("user_id")
|
|
if !exists {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
|
|
return
|
|
}
|
|
userID, _ := uuid.Parse(userIdStr.(string))
|
|
|
|
var req struct {
|
|
FCMToken string `json:"fcm_token" binding:"required"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
|
|
return
|
|
}
|
|
|
|
if err := h.notifRepo.DeleteFCMToken(c.Request.Context(), userID.String(), req.FCMToken); err != nil {
|
|
log.Error().Err(err).Msg("Failed to unregister device")
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to unregister device", "details": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": "Device unregistered"})
|
|
}
|