gosora/common/topic.go

1227 lines
43 KiB
Go
Raw Normal View History

/*
*
2022-02-21 03:32:53 +00:00
* Gosora Topic File
* Copyright Azareal 2017 - 2020
*
*/
package common
import (
2022-02-21 03:32:53 +00:00
"database/sql"
"html"
"html/template"
2022-02-21 03:32:53 +00:00
"strconv"
"strings"
"time"
2022-02-21 03:32:53 +00:00
//"log"
2022-02-21 03:32:53 +00:00
p "github.com/Azareal/Gosora/common/phrases"
qgen "github.com/Azareal/Gosora/query_gen"
)
// This is also in reply.go
//var ErrAlreadyLiked = errors.New("This item was already liked by this user")
// ? - Add a TopicMeta struct for *Forums?
2016-12-02 07:38:54 +00:00
type Topic struct {
2022-02-21 03:32:53 +00:00
ID int
Link string
Title string
Content string
CreatedBy int
IsClosed bool
Sticky bool
CreatedAt time.Time
LastReplyAt time.Time
LastReplyBy int
LastReplyID int
ParentID int
Status string // Deprecated. Marked for removal. -Is there anything we could use it for?
IP string
ViewCount int64
PostCount int
LikeCount int
AttachCount int
WeekViews int
ClassName string // CSS Class Name
Poll int
Data string // Used for report metadata
Rids []int
2016-12-02 07:38:54 +00:00
}
type TopicUser struct {
2022-02-21 03:32:53 +00:00
ID int
Link string
Title string
Content string // TODO: Avoid converting this to bytes in templates, particularly if it's long
CreatedBy int
IsClosed bool
Sticky bool
CreatedAt time.Time
LastReplyAt time.Time
LastReplyBy int
LastReplyID int
ParentID int
Status string // Deprecated. Marked for removal.
IP string
ViewCount int64
PostCount int
LikeCount int
AttachCount int
ClassName string
Poll int
Data string // Used for report metadata
UserLink string
CreatedByName string
Group int
Avatar string
MicroAvatar string
ContentLines int
ContentHTML string // TODO: Avoid converting this to bytes in templates, particularly if it's long
Tag string
URL string
//URLPrefix string
//URLName string
Level int
Liked bool
Attachments []*MiniAttachment
Rids []int
Deletable bool
}
type TopicsRowMut struct {
2022-02-21 03:32:53 +00:00
*TopicsRow
CanMod bool
}
// TODO: Embed TopicUser to simplify this structure and it's related logic?
type TopicsRow struct {
2022-02-21 03:32:53 +00:00
Topic
LastPage int
2022-02-21 03:32:53 +00:00
Creator *User
CSS template.CSS
ContentLines int
LastUser *User
2022-02-21 03:32:53 +00:00
ForumName string //TopicsRow
ForumLink string
}
Almost finished live topic lists, you can find them at /topics/. You can disable them via config.json The topic list cache can handle more groups now, but don't go too crazy with groups (e.g. thousands of them). Make the suspicious request logs more descriptive. Added the phrases API endpoint. Split the template phrases up by prefix, more work on this coming up. Removed #dash_saved and part of #dash_username. Removed some temporary artifacts from trying to implement FA5 in Nox. Removed some commented CSS. Fixed template artifact deletion on Windows. Tweaked HTTPSRedirect to make it more compact. Fixed NullUserCache not complying with the expectations for BulkGet. Swapped out a few RunVhook calls for more appropriate RunVhookNoreturn calls. Removed a few redundant IsAdmin checks when IsMod would suffice. Commented out a few pushers. Desktop notification permission requests are no longer served to guests. Split topics.html into topics.html and topics_topic.html RunThemeTemplate should now fallback to interpreted templates properly when the transpiled variants aren't avaialb.e Changed TopicsRow.CreatedAt from a string to a time.Time Added SkipTmplPtrMap to CTemplateConfig. Added SetBuildTags to CTemplateSet. A bit more data is dumped when something goes wrong while transpiling templates now. topics_topic, topic_posts, and topic_alt_posts are now transpiled for the client, although not all of them are ready to be served to the client yet. Client rendered templates now support phrases. Client rendered templates now support loops. Fixed loadAlerts in global.js Refactored some of the template initialisation code to make it less repetitive. Split topic.html into topic.html and topic_posts.html Split topic_alt.html into topic_alt.html and topic_alt_posts.html Added comments for PollCache. Fixed a data race in the MemoryPollCache. The writer is now closed properly in WsHubImpl.broadcastMessage. Fixed a potential deadlock in WsHubImpl.broadcastMessage. Removed some old commented code in websockets.go Added the DisableLiveTopicList config setting.
2018-06-24 13:49:29 +00:00
type WsTopicsRow struct {
2022-02-21 03:32:53 +00:00
ID int
Link string
Title string
CreatedBy int
IsClosed bool
Sticky bool
CreatedAt time.Time
LastReplyAt time.Time
RelativeLastReplyAt string
LastReplyBy int
LastReplyID int
ParentID int
ViewCount int64
PostCount int
LikeCount int
AttachCount int
ClassName string
Creator *WsJSONUser
LastUser *WsJSONUser
ForumName string
ForumLink string
CanMod bool
Almost finished live topic lists, you can find them at /topics/. You can disable them via config.json The topic list cache can handle more groups now, but don't go too crazy with groups (e.g. thousands of them). Make the suspicious request logs more descriptive. Added the phrases API endpoint. Split the template phrases up by prefix, more work on this coming up. Removed #dash_saved and part of #dash_username. Removed some temporary artifacts from trying to implement FA5 in Nox. Removed some commented CSS. Fixed template artifact deletion on Windows. Tweaked HTTPSRedirect to make it more compact. Fixed NullUserCache not complying with the expectations for BulkGet. Swapped out a few RunVhook calls for more appropriate RunVhookNoreturn calls. Removed a few redundant IsAdmin checks when IsMod would suffice. Commented out a few pushers. Desktop notification permission requests are no longer served to guests. Split topics.html into topics.html and topics_topic.html RunThemeTemplate should now fallback to interpreted templates properly when the transpiled variants aren't avaialb.e Changed TopicsRow.CreatedAt from a string to a time.Time Added SkipTmplPtrMap to CTemplateConfig. Added SetBuildTags to CTemplateSet. A bit more data is dumped when something goes wrong while transpiling templates now. topics_topic, topic_posts, and topic_alt_posts are now transpiled for the client, although not all of them are ready to be served to the client yet. Client rendered templates now support phrases. Client rendered templates now support loops. Fixed loadAlerts in global.js Refactored some of the template initialisation code to make it less repetitive. Split topic.html into topic.html and topic_posts.html Split topic_alt.html into topic_alt.html and topic_alt_posts.html Added comments for PollCache. Fixed a data race in the MemoryPollCache. The writer is now closed properly in WsHubImpl.broadcastMessage. Fixed a potential deadlock in WsHubImpl.broadcastMessage. Removed some old commented code in websockets.go Added the DisableLiveTopicList config setting.
2018-06-24 13:49:29 +00:00
}
You can now manage the attachments for an opening post by hitting edit. The update system now uses the database as the source of truth for the last version rather than lastSchema.json Refactored several structs and bits of code, so we can avoid allocations for contexts where we never use a relative time. Clicking on the relative times on the topic list and the forum page should now take you to the post on the last page rather than just the last page. Added the reltime template function. Fixed some obsolete bits of code. Fixed some spelling mistakes. Fixed a bug where MaxBytesReader was capped at the maxFileSize rather than r.ContentLength. All of the client side templates should work again now. Shortened some statement names to save some horizontal space. accUpdateBuilder and SimpleUpdate now use updatePrebuilder behind the scenes to simplify things. Renamed selectItem to builder in AccSelectBuilder. Added a Total() method to accCountBuilder to reduce the amount of boilerplate used for row count queries. The "_builder" strings have been replaced with empty strings to help save memory, to make things slightly faster and to open the door to removing the query name in many contexts down the line. Added the open_edit and close_edit client hooks. Removed many query name checks. Split the attachment logic into separate functions and de-duplicated it between replies and topics. Improved the UI for editing topics in Nox. Used type aliases to reduce the amount of boilerplate in tables.go and patches.go Reduced the amount of boilerplate in the action post logic. Eliminated a map and a slice in the topic page for users who haven't given any likes. E.g. Guests. Fixed some long out-dated parts of the update instructions. Updated the update instructions to remove mention of the obsolete lastSchema.json Fixed a bug in init.js where /api/me was being loaded for guests. Added the MiniTopicGet, GlobalCount and CountInTopic methods to AttachmentStore. Added the MiniAttachment struct. Split the mod floaters out into their own template to reduce duplication. Removed a couple of redundant ParseForms. Added the common.skipUntilIfExistsOrLine function. Added the NotFoundJS and NotFoundJSQ functions. Added the lastReplyID and attachCount columns to the topics table.
2018-12-27 05:42:41 +00:00
// TODO: Can we get the client side to render the relative times instead?
func (r *TopicsRow) WebSockets() *WsTopicsRow {
2022-02-21 03:32:53 +00:00
return &WsTopicsRow{r.ID, r.Link, r.Title, r.CreatedBy, r.IsClosed, r.Sticky, r.CreatedAt, r.LastReplyAt, RelativeTime(r.LastReplyAt), r.LastReplyBy, r.LastReplyID, r.ParentID, r.ViewCount, r.PostCount, r.LikeCount, r.AttachCount, r.ClassName, r.Creator.WebSockets(), r.LastUser.WebSockets(), r.ForumName, r.ForumLink, false}
}
// TODO: Can we get the client side to render the relative times instead?
func (r *TopicsRow) WebSockets2(canMod bool) *WsTopicsRow {
2022-02-21 03:32:53 +00:00
return &WsTopicsRow{r.ID, r.Link, r.Title, r.CreatedBy, r.IsClosed, r.Sticky, r.CreatedAt, r.LastReplyAt, RelativeTime(r.LastReplyAt), r.LastReplyBy, r.LastReplyID, r.ParentID, r.ViewCount, r.PostCount, r.LikeCount, r.AttachCount, r.ClassName, r.Creator.WebSockets(), r.LastUser.WebSockets(), r.ForumName, r.ForumLink, canMod}
Almost finished live topic lists, you can find them at /topics/. You can disable them via config.json The topic list cache can handle more groups now, but don't go too crazy with groups (e.g. thousands of them). Make the suspicious request logs more descriptive. Added the phrases API endpoint. Split the template phrases up by prefix, more work on this coming up. Removed #dash_saved and part of #dash_username. Removed some temporary artifacts from trying to implement FA5 in Nox. Removed some commented CSS. Fixed template artifact deletion on Windows. Tweaked HTTPSRedirect to make it more compact. Fixed NullUserCache not complying with the expectations for BulkGet. Swapped out a few RunVhook calls for more appropriate RunVhookNoreturn calls. Removed a few redundant IsAdmin checks when IsMod would suffice. Commented out a few pushers. Desktop notification permission requests are no longer served to guests. Split topics.html into topics.html and topics_topic.html RunThemeTemplate should now fallback to interpreted templates properly when the transpiled variants aren't avaialb.e Changed TopicsRow.CreatedAt from a string to a time.Time Added SkipTmplPtrMap to CTemplateConfig. Added SetBuildTags to CTemplateSet. A bit more data is dumped when something goes wrong while transpiling templates now. topics_topic, topic_posts, and topic_alt_posts are now transpiled for the client, although not all of them are ready to be served to the client yet. Client rendered templates now support phrases. Client rendered templates now support loops. Fixed loadAlerts in global.js Refactored some of the template initialisation code to make it less repetitive. Split topic.html into topic.html and topic_posts.html Split topic_alt.html into topic_alt.html and topic_alt_posts.html Added comments for PollCache. Fixed a data race in the MemoryPollCache. The writer is now closed properly in WsHubImpl.broadcastMessage. Fixed a potential deadlock in WsHubImpl.broadcastMessage. Removed some old commented code in websockets.go Added the DisableLiveTopicList config setting.
2018-06-24 13:49:29 +00:00
}
Basic search now works for the Search & Filter Widget. ElasticSearch has been temporarily delayed, so I can push through this update. Added the three month time range to the analytics panes. Began work on adding new graphs to the analytics panes. Began work on the ElasticSearch adapter for the search system. Added the currently limited AddKey method to the database adapters. Expanded upon the column parsing logic in the database adapters to ease the use of InsertSelects. Added the BulkGet method to TopicCache. Added the BulkGetMap method to TopicStore. TopicStore methods should now properly retrieve lastReplyBy. Added the panel_analytics_script template to de-dupe part of the analytics logic. We plan to tidy this up further, but for now, it'll suffice. Added plugin_sendmail and plugin_hyperdrive to the continuous integration test list. Tweaked the width and heights of the textareas for the Widget Editor. Added the AddKey method to *qgen.builder Fixed a bug where using the inline forum editor would crash Gosora and wouldn't set the preset permissions for that forum properly. Added DotBot to the user agent analytics. Invisibles should be better handled when they're encountered now in user agent strings. Unknown language ISO Codes in headers now have the requests fully logged for debugging purposes. Shortened some of the pointer receiver names. Shortened some variable names. Added the dotbot phrase. Added the panel_statistics_time_range_three_months phrase. Added gopkg.in/olivere/elastic.v6 as a dependency. You will need to run the patcher or updater for this commit.
2019-02-23 06:29:19 +00:00
// TODO: Stop relying on so many struct types?
// ! Not quite safe as Topic doesn't contain all the data needed to constructs a TopicsRow
func (t *Topic) TopicsRow() *TopicsRow {
2022-02-21 03:32:53 +00:00
lastPage := 1
var creator *User = nil
contentLines := 1
var lastUser *User = nil
forumName := ""
forumLink := ""
//return &TopicsRow{t.ID, t.Link, t.Title, t.Content, t.CreatedBy, t.IsClosed, t.Sticky, t.CreatedAt, t.LastReplyAt, t.LastReplyBy, t.LastReplyID, t.ParentID, t.Status, t.IP, t.ViewCount, t.PostCount, t.LikeCount, t.AttachCount, lastPage, t.ClassName, t.Poll, t.Data, creator, "", contentLines, lastUser, forumName, forumLink, t.Rids}
return &TopicsRow{*t, lastPage, creator, "", contentLines, lastUser, forumName, forumLink}
}
// ! Some data may be lost in the conversion
/*func (t *TopicsRow) Topic() *Topic {
2022-02-21 03:32:53 +00:00
//return &Topic{t.ID, t.Link, t.Title, t.Content, t.CreatedBy, t.IsClosed, t.Sticky, t.CreatedAt, t.LastReplyAt, t.LastReplyBy, t.LastReplyID, t.ParentID, t.Status, t.IP, t.ViewCount, t.PostCount, t.LikeCount, t.AttachCount, t.ClassName, t.Poll, t.Data, t.Rids}
return &t.Topic
}*/
Basic search now works for the Search & Filter Widget. ElasticSearch has been temporarily delayed, so I can push through this update. Added the three month time range to the analytics panes. Began work on adding new graphs to the analytics panes. Began work on the ElasticSearch adapter for the search system. Added the currently limited AddKey method to the database adapters. Expanded upon the column parsing logic in the database adapters to ease the use of InsertSelects. Added the BulkGet method to TopicCache. Added the BulkGetMap method to TopicStore. TopicStore methods should now properly retrieve lastReplyBy. Added the panel_analytics_script template to de-dupe part of the analytics logic. We plan to tidy this up further, but for now, it'll suffice. Added plugin_sendmail and plugin_hyperdrive to the continuous integration test list. Tweaked the width and heights of the textareas for the Widget Editor. Added the AddKey method to *qgen.builder Fixed a bug where using the inline forum editor would crash Gosora and wouldn't set the preset permissions for that forum properly. Added DotBot to the user agent analytics. Invisibles should be better handled when they're encountered now in user agent strings. Unknown language ISO Codes in headers now have the requests fully logged for debugging purposes. Shortened some of the pointer receiver names. Shortened some variable names. Added the dotbot phrase. Added the panel_statistics_time_range_three_months phrase. Added gopkg.in/olivere/elastic.v6 as a dependency. You will need to run the patcher or updater for this commit.
2019-02-23 06:29:19 +00:00
// ! Not quite safe as Topic doesn't contain all the data needed to constructs a WsTopicsRow
/*func (t *Topic) WsTopicsRows() *WsTopicsRow {
2022-02-21 03:32:53 +00:00
var creator *User = nil
var lastUser *User = nil
forumName := ""
forumLink := ""
return &WsTopicsRow{t.ID, t.Link, t.Title, t.CreatedBy, t.IsClosed, t.Sticky, t.CreatedAt, t.LastReplyAt, RelativeTime(t.LastReplyAt), t.LastReplyBy, t.LastReplyID, t.ParentID, t.ViewCount, t.PostCount, t.LikeCount, t.AttachCount, t.ClassName, creator, lastUser, forumName, forumLink}
Basic search now works for the Search & Filter Widget. ElasticSearch has been temporarily delayed, so I can push through this update. Added the three month time range to the analytics panes. Began work on adding new graphs to the analytics panes. Began work on the ElasticSearch adapter for the search system. Added the currently limited AddKey method to the database adapters. Expanded upon the column parsing logic in the database adapters to ease the use of InsertSelects. Added the BulkGet method to TopicCache. Added the BulkGetMap method to TopicStore. TopicStore methods should now properly retrieve lastReplyBy. Added the panel_analytics_script template to de-dupe part of the analytics logic. We plan to tidy this up further, but for now, it'll suffice. Added plugin_sendmail and plugin_hyperdrive to the continuous integration test list. Tweaked the width and heights of the textareas for the Widget Editor. Added the AddKey method to *qgen.builder Fixed a bug where using the inline forum editor would crash Gosora and wouldn't set the preset permissions for that forum properly. Added DotBot to the user agent analytics. Invisibles should be better handled when they're encountered now in user agent strings. Unknown language ISO Codes in headers now have the requests fully logged for debugging purposes. Shortened some of the pointer receiver names. Shortened some variable names. Added the dotbot phrase. Added the panel_statistics_time_range_three_months phrase. Added gopkg.in/olivere/elastic.v6 as a dependency. You will need to run the patcher or updater for this commit.
2019-02-23 06:29:19 +00:00
}*/
type TopicStmts struct {
2022-02-21 03:32:53 +00:00
getRids *sql.Stmt
getReplies *sql.Stmt
getReplies2 *sql.Stmt
getReplies3 *sql.Stmt
addReplies *sql.Stmt
updateLastReply *sql.Stmt
lock *sql.Stmt
unlock *sql.Stmt
moveTo *sql.Stmt
stick *sql.Stmt
unstick *sql.Stmt
hasLikedTopic *sql.Stmt
createLike *sql.Stmt
addLikesToTopic *sql.Stmt
delete *sql.Stmt
deleteReplies *sql.Stmt
deleteLikesForTopic *sql.Stmt
deleteActivity *sql.Stmt
edit *sql.Stmt
setPoll *sql.Stmt
removePoll *sql.Stmt
testSetCreatedAt *sql.Stmt
createAction *sql.Stmt
getTopicUser *sql.Stmt // TODO: Can we get rid of this?
getByReplyID *sql.Stmt
}
var topicStmts TopicStmts
func init() {
2022-02-21 03:32:53 +00:00
DbInits.Add(func(acc *qgen.Accumulator) error {
t, w := "topics", "tid=?"
set := func(s string) *sql.Stmt {
return acc.Update(t).Set(s).Where(w).Prepare()
}
topicStmts = TopicStmts{
getRids: acc.Select("replies").Columns("rid").Where(w).Orderby("rid ASC").Limit("?,?").Prepare(),
getReplies: acc.SimpleLeftJoin("replies AS r", "users AS u", "r.rid, r.content, r.createdBy, r.createdAt, r.lastEdit, r.lastEditBy, u.avatar, u.name, u.group, u.level, r.ip, r.likeCount, r.attachCount, r.actionType", "r.createdBy=u.uid", "r.tid=?", "r.rid ASC", "?,?"),
getReplies2: acc.SimpleLeftJoin("replies AS r", "users AS u", "r.rid, r.content, r.createdBy, r.createdAt, r.lastEdit, r.lastEditBy, u.avatar, u.name, u.group, u.level, r.likeCount, r.attachCount, r.actionType", "r.createdBy=u.uid", "r.tid=?", "r.rid ASC", "?,?"),
getReplies3: acc.Select("replies").Columns("rid,content,createdBy,createdAt,lastEdit,lastEditBy,likeCount,attachCount,actionType").Where(w).Orderby("rid ASC").Limit("?,?").Prepare(),
addReplies: set("postCount=postCount+?,lastReplyBy=?,lastReplyAt=UTC_TIMESTAMP()"),
updateLastReply: acc.Update(t).Set("lastReplyID=?").Where("lastReplyID<? AND tid=?").Prepare(),
lock: set("is_closed=1"),
unlock: set("is_closed=0"),
moveTo: set("parentID=?"),
stick: set("sticky=1"),
unstick: set("sticky=0"),
hasLikedTopic: acc.Select("likes").Columns("targetItem").Where("sentBy=? and targetItem=? and targetType='topics'").Prepare(),
createLike: acc.Insert("likes").Columns("weight,targetItem,targetType,sentBy,createdAt").Fields("?,?,?,?,UTC_TIMESTAMP()").Prepare(),
addLikesToTopic: set("likeCount=likeCount+?"),
delete: acc.Delete(t).Where(w).Prepare(),
deleteReplies: acc.Delete("replies").Where(w).Prepare(),
deleteLikesForTopic: acc.Delete("likes").Where("targetItem=? AND targetType='topics'").Prepare(),
deleteActivity: acc.Delete("activity_stream").Where("elementID=? AND elementType='topic'").Prepare(),
edit: set("title=?,content=?,parsed_content=?"), // TODO: Only run the content update bits on non-polls, does this matter?
setPoll: acc.Update(t).Set("poll=?").Where("tid=? AND poll=0").Prepare(),
removePoll: acc.Update(t).Set("poll=0").Where("tid=?").Prepare(),
testSetCreatedAt: set("createdAt=?"),
createAction: acc.Insert("replies").Columns("tid,actionType,ip,createdBy,createdAt,lastUpdated,content,parsed_content").Fields("?,?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),'',''").Prepare(),
getTopicUser: acc.SimpleLeftJoin("topics AS t", "users AS u", "t.title, t.content, t.createdBy, t.createdAt, t.lastReplyAt, t.lastReplyBy, t.lastReplyID, t.is_closed, t.sticky, t.parentID, t.ip, t.views, t.postCount, t.likeCount, t.attachCount,t.poll, u.name, u.avatar, u.group, u.level", "t.createdBy=u.uid", w, "", ""),
getByReplyID: acc.SimpleLeftJoin("replies AS r", "topics AS t", "t.tid, t.title, t.content, t.createdBy, t.createdAt, t.is_closed, t.sticky, t.parentID, t.ip, t.views, t.postCount, t.likeCount, t.poll, t.data", "r.tid=t.tid", "rid=?", "", ""),
}
return acc.FirstError()
})
}
// Flush the topic out of the cache
// ? - We do a CacheRemove() here instead of mutating the pointer to avoid creating a race condition
func (t *Topic) cacheRemove() {
2022-02-21 03:32:53 +00:00
if tc := Topics.GetCache(); tc != nil {
tc.Remove(t.ID)
}
TopicListThaw.Thaw()
}
// TODO: Write a test for this
WIP forum action code. Currently disabled. Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
2021-04-07 14:23:11 +00:00
func (t *Topic) AddReply(rid, uid int) (e error) {
2022-02-21 03:32:53 +00:00
_, e = topicStmts.addReplies.Exec(1, uid, t.ID)
if e != nil {
return e
}
_, e = topicStmts.updateLastReply.Exec(rid, rid, t.ID)
t.cacheRemove()
return e
}
WIP forum action code. Currently disabled. Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
2021-04-07 14:23:11 +00:00
func (t *Topic) Lock() (e error) {
2022-02-21 03:32:53 +00:00
_, e = topicStmts.lock.Exec(t.ID)
t.cacheRemove()
return e
}
WIP forum action code. Currently disabled. Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
2021-04-07 14:23:11 +00:00
func (t *Topic) Unlock() (e error) {
2022-02-21 03:32:53 +00:00
_, e = topicStmts.unlock.Exec(t.ID)
t.cacheRemove()
return e
}
WIP forum action code. Currently disabled. Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
2021-04-07 14:23:11 +00:00
func (t *Topic) MoveTo(destForum int) (e error) {
2022-02-21 03:32:53 +00:00
_, e = topicStmts.moveTo.Exec(destForum, t.ID)
t.cacheRemove()
if e != nil {
return e
}
e = Attachments.MoveTo(destForum, t.ID, "topics")
if e != nil {
return e
}
return Attachments.MoveToByExtra(destForum, "replies", strconv.Itoa(t.ID))
}
WIP forum action code. Currently disabled. Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
2021-04-07 14:23:11 +00:00
func (t *Topic) TestSetCreatedAt(s time.Time) (e error) {
2022-02-21 03:32:53 +00:00
_, e = topicStmts.testSetCreatedAt.Exec(s, t.ID)
t.cacheRemove()
return e
WIP forum action code. Currently disabled. Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
2021-04-07 14:23:11 +00:00
}
// TODO: We might want more consistent terminology rather than using stick in some places and pin in others. If you don't understand the difference, there is none, they are one and the same.
WIP forum action code. Currently disabled. Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
2021-04-07 14:23:11 +00:00
func (t *Topic) Stick() (e error) {
2022-02-21 03:32:53 +00:00
_, e = topicStmts.stick.Exec(t.ID)
t.cacheRemove()
return e
}
WIP forum action code. Currently disabled. Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
2021-04-07 14:23:11 +00:00
func (t *Topic) Unstick() (e error) {
2022-02-21 03:32:53 +00:00
_, e = topicStmts.unstick.Exec(t.ID)
t.cacheRemove()
return e
}
// TODO: Test this
// TODO: Use a transaction for this
func (t *Topic) Like(score, uid int) (err error) {
2022-02-21 03:32:53 +00:00
var disp int // Unused
err = topicStmts.hasLikedTopic.QueryRow(uid, t.ID).Scan(&disp)
if err != nil && err != ErrNoRows {
return err
} else if err != ErrNoRows {
return ErrAlreadyLiked
}
_, err = topicStmts.createLike.Exec(score, t.ID, "topics", uid)
if err != nil {
return err
}
_, err = topicStmts.addLikesToTopic.Exec(1, t.ID)
if err != nil {
return err
}
_, err = userStmts.incLiked.Exec(1, uid)
t.cacheRemove()
return err
}
// TODO: Use a transaction
func (t *Topic) Unlike(uid int) error {
2022-02-21 03:32:53 +00:00
e := Likes.Delete(t.ID, "topics")
if e != nil {
return e
}
_, e = topicStmts.addLikesToTopic.Exec(-1, t.ID)
if e != nil {
return e
}
_, e = userStmts.decLiked.Exec(1, uid)
t.cacheRemove()
return e
}
func handleLikedTopicReplies(tid int) error {
2022-02-21 03:32:53 +00:00
rows, e := userStmts.getLikedRepliesOfTopic.Query(tid)
if e != nil {
return e
}
defer rows.Close()
for rows.Next() {
var rid int
if e := rows.Scan(&rid); e != nil {
return e
}
_, e = replyStmts.deleteLikesForReply.Exec(rid)
if e != nil {
return e
}
e = Activity.DeleteByParams("like", rid, "post")
if e != nil {
return e
}
}
return rows.Err()
}
func handleTopicAttachments(tid int) error {
2022-02-21 03:32:53 +00:00
e := handleAttachments(userStmts.getAttachmentsOfTopic, tid)
if e != nil {
return e
}
return handleAttachments(userStmts.getAttachmentsOfTopic2, tid)
}
func handleReplyAttachments(rid int) error {
2022-02-21 03:32:53 +00:00
return handleAttachments(replyStmts.getAidsOfReply, rid)
}
func handleAttachments(stmt *sql.Stmt, id int) error {
2022-02-21 03:32:53 +00:00
rows, e := stmt.Query(id)
if e != nil {
return e
}
defer rows.Close()
for rows.Next() {
var aid int
if e := rows.Scan(&aid); e != nil {
return e
}
a, e := Attachments.FGet(aid)
if e != nil {
return e
}
e = deleteAttachment(a)
if e != nil && e != sql.ErrNoRows {
return e
}
}
return rows.Err()
}
// TODO: Only load a row per createdBy, maybe with group by?
func handleTopicReplies(umap map[int]struct{}, uid, tid int) error {
2022-02-21 03:32:53 +00:00
rows, e := userStmts.getRepliesOfTopic.Query(uid, tid)
if e != nil {
return e
}
defer rows.Close()
var createdBy int
for rows.Next() {
if e := rows.Scan(&createdBy); e != nil {
return e
}
umap[createdBy] = struct{}{}
}
return rows.Err()
}
// TODO: Use a transaction here
func (t *Topic) Delete() error {
2022-02-21 03:32:53 +00:00
/*creator, e := Users.Get(t.CreatedBy)
if e == nil {
e = creator.DecreasePostStats(WordCount(t.Content), true)
if e != nil {
return e
}
} else if e != ErrNoRows {
return e
}*/
// TODO: Clear reply cache too
_, e := topicStmts.delete.Exec(t.ID)
t.cacheRemove()
if e != nil {
return e
}
e = Forums.RemoveTopic(t.ParentID)
if e != nil && e != ErrNoRows {
return e
}
_, e = topicStmts.deleteLikesForTopic.Exec(t.ID)
if e != nil {
return e
}
if t.PostCount > 1 {
if e = handleLikedTopicReplies(t.ID); e != nil {
return e
}
umap := make(map[int]struct{})
e = handleTopicReplies(umap, t.CreatedBy, t.ID)
if e != nil {
return e
}
_, e = topicStmts.deleteReplies.Exec(t.ID)
if e != nil {
return e
}
for uid := range umap {
e = (&User{ID: uid}).RecalcPostStats()
if e != nil {
//log.Printf("e: %+v\n", e)
return e
}
}
}
e = (&User{ID: t.CreatedBy}).RecalcPostStats()
if e != nil {
return e
}
e = handleTopicAttachments(t.ID)
if e != nil {
return e
}
e = Subscriptions.DeleteResource(t.ID, "topic")
if e != nil {
return e
}
_, e = topicStmts.deleteActivity.Exec(t.ID)
if e != nil {
return e
}
if t.Poll > 0 {
e = (&Poll{ID: t.Poll}).Delete()
if e != nil {
return e
}
}
return nil
}
2017-12-30 10:07:57 +00:00
// TODO: Write tests for this
func (t *Topic) Update(name, content string) error {
2022-02-21 03:32:53 +00:00
name = SanitiseSingleLine(html.UnescapeString(name))
if name == "" {
return ErrNoTitle
}
// ? This number might be a little screwy with Unicode, but it's the only consistent thing we have, as Unicode characters can be any number of bytes in theory?
if len(name) > Config.MaxTopicTitleLength {
return ErrLongTitle
}
content = PreparseMessage(html.UnescapeString(content))
parsedContent := ParseMessage(content, t.ParentID, "forums", nil, nil)
_, err := topicStmts.edit.Exec(name, content, parsedContent, t.ID)
t.cacheRemove()
return err
}
func (t *Topic) SetPoll(pollID int) error {
2022-02-21 03:32:53 +00:00
_, e := topicStmts.setPoll.Exec(pollID, t.ID) // TODO: Sniff if this changed anything to see if we hit an existing poll
t.cacheRemove()
return e
}
func (t *Topic) RemovePoll() error {
2022-02-21 03:32:53 +00:00
_, e := topicStmts.removePoll.Exec(t.ID) // TODO: Sniff if this changed anything to see if we hit an existing poll
t.cacheRemove()
return e
}
// TODO: Have this go through the ReplyStore?
// TODO: Return the rid?
func (t *Topic) CreateActionReply(action, ip string, uid int) (err error) {
2022-02-21 03:32:53 +00:00
if Config.DisablePostIP {
ip = ""
}
res, err := topicStmts.createAction.Exec(t.ID, action, ip, uid)
if err != nil {
return err
}
_, err = topicStmts.addReplies.Exec(1, uid, t.ID)
if err != nil {
return err
}
lid, err := res.LastInsertId()
if err != nil {
return err
}
rid := int(lid)
_, err = topicStmts.updateLastReply.Exec(rid, rid, t.ID)
t.cacheRemove()
// ? - Update the last topic cache for the parent forum?
return err
}
WIP forum action code. Currently disabled. Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
2021-04-07 14:23:11 +00:00
func GetRidsForTopic(tid, offset int) (rids []int, e error) {
2022-02-21 03:32:53 +00:00
rows, e := topicStmts.getRids.Query(tid, offset, Config.ItemsPerPage)
if e != nil {
return nil, e
}
defer rows.Close()
var rid int
for rows.Next() {
if e := rows.Scan(&rid); e != nil {
return nil, e
}
rids = append(rids, rid)
}
return rids, rows.Err()
}
var aipost = ";&#xFE0E"
var lockai = "&#x1F512" + aipost
var unlockai = "&#x1F513"
var stickai = "&#x1F4CC"
var unstickai = "&#x1F4CC" + aipost
func (ru *ReplyUser) Init(u *User) (group *Group, err error) {
2022-02-21 03:32:53 +00:00
ru.ContentLines = strings.Count(ru.Content, "\n")
postGroup, err := Groups.Get(ru.Group)
if err != nil {
return nil, err
}
if postGroup.IsMod {
ru.ClassName = Config.StaffCSS
}
ru.Tag = postGroup.Tag
if u.ID != ru.CreatedBy {
ru.UserLink = BuildProfileURL(NameToSlug(ru.CreatedByName), ru.CreatedBy)
// TODO: Make a function for this? Build a more sophisticated noavatar handling system? Do bulk user loads and let the c.UserStore initialise this?
ru.Avatar, ru.MicroAvatar = BuildAvatar(ru.CreatedBy, ru.Avatar)
} else {
ru.UserLink = u.Link
ru.Avatar, ru.MicroAvatar = u.Avatar, u.MicroAvatar
}
// We really shouldn't have inline HTML, we should do something about this...
if ru.ActionType != "" {
aarr := strings.Split(ru.ActionType, "-")
action := aarr[0]
switch action {
case "lock":
ru.ActionIcon = lockai
case "unlock":
ru.ActionIcon = unlockai
case "stick":
ru.ActionIcon = stickai
case "unstick":
ru.ActionIcon = unstickai
case "move":
if len(aarr) == 2 {
fid, _ := strconv.Atoi(aarr[1])
forum, err := Forums.Get(fid)
if err == nil {
ru.ActionType = p.GetTmplPhrasef("topic.action_topic_move_dest", forum.Link, forum.Name, ru.UserLink, ru.CreatedByName)
return postGroup, nil
}
}
default:
// TODO: Only fire this off if a corresponding phrase for the ActionType doesn't exist? Or maybe have some sort of action registry?
ru.ActionType = p.GetTmplPhrasef("topic.action_topic_default", ru.ActionType)
return postGroup, nil
}
ru.ActionType = p.GetTmplPhrasef("topic.action_topic_"+action, ru.UserLink, ru.CreatedByName)
}
return postGroup, nil
}
func (ru *ReplyUser) Init2() (group *Group, err error) {
2022-02-21 03:32:53 +00:00
//ru.UserLink = BuildProfileURL(NameToSlug(ru.CreatedByName), ru.CreatedBy)
ru.ContentLines = strings.Count(ru.Content, "\n")
postGroup, err := Groups.Get(ru.Group)
if err != nil {
return postGroup, err
}
if postGroup.IsMod {
ru.ClassName = Config.StaffCSS
}
ru.Tag = postGroup.Tag
// We really shouldn't have inline HTML, we should do something about this...
if ru.ActionType != "" {
aarr := strings.Split(ru.ActionType, "-")
action := aarr[0]
switch action {
case "lock":
ru.ActionIcon = lockai
case "unlock":
ru.ActionIcon = unlockai
case "stick":
ru.ActionIcon = stickai
case "unstick":
ru.ActionIcon = unstickai
case "move":
if len(aarr) == 2 {
fid, _ := strconv.Atoi(aarr[1])
forum, err := Forums.Get(fid)
if err == nil {
ru.ActionType = p.GetTmplPhrasef("topic.action_topic_move_dest", forum.Link, forum.Name, ru.UserLink, ru.CreatedByName)
return postGroup, nil
}
}
default:
// TODO: Only fire this off if a corresponding phrase for the ActionType doesn't exist? Or maybe have some sort of action registry?
ru.ActionType = p.GetTmplPhrasef("topic.action_topic_default", ru.ActionType)
return postGroup, nil
}
ru.ActionType = p.GetTmplPhrasef("topic.action_topic_"+action, ru.UserLink, ru.CreatedByName)
}
return postGroup, nil
}
func (ru *ReplyUser) Init3(u *User, tu *TopicUser) (group *Group, err error) {
2022-02-21 03:32:53 +00:00
ru.ContentLines = strings.Count(ru.Content, "\n")
postGroup, err := Groups.Get(ru.Group)
if err != nil {
return postGroup, err
}
if postGroup.IsMod {
ru.ClassName = Config.StaffCSS
}
ru.Tag = postGroup.Tag
if u.ID == ru.CreatedBy {
ru.UserLink = u.Link
ru.Avatar, ru.MicroAvatar = u.Avatar, u.MicroAvatar
} else if tu.CreatedBy == ru.CreatedBy {
ru.UserLink = tu.UserLink
ru.Avatar, ru.MicroAvatar = tu.Avatar, tu.MicroAvatar
} else {
ru.UserLink = BuildProfileURL(NameToSlug(ru.CreatedByName), ru.CreatedBy)
// TODO: Make a function for this? Build a more sophisticated noavatar handling system? Do bulk user loads and let the c.UserStore initialise this?
ru.Avatar, ru.MicroAvatar = BuildAvatar(ru.CreatedBy, ru.Avatar)
}
// We really shouldn't have inline HTML, we should do something about this...
if ru.ActionType != "" {
aarr := strings.Split(ru.ActionType, "-")
action := aarr[0]
switch action {
case "lock":
ru.ActionIcon = lockai
action = "topic.action_topic_lock"
case "unlock":
ru.ActionIcon = unlockai
action = "topic.action_topic_unlock"
case "stick":
ru.ActionIcon = stickai
action = "topic.action_topic_stick"
case "unstick":
ru.ActionIcon = unstickai
action = "topic.action_topic_unstick"
case "move":
if len(aarr) == 2 {
fid, _ := strconv.Atoi(aarr[1])
forum, err := Forums.Get(fid)
if err == nil {
ru.ActionType = p.GetTmplPhrasef("topic.action_topic_move_dest", forum.Link, forum.Name, ru.UserLink, ru.CreatedByName)
return postGroup, nil
}
}
default:
// TODO: Only fire this off if a corresponding phrase for the ActionType doesn't exist? Or maybe have some sort of action registry?
ru.ActionType = p.GetTmplPhrasef("topic.action_topic_default", ru.ActionType)
return postGroup, nil
}
ru.ActionType = p.GetTmplPhrasef(action, ru.UserLink, ru.CreatedByName)
}
return postGroup, nil
}
// TODO: Factor TopicUser into a *Topic and *User, as this starting to become overly complicated x.x
func (t *TopicUser) Replies(offset int /*pFrag int, */, user *User) (rlist []*ReplyUser /*, ogdesc string*/, externalHead bool, err error) {
2022-02-21 03:32:53 +00:00
var likedMap, attachMap map[int]int
var likedQueryList, attachQueryList []int
var rid int
if len(t.Rids) > 0 {
//log.Print("have rid")
rid = t.Rids[0]
}
re, err := Rstore.GetCache().Get(rid)
ucache := Users.GetCache()
var ruser *User
if ucache != nil {
//log.Print("ucache step")
if err == nil {
ruser = ucache.Getn(re.CreatedBy)
} else if t.PostCount == 2 {
ruser = ucache.Getn(t.LastReplyBy)
}
}
hTbl := GetHookTable()
rf := func(r *ReplyUser) (err error) {
//log.Printf("before r: %+v\n", r)
postGroup, err := r.Init3(user, t)
if err != nil {
return err
}
//log.Printf("after r: %+v\n", r)
var parseSettings *ParseSettings
if (Config.NoEmbed || !postGroup.Perms.AutoEmbed) && (user.ParseSettings == nil || !user.ParseSettings.NoEmbed) {
parseSettings = DefaultParseSettings.CopyPtr()
parseSettings.NoEmbed = true
} else {
parseSettings = user.ParseSettings
}
/*if user.ParseSettings == nil {
parseSettings = DefaultParseSettings.CopyPtr()
parseSettings.NoEmbed = Config.NoEmbed || !postGroup.Perms.AutoEmbed
parseSettings.NoLink = !postGroup.Perms.AutoLink
} else {
parseSettings = user.ParseSettings
}*/
var eh bool
r.ContentHtml, eh = ParseMessage2(r.Content, t.ParentID, "forums", parseSettings, user)
if eh {
externalHead = true
}
// TODO: Do this more efficiently by avoiding the allocations entirely in ParseMessage, if there's nothing to do.
if r.ContentHtml == r.Content {
r.ContentHtml = r.Content
}
r.Deletable = user.Perms.DeleteReply || r.CreatedBy == user.ID
// TODO: This doesn't work properly so pick the first one instead?
/*if r.ID == pFrag {
ogdesc = r.Content
if len(ogdesc) > 200 {
ogdesc = ogdesc[:197] + "..."
}
}*/
return nil
}
rf3 := func(r *ReplyUser) error {
//log.Printf("before r: %+v\n", r)
postGroup, err := r.Init2()
if err != nil {
return err
}
var parseSettings *ParseSettings
if (Config.NoEmbed || !postGroup.Perms.AutoEmbed) && (user.ParseSettings == nil || !user.ParseSettings.NoEmbed) {
parseSettings = DefaultParseSettings.CopyPtr()
parseSettings.NoEmbed = true
} else {
parseSettings = user.ParseSettings
}
var eh bool
r.ContentHtml, eh = ParseMessage2(r.Content, t.ParentID, "forums", parseSettings, user)
if eh {
externalHead = true
}
// TODO: Do this more efficiently by avoiding the allocations entirely in ParseMessage, if there's nothing to do.
if r.ContentHtml == r.Content {
r.ContentHtml = r.Content
}
r.Deletable = user.Perms.DeleteReply || r.CreatedBy == user.ID
return nil
}
// TODO: Factor the user fields out and embed a user struct instead
if err == nil && ruser != nil {
//log.Print("reply cached serve")
r := &ReplyUser{ /*ClassName: "", */ Reply: *re, CreatedByName: ruser.Name, UserLink: ruser.Link, Avatar: ruser.Avatar, MicroAvatar: ruser.MicroAvatar /*URLPrefix: ruser.URLPrefix, URLName: ruser.URLName, */, Group: ruser.Group, Level: ruser.Level, Tag: ruser.Tag}
if err = rf3(r); err != nil {
return nil, externalHead, err
}
if r.LikeCount > 0 && user.Liked > 0 {
likedMap = map[int]int{r.ID: 0}
likedQueryList = []int{r.ID}
}
if user.Perms.EditReply && r.AttachCount > 0 {
if likedMap == nil {
attachMap = map[int]int{r.ID: 0}
attachQueryList = []int{r.ID}
} else {
attachMap = likedMap
attachQueryList = likedQueryList
}
}
H_topic_reply_row_assign_hook(hTbl, r)
// TODO: Use a pointer instead to make it easier to abstract this loop? What impact would this have on escape analysis?
rlist = []*ReplyUser{r}
//log.Printf("r: %d-%d", r.ID, len(rlist)-1)
} else {
//log.Print("reply query serve")
ap1 := func(r *ReplyUser) {
H_topic_reply_row_assign_hook(hTbl, r)
// TODO: Use a pointer instead to make it easier to abstract this loop? What impact would this have on escape analysis?
rlist = append(rlist, r)
//log.Printf("r: %d-%d", r.ID, len(rlist)-1)
}
rf2 := func(r *ReplyUser) {
if r.LikeCount > 0 && user.Liked > 0 {
if likedMap == nil {
likedMap = map[int]int{r.ID: len(rlist)}
likedQueryList = []int{r.ID}
} else {
likedMap[r.ID] = len(rlist)
likedQueryList = append(likedQueryList, r.ID)
}
}
if user.Perms.EditReply && r.AttachCount > 0 {
if attachMap == nil {
attachMap = map[int]int{r.ID: len(rlist)}
attachQueryList = []int{r.ID}
} else {
attachMap[r.ID] = len(rlist)
attachQueryList = append(attachQueryList, r.ID)
}
}
}
if !user.Perms.ViewIPs && ruser != nil {
rows, e := topicStmts.getReplies3.Query(t.ID, offset, Config.ItemsPerPage)
if err != nil {
return nil, externalHead, e
}
defer rows.Close()
for rows.Next() {
r := &ReplyUser{Avatar: ruser.Avatar, MicroAvatar: ruser.MicroAvatar, UserLink: ruser.Link, CreatedByName: ruser.Name, Group: ruser.Group, Level: ruser.Level}
e := rows.Scan(&r.ID, &r.Content, &r.CreatedBy, &r.CreatedAt, &r.LastEdit, &r.LastEditBy, &r.LikeCount, &r.AttachCount, &r.ActionType)
if e != nil {
return nil, externalHead, e
}
if e = rf3(r); e != nil {
return nil, externalHead, e
}
rf2(r)
ap1(r)
}
if e = rows.Err(); e != nil {
return nil, externalHead, e
}
} else if user.Perms.ViewIPs {
rows, err := topicStmts.getReplies.Query(t.ID, offset, Config.ItemsPerPage)
if err != nil {
return nil, externalHead, err
}
defer rows.Close()
for rows.Next() {
r := &ReplyUser{}
err := rows.Scan(&r.ID, &r.Content, &r.CreatedBy, &r.CreatedAt, &r.LastEdit, &r.LastEditBy, &r.Avatar, &r.CreatedByName, &r.Group /*&r.URLPrefix, &r.URLName,*/, &r.Level, &r.IP, &r.LikeCount, &r.AttachCount, &r.ActionType)
if err != nil {
return nil, externalHead, err
}
if err = rf(r); err != nil {
return nil, externalHead, err
}
rf2(r)
ap1(r)
}
if err = rows.Err(); err != nil {
return nil, externalHead, err
}
} else if t.PostCount >= 20 {
//log.Print("t.PostCount >= 20")
rows, err := topicStmts.getReplies3.Query(t.ID, offset, Config.ItemsPerPage)
if err != nil {
return nil, externalHead, err
}
defer rows.Close()
reqUserList := make(map[int]bool)
for rows.Next() {
r := &ReplyUser{}
err := rows.Scan(&r.ID, &r.Content, &r.CreatedBy, &r.CreatedAt, &r.LastEdit, &r.LastEditBy /*&r.URLPrefix, &r.URLName,*/, &r.LikeCount, &r.AttachCount, &r.ActionType)
if err != nil {
return nil, externalHead, err
}
if r.CreatedBy != t.CreatedBy && r.CreatedBy != user.ID {
reqUserList[r.CreatedBy] = true
}
ap1(r)
}
if err = rows.Err(); err != nil {
return nil, externalHead, err
}
if len(reqUserList) == 1 {
//log.Print("len(reqUserList) == 1: ", len(reqUserList) == 1)
var uitem *User
for uid, _ := range reqUserList {
uitem, err = Users.Get(uid)
if err != nil {
return nil, externalHead, nil // TODO: Implement this!
}
}
for _, r := range rlist {
if r.CreatedBy == t.CreatedBy {
r.CreatedByName = t.CreatedByName
r.Avatar = t.Avatar
r.MicroAvatar = t.MicroAvatar
r.Group = t.Group
r.Level = t.Level
} else {
var u *User
if r.CreatedBy == user.ID {
u = user
} else {
u = uitem
}
r.CreatedByName = u.Name
r.Avatar = u.Avatar
r.MicroAvatar = u.MicroAvatar
r.Group = u.Group
r.Level = u.Level
}
if err = rf(r); err != nil {
return nil, externalHead, err
}
rf2(r)
}
} else {
//log.Print("len(reqUserList) != 1: ", len(reqUserList) != 1)
var userList map[int]*User
if len(reqUserList) > 0 {
//log.Print("len(reqUserList) > 0: ", len(reqUserList) > 0)
// Convert the user ID map to a slice, then bulk load the users
idSlice := make([]int, len(reqUserList))
var i int
for userID := range reqUserList {
idSlice[i] = userID
i++
}
userList, err = Users.BulkGetMap(idSlice)
if err != nil {
return nil, externalHead, nil // TODO: Implement this!
}
}
for _, r := range rlist {
if r.CreatedBy == t.CreatedBy {
r.CreatedByName = t.CreatedByName
r.Avatar = t.Avatar
r.MicroAvatar = t.MicroAvatar
r.Group = t.Group
r.Level = t.Level
} else {
var u *User
if r.CreatedBy == user.ID {
u = user
} else {
u = userList[r.CreatedBy]
}
r.CreatedByName = u.Name
r.Avatar = u.Avatar
r.MicroAvatar = u.MicroAvatar
r.Group = u.Group
r.Level = u.Level
}
if err = rf(r); err != nil {
return nil, externalHead, err
}
rf2(r)
}
}
} else {
//log.Print("reply fallback")
rows, err := topicStmts.getReplies2.Query(t.ID, offset, Config.ItemsPerPage)
if err != nil {
return nil, externalHead, err
}
defer rows.Close()
for rows.Next() {
r := &ReplyUser{}
err := rows.Scan(&r.ID, &r.Content, &r.CreatedBy, &r.CreatedAt, &r.LastEdit, &r.LastEditBy, &r.Avatar, &r.CreatedByName, &r.Group /*&r.URLPrefix, &r.URLName,*/, &r.Level, &r.LikeCount, &r.AttachCount, &r.ActionType)
if err != nil {
return nil, externalHead, err
}
if err = rf(r); err != nil {
return nil, externalHead, err
}
rf2(r)
ap1(r)
}
if err = rows.Err(); err != nil {
return nil, externalHead, err
}
}
}
// TODO: Add a config setting to disable the liked query for a burst of extra speed
if user.Liked > 0 && len(likedQueryList) > 0 /*&& user.LastLiked <= time.Now()*/ {
e := Likes.BulkExistsFunc(likedQueryList, user.ID, "replies", func(eid int) error {
rlist[likedMap[eid]].Liked = true
return nil
})
if e != nil {
return nil, externalHead, e
}
}
if user.Perms.EditReply && len(attachQueryList) > 0 {
//log.Printf("attachQueryList: %+v\n", attachQueryList)
amap, err := Attachments.BulkMiniGetList("replies", attachQueryList)
if err != nil && err != sql.ErrNoRows {
return nil, externalHead, err
}
//log.Printf("amap: %+v\n", amap)
//log.Printf("attachMap: %+v\n", attachMap)
for id, attach := range amap {
//log.Print("id:", id)
rlist[attachMap[id]].Attachments = attach
/*for _, a := range attach {
log.Printf("a: %+v\n", a)
}*/
}
}
//hTbl.VhookNoRet("topic_reply_end", &rlist)
return rlist, externalHead, nil
}
// TODO: Test this
func (t *Topic) Author() (*User, error) {
2022-02-21 03:32:53 +00:00
return Users.Get(t.CreatedBy)
}
func (t *Topic) GetID() int {
2022-02-21 03:32:53 +00:00
return t.ID
}
func (t *Topic) GetTable() string {
2022-02-21 03:32:53 +00:00
return "topics"
}
// Copy gives you a non-pointer concurrency safe copy of the topic
func (t *Topic) Copy() Topic {
2022-02-21 03:32:53 +00:00
return *t
}
You can now manage the attachments for an opening post by hitting edit. The update system now uses the database as the source of truth for the last version rather than lastSchema.json Refactored several structs and bits of code, so we can avoid allocations for contexts where we never use a relative time. Clicking on the relative times on the topic list and the forum page should now take you to the post on the last page rather than just the last page. Added the reltime template function. Fixed some obsolete bits of code. Fixed some spelling mistakes. Fixed a bug where MaxBytesReader was capped at the maxFileSize rather than r.ContentLength. All of the client side templates should work again now. Shortened some statement names to save some horizontal space. accUpdateBuilder and SimpleUpdate now use updatePrebuilder behind the scenes to simplify things. Renamed selectItem to builder in AccSelectBuilder. Added a Total() method to accCountBuilder to reduce the amount of boilerplate used for row count queries. The "_builder" strings have been replaced with empty strings to help save memory, to make things slightly faster and to open the door to removing the query name in many contexts down the line. Added the open_edit and close_edit client hooks. Removed many query name checks. Split the attachment logic into separate functions and de-duplicated it between replies and topics. Improved the UI for editing topics in Nox. Used type aliases to reduce the amount of boilerplate in tables.go and patches.go Reduced the amount of boilerplate in the action post logic. Eliminated a map and a slice in the topic page for users who haven't given any likes. E.g. Guests. Fixed some long out-dated parts of the update instructions. Updated the update instructions to remove mention of the obsolete lastSchema.json Fixed a bug in init.js where /api/me was being loaded for guests. Added the MiniTopicGet, GlobalCount and CountInTopic methods to AttachmentStore. Added the MiniAttachment struct. Split the mod floaters out into their own template to reduce duplication. Removed a couple of redundant ParseForms. Added the common.skipUntilIfExistsOrLine function. Added the NotFoundJS and NotFoundJSQ functions. Added the lastReplyID and attachCount columns to the topics table.
2018-12-27 05:42:41 +00:00
// TODO: Load LastReplyAt and LastReplyID?
func TopicByReplyID(rid int) (*Topic, error) {
2022-02-21 03:32:53 +00:00
t := Topic{ID: 0}
err := topicStmts.getByReplyID.QueryRow(rid).Scan(&t.ID, &t.Title, &t.Content, &t.CreatedBy, &t.CreatedAt, &t.IsClosed, &t.Sticky, &t.ParentID, &t.IP, &t.ViewCount, &t.PostCount, &t.LikeCount, &t.Poll, &t.Data)
t.Link = BuildTopicURL(NameToSlug(t.Title), t.ID)
return &t, err
}
// TODO: Refactor the caller to take a Topic and a User rather than a combined TopicUser
Almost finished live topic lists, you can find them at /topics/. You can disable them via config.json The topic list cache can handle more groups now, but don't go too crazy with groups (e.g. thousands of them). Make the suspicious request logs more descriptive. Added the phrases API endpoint. Split the template phrases up by prefix, more work on this coming up. Removed #dash_saved and part of #dash_username. Removed some temporary artifacts from trying to implement FA5 in Nox. Removed some commented CSS. Fixed template artifact deletion on Windows. Tweaked HTTPSRedirect to make it more compact. Fixed NullUserCache not complying with the expectations for BulkGet. Swapped out a few RunVhook calls for more appropriate RunVhookNoreturn calls. Removed a few redundant IsAdmin checks when IsMod would suffice. Commented out a few pushers. Desktop notification permission requests are no longer served to guests. Split topics.html into topics.html and topics_topic.html RunThemeTemplate should now fallback to interpreted templates properly when the transpiled variants aren't avaialb.e Changed TopicsRow.CreatedAt from a string to a time.Time Added SkipTmplPtrMap to CTemplateConfig. Added SetBuildTags to CTemplateSet. A bit more data is dumped when something goes wrong while transpiling templates now. topics_topic, topic_posts, and topic_alt_posts are now transpiled for the client, although not all of them are ready to be served to the client yet. Client rendered templates now support phrases. Client rendered templates now support loops. Fixed loadAlerts in global.js Refactored some of the template initialisation code to make it less repetitive. Split topic.html into topic.html and topic_posts.html Split topic_alt.html into topic_alt.html and topic_alt_posts.html Added comments for PollCache. Fixed a data race in the MemoryPollCache. The writer is now closed properly in WsHubImpl.broadcastMessage. Fixed a potential deadlock in WsHubImpl.broadcastMessage. Removed some old commented code in websockets.go Added the DisableLiveTopicList config setting.
2018-06-24 13:49:29 +00:00
// TODO: Load LastReplyAt everywhere in here?
func GetTopicUser(user *User, tid int) (tu TopicUser, err error) {
2022-02-21 03:32:53 +00:00
tcache := Topics.GetCache()
ucache := Users.GetCache()
if tcache != nil && ucache != nil {
topic, err := tcache.Get(tid)
if err == nil {
if topic.CreatedBy != user.ID {
user, err = Users.Get(topic.CreatedBy)
if err != nil {
return TopicUser{ID: tid}, err
}
}
// We might be better off just passing separate topic and user structs to the caller?
return copyTopicToTopicUser(topic, user), nil
} else if ucache.Length() < ucache.GetCapacity() {
topic, err = Topics.Get(tid)
if err != nil {
return TopicUser{ID: tid}, err
}
if topic.CreatedBy != user.ID {
user, err = Users.Get(topic.CreatedBy)
if err != nil {
return TopicUser{ID: tid}, err
}
}
return copyTopicToTopicUser(topic, user), nil
}
}
tu = TopicUser{ID: tid}
// TODO: This misses some important bits...
err = topicStmts.getTopicUser.QueryRow(tid).Scan(&tu.Title, &tu.Content, &tu.CreatedBy, &tu.CreatedAt, &tu.LastReplyAt, &tu.LastReplyBy, &tu.LastReplyID, &tu.IsClosed, &tu.Sticky, &tu.ParentID, &tu.IP, &tu.ViewCount, &tu.PostCount, &tu.LikeCount, &tu.AttachCount, &tu.Poll, &tu.CreatedByName, &tu.Avatar, &tu.Group, &tu.Level)
tu.Avatar, tu.MicroAvatar = BuildAvatar(tu.CreatedBy, tu.Avatar)
tu.Link = BuildTopicURL(NameToSlug(tu.Title), tu.ID)
tu.UserLink = BuildProfileURL(NameToSlug(tu.CreatedByName), tu.CreatedBy)
tu.Tag = Groups.DirtyGet(tu.Group).Tag
if tcache != nil {
// TODO: weekly views
theTopic := Topic{ID: tu.ID, Link: tu.Link, Title: tu.Title, Content: tu.Content, CreatedBy: tu.CreatedBy, IsClosed: tu.IsClosed, Sticky: tu.Sticky, CreatedAt: tu.CreatedAt, LastReplyAt: tu.LastReplyAt, LastReplyID: tu.LastReplyID, ParentID: tu.ParentID, IP: tu.IP, ViewCount: tu.ViewCount, PostCount: tu.PostCount, LikeCount: tu.LikeCount, AttachCount: tu.AttachCount, Poll: tu.Poll}
//log.Printf("theTopic: %+v\n", theTopic)
_ = tcache.Set(&theTopic)
}
return tu, err
}
func copyTopicToTopicUser(t *Topic, u *User) (tu TopicUser) {
2022-02-21 03:32:53 +00:00
tu.UserLink = u.Link
tu.CreatedByName = u.Name
tu.Group = u.Group
tu.Avatar = u.Avatar
tu.MicroAvatar = u.MicroAvatar
//tu.URLPrefix = u.URLPrefix
//tu.URLName = u.URLName
tu.Level = u.Level
tu.ID = t.ID
tu.Link = t.Link
tu.Title = t.Title
tu.Content = t.Content
tu.CreatedBy = t.CreatedBy
tu.IsClosed = t.IsClosed
tu.Sticky = t.Sticky
tu.CreatedAt = t.CreatedAt
tu.LastReplyAt = t.LastReplyAt
tu.LastReplyBy = t.LastReplyBy
tu.ParentID = t.ParentID
tu.IP = t.IP
tu.ViewCount = t.ViewCount
tu.PostCount = t.PostCount
tu.LikeCount = t.LikeCount
tu.AttachCount = t.AttachCount
tu.Poll = t.Poll
tu.Data = t.Data
tu.Rids = t.Rids
return tu
}
// For use in tests and for generating blank topics for forums which don't have a last poster
func BlankTopic() *Topic {
2022-02-21 03:32:53 +00:00
return new(Topic)
}
func BuildTopicURL(slug string, tid int) string {
2022-02-21 03:32:53 +00:00
if slug == "" || !Config.BuildSlugs {
return "/topic/" + strconv.Itoa(tid)
}
return "/topic/" + slug + "." + strconv.Itoa(tid)
}
Added the Social Groups plugin. This is still under construction. Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places. The auth interface now handles all the authentication stuff. Renamed the debug config variable to debug_mode. Added the PluginPerms API. Internal Errors will now dump the stack trace in the console. Added support for installable plugins. Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/) Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems. Added the same CreateTable method to the query builder. Began work on PostgreSQL support. Added the string-string hook type Added the pre_render hook type. Added the ParentID and ParentType fields to forums. Added the get_forum_url_prefix function. Added a more generic build_slug function. Added the get_topic_url_prefix function. Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions. Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there. Plugins can now see the router instance. The plugin initialisation handlers can now throw errors. Plugins are now initialised after all the forum's subsystems are. Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases. Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code. Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start. Fixed an issue with forum creation where the forum permissions didn't get cached. Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora. Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests. Revamped the phrase system to make it easier for us to add language pack related features in the future. Added the WidgetMenu widget type. Revamped the theme again. I'm experimenting to see which approach I like most. - Excuse the little W3C rage. Some things about CSS drive me crazy :p Tests: Added 22 bbcode_full_parse tests. Added 19 bbcode_regex_parse tests. Added 27 markdown_parse tests. Added four UserStore tests. More to come when the test database functionality is added. Added 18 name_to_slug tests. Hooks: Added the pre_render hook. Added the pre_render_forum_list hook. Added the pre_render_view_forum hook. Added the pre_render_topic_list hook. Added the pre_render_view_topic hook. Added the pre_render_profile hook. Added the pre_render_custom_page hook. Added the pre_render_overview hook. Added the pre_render_create_topic hook. Added the pre_render_account_own_edit_critical hook. Added the pre_render_account_own_edit_avatar hook. Added the pre_render_account_own_edit_username hook. Added the pre_render_account_own_edit_email hook. Added the pre_render_login hook. Added the pre_render_register hook. Added the pre_render_ban hook. Added the pre_render_panel_dashboard hook. Added the pre_render_panel_forums hook. Added the pre_render_panel_delete_forum hook. Added the pre_render_panel_edit_forum hook. Added the pre_render_panel_settings hook. Added the pre_render_panel_setting hook. Added the pre_render_panel_plugins hook. Added the pre_render_panel_users hook. Added the pre_render_panel_edit_user hook. Added the pre_render_panel_groups hook. Added the pre_render_panel_edit_group hook. Added the pre_render_panel_edit_group_perms hook. Added the pre_render_panel_themes hook. Added the pre_render_panel_mod_log hook. Added the pre_render_error hook. Added the pre_render_security_error hook. Added the create_group_preappend hook. Added the intercept_build_widgets hook. Added the simple_forum_check_pre_perms hook. Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
func BuildTopicURLSb(sb *strings.Builder, slug string, tid int) {
2022-02-21 03:32:53 +00:00
if slug == "" || !Config.BuildSlugs {
sb.Grow(7 + 2)
sb.WriteString("/topic/")
sb.WriteString(strconv.Itoa(tid))
return
}
sb.Grow(7 + 3 + len(slug))
sb.WriteString("/topic/")
sb.WriteString(slug)
sb.WriteRune('.')
sb.WriteString(strconv.Itoa(tid))
}
// I don't care if it isn't used,, it will likely be in the future. Nolint.
// nolint
func getTopicURLPrefix() string {
2022-02-21 03:32:53 +00:00
return "/topic/"
Added the Social Groups plugin. This is still under construction. Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places. The auth interface now handles all the authentication stuff. Renamed the debug config variable to debug_mode. Added the PluginPerms API. Internal Errors will now dump the stack trace in the console. Added support for installable plugins. Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/) Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems. Added the same CreateTable method to the query builder. Began work on PostgreSQL support. Added the string-string hook type Added the pre_render hook type. Added the ParentID and ParentType fields to forums. Added the get_forum_url_prefix function. Added a more generic build_slug function. Added the get_topic_url_prefix function. Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions. Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there. Plugins can now see the router instance. The plugin initialisation handlers can now throw errors. Plugins are now initialised after all the forum's subsystems are. Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases. Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code. Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start. Fixed an issue with forum creation where the forum permissions didn't get cached. Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora. Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests. Revamped the phrase system to make it easier for us to add language pack related features in the future. Added the WidgetMenu widget type. Revamped the theme again. I'm experimenting to see which approach I like most. - Excuse the little W3C rage. Some things about CSS drive me crazy :p Tests: Added 22 bbcode_full_parse tests. Added 19 bbcode_regex_parse tests. Added 27 markdown_parse tests. Added four UserStore tests. More to come when the test database functionality is added. Added 18 name_to_slug tests. Hooks: Added the pre_render hook. Added the pre_render_forum_list hook. Added the pre_render_view_forum hook. Added the pre_render_topic_list hook. Added the pre_render_view_topic hook. Added the pre_render_profile hook. Added the pre_render_custom_page hook. Added the pre_render_overview hook. Added the pre_render_create_topic hook. Added the pre_render_account_own_edit_critical hook. Added the pre_render_account_own_edit_avatar hook. Added the pre_render_account_own_edit_username hook. Added the pre_render_account_own_edit_email hook. Added the pre_render_login hook. Added the pre_render_register hook. Added the pre_render_ban hook. Added the pre_render_panel_dashboard hook. Added the pre_render_panel_forums hook. Added the pre_render_panel_delete_forum hook. Added the pre_render_panel_edit_forum hook. Added the pre_render_panel_settings hook. Added the pre_render_panel_setting hook. Added the pre_render_panel_plugins hook. Added the pre_render_panel_users hook. Added the pre_render_panel_edit_user hook. Added the pre_render_panel_groups hook. Added the pre_render_panel_edit_group hook. Added the pre_render_panel_edit_group_perms hook. Added the pre_render_panel_themes hook. Added the pre_render_panel_mod_log hook. Added the pre_render_error hook. Added the pre_render_security_error hook. Added the create_group_preappend hook. Added the intercept_build_widgets hook. Added the simple_forum_check_pre_perms hook. Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
}