mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-08 16:15:33 +00:00
update for lemmy 0.19
This commit is contained in:
parent
4b5b4aa6e9
commit
3f074ce7ed
1
go.mod
1
go.mod
|
@ -15,4 +15,5 @@ require (
|
||||||
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
|
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
|
||||||
github.com/google/go-querystring v1.1.0 // indirect
|
github.com/google/go-querystring v1.1.0 // indirect
|
||||||
github.com/gorilla/websocket v1.4.2 // indirect
|
github.com/gorilla/websocket v1.4.2 // indirect
|
||||||
|
go.elara.ws/go-lemmy v0.19.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -26,6 +26,8 @@ github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIK
|
||||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||||
github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU=
|
github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU=
|
||||||
github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
go.elara.ws/go-lemmy v0.19.0 h1:FdPfiA+8yOa2IhrLdBp8jdYbnY6H55bfwnBbiGr0OHg=
|
||||||
|
go.elara.ws/go-lemmy v0.19.0/go.mod h1:aZbF/4c1VA7qPXsP4Pth0ERu3HGZFPPl8bTY1ltBrcQ=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
|
211
routes.go
211
routes.go
|
@ -19,8 +19,7 @@ import (
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"github.com/k3a/html2text"
|
"github.com/k3a/html2text"
|
||||||
"github.com/rystaf/go-lemmy"
|
"go.elara.ws/go-lemmy"
|
||||||
"github.com/rystaf/go-lemmy/types"
|
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
"golang.org/x/text/message"
|
"golang.org/x/text/message"
|
||||||
)
|
)
|
||||||
|
@ -43,10 +42,10 @@ var funcMap = template.FuncMap{
|
||||||
p := message.NewPrinter(language.English)
|
p := message.NewPrinter(language.English)
|
||||||
return p.Sprintf("%d", n)
|
return p.Sprintf("%d", n)
|
||||||
},
|
},
|
||||||
"likedPerc": func(c types.PostAggregates) string {
|
"likedPerc": func(c lemmy.PostAggregates) string {
|
||||||
return fmt.Sprintf("%.1f", (float64(c.Upvotes)/float64(c.Upvotes+c.Downvotes))*100)
|
return fmt.Sprintf("%.1f", (float64(c.Upvotes)/float64(c.Upvotes+c.Downvotes))*100)
|
||||||
},
|
},
|
||||||
"fullname": func(person types.PersonSafe) string {
|
"fullname": func(person lemmy.Person) string {
|
||||||
if person.Local {
|
if person.Local {
|
||||||
return person.Name
|
return person.Name
|
||||||
}
|
}
|
||||||
|
@ -57,7 +56,7 @@ var funcMap = template.FuncMap{
|
||||||
}
|
}
|
||||||
return person.Name + "@" + l.Host
|
return person.Name + "@" + l.Host
|
||||||
},
|
},
|
||||||
"fullcname": func(c types.CommunitySafe) string {
|
"fullcname": func(c lemmy.Community) string {
|
||||||
if c.Local {
|
if c.Local {
|
||||||
return c.Name
|
return c.Name
|
||||||
}
|
}
|
||||||
|
@ -68,7 +67,7 @@ var funcMap = template.FuncMap{
|
||||||
}
|
}
|
||||||
return c.Name + "@" + l.Host
|
return c.Name + "@" + l.Host
|
||||||
},
|
},
|
||||||
"isMod": func(c *types.GetCommunityResponse, username string) bool {
|
"isMod": func(c *lemmy.GetCommunityResponse, username string) bool {
|
||||||
for _, mod := range c.Moderators {
|
for _, mod := range c.Moderators {
|
||||||
if mod.Moderator.Local && username == mod.Moderator.Name {
|
if mod.Moderator.Local && username == mod.Moderator.Name {
|
||||||
return true
|
return true
|
||||||
|
@ -93,13 +92,13 @@ var funcMap = template.FuncMap{
|
||||||
}
|
}
|
||||||
return l.Host
|
return l.Host
|
||||||
},
|
},
|
||||||
"membership": func(s types.SubscribedType) string {
|
"membership": func(s lemmy.SubscribedType) string {
|
||||||
switch s {
|
switch s {
|
||||||
case types.SubscribedTypeSubscribed:
|
case lemmy.SubscribedTypeSubscribed:
|
||||||
return "leave"
|
return "leave"
|
||||||
case types.SubscribedTypeNotSubscribed:
|
case lemmy.SubscribedTypeNotSubscribed:
|
||||||
return "join"
|
return "join"
|
||||||
case types.SubscribedTypePending:
|
case lemmy.SubscribedTypePending:
|
||||||
return "pending"
|
return "pending"
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
|
@ -111,7 +110,7 @@ var funcMap = template.FuncMap{
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
"thumbnail": func(p types.Post) string {
|
"thumbnail": func(p lemmy.Post) string {
|
||||||
if p.ThumbnailURL.IsValid() {
|
if p.ThumbnailURL.IsValid() {
|
||||||
return p.ThumbnailURL.String() + "?format=jpg&thumbnail=96"
|
return p.ThumbnailURL.String() + "?format=jpg&thumbnail=96"
|
||||||
}
|
}
|
||||||
|
@ -156,10 +155,10 @@ var funcMap = template.FuncMap{
|
||||||
return re.ReplaceAllString(text, "")
|
return re.ReplaceAllString(text, "")
|
||||||
},
|
},
|
||||||
"contains": strings.Contains,
|
"contains": strings.Contains,
|
||||||
"sub": func(a int32, b int) int {
|
"sub": func(a int64, b int) int {
|
||||||
return int(a) - b
|
return int(a) - b
|
||||||
},
|
},
|
||||||
"add": func(a int32, b int) int {
|
"add": func(a int64, b int) int {
|
||||||
return int(a) + b
|
return int(a) + b
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -410,7 +409,7 @@ func GetIcon(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
}
|
}
|
||||||
state, err := Initialize(ps.ByName("host"), r)
|
state, err := Initialize(ps.ByName("host"), r)
|
||||||
state.Client.Token = ""
|
state.Client.Token = ""
|
||||||
resp, err := state.Client.Site(context.Background(), types.GetSite{})
|
resp, err := state.Client.Site(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("500 - Server Error"))
|
w.Write([]byte("500 - Server Error"))
|
||||||
|
@ -478,17 +477,17 @@ func ResolveId(r *http.Request, class string, id string, host string) string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
idn, _ := strconv.Atoi(id)
|
idn, _ := strconv.ParseInt(id, 10, 64)
|
||||||
if class == "post" {
|
if class == "post" {
|
||||||
resp, err := c.Post(context.Background(), types.GetPost{
|
resp, err := c.Post(context.Background(), lemmy.GetPost{
|
||||||
ID: types.NewOptional(idn),
|
ID: lemmy.NewOptional(idn),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return resp.PostView.Post.ApID
|
return resp.PostView.Post.ApID
|
||||||
}
|
}
|
||||||
resp, err := c.Comment(context.Background(), types.GetComment{
|
resp, err := c.Comment(context.Background(), lemmy.GetComment{
|
||||||
ID: idn,
|
ID: idn,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -507,7 +506,7 @@ func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
if path := strings.Split(ps.ByName("postid"), "@"); len(path) > 1 {
|
if path := strings.Split(ps.ByName("postid"), "@"); len(path) > 1 {
|
||||||
apid := ResolveId(r, "post", path[0], path[1])
|
apid := ResolveId(r, "post", path[0], path[1])
|
||||||
if apid != "" {
|
if apid != "" {
|
||||||
resp, err := state.Client.ResolveObject(context.Background(), types.ResolveObject{
|
resp, err := state.Client.ResolveObject(context.Background(), lemmy.ResolveObject{
|
||||||
Q: apid,
|
Q: apid,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -521,7 +520,7 @@ func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
post, _ := resp.Post.Value()
|
post, _ := resp.Post.Value()
|
||||||
if post.Post.ID > 0 {
|
if post.Post.ID > 0 {
|
||||||
dest := RegReplace(r.URL.String(), `(([a-zA-Z0-9\.\-]+)?/post/)([a-zA-Z0-9\-\.@]+)`, `$1`)
|
dest := RegReplace(r.URL.String(), `(([a-zA-Z0-9\.\-]+)?/post/)([a-zA-Z0-9\-\.@]+)`, `$1`)
|
||||||
dest += strconv.Itoa(post.Post.ID)
|
dest += strconv.FormatInt(post.Post.ID, 10)
|
||||||
http.Redirect(w, r, dest, 302)
|
http.Redirect(w, r, dest, 302)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
@ -538,7 +537,7 @@ func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
if len(m["content"]) > 0 {
|
if len(m["content"]) > 0 {
|
||||||
state.Content = m["content"][0]
|
state.Content = m["content"][0]
|
||||||
}
|
}
|
||||||
postid, _ := strconv.Atoi(ps.ByName("postid"))
|
postid, _ := strconv.ParseInt(ps.ByName("postid"), 10, 64)
|
||||||
state.GetPost(postid)
|
state.GetPost(postid)
|
||||||
if ps.ByName("op") == "block" {
|
if ps.ByName("op") == "block" {
|
||||||
state.Op = "block"
|
state.Op = "block"
|
||||||
|
@ -557,7 +556,7 @@ func GetComment(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
if path := strings.Split(ps.ByName("commentid"), "@"); len(path) > 1 {
|
if path := strings.Split(ps.ByName("commentid"), "@"); len(path) > 1 {
|
||||||
apid := ResolveId(r, "comment", path[0], path[1])
|
apid := ResolveId(r, "comment", path[0], path[1])
|
||||||
if apid != "" {
|
if apid != "" {
|
||||||
resp, err := state.Client.ResolveObject(context.Background(), types.ResolveObject{
|
resp, err := state.Client.ResolveObject(context.Background(), lemmy.ResolveObject{
|
||||||
Q: apid,
|
Q: apid,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -571,7 +570,7 @@ func GetComment(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
comment, _ := resp.Comment.Value()
|
comment, _ := resp.Comment.Value()
|
||||||
if comment.Comment.ID > 0 {
|
if comment.Comment.ID > 0 {
|
||||||
dest := RegReplace(r.URL.String(), `(([a-zA-Z0-9\.\-]+)?/comment/)([a-zA-Z0-9\-\.@]+)`, `$1`)
|
dest := RegReplace(r.URL.String(), `(([a-zA-Z0-9\.\-]+)?/comment/)([a-zA-Z0-9\-\.@]+)`, `$1`)
|
||||||
dest += strconv.Itoa(comment.Comment.ID)
|
dest += strconv.FormatInt(comment.Comment.ID, 10)
|
||||||
http.Redirect(w, r, dest, 302)
|
http.Redirect(w, r, dest, 302)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
@ -597,7 +596,7 @@ func GetComment(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
ctx, _ := strconv.Atoi(m["context"][0])
|
ctx, _ := strconv.Atoi(m["context"][0])
|
||||||
state.Context = ctx
|
state.Context = ctx
|
||||||
}
|
}
|
||||||
commentid, _ := strconv.Atoi(ps.ByName("commentid"))
|
commentid, _ := strconv.ParseInt(ps.ByName("commentid"), 10, 64)
|
||||||
state.GetComment(commentid)
|
state.GetComment(commentid)
|
||||||
if state.XHR && len(m["content"]) > 0 {
|
if state.XHR && len(m["content"]) > 0 {
|
||||||
Render(w, "create_comment.html", state)
|
Render(w, "create_comment.html", state)
|
||||||
|
@ -634,8 +633,8 @@ func SendMessage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userid, _ := strconv.Atoi(r.FormValue("userid"))
|
userid, _ := strconv.ParseInt(r.FormValue("userid"), 10, 64)
|
||||||
_, err = state.Client.CreatePrivateMessage(context.Background(), types.CreatePrivateMessage{
|
_, err = state.Client.CreatePrivateMessage(context.Background(), lemmy.CreatePrivateMessage{
|
||||||
Content: r.FormValue("content"),
|
Content: r.FormValue("content"),
|
||||||
RecipientID: userid,
|
RecipientID: userid,
|
||||||
})
|
})
|
||||||
|
@ -800,12 +799,12 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
|
||||||
var username string
|
var username string
|
||||||
switch r.FormValue("submit") {
|
switch r.FormValue("submit") {
|
||||||
case "log in":
|
case "log in":
|
||||||
login := types.Login{
|
login := lemmy.Login{
|
||||||
UsernameOrEmail: r.FormValue("username"),
|
UsernameOrEmail: r.FormValue("username"),
|
||||||
Password: r.FormValue("password"),
|
Password: r.FormValue("password"),
|
||||||
}
|
}
|
||||||
if r.FormValue("totp") != "" {
|
if r.FormValue("totp") != "" {
|
||||||
login.Totp2faToken = types.NewOptional(r.FormValue("totp"))
|
login.TOTP2FAToken = lemmy.NewOptional(r.FormValue("totp"))
|
||||||
}
|
}
|
||||||
resp, err := state.Client.Login(context.Background(), login)
|
resp, err := state.Client.Login(context.Background(), login)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -825,23 +824,23 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
|
||||||
deleteCookie(w, state.Host, "ShowNSFW")
|
deleteCookie(w, state.Host, "ShowNSFW")
|
||||||
}
|
}
|
||||||
case "sign up":
|
case "sign up":
|
||||||
register := types.Register{
|
register := lemmy.Register{
|
||||||
Username: r.FormValue("username"),
|
Username: r.FormValue("username"),
|
||||||
Password: r.FormValue("password"),
|
Password: r.FormValue("password"),
|
||||||
PasswordVerify: r.FormValue("passwordverify"),
|
PasswordVerify: r.FormValue("passwordverify"),
|
||||||
ShowNSFW: r.FormValue("nsfw") != "",
|
ShowNSFW: r.FormValue("nsfw") != "",
|
||||||
}
|
}
|
||||||
if r.FormValue("email") != "" {
|
if r.FormValue("email") != "" {
|
||||||
register.Email = types.NewOptional(r.FormValue("email"))
|
register.Email = lemmy.NewOptional(r.FormValue("email"))
|
||||||
}
|
}
|
||||||
if r.FormValue("answer") != "" {
|
if r.FormValue("answer") != "" {
|
||||||
register.Answer = types.NewOptional(r.FormValue("answer"))
|
register.Answer = lemmy.NewOptional(r.FormValue("answer"))
|
||||||
}
|
}
|
||||||
if r.FormValue("captchauuid") != "" {
|
if r.FormValue("captchauuid") != "" {
|
||||||
register.CaptchaUuid = types.NewOptional(r.FormValue("captchauuid"))
|
register.CaptchaUUID = lemmy.NewOptional(r.FormValue("captchauuid"))
|
||||||
}
|
}
|
||||||
if r.FormValue("captchaanswer") != "" {
|
if r.FormValue("captchaanswer") != "" {
|
||||||
register.CaptchaAnswer = types.NewOptional(r.FormValue("captchaanswer"))
|
register.CaptchaAnswer = lemmy.NewOptional(r.FormValue("captchaanswer"))
|
||||||
}
|
}
|
||||||
resp, err := state.Client.Register(context.Background(), register)
|
resp, err := state.Client.Register(context.Background(), register)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -875,7 +874,7 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setCookie(w, state.Host, "jwt", token)
|
setCookie(w, state.Host, "jwt", token)
|
||||||
userid := strconv.Itoa(state.User.PersonView.Person.ID)
|
userid := strconv.FormatInt(state.User.PersonView.Person.ID, 10)
|
||||||
setCookie(w, state.Host, "user", state.User.PersonView.Person.Name+":"+userid)
|
setCookie(w, state.Host, "user", state.User.PersonView.Person.Name+":"+userid)
|
||||||
setCookie(w, state.Host, "jwt", token)
|
setCookie(w, state.Host, "jwt", token)
|
||||||
r.URL.Path = "/" + state.Host
|
r.URL.Path = "/" + state.Host
|
||||||
|
@ -945,36 +944,36 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
}
|
}
|
||||||
switch r.FormValue("op") {
|
switch r.FormValue("op") {
|
||||||
case "leave":
|
case "leave":
|
||||||
communityid, _ := strconv.Atoi(r.FormValue("communityid"))
|
communityid, _ := strconv.ParseInt(r.FormValue("communityid"), 10, 64)
|
||||||
state.Client.FollowCommunity(context.Background(), types.FollowCommunity{
|
state.Client.FollowCommunity(context.Background(), lemmy.FollowCommunity{
|
||||||
CommunityID: communityid,
|
CommunityID: communityid,
|
||||||
Follow: false,
|
Follow: false,
|
||||||
})
|
})
|
||||||
case "join":
|
case "join":
|
||||||
communityid, _ := strconv.Atoi(r.FormValue("communityid"))
|
communityid, _ := strconv.ParseInt(r.FormValue("communityid"), 10, 64)
|
||||||
state.Client.FollowCommunity(context.Background(), types.FollowCommunity{
|
state.Client.FollowCommunity(context.Background(), lemmy.FollowCommunity{
|
||||||
CommunityID: communityid,
|
CommunityID: communityid,
|
||||||
Follow: true,
|
Follow: true,
|
||||||
})
|
})
|
||||||
case "block":
|
case "block":
|
||||||
communityid, _ := strconv.Atoi(r.FormValue("communityid"))
|
communityid, _ := strconv.ParseInt(r.FormValue("communityid"), 10, 64)
|
||||||
state.Client.BlockCommunity(context.Background(), types.BlockCommunity{
|
state.Client.BlockCommunity(context.Background(), lemmy.BlockCommunity{
|
||||||
CommunityID: communityid,
|
CommunityID: communityid,
|
||||||
Block: true,
|
Block: true,
|
||||||
})
|
})
|
||||||
case "unblock":
|
case "unblock":
|
||||||
communityid, _ := strconv.Atoi(r.FormValue("communityid"))
|
communityid, _ := strconv.ParseInt(r.FormValue("communityid"), 10, 64)
|
||||||
state.Client.BlockCommunity(context.Background(), types.BlockCommunity{
|
state.Client.BlockCommunity(context.Background(), lemmy.BlockCommunity{
|
||||||
CommunityID: communityid,
|
CommunityID: communityid,
|
||||||
Block: false,
|
Block: false,
|
||||||
})
|
})
|
||||||
case "block_user":
|
case "block_user":
|
||||||
personId, _ := strconv.Atoi(r.FormValue("user_id"))
|
personId, _ := strconv.ParseInt(r.FormValue("user_id"), 10, 64)
|
||||||
if personId == 0 {
|
if personId == 0 {
|
||||||
state.GetUser(ps.ByName("username"))
|
state.GetUser(ps.ByName("username"))
|
||||||
personId = state.User.PersonView.Person.ID
|
personId = state.User.PersonView.Person.ID
|
||||||
}
|
}
|
||||||
state.Client.BlockPerson(context.Background(), types.BlockPerson{
|
state.Client.BlockPerson(context.Background(), lemmy.BlockPerson{
|
||||||
PersonID: personId,
|
PersonID: personId,
|
||||||
Block: r.FormValue("submit") == "block",
|
Block: r.FormValue("submit") == "block",
|
||||||
})
|
})
|
||||||
|
@ -986,12 +985,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
deleteCookie(w, state.Host, "jwt")
|
deleteCookie(w, state.Host, "jwt")
|
||||||
deleteCookie(w, state.Host, "user")
|
deleteCookie(w, state.Host, "user")
|
||||||
case "login":
|
case "login":
|
||||||
login := types.Login{
|
login := lemmy.Login{
|
||||||
UsernameOrEmail: r.FormValue("username"),
|
UsernameOrEmail: r.FormValue("username"),
|
||||||
Password: r.FormValue("password"),
|
Password: r.FormValue("password"),
|
||||||
}
|
}
|
||||||
if r.FormValue("totp") != "" {
|
if r.FormValue("totp") != "" {
|
||||||
login.Totp2faToken = types.NewOptional(r.FormValue("totp"))
|
login.TOTP2FAToken = lemmy.NewOptional(r.FormValue("totp"))
|
||||||
}
|
}
|
||||||
resp, err := state.Client.Login(context.Background(), login)
|
resp, err := state.Client.Login(context.Background(), login)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1010,18 +1009,18 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
state.GetUser(r.FormValue("username"))
|
state.GetUser(r.FormValue("username"))
|
||||||
if state.User != nil {
|
if state.User != nil {
|
||||||
setCookie(w, state.Host, "jwt", resp.JWT.String())
|
setCookie(w, state.Host, "jwt", resp.JWT.String())
|
||||||
userid := strconv.Itoa(state.User.PersonView.Person.ID)
|
userid := strconv.FormatInt(state.User.PersonView.Person.ID, 10)
|
||||||
setCookie(w, state.Host, "user", state.User.PersonView.Person.Name+":"+userid)
|
setCookie(w, state.Host, "user", state.User.PersonView.Person.Name+":"+userid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "create_community":
|
case "create_community":
|
||||||
state.GetSite()
|
state.GetSite()
|
||||||
community := types.CreateCommunity{
|
community := lemmy.CreateCommunity{
|
||||||
Name: r.FormValue("name"),
|
Name: r.FormValue("name"),
|
||||||
Title: r.FormValue("title"),
|
Title: r.FormValue("title"),
|
||||||
}
|
}
|
||||||
if r.FormValue("description") != "" {
|
if r.FormValue("description") != "" {
|
||||||
community.Description = types.NewOptional(r.FormValue("description"))
|
community.Description = lemmy.NewOptional(r.FormValue("description"))
|
||||||
}
|
}
|
||||||
if file, handler, err := r.FormFile("icon"); err == nil {
|
if file, handler, err := r.FormFile("icon"); err == nil {
|
||||||
pres, err := state.UploadImage(file, handler)
|
pres, err := state.UploadImage(file, handler)
|
||||||
|
@ -1030,7 +1029,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
community.Icon = types.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
community.Icon = lemmy.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
||||||
}
|
}
|
||||||
if file, handler, err := r.FormFile("banner"); err == nil {
|
if file, handler, err := r.FormFile("banner"); err == nil {
|
||||||
pres, err := state.UploadImage(file, handler)
|
pres, err := state.UploadImage(file, handler)
|
||||||
|
@ -1039,7 +1038,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
community.Banner = types.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
community.Banner = lemmy.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
||||||
}
|
}
|
||||||
resp, err := state.Client.CreateCommunity(context.Background(), community)
|
resp, err := state.Client.CreateCommunity(context.Background(), community)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -1055,14 +1054,14 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
state.GetSite()
|
state.GetSite()
|
||||||
community := types.EditCommunity{
|
community := lemmy.EditCommunity{
|
||||||
CommunityID: state.Community.CommunityView.Community.ID,
|
CommunityID: state.Community.CommunityView.Community.ID,
|
||||||
}
|
}
|
||||||
if r.FormValue("title") != "" {
|
if r.FormValue("title") != "" {
|
||||||
community.Title = types.NewOptional(r.FormValue("title"))
|
community.Title = lemmy.NewOptional(r.FormValue("title"))
|
||||||
}
|
}
|
||||||
if r.FormValue("description") != "" {
|
if r.FormValue("description") != "" {
|
||||||
community.Description = types.NewOptional(r.FormValue("description"))
|
community.Description = lemmy.NewOptional(r.FormValue("description"))
|
||||||
}
|
}
|
||||||
if file, handler, err := r.FormFile("icon"); err == nil {
|
if file, handler, err := r.FormFile("icon"); err == nil {
|
||||||
pres, err := state.UploadImage(file, handler)
|
pres, err := state.UploadImage(file, handler)
|
||||||
|
@ -1071,7 +1070,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
community.Icon = types.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
community.Icon = lemmy.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
||||||
}
|
}
|
||||||
if file, handler, err := r.FormFile("banner"); err == nil {
|
if file, handler, err := r.FormFile("banner"); err == nil {
|
||||||
pres, err := state.UploadImage(file, handler)
|
pres, err := state.UploadImage(file, handler)
|
||||||
|
@ -1080,7 +1079,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
community.Banner = types.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
community.Banner = lemmy.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
||||||
}
|
}
|
||||||
resp, err := state.Client.EditCommunity(context.Background(), community)
|
resp, err := state.Client.EditCommunity(context.Background(), community)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -1100,12 +1099,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
post := types.CreatePost{
|
post := lemmy.CreatePost{
|
||||||
Name: r.FormValue("name"),
|
Name: r.FormValue("name"),
|
||||||
CommunityID: state.Community.CommunityView.Community.ID,
|
CommunityID: state.Community.CommunityView.Community.ID,
|
||||||
}
|
}
|
||||||
if r.FormValue("url") != "" {
|
if r.FormValue("url") != "" {
|
||||||
post.URL = types.NewOptional(r.FormValue("url"))
|
post.URL = lemmy.NewOptional(r.FormValue("url"))
|
||||||
}
|
}
|
||||||
file, handler, err := r.FormFile("file")
|
file, handler, err := r.FormFile("file")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -1115,18 +1114,18 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
post.URL = types.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
post.URL = lemmy.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
||||||
}
|
}
|
||||||
if r.FormValue("body") != "" {
|
if r.FormValue("body") != "" {
|
||||||
post.Body = types.NewOptional(r.FormValue("body"))
|
post.Body = lemmy.NewOptional(r.FormValue("body"))
|
||||||
}
|
}
|
||||||
if r.FormValue("language") != "" {
|
if r.FormValue("language") != "" {
|
||||||
languageid, _ := strconv.Atoi(r.FormValue("language"))
|
languageid, _ := strconv.ParseInt(r.FormValue("language"), 10, 64)
|
||||||
post.LanguageID = types.NewOptional(languageid)
|
post.LanguageID = lemmy.NewOptional(languageid)
|
||||||
}
|
}
|
||||||
resp, err := state.Client.CreatePost(context.Background(), post)
|
resp, err := state.Client.CreatePost(context.Background(), post)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
postid := strconv.Itoa(resp.PostView.Post.ID)
|
postid := strconv.FormatInt(resp.PostView.Post.ID, 10)
|
||||||
r.URL.Path = "/" + state.Host + "/post/" + postid
|
r.URL.Path = "/" + state.Host + "/post/" + postid
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -1134,19 +1133,19 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
case "edit_post":
|
case "edit_post":
|
||||||
r.ParseMultipartForm(10 << 20)
|
r.ParseMultipartForm(10 << 20)
|
||||||
state.GetSite()
|
state.GetSite()
|
||||||
postid, _ := strconv.Atoi(ps.ByName("postid"))
|
postid, _ := strconv.ParseInt(ps.ByName("postid"), 10, 64)
|
||||||
post := types.EditPost{
|
post := lemmy.EditPost{
|
||||||
PostID: postid,
|
PostID: postid,
|
||||||
Body: types.NewOptional(r.FormValue("body")),
|
Body: lemmy.NewOptional(r.FormValue("body")),
|
||||||
Name: types.NewOptional(r.FormValue("name")),
|
Name: lemmy.NewOptional(r.FormValue("name")),
|
||||||
URL: types.NewOptional(r.FormValue("url")),
|
URL: lemmy.NewOptional(r.FormValue("url")),
|
||||||
}
|
}
|
||||||
if r.FormValue("url") == "" {
|
if r.FormValue("url") == "" {
|
||||||
post.URL = types.Optional[string]{}
|
post.URL = lemmy.Optional[string]{}
|
||||||
}
|
}
|
||||||
if r.FormValue("language") != "" {
|
if r.FormValue("language") != "" {
|
||||||
languageid, _ := strconv.Atoi(r.FormValue("language"))
|
languageid, _ := strconv.ParseInt(r.FormValue("language"), 10, 64)
|
||||||
post.LanguageID = types.NewOptional(languageid)
|
post.LanguageID = lemmy.NewOptional(languageid)
|
||||||
}
|
}
|
||||||
file, handler, err := r.FormFile("file")
|
file, handler, err := r.FormFile("file")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -1156,12 +1155,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
post.URL = types.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
post.URL = lemmy.NewOptional("https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := state.Client.EditPost(context.Background(), post)
|
resp, err := state.Client.EditPost(context.Background(), post)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
postid := strconv.Itoa(resp.PostView.Post.ID)
|
postid := strconv.FormatInt(resp.PostView.Post.ID, 10)
|
||||||
r.URL.Path = "/" + state.Host + "/post/" + postid
|
r.URL.Path = "/" + state.Host + "/post/" + postid
|
||||||
r.URL.RawQuery = ""
|
r.URL.RawQuery = ""
|
||||||
} else {
|
} else {
|
||||||
|
@ -1170,8 +1169,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
case "save_post":
|
case "save_post":
|
||||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64)
|
||||||
_, err := state.Client.SavePost(context.Background(), types.SavePost{
|
_, err := state.Client.SavePost(context.Background(), lemmy.SavePost{
|
||||||
PostID: postid,
|
PostID: postid,
|
||||||
Save: r.FormValue("submit") == "save",
|
Save: r.FormValue("submit") == "save",
|
||||||
})
|
})
|
||||||
|
@ -1187,8 +1186,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "save_comment":
|
case "save_comment":
|
||||||
commentid, _ := strconv.Atoi(r.FormValue("commentid"))
|
commentid, _ := strconv.ParseInt(r.FormValue("commentid"), 10, 64)
|
||||||
_, err := state.Client.SaveComment(context.Background(), types.SaveComment{
|
_, err := state.Client.SaveComment(context.Background(), lemmy.SaveComment{
|
||||||
CommentID: commentid,
|
CommentID: commentid,
|
||||||
Save: r.FormValue("submit") == "save",
|
Save: r.FormValue("submit") == "save",
|
||||||
})
|
})
|
||||||
|
@ -1202,8 +1201,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "delete_post":
|
case "delete_post":
|
||||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64)
|
||||||
post := types.DeletePost{
|
post := lemmy.DeletePost{
|
||||||
PostID: postid,
|
PostID: postid,
|
||||||
Deleted: true,
|
Deleted: true,
|
||||||
}
|
}
|
||||||
|
@ -1218,24 +1217,24 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
r.URL.RawQuery = ""
|
r.URL.RawQuery = ""
|
||||||
}
|
}
|
||||||
case "block_post":
|
case "block_post":
|
||||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64)
|
||||||
state.GetPost(postid)
|
state.GetPost(postid)
|
||||||
if r.FormValue("blockcommunity") != "" && len(state.Posts) > 0 {
|
if r.FormValue("blockcommunity") != "" && len(state.Posts) > 0 {
|
||||||
state.Client.BlockCommunity(context.Background(), types.BlockCommunity{
|
state.Client.BlockCommunity(context.Background(), lemmy.BlockCommunity{
|
||||||
CommunityID: state.Posts[0].Post.CommunityID,
|
CommunityID: state.Posts[0].Post.CommunityID,
|
||||||
Block: true,
|
Block: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if r.FormValue("blockuser") != "" && len(state.Posts) > 0 {
|
if r.FormValue("blockuser") != "" && len(state.Posts) > 0 {
|
||||||
state.Client.BlockPerson(context.Background(), types.BlockPerson{
|
state.Client.BlockPerson(context.Background(), lemmy.BlockPerson{
|
||||||
PersonID: state.Posts[0].Post.CreatorID,
|
PersonID: state.Posts[0].Post.CreatorID,
|
||||||
Block: true,
|
Block: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case "read_post":
|
case "read_post":
|
||||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64)
|
||||||
post := types.MarkPostAsRead{
|
post := lemmy.MarkPostAsRead{
|
||||||
PostID: postid,
|
PostID: lemmy.NewOptional(postid),
|
||||||
Read: true,
|
Read: true,
|
||||||
}
|
}
|
||||||
if r.FormValue("submit") == "mark unread" {
|
if r.FormValue("submit") == "mark unread" {
|
||||||
|
@ -1249,7 +1248,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "vote_post":
|
case "vote_post":
|
||||||
var score int16
|
var score int64
|
||||||
score = 1
|
score = 1
|
||||||
if r.FormValue("vote") != "▲" {
|
if r.FormValue("vote") != "▲" {
|
||||||
score = -1
|
score = -1
|
||||||
|
@ -1257,12 +1256,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
if r.FormValue("undo") == strconv.Itoa(int(score)) {
|
if r.FormValue("undo") == strconv.Itoa(int(score)) {
|
||||||
score = 0
|
score = 0
|
||||||
}
|
}
|
||||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64)
|
||||||
post := types.CreatePostLike{
|
post := lemmy.CreatePostLike{
|
||||||
PostID: postid,
|
PostID: postid,
|
||||||
Score: score,
|
Score: score,
|
||||||
}
|
}
|
||||||
state.Client.CreatePostLike(context.Background(), post)
|
state.Client.LikePost(context.Background(), post)
|
||||||
if r.FormValue("xhr") != "" {
|
if r.FormValue("xhr") != "" {
|
||||||
state.GetPost(postid)
|
state.GetPost(postid)
|
||||||
state.PostID = 0
|
state.PostID = 0
|
||||||
|
@ -1272,7 +1271,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "vote_comment":
|
case "vote_comment":
|
||||||
var score int16
|
var score int64
|
||||||
score = 1
|
score = 1
|
||||||
if r.FormValue("submit") != "▲" {
|
if r.FormValue("submit") != "▲" {
|
||||||
score = -1
|
score = -1
|
||||||
|
@ -1280,12 +1279,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
if r.FormValue("undo") == strconv.Itoa(int(score)) {
|
if r.FormValue("undo") == strconv.Itoa(int(score)) {
|
||||||
score = 0
|
score = 0
|
||||||
}
|
}
|
||||||
commentid, _ := strconv.Atoi(r.FormValue("commentid"))
|
commentid, _ := strconv.ParseInt(r.FormValue("commentid"), 10, 64)
|
||||||
post := types.CreateCommentLike{
|
post := lemmy.CreateCommentLike{
|
||||||
CommentID: commentid,
|
CommentID: commentid,
|
||||||
Score: score,
|
Score: score,
|
||||||
}
|
}
|
||||||
state.Client.CreateCommentLike(context.Background(), post)
|
state.Client.LikeComment(context.Background(), post)
|
||||||
if r.FormValue("xhr") != "" {
|
if r.FormValue("xhr") != "" {
|
||||||
state.XHR = true
|
state.XHR = true
|
||||||
state.GetComment(commentid)
|
state.GetComment(commentid)
|
||||||
|
@ -1294,11 +1293,11 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
}
|
}
|
||||||
case "create_comment":
|
case "create_comment":
|
||||||
if ps.ByName("postid") != "" {
|
if ps.ByName("postid") != "" {
|
||||||
postid, _ := strconv.Atoi(ps.ByName("postid"))
|
postid, _ := strconv.ParseInt(ps.ByName("postid"), 10, 64)
|
||||||
state.PostID = postid
|
state.PostID = postid
|
||||||
}
|
}
|
||||||
if r.FormValue("parentid") != "" && r.FormValue("parentid") != "0" {
|
if r.FormValue("parentid") != "" && r.FormValue("parentid") != "0" {
|
||||||
parentid, _ := strconv.Atoi(r.FormValue("parentid"))
|
parentid, _ := strconv.ParseInt(r.FormValue("parentid"), 10, 64)
|
||||||
state.GetComment(parentid)
|
state.GetComment(parentid)
|
||||||
}
|
}
|
||||||
content := r.FormValue("content")
|
content := r.FormValue("content")
|
||||||
|
@ -1313,12 +1312,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
content += ("![](https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename + ")")
|
content += ("![](https://" + state.Host + "/pictrs/image/" + pres.Files[0].Filename + ")")
|
||||||
}
|
}
|
||||||
if r.FormValue("submit") == "save" {
|
if r.FormValue("submit") == "save" {
|
||||||
createComment := types.CreateComment{
|
createComment := lemmy.CreateComment{
|
||||||
Content: content,
|
Content: content,
|
||||||
PostID: state.PostID,
|
PostID: state.PostID,
|
||||||
}
|
}
|
||||||
if state.CommentID > 0 {
|
if state.CommentID > 0 {
|
||||||
createComment.ParentID = types.NewOptional(state.CommentID)
|
createComment.ParentID = lemmy.NewOptional(state.CommentID)
|
||||||
}
|
}
|
||||||
resp, err := state.Client.CreateComment(context.Background(), createComment)
|
resp, err := state.Client.CreateComment(context.Background(), createComment)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -1329,8 +1328,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
postid := strconv.Itoa(state.PostID)
|
postid := strconv.FormatInt(state.PostID, 10)
|
||||||
commentid := strconv.Itoa(resp.CommentView.Comment.ID)
|
commentid := strconv.FormatInt(resp.CommentView.Comment.ID, 10)
|
||||||
r.URL.Path = "/" + state.Host + "/post/" + postid
|
r.URL.Path = "/" + state.Host + "/post/" + postid
|
||||||
r.URL.Fragment = "c" + commentid
|
r.URL.Fragment = "c" + commentid
|
||||||
} else {
|
} else {
|
||||||
|
@ -1360,7 +1359,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
r.URL.RawQuery = ""
|
r.URL.RawQuery = ""
|
||||||
}
|
}
|
||||||
case "edit_comment":
|
case "edit_comment":
|
||||||
commentid, _ := strconv.Atoi(r.FormValue("commentid"))
|
commentid, _ := strconv.ParseInt(r.FormValue("commentid"), 10, 64)
|
||||||
q := r.URL.Query()
|
q := r.URL.Query()
|
||||||
content := r.FormValue("content")
|
content := r.FormValue("content")
|
||||||
file, handler, err := r.FormFile("file")
|
file, handler, err := r.FormFile("file")
|
||||||
|
@ -1375,14 +1374,14 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.FormValue("submit") == "save" {
|
if r.FormValue("submit") == "save" {
|
||||||
resp, err := state.Client.EditComment(context.Background(), types.EditComment{
|
resp, err := state.Client.EditComment(context.Background(), lemmy.EditComment{
|
||||||
CommentID: commentid,
|
CommentID: commentid,
|
||||||
Content: types.NewOptional(content),
|
Content: lemmy.NewOptional(content),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
commentid := strconv.Itoa(resp.CommentView.Comment.ID)
|
commentid := strconv.FormatInt(resp.CommentView.Comment.ID, 10)
|
||||||
r.URL.Fragment = "c" + commentid
|
r.URL.Fragment = "c" + commentid
|
||||||
r.URL.RawQuery = ""
|
r.URL.RawQuery = ""
|
||||||
}
|
}
|
||||||
|
@ -1420,8 +1419,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
r.URL.RawQuery = ""
|
r.URL.RawQuery = ""
|
||||||
}
|
}
|
||||||
case "delete_comment":
|
case "delete_comment":
|
||||||
commentid, _ := strconv.Atoi(r.FormValue("commentid"))
|
commentid, _ := strconv.ParseInt(r.FormValue("commentid"), 10, 64)
|
||||||
resp, err := state.Client.DeleteComment(context.Background(), types.DeleteComment{
|
resp, err := state.Client.DeleteComment(context.Background(), lemmy.DeleteComment{
|
||||||
CommentID: commentid,
|
CommentID: commentid,
|
||||||
Deleted: true,
|
Deleted: true,
|
||||||
})
|
})
|
||||||
|
@ -1435,7 +1434,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
commentid := strconv.Itoa(resp.CommentView.Comment.ID)
|
commentid := strconv.FormatInt(resp.CommentView.Comment.ID, 10)
|
||||||
r.URL.Fragment = "c" + commentid
|
r.URL.Fragment = "c" + commentid
|
||||||
r.URL.RawQuery = ""
|
r.URL.RawQuery = ""
|
||||||
}
|
}
|
||||||
|
|
175
state.go
175
state.go
|
@ -18,12 +18,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rystaf/go-lemmy"
|
"go.elara.ws/go-lemmy"
|
||||||
"github.com/rystaf/go-lemmy/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Comment struct {
|
type Comment struct {
|
||||||
P types.CommentView
|
P lemmy.CommentView
|
||||||
C []Comment
|
C []Comment
|
||||||
Selected bool
|
Selected bool
|
||||||
State *State
|
State *State
|
||||||
|
@ -35,25 +34,25 @@ func (c *Comment) Submitter() bool {
|
||||||
return c.P.Comment.CreatorID == c.P.Post.CreatorID
|
return c.P.Comment.CreatorID == c.P.Post.CreatorID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Comment) ParentID() int {
|
func (c *Comment) ParentID() int64 {
|
||||||
path := strings.Split(c.P.Comment.Path, ".")
|
path := strings.Split(c.P.Comment.Path, ".")
|
||||||
id, _ := strconv.Atoi(path[len(path)-2])
|
id, _ := strconv.ParseInt(path[len(path)-2], 10, 64)
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
type Person struct {
|
type Person struct {
|
||||||
types.PersonViewSafe
|
lemmy.PersonView
|
||||||
}
|
}
|
||||||
|
|
||||||
type Activity struct {
|
type Activity struct {
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
Comment *Comment
|
Comment *Comment
|
||||||
Post *Post
|
Post *Post
|
||||||
Message *types.PrivateMessageView
|
Message *lemmy.PrivateMessageView
|
||||||
}
|
}
|
||||||
|
|
||||||
type Post struct {
|
type Post struct {
|
||||||
types.PostView
|
lemmy.PostView
|
||||||
Rank int
|
Rank int
|
||||||
State *State
|
State *State
|
||||||
}
|
}
|
||||||
|
@ -61,7 +60,7 @@ type Post struct {
|
||||||
type Session struct {
|
type Session struct {
|
||||||
UserName string
|
UserName string
|
||||||
UserID int
|
UserID int
|
||||||
Communities []types.CommunityView
|
Communities []lemmy.CommunityView
|
||||||
}
|
}
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
|
@ -75,9 +74,9 @@ type State struct {
|
||||||
Alert string
|
Alert string
|
||||||
Host string
|
Host string
|
||||||
CommunityName string
|
CommunityName string
|
||||||
Community *types.GetCommunityResponse
|
Community *lemmy.GetCommunityResponse
|
||||||
TopCommunities []types.CommunityView
|
TopCommunities []lemmy.CommunityView
|
||||||
Communities []types.CommunityView
|
Communities []lemmy.CommunityView
|
||||||
UnreadCount int64
|
UnreadCount int64
|
||||||
Sort string
|
Sort string
|
||||||
CommentSort string
|
CommentSort string
|
||||||
|
@ -88,19 +87,19 @@ type State struct {
|
||||||
Comments []Comment
|
Comments []Comment
|
||||||
Activities []Activity
|
Activities []Activity
|
||||||
CommentCount int
|
CommentCount int
|
||||||
PostID int
|
PostID int64
|
||||||
CommentID int
|
CommentID int64
|
||||||
Context int
|
Context int
|
||||||
UserName string
|
UserName string
|
||||||
User *types.GetPersonDetailsResponse
|
User *lemmy.GetPersonDetailsResponse
|
||||||
Now int64
|
Now int64
|
||||||
XHR bool
|
XHR bool
|
||||||
Op string
|
Op string
|
||||||
Site *types.GetSiteResponse
|
Site *lemmy.GetSiteResponse
|
||||||
Query string
|
Query string
|
||||||
Content string
|
Content string
|
||||||
SearchType string
|
SearchType string
|
||||||
Captcha *types.CaptchaResponse
|
Captcha *lemmy.CaptchaResponse
|
||||||
Dark bool
|
Dark bool
|
||||||
ShowNSFW bool
|
ShowNSFW bool
|
||||||
HideInstanceNames bool
|
HideInstanceNames bool
|
||||||
|
@ -115,7 +114,7 @@ func (s State) UserBlocked() bool {
|
||||||
if s.User == nil || s.Site == nil || !s.Site.MyUser.IsValid() {
|
if s.User == nil || s.Site == nil || !s.Site.MyUser.IsValid() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, p := range s.Site.MyUser.MustValue().PersonBlocks {
|
for _, p := range s.Site.MyUser.ValueOrZero().PersonBlocks {
|
||||||
if p.Target.ID == s.User.PersonView.Person.ID {
|
if p.Target.ID == s.User.PersonView.Person.ID {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -261,7 +260,7 @@ func (state *State) LemmyError(domain string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *State) GetCaptcha() {
|
func (state *State) GetCaptcha() {
|
||||||
resp, err := state.Client.Captcha(context.Background(), types.GetCaptcha{})
|
resp, err := state.Client.Captcha(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Get %v %v", err, resp)
|
fmt.Printf("Get %v %v", err, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -272,7 +271,7 @@ func (state *State) GetCaptcha() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (state *State) GetSite() {
|
func (state *State) GetSite() {
|
||||||
resp, err := state.Client.Site(context.Background(), types.GetSite{})
|
resp, err := state.Client.Site(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
state.Status = http.StatusInternalServerError
|
state.Status = http.StatusInternalServerError
|
||||||
|
@ -284,8 +283,8 @@ func (state *State) GetSite() {
|
||||||
if !state.Site.MyUser.IsValid() {
|
if !state.Site.MyUser.IsValid() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, c := range state.Site.MyUser.MustValue().Follows {
|
for _, c := range state.Site.MyUser.ValueOrZero().Follows {
|
||||||
state.Session.Communities = append(state.Session.Communities, types.CommunityView{
|
state.Session.Communities = append(state.Session.Communities, lemmy.CommunityView{
|
||||||
Community: c.Community,
|
Community: c.Community,
|
||||||
Subscribed: "Subscribed",
|
Subscribed: "Subscribed",
|
||||||
})
|
})
|
||||||
|
@ -295,16 +294,16 @@ func (state *State) GetSite() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *State) GetComment(commentid int) {
|
func (state *State) GetComment(commentid int64) {
|
||||||
if state.Sort != "Hot" && state.Sort != "Top" && state.Sort != "Old" && state.Sort != "New" {
|
if state.Sort != "Hot" && state.Sort != "Top" && state.Sort != "Old" && state.Sort != "New" {
|
||||||
state.Sort = "Hot"
|
state.Sort = "Hot"
|
||||||
}
|
}
|
||||||
state.CommentID = commentid
|
state.CommentID = commentid
|
||||||
cresp, err := state.Client.Comments(context.Background(), types.GetComments{
|
cresp, err := state.Client.Comments(context.Background(), lemmy.GetComments{
|
||||||
ParentID: types.NewOptional(state.CommentID),
|
ParentID: lemmy.NewOptional(state.CommentID),
|
||||||
Sort: types.NewOptional(types.CommentSortType(state.CommentSort)),
|
Sort: lemmy.NewOptional(lemmy.CommentSortType(state.CommentSort)),
|
||||||
Type: types.NewOptional(types.ListingType("All")),
|
Type: lemmy.NewOptional(lemmy.ListingType("All")),
|
||||||
Limit: types.NewOptional(int64(50)),
|
Limit: lemmy.NewOptional(int64(50)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -340,7 +339,7 @@ func (state *State) GetContext(depth int, comment Comment) (ctx Comment, err err
|
||||||
if depth < 1 || comment.ParentID() == 0 {
|
if depth < 1 || comment.ParentID() == 0 {
|
||||||
return comment, nil
|
return comment, nil
|
||||||
}
|
}
|
||||||
cresp, err := state.Client.Comment(context.Background(), types.GetComment{
|
cresp, err := state.Client.Comment(context.Background(), lemmy.GetComment{
|
||||||
ID: comment.ParentID(),
|
ID: comment.ParentID(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -358,12 +357,12 @@ func (state *State) GetComments() {
|
||||||
if state.Sort != "Hot" && state.Sort != "Top" && state.Sort != "Old" && state.Sort != "New" {
|
if state.Sort != "Hot" && state.Sort != "Top" && state.Sort != "Old" && state.Sort != "New" {
|
||||||
state.Sort = "Hot"
|
state.Sort = "Hot"
|
||||||
}
|
}
|
||||||
cresp, err := state.Client.Comments(context.Background(), types.GetComments{
|
cresp, err := state.Client.Comments(context.Background(), lemmy.GetComments{
|
||||||
PostID: types.NewOptional(state.PostID),
|
PostID: lemmy.NewOptional(state.PostID),
|
||||||
Sort: types.NewOptional(types.CommentSortType(state.CommentSort)),
|
Sort: lemmy.NewOptional(lemmy.CommentSortType(state.CommentSort)),
|
||||||
Type: types.NewOptional(types.ListingType("All")),
|
Type: lemmy.NewOptional(lemmy.ListingType("All")),
|
||||||
Limit: types.NewOptional(int64(50)),
|
Limit: lemmy.NewOptional(int64(50)),
|
||||||
Page: types.NewOptional(int64(state.Page)),
|
Page: lemmy.NewOptional(int64(state.Page)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Status = http.StatusInternalServerError
|
state.Status = http.StatusInternalServerError
|
||||||
|
@ -377,7 +376,7 @@ func (state *State) GetComments() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
comment := Comment{P: c, State: state}
|
comment := Comment{P: c, State: state}
|
||||||
var postCreatorID int
|
var postCreatorID int64
|
||||||
if len(state.Posts) > 0 {
|
if len(state.Posts) > 0 {
|
||||||
postCreatorID = state.Posts[0].Post.CreatorID
|
postCreatorID = state.Posts[0].Post.CreatorID
|
||||||
}
|
}
|
||||||
|
@ -387,8 +386,8 @@ func (state *State) GetComments() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *State) GetMessages() {
|
func (state *State) GetMessages() {
|
||||||
if resp, err := state.Client.PrivateMessages(context.Background(), types.GetPrivateMessages{
|
if resp, err := state.Client.PrivateMessages(context.Background(), lemmy.GetPrivateMessages{
|
||||||
Page: types.NewOptional(int64(state.Page)),
|
Page: lemmy.NewOptional(int64(state.Page)),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
state.Status = http.StatusInternalServerError
|
state.Status = http.StatusInternalServerError
|
||||||
|
@ -397,13 +396,13 @@ func (state *State) GetMessages() {
|
||||||
for _, m := range resp.PrivateMessages {
|
for _, m := range resp.PrivateMessages {
|
||||||
message := m
|
message := m
|
||||||
state.Activities = append(state.Activities, Activity{
|
state.Activities = append(state.Activities, Activity{
|
||||||
Timestamp: m.PrivateMessage.Published.Time,
|
Timestamp: m.PrivateMessage.Published,
|
||||||
Message: &message,
|
Message: &message,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if resp, err := state.Client.PersonMentions(context.Background(), types.GetPersonMentions{
|
if resp, err := state.Client.PersonMentions(context.Background(), lemmy.GetPersonMentions{
|
||||||
Page: types.NewOptional(int64(state.Page)),
|
Page: lemmy.NewOptional(int64(state.Page)),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
state.Status = http.StatusInternalServerError
|
state.Status = http.StatusInternalServerError
|
||||||
|
@ -415,20 +414,20 @@ func (state *State) GetMessages() {
|
||||||
unread = "unread"
|
unread = "unread"
|
||||||
}
|
}
|
||||||
comment := Comment{
|
comment := Comment{
|
||||||
P: types.CommentView{
|
P: lemmy.CommentView{
|
||||||
Comment: m.Comment,
|
Comment: m.Comment,
|
||||||
},
|
},
|
||||||
Op: unread,
|
Op: unread,
|
||||||
State: state,
|
State: state,
|
||||||
}
|
}
|
||||||
state.Activities = append(state.Activities, Activity{
|
state.Activities = append(state.Activities, Activity{
|
||||||
Timestamp: m.Comment.Published.Time,
|
Timestamp: m.Comment.Published,
|
||||||
Comment: &comment,
|
Comment: &comment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if resp, err := state.Client.Replies(context.Background(), types.GetReplies{
|
if resp, err := state.Client.Replies(context.Background(), lemmy.GetReplies{
|
||||||
Page: types.NewOptional(int64(state.Page)),
|
Page: lemmy.NewOptional(int64(state.Page)),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
state.Status = http.StatusInternalServerError
|
state.Status = http.StatusInternalServerError
|
||||||
|
@ -440,7 +439,7 @@ func (state *State) GetMessages() {
|
||||||
unread = "unread"
|
unread = "unread"
|
||||||
}
|
}
|
||||||
comment := Comment{
|
comment := Comment{
|
||||||
P: types.CommentView{
|
P: lemmy.CommentView{
|
||||||
Comment: m.Comment,
|
Comment: m.Comment,
|
||||||
Post: m.Post,
|
Post: m.Post,
|
||||||
Creator: m.Creator,
|
Creator: m.Creator,
|
||||||
|
@ -451,7 +450,7 @@ func (state *State) GetMessages() {
|
||||||
State: state,
|
State: state,
|
||||||
}
|
}
|
||||||
state.Activities = append(state.Activities, Activity{
|
state.Activities = append(state.Activities, Activity{
|
||||||
Timestamp: m.Comment.Published.Time,
|
Timestamp: m.Comment.Published,
|
||||||
Comment: &comment,
|
Comment: &comment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -464,11 +463,11 @@ func (state *State) GetUser(username string) {
|
||||||
if state.Op == "send_message" {
|
if state.Op == "send_message" {
|
||||||
limit = 1
|
limit = 1
|
||||||
}
|
}
|
||||||
resp, err := state.Client.PersonDetails(context.Background(), types.GetPersonDetails{
|
resp, err := state.Client.PersonDetails(context.Background(), lemmy.GetPersonDetails{
|
||||||
Username: types.NewOptional(state.UserName),
|
Username: lemmy.NewOptional(state.UserName),
|
||||||
Page: types.NewOptional(int64(state.Page)),
|
Page: lemmy.NewOptional(int64(state.Page)),
|
||||||
Limit: types.NewOptional(int64(limit)),
|
Limit: lemmy.NewOptional(int64(limit)),
|
||||||
SavedOnly: types.NewOptional(state.Op == "Saved"),
|
SavedOnly: lemmy.NewOptional(state.Op == "Saved"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -487,14 +486,14 @@ func (state *State) GetUser(username string) {
|
||||||
State: state,
|
State: state,
|
||||||
}
|
}
|
||||||
state.Activities = append(state.Activities, Activity{
|
state.Activities = append(state.Activities, Activity{
|
||||||
Timestamp: p.Post.Published.Time,
|
Timestamp: p.Post.Published,
|
||||||
Post: &post,
|
Post: &post,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for _, c := range resp.Comments {
|
for _, c := range resp.Comments {
|
||||||
comment := Comment{P: c, State: state}
|
comment := Comment{P: c, State: state}
|
||||||
state.Activities = append(state.Activities, Activity{
|
state.Activities = append(state.Activities, Activity{
|
||||||
Timestamp: c.Comment.Published.Time,
|
Timestamp: c.Comment.Published,
|
||||||
Comment: &comment,
|
Comment: &comment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -504,7 +503,7 @@ func (state *State) GetUser(username string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *State) GetUnreadCount() {
|
func (state *State) GetUnreadCount() {
|
||||||
resp, err := state.Client.UnreadCount(context.Background(), types.GetUnreadCount{})
|
resp, err := state.Client.UnreadCount(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -512,9 +511,9 @@ func (state *State) GetUnreadCount() {
|
||||||
state.UnreadCount = resp.PrivateMessages + resp.Mentions + resp.Replies
|
state.UnreadCount = resp.PrivateMessages + resp.Mentions + resp.Replies
|
||||||
}
|
}
|
||||||
func (state *State) GetCommunities() {
|
func (state *State) GetCommunities() {
|
||||||
resp, err := state.Client.Communities(context.Background(), types.ListCommunities{
|
resp, err := state.Client.Communities(context.Background(), lemmy.ListCommunities{
|
||||||
Sort: types.NewOptional(types.SortType("TopAll")),
|
Sort: lemmy.NewOptional(lemmy.SortType("TopAll")),
|
||||||
Limit: types.NewOptional(int64(20)),
|
Limit: lemmy.NewOptional(int64(20)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -522,7 +521,7 @@ func (state *State) GetCommunities() {
|
||||||
state.TopCommunities = resp.Communities
|
state.TopCommunities = resp.Communities
|
||||||
}
|
}
|
||||||
func (state *State) MarkAllAsRead() {
|
func (state *State) MarkAllAsRead() {
|
||||||
_, err := state.Client.MarkAllAsRead(context.Background(), types.MarkAllAsRead{})
|
_, err := state.Client.MarkAllAsRead(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -530,14 +529,14 @@ func (state *State) MarkAllAsRead() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *State) GetPosts() {
|
func (state *State) GetPosts() {
|
||||||
posts := types.GetPosts{
|
posts := lemmy.GetPosts{
|
||||||
Sort: types.NewOptional(types.SortType(state.Sort)),
|
Sort: lemmy.NewOptional(lemmy.SortType(state.Sort)),
|
||||||
Type: types.NewOptional(types.ListingType(state.Listing)),
|
Type: lemmy.NewOptional(lemmy.ListingType(state.Listing)),
|
||||||
Limit: types.NewOptional(int64(25)),
|
Limit: lemmy.NewOptional(int64(25)),
|
||||||
Page: types.NewOptional(int64(state.Page)),
|
Page: lemmy.NewOptional(int64(state.Page)),
|
||||||
}
|
}
|
||||||
if state.CommunityName != "" {
|
if state.CommunityName != "" {
|
||||||
posts.CommunityName = types.NewOptional(state.CommunityName)
|
posts.CommunityName = lemmy.NewOptional(state.CommunityName)
|
||||||
}
|
}
|
||||||
resp, err := state.Client.Posts(context.Background(), posts)
|
resp, err := state.Client.Posts(context.Background(), posts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -567,11 +566,11 @@ func (state *State) Search(searchtype string) {
|
||||||
state.Communities = state.Session.Communities
|
state.Communities = state.Session.Communities
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err := state.Client.Communities(context.Background(), types.ListCommunities{
|
resp, err := state.Client.Communities(context.Background(), lemmy.ListCommunities{
|
||||||
Type: types.NewOptional(types.ListingType(state.Listing)),
|
Type: lemmy.NewOptional(lemmy.ListingType(state.Listing)),
|
||||||
Sort: types.NewOptional(types.SortType(state.Sort)),
|
Sort: lemmy.NewOptional(lemmy.SortType(state.Sort)),
|
||||||
Limit: types.NewOptional(int64(25)),
|
Limit: lemmy.NewOptional(int64(25)),
|
||||||
Page: types.NewOptional(int64(state.Page)),
|
Page: lemmy.NewOptional(int64(state.Page)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -580,21 +579,21 @@ func (state *State) Search(searchtype string) {
|
||||||
state.Communities = resp.Communities
|
state.Communities = resp.Communities
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
search := types.Search{
|
search := lemmy.Search{
|
||||||
Q: state.Query,
|
Q: state.Query,
|
||||||
Sort: types.NewOptional(types.SortType(state.Sort)),
|
Sort: lemmy.NewOptional(lemmy.SortType(state.Sort)),
|
||||||
ListingType: types.NewOptional(types.ListingType(state.Listing)),
|
ListingType: lemmy.NewOptional(lemmy.ListingType(state.Listing)),
|
||||||
Type: types.NewOptional(types.SearchType(searchtype)),
|
Type: lemmy.NewOptional(lemmy.SearchType(searchtype)),
|
||||||
Limit: types.NewOptional(int64(25)),
|
Limit: lemmy.NewOptional(int64(25)),
|
||||||
Page: types.NewOptional(int64(state.Page)),
|
Page: lemmy.NewOptional(int64(state.Page)),
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.CommunityName != "" {
|
if state.CommunityName != "" {
|
||||||
search.CommunityName = types.NewOptional(state.CommunityName)
|
search.CommunityName = lemmy.NewOptional(state.CommunityName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.User != nil {
|
if state.User != nil {
|
||||||
search.CreatorID = types.NewOptional(state.User.PersonView.Person.ID)
|
search.CreatorID = lemmy.NewOptional(state.User.PersonView.Person.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := state.Client.Search(context.Background(), search)
|
resp, err := state.Client.Search(context.Background(), search)
|
||||||
|
@ -616,7 +615,7 @@ func (state *State) Search(searchtype string) {
|
||||||
State: state,
|
State: state,
|
||||||
}
|
}
|
||||||
state.Activities = append(state.Activities, Activity{
|
state.Activities = append(state.Activities, Activity{
|
||||||
Timestamp: c.Comment.Published.Time,
|
Timestamp: c.Comment.Published,
|
||||||
Comment: &comment,
|
Comment: &comment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -624,14 +623,14 @@ func (state *State) Search(searchtype string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *State) GetPost(postid int) {
|
func (state *State) GetPost(postid int64) {
|
||||||
if postid == 0 {
|
if postid == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
state.PostID = postid
|
state.PostID = postid
|
||||||
// get post
|
// get post
|
||||||
resp, err := state.Client.Post(context.Background(), types.GetPost{
|
resp, err := state.Client.Post(context.Background(), lemmy.GetPost{
|
||||||
ID: types.NewOptional(state.PostID),
|
ID: lemmy.NewOptional(state.PostID),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Status = http.StatusInternalServerError
|
state.Status = http.StatusInternalServerError
|
||||||
|
@ -646,7 +645,7 @@ func (state *State) GetPost(postid int) {
|
||||||
state.Posts[0].Rank = -1
|
state.Posts[0].Rank = -1
|
||||||
}
|
}
|
||||||
state.CommunityName = resp.PostView.Community.Name
|
state.CommunityName = resp.PostView.Community.Name
|
||||||
cresp := types.GetCommunityResponse{
|
cresp := lemmy.GetCommunityResponse{
|
||||||
CommunityView: resp.CommunityView,
|
CommunityView: resp.CommunityView,
|
||||||
Moderators: resp.Moderators,
|
Moderators: resp.Moderators,
|
||||||
}
|
}
|
||||||
|
@ -660,8 +659,8 @@ func (state *State) GetCommunity(communityName string) {
|
||||||
if state.CommunityName == "" {
|
if state.CommunityName == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err := state.Client.Community(context.Background(), types.GetCommunity{
|
resp, err := state.Client.Community(context.Background(), lemmy.GetCommunity{
|
||||||
Name: types.NewOptional(state.CommunityName),
|
Name: lemmy.NewOptional(state.CommunityName),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Error = err
|
state.Error = err
|
||||||
|
@ -701,13 +700,13 @@ func (state *State) UploadImage(file multipart.File, header *multipart.FileHeade
|
||||||
return &pres, nil
|
return &pres, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getChildren(parent *Comment, pool []types.CommentView, postCreatorID int) {
|
func getChildren(parent *Comment, pool []lemmy.CommentView, postCreatorID int64) {
|
||||||
var children []Comment
|
var children []Comment
|
||||||
total := int32(0)
|
var total int64
|
||||||
for _, c := range pool {
|
for _, c := range pool {
|
||||||
levels := strings.Split(c.Comment.Path, ".")
|
levels := strings.Split(c.Comment.Path, ".")
|
||||||
for i, l := range levels {
|
for i, l := range levels {
|
||||||
id, _ := strconv.Atoi(l)
|
id, _ := strconv.ParseInt(l, 10, 64)
|
||||||
if id == parent.P.Comment.ID {
|
if id == parent.P.Comment.ID {
|
||||||
if i == (len(levels) - 2) {
|
if i == (len(levels) - 2) {
|
||||||
children = append(children, Comment{
|
children = append(children, Comment{
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
sent {{ humanize $activity.Message.PrivateMessage.Published.Time }}
|
sent {{ humanize $activity.Message.PrivateMessage.Published }}
|
||||||
</span>
|
</span>
|
||||||
<div>{{ markdown "" $activity.Message.PrivateMessage.Content }}</div>
|
<div>{{ markdown "" $activity.Message.PrivateMessage.Content }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -21,16 +21,16 @@
|
||||||
[-]
|
[-]
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</a>
|
</a>
|
||||||
<a class="creator{{ if .P.Comment.Distinguished}}{{if .P.Creator.Admin}} admin{{end}} distinguished{{ else if .Submitter }} submitter{{end}}" href="/{{.State.Host}}/u/{{fullname .P.Creator}}">
|
<a class="creator{{ if .P.Comment.Distinguished}}{{if false}} admin{{end}} distinguished{{ else if .Submitter }} submitter{{end}}" href="/{{.State.Host}}/u/{{fullname .P.Creator}}">
|
||||||
{{- if .State.HideInstanceNames -}}
|
{{- if .State.HideInstanceNames -}}
|
||||||
{{ .P.Creator.Name }}
|
{{ .P.Creator.Name }}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
{{ fullname .P.Creator }}
|
{{ fullname .P.Creator }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</a>
|
</a>
|
||||||
<b>{{.P.Counts.Score}} points</b> <span title="{{.P.Comment.Published.Time}}">{{ humanize .P.Comment.Published.Time }}</span>
|
<b>{{.P.Counts.Score}} points</b> <span title="{{.P.Comment.Published}}">{{ humanize .P.Comment.Published }}</span>
|
||||||
{{- if gt .P.Comment.Updated.Time.Unix .P.Comment.Published.Time.Unix -}}
|
{{- if gt .P.Comment.Updated.Unix .P.Comment.Published.Unix -}}
|
||||||
* (last edited <span title="{{.P.Comment.Updated.Time}}">{{ humanize .P.Comment.Updated.Time }}</span>)
|
* (last edited <span title="{{.P.Comment.Updated}}">{{ humanize .P.Comment.Updated }}</span>)
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<div class="gray">
|
<div class="gray">
|
||||||
{{ if .Counts.Subscribers }}{{ printer .Counts.Subscribers }} subscribers,{{end}}
|
{{ if .Counts.Subscribers }}{{ printer .Counts.Subscribers }} subscribers,{{end}}
|
||||||
a community founded {{ humanize .Community.Published.Time }}
|
a community founded {{ humanize .Community.Published }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -44,12 +44,12 @@
|
||||||
<div class="expando-button{{ if and (not (and .Post.Body.IsValid .Post.Body.String )) (not (isImage .Post.URL.String)) }} hidden{{else if eq .Rank 0}} open{{ end }}"></div>
|
<div class="expando-button{{ if and (not (and .Post.Body.IsValid .Post.Body.String )) (not (isImage .Post.URL.String)) }} hidden{{else if eq .Rank 0}} open{{ end }}"></div>
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
submitted
|
submitted
|
||||||
<span title="{{.Post.Published.Time}}">{{ humanize .Post.Published.Time -}}</span>
|
<span title="{{.Post.Published}}">{{ humanize .Post.Published -}}</span>
|
||||||
{{- if gt .Post.Updated.Time.Unix .Post.Published.Time.Unix -}}
|
{{- if gt .Post.Updated.Unix .Post.Published.Unix -}}
|
||||||
* (last edited <span title="{{.Post.Updated.Time}}">{{ humanize .Post.Updated.Time }}</span>)
|
* (last edited <span title="{{.Post.Updated}}">{{ humanize .Post.Updated }}</span>)
|
||||||
{{ end }}
|
{{ end }}
|
||||||
by
|
by
|
||||||
<a class="submitter{{ if .Creator.Admin}} admin{{end}}" href="/{{ .State.Host }}/u/{{ fullname .Creator }}">
|
<a class="submitter{{ if false}} admin{{end}}" href="/{{ .State.Host }}/u/{{ fullname .Creator }}">
|
||||||
{{- if .State.HideInstanceNames -}}
|
{{- if .State.HideInstanceNames -}}
|
||||||
{{ .Creator.Name }}
|
{{ .Creator.Name }}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
{{ if .State.PostID }}
|
{{ if .State.PostID }}
|
||||||
<a id="hidechildren" class="scripting" href="">hide all child comments</a>
|
<a id="hidechildren" class="scripting" href="">hide all child comments</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if and .State.Site .State.Site.MyUser.IsValid (not .State.Site.MyUser.MustValue.LocalUserView.LocalUser.ShowReadPosts) }}
|
{{ if and .State.Site .State.Site.MyUser.IsValid (not .State.Site.MyUser.ValueOrZero.LocalUserView.LocalUser.ShowReadPosts) }}
|
||||||
<form class="link-btn" method="POST">
|
<form class="link-btn" method="POST">
|
||||||
<input type="hidden" name="postid" value="{{.Post.ID }}">
|
<input type="hidden" name="postid" value="{{.Post.ID }}">
|
||||||
<input type="hidden" name="op" value="read_post">
|
<input type="hidden" name="op" value="read_post">
|
||||||
|
|
|
@ -31,11 +31,9 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<b>{{ .User.PersonView.Counts.PostScore}}</b> post score <br>
|
|
||||||
<b>{{ .User.PersonView.Counts.CommentScore}}</b> comment score <br>
|
|
||||||
<div class="age">
|
<div class="age">
|
||||||
{{ if .Session }}<span class="left">✉ <a href="/{{ $host}}/u/{{ fullname .User.PersonView.Person }}/message">send a message</a></span>{{end}}
|
{{ if .Session }}<span class="left">✉ <a href="/{{ $host}}/u/{{ fullname .User.PersonView.Person }}/message">send a message</a></span>{{end}}
|
||||||
<span title="{{ .User.PersonView.Person.Published.Time}}">joined {{ humanize .User.PersonView.Person.Published.Time }}</span>
|
<span title="{{ .User.PersonView.Person.Published}}">joined {{ humanize .User.PersonView.Person.Published }}</span>
|
||||||
</div>
|
</div>
|
||||||
{{ if .User.Moderates }}
|
{{ if .User.Moderates }}
|
||||||
MODERATOR OF
|
MODERATOR OF
|
||||||
|
@ -49,7 +47,7 @@
|
||||||
|
|
||||||
{{ if and .PostID .Posts }}
|
{{ if and .PostID .Posts }}
|
||||||
<div class="stats">
|
<div class="stats">
|
||||||
this post was submitted on {{ (index .Posts 0).Post.Published.Time.Format "02 Jan 2006" }}
|
this post was submitted on {{ (index .Posts 0).Post.Published.Format "02 Jan 2006" }}
|
||||||
<div><b><span>{{ (index .Posts 0).Counts.Score }}</span> points</b> ({{likedPerc (index .Posts 0).Counts}}% liked)</div>
|
<div><b><span>{{ (index .Posts 0).Counts.Score }}</span> points</b> ({{likedPerc (index .Posts 0).Counts}}% liked)</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -74,7 +72,7 @@
|
||||||
<span class="green" title="Users active in the last day"></span>
|
<span class="green" title="Users active in the last day"></span>
|
||||||
{{ printer .Site.SiteView.Counts.UsersActiveDay }} users here now
|
{{ printer .Site.SiteView.Counts.UsersActiveDay }} users here now
|
||||||
{{ markdown .Host .Site.SiteView.Site.Sidebar.String }}
|
{{ markdown .Host .Site.SiteView.Site.Sidebar.String }}
|
||||||
<div class="age" title="{{ .Site.SiteView.Site.Published.Time}}">founded {{ humanize .Site.SiteView.Site.Published.Time }}</div>
|
<div class="age" title="{{ .Site.SiteView.Site.Published}}">founded {{ humanize .Site.SiteView.Site.Published }}</div>
|
||||||
{{ if .Site.Admins }}
|
{{ if .Site.Admins }}
|
||||||
ADMINS
|
ADMINS
|
||||||
<div class="moderators">
|
<div class="moderators">
|
||||||
|
@ -112,8 +110,8 @@
|
||||||
<p class="gray">you are a moderator of this community</p>
|
<p class="gray">you are a moderator of this community</p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<p>{{ markdown .Host .Community.CommunityView.Community.Description.String }}</p>
|
<p>{{ markdown .Host .Community.CommunityView.Community.Description.String }}</p>
|
||||||
<div class="age" title="{{ .Community.CommunityView.Counts.Published.Time}}">
|
<div class="age" title="{{ .Community.CommunityView.Counts.Published}}">
|
||||||
founded {{ humanize .Community.CommunityView.Counts.Published.Time }}
|
founded {{ humanize .Community.CommunityView.Counts.Published }}
|
||||||
</div>
|
</div>
|
||||||
{{ if and .Session (isMod .Community .Session.UserName) }}
|
{{ if and .Session (isMod .Community .Session.UserName) }}
|
||||||
MODERATOR TOOLS
|
MODERATOR TOOLS
|
||||||
|
|
Loading…
Reference in a new issue