Noah
e42cebe4b8
* Add the Contact page where users can contact the site admins for feedback or to report a problematic user, photo or message. * Reports go into the admin Feedback table. * Admin nav bar indicates number of unread feedbacks. * Add "Report" button to profile pages, photo cards, and the top of Direct Message threads. Misc changes: * Send emails out asynchronously for more responsive page loads.
90 lines
1.9 KiB
Go
90 lines
1.9 KiB
Go
package models
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
"git.kirsle.net/apps/gosocial/pkg/log"
|
|
)
|
|
|
|
// Feedback table for Contact Us & Reporting to admins.
|
|
type Feedback struct {
|
|
ID uint64 `gorm:"primaryKey"`
|
|
UserID uint64 `gorm:"index"` // if logged-in user posted this
|
|
Acknowledged bool `gorm:"index"` // admin dashboard "read" status
|
|
Intent string
|
|
Subject string
|
|
Message string
|
|
TableName string
|
|
TableID uint64
|
|
ReplyTo string // logged-out user may leave their email for reply
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
// GetFeedback by ID.
|
|
func GetFeedback(id uint64) (*Feedback, error) {
|
|
m := &Feedback{}
|
|
result := DB.First(&m, id)
|
|
return m, result.Error
|
|
}
|
|
|
|
// CountUnreadFeedback gets the count of unacknowledged feedback for admins.
|
|
func CountUnreadFeedback() int64 {
|
|
query := DB.Where(
|
|
"acknowledged = ?",
|
|
false,
|
|
)
|
|
|
|
var count int64
|
|
result := query.Model(&Feedback{}).Count(&count)
|
|
if result.Error != nil {
|
|
log.Error("models.CountUnreadFeedback: %s", result.Error)
|
|
}
|
|
return count
|
|
}
|
|
|
|
// PaginateFeedback
|
|
func PaginateFeedback(acknowledged bool, intent string, pager *Pagination) ([]*Feedback, error) {
|
|
var (
|
|
fb = []*Feedback{}
|
|
wheres = []string{}
|
|
placeholders = []interface{}{}
|
|
)
|
|
|
|
wheres = append(wheres, "acknowledged = ?")
|
|
placeholders = append(placeholders, acknowledged)
|
|
|
|
if intent != "" {
|
|
wheres = append(wheres, "intent = ?")
|
|
placeholders = append(placeholders, intent)
|
|
}
|
|
|
|
query := DB.Where(
|
|
strings.Join(wheres, " AND "),
|
|
placeholders...,
|
|
).Order(
|
|
pager.Sort,
|
|
)
|
|
|
|
query.Model(&Feedback{}).Count(&pager.Total)
|
|
|
|
result := query.Offset(
|
|
pager.GetOffset(),
|
|
).Limit(pager.PerPage).Find(&fb)
|
|
|
|
return fb, result.Error
|
|
}
|
|
|
|
// CreateFeedback saves a new Feedback row to the DB.
|
|
func CreateFeedback(fb *Feedback) error {
|
|
result := DB.Create(fb)
|
|
return result.Error
|
|
}
|
|
|
|
// Save Feedback.
|
|
func (fb *Feedback) Save() error {
|
|
result := DB.Save(fb)
|
|
return result.Error
|
|
}
|