Show the users in a convo.
This commit is contained in:
parent
0e9c459446
commit
cae7e00b0c
|
@ -25,6 +25,8 @@ type ConvoStmts struct {
|
|||
editPost *sql.Stmt
|
||||
createPost *sql.Stmt
|
||||
deletePost *sql.Stmt
|
||||
|
||||
getUsers *sql.Stmt
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -40,6 +42,8 @@ func init() {
|
|||
editPost: acc.Update("conversations_posts").Set("body = ?, post = ?").Where("pid = ?").Prepare(),
|
||||
createPost: acc.Insert("conversations_posts").Columns("cid, body, post, createdBy").Fields("?,?,?,?").Prepare(),
|
||||
deletePost: acc.Delete("conversations_posts").Where("pid = ?").Prepare(),
|
||||
|
||||
getUsers: acc.Select("conversations_participants").Columns("uid").Where("cid = ?").Prepare(),
|
||||
}
|
||||
return acc.FirstError()
|
||||
})
|
||||
|
@ -84,6 +88,24 @@ func (co *Conversation) PostsCount() (count int) {
|
|||
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) {
|
||||
var count int
|
||||
err := convoStmts.has.QueryRow(uid, co.ID).Scan(&count)
|
||||
|
|
|
@ -282,6 +282,7 @@ type ConvoViewPage struct {
|
|||
*Header
|
||||
Convo *Conversation
|
||||
Posts []ConvoViewRow
|
||||
Users []*User
|
||||
Paginator
|
||||
}
|
||||
|
||||
|
|
|
@ -348,9 +348,10 @@ func compileTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName string
|
|||
accountPage := Account{header, "dashboard", "account_own_edit", inter}
|
||||
tmpls.AddStd("account", "c.Account", accountPage)
|
||||
|
||||
parti := []*User{&user}
|
||||
convo := &Conversation{1,user.ID,time.Now(),0,time.Now()}
|
||||
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)
|
||||
|
||||
basePage := &BasePanelPage{header, PanelStats{}, "dashboard", ReportForumID}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"errors"
|
||||
|
||||
c "github.com/Azareal/Gosora/common"
|
||||
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)
|
||||
}
|
||||
|
||||
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))
|
||||
for i, post := range posts {
|
||||
uuser, err := c.Users.Get(post.CreatedBy)
|
||||
if err != nil {
|
||||
return c.InternalError(err, w, r)
|
||||
uuser, ok := umap[post.CreatedBy]
|
||||
if !ok {
|
||||
return c.InternalError(errors.New("convo post creator not in umap"), w, r)
|
||||
}
|
||||
canModify := user.ID == post.CreatedBy || user.IsSuperMod
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="colstack_item parti">
|
||||
<div class="rowitem">Participants: Blah, Blah 2, Blah 3</div>
|
||||
<div class="rowitem">
|
||||
<div>Participants: </div>
|
||||
{{range .Users}}<div class="parti_user"><a href="{{.Link}}">{{.Name}}</a></div> {{end}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="colstack_item">{{template "convo_row.html" .}}</div>
|
||||
{{if not .CurrentUser.IsBanned}}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
.parti {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.parti .rowitem {
|
||||
display: flex;
|
||||
}
|
||||
.parti_user:not(:last-child):after {
|
||||
content: ",";
|
||||
}
|
||||
|
||||
.rowitem .topRow {
|
||||
display: flex;
|
||||
|
|
Loading…
Reference in New Issue