2017-09-03 04:50:31 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Reply Resources File
|
|
|
|
* Copyright Azareal 2016 - 2018
|
|
|
|
*
|
|
|
|
*/
|
2017-11-10 03:33:11 +00:00
|
|
|
package common
|
2016-12-02 07:38:54 +00:00
|
|
|
|
2017-11-02 02:52:21 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
2017-10-12 03:24:14 +00:00
|
|
|
|
2017-09-28 22:16:34 +00:00
|
|
|
type ReplyUser struct {
|
2017-11-02 02:52:21 +00:00
|
|
|
ID int
|
|
|
|
ParentID int
|
|
|
|
Content string
|
|
|
|
ContentHtml string
|
|
|
|
CreatedBy int
|
|
|
|
UserLink string
|
|
|
|
CreatedByName string
|
|
|
|
Group int
|
|
|
|
CreatedAt time.Time
|
|
|
|
RelativeCreatedAt string
|
|
|
|
LastEdit int
|
|
|
|
LastEditBy int
|
|
|
|
Avatar string
|
|
|
|
ClassName string
|
|
|
|
ContentLines int
|
|
|
|
Tag string
|
|
|
|
URL string
|
|
|
|
URLPrefix string
|
|
|
|
URLName string
|
|
|
|
Level int
|
|
|
|
IPAddress string
|
|
|
|
Liked bool
|
|
|
|
LikeCount int
|
|
|
|
ActionType string
|
|
|
|
ActionIcon string
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
2017-02-10 13:39:13 +00:00
|
|
|
|
2017-09-28 22:16:34 +00:00
|
|
|
type Reply struct {
|
2017-11-02 02:52:21 +00:00
|
|
|
ID int
|
|
|
|
ParentID int
|
|
|
|
Content string
|
|
|
|
CreatedBy int
|
|
|
|
Group int
|
|
|
|
CreatedAt time.Time
|
|
|
|
RelativeCreatedAt string
|
|
|
|
LastEdit int
|
|
|
|
LastEditBy int
|
|
|
|
ContentLines int
|
|
|
|
IPAddress string
|
|
|
|
Liked bool
|
|
|
|
LikeCount int
|
2017-02-28 09:27:28 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 03:24:14 +00:00
|
|
|
var ErrAlreadyLiked = errors.New("You already liked this!")
|
|
|
|
|
|
|
|
// TODO: Write tests for this
|
|
|
|
// TODO: Wrap these queries in a transaction to make sure the state is consistent
|
|
|
|
func (reply *Reply) Like(uid int) (err error) {
|
|
|
|
var rid int // unused, just here to avoid mutating reply.ID
|
2017-11-05 09:55:34 +00:00
|
|
|
err = stmts.hasLikedReply.QueryRow(uid, reply.ID).Scan(&rid)
|
2017-10-12 03:24:14 +00:00
|
|
|
if err != nil && err != ErrNoRows {
|
|
|
|
return err
|
|
|
|
} else if err != ErrNoRows {
|
|
|
|
return ErrAlreadyLiked
|
|
|
|
}
|
|
|
|
|
|
|
|
score := 1
|
2017-11-05 09:55:34 +00:00
|
|
|
_, err = stmts.createLike.Exec(score, reply.ID, "replies", uid)
|
2017-10-12 03:24:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-05 09:55:34 +00:00
|
|
|
_, err = stmts.addLikesToReply.Exec(1, reply.ID)
|
2017-10-12 03:24:14 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Write tests for this
|
|
|
|
func (reply *Reply) Delete() error {
|
2017-11-05 09:55:34 +00:00
|
|
|
_, err := stmts.deleteReply.Exec(reply.ID)
|
2017-10-12 03:24:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-05 09:55:34 +00:00
|
|
|
_, err = stmts.removeRepliesFromTopic.Exec(1, reply.ParentID)
|
2017-10-12 03:24:14 +00:00
|
|
|
tcache, ok := topics.(TopicCache)
|
|
|
|
if ok {
|
|
|
|
tcache.CacheRemove(reply.ParentID)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
// Copy gives you a non-pointer concurrency safe copy of the reply
|
2017-09-28 22:16:34 +00:00
|
|
|
func (reply *Reply) Copy() Reply {
|
|
|
|
return *reply
|
|
|
|
}
|