2018-01-20 06:50:29 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"html"
|
|
|
|
"time"
|
|
|
|
|
2018-10-27 03:21:02 +00:00
|
|
|
"github.com/Azareal/Gosora/query_gen"
|
2018-01-20 06:50:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var profileReplyStmts ProfileReplyStmts
|
|
|
|
|
|
|
|
type ProfileReply struct {
|
2018-12-27 05:42:41 +00:00
|
|
|
ID int
|
|
|
|
ParentID int
|
|
|
|
Content string
|
|
|
|
CreatedBy int
|
|
|
|
Group int
|
|
|
|
CreatedAt time.Time
|
|
|
|
LastEdit int
|
|
|
|
LastEditBy int
|
|
|
|
ContentLines int
|
|
|
|
IPAddress string
|
2018-01-20 06:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileReplyStmts struct {
|
|
|
|
edit *sql.Stmt
|
|
|
|
delete *sql.Stmt
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
DbInits.Add(func(acc *qgen.Accumulator) error {
|
|
|
|
profileReplyStmts = ProfileReplyStmts{
|
|
|
|
edit: acc.Update("users_replies").Set("content = ?, parsed_content = ?").Where("rid = ?").Prepare(),
|
|
|
|
delete: acc.Delete("users_replies").Where("rid = ?").Prepare(),
|
|
|
|
}
|
|
|
|
return acc.FirstError()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-28 06:27:12 +00:00
|
|
|
// Mostly for tests, so we don't wind up with out-of-date profile reply initialisation logic there
|
|
|
|
func BlankProfileReply(id int) *ProfileReply {
|
|
|
|
return &ProfileReply{ID: id}
|
|
|
|
}
|
|
|
|
|
2018-01-20 06:50:29 +00:00
|
|
|
// TODO: Write tests for this
|
|
|
|
func (reply *ProfileReply) Delete() error {
|
|
|
|
_, err := profileReplyStmts.delete.Exec(reply.ID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (reply *ProfileReply) SetBody(content string) error {
|
|
|
|
content = PreparseMessage(html.UnescapeString(content))
|
2019-07-28 23:19:46 +00:00
|
|
|
_, err := profileReplyStmts.edit.Exec(content, ParseMessage(content, 0, ""), reply.ID)
|
2018-01-20 06:50:29 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: We can get this from the topic store instead of a query which will always miss the cache...
|
|
|
|
func (reply *ProfileReply) Creator() (*User, error) {
|
|
|
|
return Users.Get(reply.CreatedBy)
|
|
|
|
}
|