From 0dd4db4d03966f3e75bc31a9756ac51ca1464afc Mon Sep 17 00:00:00 2001 From: Azareal Date: Mon, 8 Apr 2019 17:44:41 +1000 Subject: [PATCH] 0.2.0 tag, checkpoint release. 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. --- common/common.go | 10 +++++++++- common/extend.go | 2 ++ common/topic.go | 5 +++++ routes/reply.go | 17 +++++++++++++---- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/common/common.go b/common/common.go index 8aa1d3ba..d82d9a24 100644 --- a/common/common.go +++ b/common/common.go @@ -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 @@ -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...) +} diff --git a/common/extend.go b/common/extend.go index e0080f2b..fe7d49f7 100644 --- a/common/extend.go +++ b/common/extend.go @@ -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, }, diff --git a/common/topic.go b/common/topic.go index 73c537c3..242322b5 100644 --- a/common/topic.go +++ b/common/topic.go @@ -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 } diff --git a/routes/reply.go b/routes/reply.go index 4c858ba2..2c3e99ca 100644 --- a/routes/reply.go +++ b/routes/reply.go @@ -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) @@ -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 } @@ -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 { @@ -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) @@ -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 } @@ -313,6 +316,11 @@ 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) @@ -320,6 +328,7 @@ func ReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user common.User, 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)