Show the users in a convo.

This commit is contained in:
Azareal 2019-08-21 11:31:13 +10:00
parent 0e9c459446
commit cae7e00b0c
6 changed files with 59 additions and 6 deletions

View File

@ -25,6 +25,8 @@ type ConvoStmts struct {
editPost *sql.Stmt editPost *sql.Stmt
createPost *sql.Stmt createPost *sql.Stmt
deletePost *sql.Stmt deletePost *sql.Stmt
getUsers *sql.Stmt
} }
func init() { func init() {
@ -40,6 +42,8 @@ func init() {
editPost: acc.Update("conversations_posts").Set("body = ?, post = ?").Where("pid = ?").Prepare(), editPost: acc.Update("conversations_posts").Set("body = ?, post = ?").Where("pid = ?").Prepare(),
createPost: acc.Insert("conversations_posts").Columns("cid, body, post, createdBy").Fields("?,?,?,?").Prepare(), createPost: acc.Insert("conversations_posts").Columns("cid, body, post, createdBy").Fields("?,?,?,?").Prepare(),
deletePost: acc.Delete("conversations_posts").Where("pid = ?").Prepare(), deletePost: acc.Delete("conversations_posts").Where("pid = ?").Prepare(),
getUsers: acc.Select("conversations_participants").Columns("uid").Where("cid = ?").Prepare(),
} }
return acc.FirstError() return acc.FirstError()
}) })
@ -84,6 +88,24 @@ func (co *Conversation) PostsCount() (count int) {
return count return count
} }
func (co *Conversation) Uids() (ids []int, err error) {
rows, err := convoStmts.getUsers.Query(co.ID)
if err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var id int
err := rows.Scan(&id)
if err != nil {
return nil, err
}
ids = append(ids, id)
}
return ids, rows.Err()
}
func (co *Conversation) Has(uid int) (in bool) { func (co *Conversation) Has(uid int) (in bool) {
var count int var count int
err := convoStmts.has.QueryRow(uid, co.ID).Scan(&count) err := convoStmts.has.QueryRow(uid, co.ID).Scan(&count)

View File

@ -282,6 +282,7 @@ type ConvoViewPage struct {
*Header *Header
Convo *Conversation Convo *Conversation
Posts []ConvoViewRow Posts []ConvoViewRow
Users []*User
Paginator Paginator
} }

View File

@ -348,9 +348,10 @@ func compileTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName string
accountPage := Account{header, "dashboard", "account_own_edit", inter} accountPage := Account{header, "dashboard", "account_own_edit", inter}
tmpls.AddStd("account", "c.Account", accountPage) tmpls.AddStd("account", "c.Account", accountPage)
parti := []*User{&user}
convo := &Conversation{1,user.ID,time.Now(),0,time.Now()} convo := &Conversation{1,user.ID,time.Now(),0,time.Now()}
convoItems := []ConvoViewRow{ConvoViewRow{&ConversationPost{1,1,"hey","",user.ID}, &user, "", 4, true}} convoItems := []ConvoViewRow{ConvoViewRow{&ConversationPost{1,1,"hey","",user.ID}, &user, "", 4, true}}
convoPage := ConvoViewPage{header, convo, convoItems, Paginator{[]int{1}, 1, 1}} convoPage := ConvoViewPage{header, convo, convoItems, parti, Paginator{[]int{1}, 1, 1}}
tmpls.AddStd("convo", "c.ConvoViewPage", convoPage) tmpls.AddStd("convo", "c.ConvoViewPage", convoPage)
basePage := &BasePanelPage{header, PanelStats{}, "dashboard", ReportForumID} basePage := &BasePanelPage{header, PanelStats{}, "dashboard", ReportForumID}

View File

@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"errors"
c "github.com/Azareal/Gosora/common" c "github.com/Azareal/Gosora/common"
p "github.com/Azareal/Gosora/common/phrases" p "github.com/Azareal/Gosora/common/phrases"
@ -61,17 +62,36 @@ func Convo(w http.ResponseWriter, r *http.Request, user c.User, header *c.Header
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
uids, err := convo.Uids()
if err == sql.ErrNoRows {
return c.NotFound(w, r, header)
} else if err != nil {
return c.InternalError(err, w, r)
}
umap, err := c.Users.BulkGetMap(uids)
if err == sql.ErrNoRows {
return c.NotFound(w, r, header)
} else if err != nil {
return c.InternalError(err, w, r)
}
users := make([]*c.User,len(umap))
i := 0
for _, user := range umap {
users[i] = user
i++
}
pitems := make([]c.ConvoViewRow, len(posts)) pitems := make([]c.ConvoViewRow, len(posts))
for i, post := range posts { for i, post := range posts {
uuser, err := c.Users.Get(post.CreatedBy) uuser, ok := umap[post.CreatedBy]
if err != nil { if !ok {
return c.InternalError(err, w, r) return c.InternalError(errors.New("convo post creator not in umap"), w, r)
} }
canModify := user.ID == post.CreatedBy || user.IsSuperMod canModify := user.ID == post.CreatedBy || user.IsSuperMod
pitems[i] = c.ConvoViewRow{post, uuser, "", 4, canModify} pitems[i] = c.ConvoViewRow{post, uuser, "", 4, canModify}
} }
pi := c.Account{header, "dashboard", "convo", c.ConvoViewPage{header, convo, pitems, c.Paginator{pageList, page, lastPage}}} pi := c.Account{header, "dashboard", "convo", c.ConvoViewPage{header, convo, pitems, users, c.Paginator{pageList, page, lastPage}}}
return renderTemplate("account", w, r, header, pi) return renderTemplate("account", w, r, header, pi)
} }

View File

@ -4,7 +4,10 @@
</div> </div>
</div> </div>
<div class="colstack_item parti"> <div class="colstack_item parti">
<div class="rowitem">Participants: Blah, Blah 2, Blah 3</div> <div class="rowitem">
<div>Participants:&nbsp;</div>
{{range .Users}}<div class="parti_user"><a href="{{.Link}}">{{.Name}}</a></div>&nbsp;{{end}}
</div>
</div> </div>
<div class="colstack_item">{{template "convo_row.html" .}}</div> <div class="colstack_item">{{template "convo_row.html" .}}</div>
{{if not .CurrentUser.IsBanned}} {{if not .CurrentUser.IsBanned}}

View File

@ -1,6 +1,12 @@
.parti { .parti {
margin-bottom: 8px; margin-bottom: 8px;
} }
.parti .rowitem {
display: flex;
}
.parti_user:not(:last-child):after {
content: ",";
}
.rowitem .topRow { .rowitem .topRow {
display: flex; display: flex;