Skip to content

Commit

Permalink
0.2.0 tag, checkpoint release.
Browse files Browse the repository at this point in the history
Added the Log function.
Added the Logf function.
Added the Author method to *Topic.
Added the action_end_edit_reply hook.
Added the action_end_delete_reply hook.
  • Loading branch information
Azareal committed Apr 8, 2019
1 parent 1115c0a commit 0dd4db4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
10 changes: 9 additions & 1 deletion common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/Azareal/Gosora/query_gen"
)

var SoftwareVersion = Version{Major: 0, Minor: 2, Patch: 0, Tag: "dev"}
var SoftwareVersion = Version{Major: 0, Minor: 2, Patch: 0, Tag: ""}

// nolint I don't want to write comments for each of these o.o
const Hour int = 60 * 60
Expand Down Expand Up @@ -139,3 +139,11 @@ func DebugLogf(str string, args ...interface{}) {
log.Printf(str, args...)
}
}

func Log(args ...interface{}) {
log.Print(args...)
}

func Logf(str string, args ...interface{}) {
log.Printf(str, args...)
}
2 changes: 2 additions & 0 deletions common/extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ var hookTable = &HookTable{

"action_end_create_topic": nil,
"action_end_create_reply": nil,
"action_end_edit_reply": nil,
"action_end_delete_reply": nil,

"router_pre_route": nil,
},
Expand Down
5 changes: 5 additions & 0 deletions common/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ func (topic *Topic) CreateActionReply(action string, ipaddress string, uid int)
return err
}

// TODO: Test this
func (topic *Topic) Author() (*User, error) {
return Users.Get(topic.CreatedBy)
}

func (topic *Topic) GetID() int {
return topic.ID
}
Expand Down
17 changes: 13 additions & 4 deletions routes/reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ func CreateReplySubmit(w http.ResponseWriter, r *http.Request, user common.User)
// TODO: Update the stats after edits so that we don't under or over decrement stats during deletes
func ReplyEditSubmit(w http.ResponseWriter, r *http.Request, user common.User, srid string) common.RouteError {
js := (r.PostFormValue("js") == "1")

rid, err := strconv.Atoi(srid)
if err != nil {
return common.PreErrorJSQ("The provided Reply ID is not a valid number.", w, r, js)
Expand All @@ -236,7 +235,7 @@ func ReplyEditSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
}

// TODO: Add hooks to make use of headerLite
_, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
if ferr != nil {
return ferr
}
Expand All @@ -262,6 +261,11 @@ func ReplyEditSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
return common.InternalErrorJSQ(err, w, r, js)
}

skip, rerr := lite.Hooks.VhookSkippable("action_end_edit_reply", reply.ID)
if skip || rerr != nil {
return rerr
}

if !js {
http.Redirect(w, r, "/topic/"+strconv.Itoa(topic.ID)+"#reply-"+strconv.Itoa(rid), http.StatusSeeOther)
} else {
Expand All @@ -279,7 +283,6 @@ func ReplyEditSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
// TODO: Disable stat updates in posts handled by plugin_guilds
func ReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user common.User, srid string) common.RouteError {
isJs := (r.PostFormValue("isJs") == "1")

rid, err := strconv.Atoi(srid)
if err != nil {
return common.PreErrorJSQ("The provided Reply ID is not a valid number.", w, r, isJs)
Expand All @@ -300,7 +303,7 @@ func ReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user common.User,
}

// TODO: Add hooks to make use of headerLite
_, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
if ferr != nil {
return ferr
}
Expand All @@ -313,13 +316,19 @@ func ReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user common.User,
return common.InternalErrorJSQ(err, w, r, isJs)
}

skip, rerr := lite.Hooks.VhookSkippable("action_end_delete_reply", reply.ID)
if skip || rerr != nil {
return rerr
}

//log.Printf("Reply #%d was deleted by common.User #%d", rid, user.ID)
if !isJs {
http.Redirect(w, r, "/topic/"+strconv.Itoa(reply.ParentID), http.StatusSeeOther)
} else {
w.Write(successJSONBytes)
}

// ? - What happens if an error fires after a redirect...?
replyCreator, err := common.Users.Get(reply.CreatedBy)
if err == nil {
wcount := common.WordCount(reply.Content)
Expand Down

0 comments on commit 0dd4db4

Please sign in to comment.