spread love

tweak variable names

phrases:
add convo_rand_0
add convo_rand_1
add convo_rand_2
add convo_rand_3
This commit is contained in:
Azareal 2021-01-25 09:16:54 +10:00
parent 70d66e7dd8
commit 6884c9afcc
2 changed files with 31 additions and 21 deletions

View File

@ -363,6 +363,10 @@
"password_reset_token_token_verified":"Your password was successfully updated.", "password_reset_token_token_verified":"Your password was successfully updated.",
"convo_dev":"Conversations are currently under development. Some features may not work yet and your messages may be purged every now and then.", "convo_dev":"Conversations are currently under development. Some features may not work yet and your messages may be purged every now and then.",
"convo_rand_0":"Remember that the person on the other end has thoughts and emotions just like you.",
"convo_rand_1":"Try to look at things from the other person's perspective.",
"convo_rand_2":"Treat others how you'd like to be treated.",
"convo_rand_3":"Having a differing opinion isn't an attack on you.",
"panel_forum_created":"The forum was successfully created.", "panel_forum_created":"The forum was successfully created.",
"panel_forum_deleted":"The forum was successfully deleted.", "panel_forum_deleted":"The forum was successfully deleted.",

View File

@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
"errors" "errors"
"html" "html"
"math/rand"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
@ -14,11 +15,17 @@ import (
p "github.com/Azareal/Gosora/common/phrases" p "github.com/Azareal/Gosora/common/phrases"
) )
func convoNotice(h *c.Header) {
//h.AddNotice("convo_dev")
c := rand.Intn(3)
h.AddNotice("convo_rand_" + strconv.Itoa(c))
}
func Convos(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Header) c.RouteError { func Convos(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Header) c.RouteError {
accountEditHead("convos", w, r, user, h) accountEditHead("convos", w, r, user, h)
h.AddScript("convo.js") h.AddScript("convo.js")
h.AddSheet(h.Theme.Name + "/convo.css") h.AddSheet(h.Theme.Name + "/convo.css")
h.AddNotice("convo_dev") convoNotice(h)
ccount := c.Convos.GetUserCount(user.ID) ccount := c.Convos.GetUserCount(user.ID)
page, _ := strconv.Atoi(r.FormValue("page")) page, _ := strconv.Atoi(r.FormValue("page"))
offset, page, lastPage := c.PageOffset(ccount, page, c.Config.ItemsPerPage) offset, page, lastPage := c.PageOffset(ccount, page, c.Config.ItemsPerPage)
@ -51,24 +58,23 @@ func Convos(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Header) c
return renderTemplate("account", w, r, h, pi) return renderTemplate("account", w, r, h, pi)
} }
func Convo(w http.ResponseWriter, r *http.Request, user *c.User, header *c.Header, scid string) c.RouteError { func Convo(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Header, scid string) c.RouteError {
accountEditHead("convo", w, r, user, header) accountEditHead("convo", w, r, user, h)
header.AddSheet(header.Theme.Name + "/convo.css") h.AddSheet(h.Theme.Name + "/convo.css")
header.AddNotice("convo_dev") convoNotice(h)
cid, err := strconv.Atoi(scid) cid, err := strconv.Atoi(scid)
if err != nil { if err != nil {
return c.LocalError(p.GetErrorPhrase("id_must_be_integer"), w, r, user) return c.LocalError(p.GetErrorPhrase("id_must_be_integer"), w, r, user)
} }
convo, err := c.Convos.Get(cid) convo, err := c.Convos.Get(cid)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return c.NotFound(w, r, header) return c.NotFound(w, r, h)
} else if err != nil { } else if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
pcount := convo.PostsCount() pcount := convo.PostsCount()
if pcount == 0 { if pcount == 0 {
return c.NotFound(w, r, header) return c.NotFound(w, r, h)
} }
page, _ := strconv.Atoi(r.FormValue("page")) page, _ := strconv.Atoi(r.FormValue("page"))
@ -78,20 +84,20 @@ func Convo(w http.ResponseWriter, r *http.Request, user *c.User, header *c.Heade
posts, err := convo.Posts(offset, c.Config.ItemsPerPage) posts, err := convo.Posts(offset, c.Config.ItemsPerPage)
// TODO: Report a better error for no posts // TODO: Report a better error for no posts
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return c.NotFound(w, r, header) return c.NotFound(w, r, h)
} else if err != nil { } else if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
uids, err := convo.Uids() uids, err := convo.Uids()
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return c.NotFound(w, r, header) return c.NotFound(w, r, h)
} else if err != nil { } else if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
umap, err := c.Users.BulkGetMap(uids) umap, err := c.Users.BulkGetMap(uids)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return c.NotFound(w, r, header) return c.NotFound(w, r, h)
} else if err != nil { } else if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
@ -123,8 +129,8 @@ func Convo(w http.ResponseWriter, r *http.Request, user *c.User, header *c.Heade
} }
} }
pi := c.Account{header, "dashboard", "convo", c.ConvoViewPage{header, convo, pitems, users, canReply, c.Paginator{pageList, page, lastPage}}} pi := c.Account{h, "dashboard", "convo", c.ConvoViewPage{h, convo, pitems, users, canReply, c.Paginator{pageList, page, lastPage}}}
return renderTemplate("account", w, r, header, pi) return renderTemplate("account", w, r, h, pi)
} }
func ConvosCreate(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Header) c.RouteError { func ConvosCreate(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Header) c.RouteError {
@ -132,17 +138,17 @@ func ConvosCreate(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Hea
if !user.Perms.UseConvos && !user.Perms.UseConvosOnlyWithMod { if !user.Perms.UseConvos && !user.Perms.UseConvosOnlyWithMod {
return c.NoPermissions(w, r, user) return c.NoPermissions(w, r, user)
} }
h.AddNotice("convo_dev") convoNotice(h)
uid, err := strconv.Atoi(r.FormValue("with")) uid, err := strconv.Atoi(r.FormValue("with"))
if err != nil { if err != nil {
return c.LocalError("invalid integer in parameter with", w, r, user) return c.LocalError("invalid integer in parameter with", w, r, user)
} }
u, err := c.Users.Get(uid) recp, err := c.Users.Get(uid)
if err != nil { if err != nil {
return c.LocalError("Unable to fetch user", w, r, user) return c.LocalError("Unable to fetch user", w, r, user)
} }
// TODO: Avoid potential double escape? // TODO: Avoid potential double escape?
pi := c.Account{h, "dashboard", "create_convo", c.ConvoCreatePage{h, html.EscapeString(u.Name)}} pi := c.Account{h, "dashboard", "create_convo", c.ConvoCreatePage{h, html.EscapeString(recp.Name)}}
return renderTemplate("account", w, r, h, pi) return renderTemplate("account", w, r, h, pi)
} }
@ -302,14 +308,14 @@ func ConvosCreateReplySubmit(w http.ResponseWriter, r *http.Request, user *c.Use
return nil return nil
} }
func ConvosDeleteReplySubmit(w http.ResponseWriter, r *http.Request, user *c.User, scpid string) c.RouteError { func ConvosDeleteReplySubmit(w http.ResponseWriter, r *http.Request, u *c.User, scpid string) c.RouteError {
_, ferr := c.SimpleUserCheck(w, r, user) _, ferr := c.SimpleUserCheck(w, r, u)
if ferr != nil { if ferr != nil {
return ferr return ferr
} }
cpid, err := strconv.Atoi(scpid) cpid, err := strconv.Atoi(scpid)
if err != nil { if err != nil {
return c.LocalError(p.GetErrorPhrase("id_must_be_integer"), w, r, user) return c.LocalError(p.GetErrorPhrase("id_must_be_integer"), w, r, u)
} }
post := &c.ConversationPost{ID: cpid} post := &c.ConversationPost{ID: cpid}
@ -330,8 +336,8 @@ func ConvosDeleteReplySubmit(w http.ResponseWriter, r *http.Request, user *c.Use
if pcount == 0 { if pcount == 0 {
return c.NotFound(w, r, nil) return c.NotFound(w, r, nil)
} }
if user.ID != post.CreatedBy && !user.IsSuperMod { if u.ID != post.CreatedBy && !u.IsSuperMod {
return c.NoPermissions(w, r, user) return c.NoPermissions(w, r, u)
} }
posts, err := convo.Posts(0, c.Config.ItemsPerPage) posts, err := convo.Posts(0, c.Config.ItemsPerPage)