diff --git a/data.sql b/data.sql
index c54754e9..22e6b6cb 100644
--- a/data.sql
+++ b/data.sql
@@ -95,6 +95,7 @@ CREATE TABLE `replies`(
`ipaddress` varchar(200) DEFAULT '0.0.0.0.0' not null,
`likeCount` int DEFAULT 0 not null,
`words` int DEFAULT 1 not null,
+ `actionType` varchar(20) DEFAULT '' not null,
primary key(`rid`)
) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
diff --git a/main.go b/main.go
index caaad5be..e1b1840a 100644
--- a/main.go
+++ b/main.go
@@ -53,7 +53,7 @@ func compile_templates() {
topic := TopicUser{1,"Blah","Hey there!",0,false,false,"Date","Date",0,"","127.0.0.1",0,1,"",default_group,"",no_css_tmpl,0,"","","","",58,false}
var replyList []Reply
- replyList = append(replyList, Reply{0,0,"","Yo!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1})
+ replyList = append(replyList, Reply{0,0,"","Yo!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
var varList map[string]VarItem = make(map[string]VarItem)
tpage := TopicPage{"Title",user,noticeList,replyList,topic,1,1,false}
diff --git a/mod_routes.go b/mod_routes.go
index 482a0ca1..2f67d42f 100644
--- a/mod_routes.go
+++ b/mod_routes.go
@@ -4,6 +4,7 @@ import "log"
import "fmt"
import "strings"
import "strconv"
+import "net"
import "net/http"
import "html"
import "encoding/json"
@@ -29,7 +30,8 @@ func route_edit_topic(w http.ResponseWriter, r *http.Request) {
return
}
- err = db.QueryRow("select parentID from topics where tid = ?", tid).Scan(&fid)
+ var old_is_closed bool
+ err = db.QueryRow("select parentID, is_closed from topics where tid = ?", tid).Scan(&fid,&old_is_closed)
if err == sql.ErrNoRows {
PreErrorJSQ("The topic you tried to edit doesn't exist.",w,r,is_js)
return
@@ -58,6 +60,37 @@ func route_edit_topic(w http.ResponseWriter, r *http.Request) {
return
}
+ ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
+ if err != nil {
+ LocalError("Bad IP",w,r,user)
+ return
+ }
+
+ if old_is_closed != is_closed {
+ var action string
+ if is_closed {
+ action = "lock"
+ } else {
+ action = "unlock"
+ }
+ _, err = create_action_reply_stmt.Exec(tid,action,ipaddress,user.ID)
+ if err != nil {
+ InternalError(err,w,r)
+ return
+ }
+
+ _, err = add_replies_to_topic_stmt.Exec(1, tid)
+ if err != nil {
+ InternalError(err,w,r)
+ return
+ }
+ _, err = update_forum_cache_stmt.Exec(topic_name, tid, user.Name, user.ID, 1)
+ if err != nil {
+ InternalError(err,w,r)
+ return
+ }
+ }
+
err = topics.Load(tid)
if err != nil {
LocalErrorJSQ("This topic no longer exists!",w,r,user,is_js)
@@ -1803,14 +1836,14 @@ func route_panel_groups_create_submit(w http.ResponseWriter, r *http.Request){
group_type := r.PostFormValue("group-type")
if group_type == "Admin" {
if !user.Perms.EditGroupAdmin {
- LocalError("You need the EditGroupAdmin permission can create admin groups",w,r,user)
+ LocalError("You need the EditGroupAdmin permission to create admin groups",w,r,user)
return
}
is_admin = true
is_mod = true
} else if group_type == "Mod" {
if !user.Perms.EditGroupSuperMod {
- LocalError("You need the EditGroupSuperMod permission can create admin groups",w,r,user)
+ LocalError("You need the EditGroupSuperMod permission to create admin groups",w,r,user)
return
}
is_mod = true
diff --git a/mysql.go b/mysql.go
index 22a9e071..a2e30564 100644
--- a/mysql.go
+++ b/mysql.go
@@ -25,6 +25,7 @@ var get_forum_topics_offset_stmt *sql.Stmt
var create_topic_stmt *sql.Stmt
var create_report_stmt *sql.Stmt
var create_reply_stmt *sql.Stmt
+var create_action_reply_stmt *sql.Stmt
var add_replies_to_topic_stmt *sql.Stmt
var remove_replies_from_topic_stmt *sql.Stmt
var add_topics_to_forum_stmt *sql.Stmt
@@ -158,7 +159,7 @@ func init_database(err error) {
}
log.Print("Preparing get_topic_replies_offset statement.")
- get_topic_replies_offset_stmt, err = db.Prepare("select replies.rid, replies.content, replies.createdBy, replies.createdAt, replies.lastEdit, replies.lastEditBy, users.avatar, users.name, users.group, users.url_prefix, users.url_name, users.level, replies.ipaddress, replies.likeCount from replies left join users on replies.createdBy = users.uid where tid = ? limit ?, " + strconv.Itoa(items_per_page))
+ get_topic_replies_offset_stmt, err = db.Prepare("select replies.rid, replies.content, replies.createdBy, replies.createdAt, replies.lastEdit, replies.lastEditBy, users.avatar, users.name, users.group, users.url_prefix, users.url_name, users.level, replies.ipaddress, replies.likeCount, replies.actionType from replies left join users on replies.createdBy = users.uid where tid = ? limit ?, " + strconv.Itoa(items_per_page))
if err != nil {
log.Fatal(err)
}
@@ -199,6 +200,12 @@ func init_database(err error) {
log.Fatal(err)
}
+ log.Print("Preparing create_action_reply statement.")
+ create_action_reply_stmt, err = db.Prepare("INSERT INTO replies(tid,actionType,ipaddress,createdBy) VALUES(?,?,?,?)")
+ if err != nil {
+ log.Fatal(err)
+ }
+
log.Print("Preparing add_replies_to_topic statement.")
add_replies_to_topic_stmt, err = db.Prepare("UPDATE topics SET postCount = postCount + ?, lastReplyAt = NOW() WHERE tid = ?")
if err != nil {
diff --git a/reply.go b/reply.go
index 86602ca2..6590239c 100644
--- a/reply.go
+++ b/reply.go
@@ -25,6 +25,8 @@ type Reply struct /* Should probably rename this to ReplyUser and rename ReplySh
IpAddress string
Liked bool
LikeCount int
+ ActionType string
+ ActionIcon string
}
type ReplyShort struct
diff --git a/routes.go b/routes.go
index 490f23fc..3a60b764 100644
--- a/routes.go
+++ b/routes.go
@@ -301,7 +301,7 @@ func route_topic_id(w http.ResponseWriter, r *http.Request){
return
}
- // Get the topic..
+ // Get the topic...
topic, err := get_topicuser(tid)
if err == sql.ErrNoRows {
NotFound(w,r)
@@ -369,7 +369,7 @@ func route_topic_id(w http.ResponseWriter, r *http.Request){
replyItem := Reply{Css: no_css_tmpl}
for rows.Next() {
- err := rows.Scan(&replyItem.ID, &replyItem.Content, &replyItem.CreatedBy, &replyItem.CreatedAt, &replyItem.LastEdit, &replyItem.LastEditBy, &replyItem.Avatar, &replyItem.CreatedByName, &replyItem.Group, &replyItem.URLPrefix, &replyItem.URLName, &replyItem.Level, &replyItem.IpAddress, &replyItem.LikeCount)
+ err := rows.Scan(&replyItem.ID, &replyItem.Content, &replyItem.CreatedBy, &replyItem.CreatedAt, &replyItem.LastEdit, &replyItem.LastEditBy, &replyItem.Avatar, &replyItem.CreatedByName, &replyItem.Group, &replyItem.URLPrefix, &replyItem.URLName, &replyItem.Level, &replyItem.IpAddress, &replyItem.LikeCount, &replyItem.ActionType)
if err != nil {
InternalError(err,w,r)
return
@@ -405,6 +405,21 @@ func route_topic_id(w http.ResponseWriter, r *http.Request){
replyItem.URL = replyItem.URL + replyItem.URLName
}
}*/
+
+ // We really shouldn't have inline HTML, we should do something about this...
+ if replyItem.ActionType != "" {
+ switch(replyItem.ActionType) {
+ case "lock":
+ replyItem.ActionType = "This topic has been locked by " + replyItem.CreatedByName + ""
+ replyItem.ActionIcon = "🔒︎"
+ case "unlock":
+ replyItem.ActionType = "This topic has been reopened by " + replyItem.CreatedByName + ""
+ replyItem.ActionIcon = "🔓︎"
+ default:
+ replyItem.ActionType = replyItem.ActionType + " has happened"
+ replyItem.ActionIcon = ""
+ }
+ }
replyItem.Liked = false
if hooks["rrow_assign"] != nil {
@@ -516,7 +531,7 @@ func route_profile(w http.ResponseWriter, r *http.Request){
replyLiked := false
replyLikeCount := 0
- replyList = append(replyList, Reply{rid,puser.ID,replyContent,parse_message(replyContent),replyCreatedBy,replyCreatedByName,replyGroup,replyCreatedAt,replyLastEdit,replyLastEditBy,replyAvatar,replyCss,replyLines,replyTag,"","","",0,"",replyLiked,replyLikeCount})
+ replyList = append(replyList, Reply{rid,puser.ID,replyContent,parse_message(replyContent),replyCreatedBy,replyCreatedByName,replyGroup,replyCreatedAt,replyLastEdit,replyLastEditBy,replyAvatar,replyCss,replyLines,replyTag,"","","",0,"",replyLiked,replyLikeCount,"",""})
}
err = rows.Err()
if err != nil {
diff --git a/template_list.go b/template_list.go
index bb5074e0..4c5bd3ce 100644
--- a/template_list.go
+++ b/template_list.go
@@ -133,47 +133,55 @@ var topic_50 []byte = []byte(`