carry over the recipient when creating a convo via profile

hide the convo reply form when we don't have permission to create a reply
This commit is contained in:
Azareal 2020-02-11 17:01:13 +10:00
parent 84cdc097e7
commit ae2a4809ba
5 changed files with 48 additions and 26 deletions

View File

@ -300,9 +300,10 @@ type ConvoViewRow struct {
type ConvoViewPage struct {
*Header
Convo *Conversation
Posts []ConvoViewRow
Users []*User
Convo *Conversation
Posts []ConvoViewRow
Users []*User
CanReply bool
Paginator
}

View File

@ -93,7 +93,7 @@ var Template_account_handle = genIntTmpl("account")
func tmplInitUsers() (User, User, User) {
avatar, microAvatar := BuildAvatar(62, "")
user := User{62, BuildProfileURL("fake-user", 62), "Fake User", "compiler@localhost", 0, false, false, false, false, false, false, GuestPerms, make(map[string]bool), "", false, "", avatar, microAvatar, "", "", 0, 0, 0, 0, StartTime,"0.0.0.0.0", "", 0, nil}
user := User{62, BuildProfileURL("fake-user", 62), "Fake User", "compiler@localhost", 0, false, false, false, false, false, false, GuestPerms, make(map[string]bool), "", false, "", avatar, microAvatar, "", "", 0, 0, 0, 0, StartTime, "0.0.0.0.0", "", 0, nil}
// TODO: Do a more accurate level calculation for this?
avatar, microAvatar = BuildAvatar(1, "")
@ -104,7 +104,7 @@ func tmplInitUsers() (User, User, User) {
return user, user2, user3
}
func tmplInitHeaders(user User, user2 User, user3 User) (*Header, *Header, *Header) {
func tmplInitHeaders(user, user2, user3 User) (*Header, *Header, *Header) {
header := &Header{
Site: Site,
Settings: SettingBox.Load().(SettingMap),
@ -147,11 +147,11 @@ type TItem struct {
type TItemHold map[string]TItem
func (h TItemHold) Add(name string, expects string, expectsInt interface{}) {
func (h TItemHold) Add(name, expects string, expectsInt interface{}) {
h[name] = TItem{expects, expectsInt, true}
}
func (h TItemHold) AddStd(name string, expects string, expectsInt interface{}) {
func (h TItemHold) AddStd(name, expects string, expectsInt interface{}) {
h[name] = TItem{expects, expectsInt, false}
}
@ -208,7 +208,7 @@ func CompileTemplates() error {
return nil
}
func compileCommons(c *tmpl.CTemplateSet, head *Header, head2 *Header, forumList []Forum, o TItemHold) error {
func compileCommons(c *tmpl.CTemplateSet, head, head2 *Header, forumList []Forum, o TItemHold) error {
// TODO: Add support for interface{}s
_, user2, user3 := tmplInitUsers()
now := time.Now()
@ -352,7 +352,7 @@ func compileTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName string
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, parti, Paginator{[]int{1}, 1, 1}}
convoPage := ConvoViewPage{header, convo, convoItems, parti, true, Paginator{[]int{1}, 1, 1}}
t.AddStd("convo", "c.ConvoViewPage", convoPage)
convos := []*ConversationExtra{&ConversationExtra{&Conversation{}, []*User{&user}}}
@ -377,7 +377,7 @@ func compileTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName string
writeTemplate := func(name string, content interface{}) {
log.Print("Writing template '" + name + "'")
writeTmpl := func(name string, content string) {
writeTmpl := func(name, content string) {
if content == "" {
return //log.Fatal("No content body for " + name)
}
@ -531,7 +531,7 @@ func compileJSTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName stri
}, VoteCount: 7}
avatar, microAvatar := BuildAvatar(62, "")
miniAttach := []*MiniAttachment{&MiniAttachment{Path: "/"}}
topic := TopicUser{1, "blah", "Blah", "Hey there!", 62, false, false, now, now, 1, 1, 0, "", "127.0.0.1", 1, 0, 1, 0, "classname", poll.ID, "weird-data", BuildProfileURL("fake-user", 62), "Fake User", Config.DefaultGroup, avatar, microAvatar, 0, "","","", 58, false, miniAttach, nil, false}
topic := TopicUser{1, "blah", "Blah", "Hey there!", 62, false, false, now, now, 1, 1, 0, "", "127.0.0.1", 1, 0, 1, 0, "classname", poll.ID, "weird-data", BuildProfileURL("fake-user", 62), "Fake User", Config.DefaultGroup, avatar, microAvatar, 0, "", "", "", 58, false, miniAttach, nil, false}
var replyList []*ReplyUser
// TODO: Do we really want the UID here to be zero?
avatar, microAvatar = BuildAvatar(0, "")
@ -559,13 +559,13 @@ func compileJSTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName stri
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, parti, Paginator{[]int{1}, 1, 1}}
convoPage := ConvoViewPage{header, convo, convoItems, parti, true, Paginator{[]int{1}, 1, 1}}
t.AddStd("convo", "c.ConvoViewPage", convoPage)
t.AddStd("notice", "string", "nonono")
dirPrefix := "./tmpl_client/"
writeTemplate := func(name string, content string) {
writeTemplate := func(name, content string) {
log.Print("Writing template '" + name + "'")
if content == "" {
return //log.Fatal("No content body")
@ -695,29 +695,29 @@ func arithToInt64(in interface{}) (out int64) {
return out
}
func arithDuoToInt64(left interface{}, right interface{}) (leftInt int64, rightInt int64) {
func arithDuoToInt64(left, right interface{}) (leftInt, rightInt int64) {
return arithToInt64(left), arithToInt64(right)
}
func initDefaultTmplFuncMap() {
// TODO: Add support for floats
fmap := make(map[string]interface{})
fmap["add"] = func(left interface{}, right interface{}) interface{} {
fmap["add"] = func(left, right interface{}) interface{} {
leftInt, rightInt := arithDuoToInt64(left, right)
return leftInt + rightInt
}
fmap["subtract"] = func(left interface{}, right interface{}) interface{} {
fmap["subtract"] = func(left, right interface{}) interface{} {
leftInt, rightInt := arithDuoToInt64(left, right)
return leftInt - rightInt
}
fmap["multiply"] = func(left interface{}, right interface{}) interface{} {
fmap["multiply"] = func(left, right interface{}) interface{} {
leftInt, rightInt := arithDuoToInt64(left, right)
return leftInt * rightInt
}
fmap["divide"] = func(left interface{}, right interface{}) interface{} {
fmap["divide"] = func(left, right interface{}) interface{} {
leftInt, rightInt := arithDuoToInt64(left, right)
if leftInt == 0 || rightInt == 0 {
return 0
@ -725,11 +725,11 @@ func initDefaultTmplFuncMap() {
return leftInt / rightInt
}
fmap["dock"] = func(dock interface{}, headerInt interface{}) interface{} {
fmap["dock"] = func(dock, headerInt interface{}) interface{} {
return template.HTML(BuildWidget(dock.(string), headerInt.(*Header)))
}
fmap["hasWidgets"] = func(dock interface{}, headerInt interface{}) interface{} {
fmap["hasWidgets"] = func(dock, headerInt interface{}) interface{} {
return HasWidgets(dock.(string), headerInt.(*Header))
}
@ -803,7 +803,7 @@ func initDefaultTmplFuncMap() {
return ""
}
fmap["dyntmpl"] = func(nameInt interface{}, pageInt interface{}, headerInt interface{}) interface{} {
fmap["dyntmpl"] = func(nameInt, pageInt, headerInt interface{}) interface{} {
header := headerInt.(*Header)
err := header.Theme.RunTmpl(nameInt.(string), pageInt, header.Writer)
if err != nil {

View File

@ -3,6 +3,7 @@ package routes
import (
"database/sql"
"errors"
"html"
"net/http"
"strconv"
"strings"
@ -94,7 +95,18 @@ func Convo(w http.ResponseWriter, r *http.Request, user c.User, header *c.Header
pitems[i] = c.ConvoViewRow{post, uuser, "", 4, canModify}
}
pi := c.Account{header, "dashboard", "convo", c.ConvoViewPage{header, convo, pitems, users, c.Paginator{pageList, page, lastPage}}}
canReply := user.Perms.UseConvos || user.Perms.UseConvosOnlyWithMod
if !user.Perms.UseConvos && user.Perms.UseConvosOnlyWithMod {
u, err := c.Users.Get(convo.CreatedBy)
if err != nil {
return c.InternalError(err, w, r)
}
if !u.IsSuperMod {
canReply = false
}
}
pi := c.Account{header, "dashboard", "convo", c.ConvoViewPage{header, convo, pitems, users, canReply, c.Paginator{pageList, page, lastPage}}}
return renderTemplate("account", w, r, header, pi)
}
@ -104,8 +116,16 @@ func ConvosCreate(w http.ResponseWriter, r *http.Request, user c.User, h *c.Head
return c.NoPermissions(w, r, user)
}
h.AddNotice("convo_dev")
recpName := ""
pi := c.Account{h, "dashboard", "create_convo", c.ConvoCreatePage{h, recpName}}
uid, err := strconv.Atoi(r.FormValue("with"))
if err != nil {
return c.LocalError("invalid integer in parameter with", w, r, user)
}
u, err := c.Users.Get(uid)
if err != nil {
return c.LocalError("Unable to fetch user", w, r, user)
}
// TODO: Avoid potential double escape?
pi := c.Account{h, "dashboard", "create_convo", c.ConvoCreatePage{h, html.EscapeString(u.Name)}}
return renderTemplate("account", w, r, h, pi)
}
@ -206,6 +226,7 @@ func ConvosCreateReplySubmit(w http.ResponseWriter, r *http.Request, user c.User
if !convo.Has(user.ID) {
return c.LocalError("You are not in this conversation.", w, r, user)
}
// TODO: Let the user reply if they're the convo creator in a convo with a mod
if !user.Perms.UseConvos && user.Perms.UseConvosOnlyWithMod {
u, err := c.Users.Get(convo.CreatedBy)
if err != nil {

View File

@ -10,7 +10,7 @@
</div>
</div>
<div class="colstack_item convo_row_box">{{template "convo_row.html" .}}</div>
{{if not .CurrentUser.IsBanned}}
{{if .CanReply}}
<form action="/user/convo/create/submit/{{.Convo.ID}}?s={{.CurrentUser.Session}}" method="post">
<div class="colstack_item topic_reply_form" style="border-top:none;">
<div class="formrow">

View File

@ -28,7 +28,7 @@
<a class="profile_menu_item">{{lang "profile.login_for_options"}}</a>
</div>{{else}}
{{if .CanMessage}}<div class="rowitem passive">
<a href="/user/convos/create/" class="profile_menu_item">{{lang "profile.send_message"}}</a>
<a href="/user/convos/create/?with={{.ProfileOwner.ID}}" class="profile_menu_item">{{lang "profile.send_message"}}</a>
</div>{{end}}
<!--<div class="rowitem passive">
<a class="profile_menu_item">{{lang "profile.add_friend"}}</a>