Add tabId to topic.

This commit is contained in:
Gucheng Wang 2021-12-04 10:30:25 +08:00
parent 2043bb60df
commit 6b3300d4e2
7 changed files with 32 additions and 11 deletions

View File

@ -213,8 +213,9 @@ func (c *ApiController) AddTopic() {
topic := object.Topic{
//Id: util.IntToString(object.GetTopicId()),
Author: GetUserName(user),
NodeId: nodeId,
NodeName: "",
NodeId: node.Id,
NodeName: node.Name,
TabId: node.TabId,
Title: title,
CreatedTime: util.GetCurrentTime(),
Tags: tags,
@ -583,7 +584,7 @@ func (c *ApiController) UpdateTopicNode() {
if err != nil {
panic(err)
}
id, nodeName, nodeId := form.Id, form.NodeName, form.NodeId
id, _, nodeId := form.Id, form.NodeName, form.NodeId
originalNode := object.GetTopicNodeId(id)
if !object.CheckIsAdmin(user) && !object.CheckNodeModerator(user, originalNode) && object.GetTopicAuthor(id).Name != GetUserName(user) {
@ -591,10 +592,17 @@ func (c *ApiController) UpdateTopicNode() {
return
}
node := object.GetNode(nodeId)
if node == nil {
c.ResponseError("Node does not exist.")
return
}
topic := object.Topic{
//Id: id,
NodeId: nodeId,
NodeName: nodeName,
NodeId: node.Id,
NodeName: node.Name,
TabId: node.TabId,
}
res := object.UpdateTopicWithLimitCols(id, &topic)
@ -791,6 +799,7 @@ func (c *ApiController) GetTopicByUrlPathAndTitle() {
Author: "Embed Plugin",
NodeId: nodeId,
NodeName: node.Name,
TabId: node.TabId,
Title: title,
CreatedTime: util.GetCurrentTime(),
LastReplyTime: util.GetCurrentTime(),

View File

@ -26,6 +26,7 @@ type Forum struct {
Threads int
Forums []*Forum `xorm:"-"`
Parent *Forum `xorm:"-"`
}
func getForums() []*Forum {
@ -62,7 +63,7 @@ func getForumMap() map[int]*Forum {
return m
}
func getStructuredForums() []*Forum {
func getForumTree() ([]*Forum, map[int]*Forum) {
res := []*Forum{}
forumMap := getForumMap()
@ -72,6 +73,7 @@ func getStructuredForums() []*Forum {
} else {
parentForum := forumMap[forum.Fup]
parentForum.Forums = append(parentForum.Forums, forum)
forum.Parent = parentForum
}
}
@ -96,5 +98,5 @@ func getStructuredForums() []*Forum {
}
}
return res
return res, forumMap
}

View File

@ -25,8 +25,8 @@ func addForums() {
tabs := []*object.Tab{}
nodes := []*object.Node{}
forums := getStructuredForums()
for i, groupForum := range forums {
forumTree, _ := getForumTree()
for i, groupForum := range forumTree {
tab := &object.Tab{
Id: groupForum.Name,
Name: groupForum.Name,
@ -36,7 +36,7 @@ func addForums() {
HomePage: false,
}
tabs = append(tabs, tab)
fmt.Printf("[%d/%d]: Synced group forum: %s\n", i+1, len(forums), groupForum.Name)
fmt.Printf("[%d/%d]: Synced group forum: %s\n", i+1, len(forumTree), groupForum.Name)
for j, forum := range groupForum.Forums {
forumNode := &object.Node{

View File

@ -70,7 +70,7 @@ func TestAddThreads(t *testing.T) {
attachmentMap := getAttachmentMap()
fmt.Printf("Loaded attachments: %d\n", len(attachmentMap))
forumMap := getForumMap()
_, forumMap := getForumTree()
fmt.Printf("Loaded forums: %d\n", len(forumMap))
classMap := getClassMap()
fmt.Printf("Loaded classes: %d\n", len(classMap))

View File

@ -67,8 +67,15 @@ func getTopicFromThread(thread *Thread, forum *Forum, classMap map[int]*Class) *
}
nodeName := strconv.Itoa(thread.Fid)
tabId := ""
if forum != nil {
nodeName = forum.Name
parentForum := forum.Parent
if parentForum.Parent != nil {
parentForum = parentForum.Parent
}
tabId = parentForum.Name
} else {
isHidden = true
}
@ -78,6 +85,7 @@ func getTopicFromThread(thread *Thread, forum *Forum, classMap map[int]*Class) *
Author: thread.Author,
NodeId: nodeName,
NodeName: nodeName,
TabId: tabId,
Title: thread.Subject,
CreatedTime: getTimeFromUnixSeconds(thread.Dateline),
Tags: tags,

View File

@ -64,6 +64,7 @@ func (n Node) SyncFromGoogleGroup() {
Author: AuthorMember.Id,
NodeId: n.Id,
NodeName: n.Name,
TabId: n.TabId,
Title: conv.Title,
Content: FilterUnsafeHTML(messages[0].Content),
CreatedTime: util.GetTimeFromTimestamp(int64(conv.Time)),

View File

@ -29,6 +29,7 @@ type Topic struct {
Author string `xorm:"varchar(100) index" json:"author"`
NodeId string `xorm:"varchar(100) index" json:"nodeId"`
NodeName string `xorm:"varchar(100)" json:"nodeName"`
TabId string `xorm:"varchar(100)" json:"tabId"`
Title string `xorm:"varchar(100)" json:"title"`
CreatedTime string `xorm:"varchar(40)" json:"createdTime"`
Tags []string `xorm:"varchar(200)" json:"tags"`