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/google/go-querystring v1.1.0 // 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/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU=
|
||||
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/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=
|
||||
|
|
211
routes.go
211
routes.go
|
@ -19,8 +19,7 @@ import (
|
|||
"github.com/dustin/go-humanize"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/k3a/html2text"
|
||||
"github.com/rystaf/go-lemmy"
|
||||
"github.com/rystaf/go-lemmy/types"
|
||||
"go.elara.ws/go-lemmy"
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
)
|
||||
|
@ -43,10 +42,10 @@ var funcMap = template.FuncMap{
|
|||
p := message.NewPrinter(language.English)
|
||||
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)
|
||||
},
|
||||
"fullname": func(person types.PersonSafe) string {
|
||||
"fullname": func(person lemmy.Person) string {
|
||||
if person.Local {
|
||||
return person.Name
|
||||
}
|
||||
|
@ -57,7 +56,7 @@ var funcMap = template.FuncMap{
|
|||
}
|
||||
return person.Name + "@" + l.Host
|
||||
},
|
||||
"fullcname": func(c types.CommunitySafe) string {
|
||||
"fullcname": func(c lemmy.Community) string {
|
||||
if c.Local {
|
||||
return c.Name
|
||||
}
|
||||
|
@ -68,7 +67,7 @@ var funcMap = template.FuncMap{
|
|||
}
|
||||
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 {
|
||||
if mod.Moderator.Local && username == mod.Moderator.Name {
|
||||
return true
|
||||
|
@ -93,13 +92,13 @@ var funcMap = template.FuncMap{
|
|||
}
|
||||
return l.Host
|
||||
},
|
||||
"membership": func(s types.SubscribedType) string {
|
||||
"membership": func(s lemmy.SubscribedType) string {
|
||||
switch s {
|
||||
case types.SubscribedTypeSubscribed:
|
||||
case lemmy.SubscribedTypeSubscribed:
|
||||
return "leave"
|
||||
case types.SubscribedTypeNotSubscribed:
|
||||
case lemmy.SubscribedTypeNotSubscribed:
|
||||
return "join"
|
||||
case types.SubscribedTypePending:
|
||||
case lemmy.SubscribedTypePending:
|
||||
return "pending"
|
||||
}
|
||||
return ""
|
||||
|
@ -111,7 +110,7 @@ var funcMap = template.FuncMap{
|
|||
}
|
||||
return false
|
||||
},
|
||||
"thumbnail": func(p types.Post) string {
|
||||
"thumbnail": func(p lemmy.Post) string {
|
||||
if p.ThumbnailURL.IsValid() {
|
||||
return p.ThumbnailURL.String() + "?format=jpg&thumbnail=96"
|
||||
}
|
||||
|
@ -156,10 +155,10 @@ var funcMap = template.FuncMap{
|
|||
return re.ReplaceAllString(text, "")
|
||||
},
|
||||
"contains": strings.Contains,
|
||||
"sub": func(a int32, b int) int {
|
||||
"sub": func(a int64, b int) int {
|
||||
return int(a) - b
|
||||
},
|
||||
"add": func(a int32, b int) int {
|
||||
"add": func(a int64, b int) int {
|
||||
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.Client.Token = ""
|
||||
resp, err := state.Client.Site(context.Background(), types.GetSite{})
|
||||
resp, err := state.Client.Site(context.Background())
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
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 {
|
||||
return ""
|
||||
}
|
||||
idn, _ := strconv.Atoi(id)
|
||||
idn, _ := strconv.ParseInt(id, 10, 64)
|
||||
if class == "post" {
|
||||
resp, err := c.Post(context.Background(), types.GetPost{
|
||||
ID: types.NewOptional(idn),
|
||||
resp, err := c.Post(context.Background(), lemmy.GetPost{
|
||||
ID: lemmy.NewOptional(idn),
|
||||
})
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return resp.PostView.Post.ApID
|
||||
}
|
||||
resp, err := c.Comment(context.Background(), types.GetComment{
|
||||
resp, err := c.Comment(context.Background(), lemmy.GetComment{
|
||||
ID: idn,
|
||||
})
|
||||
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 {
|
||||
apid := ResolveId(r, "post", path[0], path[1])
|
||||
if apid != "" {
|
||||
resp, err := state.Client.ResolveObject(context.Background(), types.ResolveObject{
|
||||
resp, err := state.Client.ResolveObject(context.Background(), lemmy.ResolveObject{
|
||||
Q: apid,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -521,7 +520,7 @@ func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
post, _ := resp.Post.Value()
|
||||
if post.Post.ID > 0 {
|
||||
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)
|
||||
return
|
||||
} else {
|
||||
|
@ -538,7 +537,7 @@ func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
if len(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)
|
||||
if ps.ByName("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 {
|
||||
apid := ResolveId(r, "comment", path[0], path[1])
|
||||
if apid != "" {
|
||||
resp, err := state.Client.ResolveObject(context.Background(), types.ResolveObject{
|
||||
resp, err := state.Client.ResolveObject(context.Background(), lemmy.ResolveObject{
|
||||
Q: apid,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -571,7 +570,7 @@ func GetComment(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
comment, _ := resp.Comment.Value()
|
||||
if comment.Comment.ID > 0 {
|
||||
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)
|
||||
return
|
||||
} else {
|
||||
|
@ -597,7 +596,7 @@ func GetComment(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
ctx, _ := strconv.Atoi(m["context"][0])
|
||||
state.Context = ctx
|
||||
}
|
||||
commentid, _ := strconv.Atoi(ps.ByName("commentid"))
|
||||
commentid, _ := strconv.ParseInt(ps.ByName("commentid"), 10, 64)
|
||||
state.GetComment(commentid)
|
||||
if state.XHR && len(m["content"]) > 0 {
|
||||
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)
|
||||
return
|
||||
}
|
||||
userid, _ := strconv.Atoi(r.FormValue("userid"))
|
||||
_, err = state.Client.CreatePrivateMessage(context.Background(), types.CreatePrivateMessage{
|
||||
userid, _ := strconv.ParseInt(r.FormValue("userid"), 10, 64)
|
||||
_, err = state.Client.CreatePrivateMessage(context.Background(), lemmy.CreatePrivateMessage{
|
||||
Content: r.FormValue("content"),
|
||||
RecipientID: userid,
|
||||
})
|
||||
|
@ -800,12 +799,12 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
|
|||
var username string
|
||||
switch r.FormValue("submit") {
|
||||
case "log in":
|
||||
login := types.Login{
|
||||
login := lemmy.Login{
|
||||
UsernameOrEmail: r.FormValue("username"),
|
||||
Password: r.FormValue("password"),
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
|
@ -825,23 +824,23 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
|
|||
deleteCookie(w, state.Host, "ShowNSFW")
|
||||
}
|
||||
case "sign up":
|
||||
register := types.Register{
|
||||
register := lemmy.Register{
|
||||
Username: r.FormValue("username"),
|
||||
Password: r.FormValue("password"),
|
||||
PasswordVerify: r.FormValue("passwordverify"),
|
||||
ShowNSFW: r.FormValue("nsfw") != "",
|
||||
}
|
||||
if r.FormValue("email") != "" {
|
||||
register.Email = types.NewOptional(r.FormValue("email"))
|
||||
register.Email = lemmy.NewOptional(r.FormValue("email"))
|
||||
}
|
||||
if r.FormValue("answer") != "" {
|
||||
register.Answer = types.NewOptional(r.FormValue("answer"))
|
||||
register.Answer = lemmy.NewOptional(r.FormValue("answer"))
|
||||
}
|
||||
if r.FormValue("captchauuid") != "" {
|
||||
register.CaptchaUuid = types.NewOptional(r.FormValue("captchauuid"))
|
||||
register.CaptchaUUID = lemmy.NewOptional(r.FormValue("captchauuid"))
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
|
@ -875,7 +874,7 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
|
|||
return
|
||||
}
|
||||
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, "jwt", token)
|
||||
r.URL.Path = "/" + state.Host
|
||||
|
@ -945,36 +944,36 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
}
|
||||
switch r.FormValue("op") {
|
||||
case "leave":
|
||||
communityid, _ := strconv.Atoi(r.FormValue("communityid"))
|
||||
state.Client.FollowCommunity(context.Background(), types.FollowCommunity{
|
||||
communityid, _ := strconv.ParseInt(r.FormValue("communityid"), 10, 64)
|
||||
state.Client.FollowCommunity(context.Background(), lemmy.FollowCommunity{
|
||||
CommunityID: communityid,
|
||||
Follow: false,
|
||||
})
|
||||
case "join":
|
||||
communityid, _ := strconv.Atoi(r.FormValue("communityid"))
|
||||
state.Client.FollowCommunity(context.Background(), types.FollowCommunity{
|
||||
communityid, _ := strconv.ParseInt(r.FormValue("communityid"), 10, 64)
|
||||
state.Client.FollowCommunity(context.Background(), lemmy.FollowCommunity{
|
||||
CommunityID: communityid,
|
||||
Follow: true,
|
||||
})
|
||||
case "block":
|
||||
communityid, _ := strconv.Atoi(r.FormValue("communityid"))
|
||||
state.Client.BlockCommunity(context.Background(), types.BlockCommunity{
|
||||
communityid, _ := strconv.ParseInt(r.FormValue("communityid"), 10, 64)
|
||||
state.Client.BlockCommunity(context.Background(), lemmy.BlockCommunity{
|
||||
CommunityID: communityid,
|
||||
Block: true,
|
||||
})
|
||||
case "unblock":
|
||||
communityid, _ := strconv.Atoi(r.FormValue("communityid"))
|
||||
state.Client.BlockCommunity(context.Background(), types.BlockCommunity{
|
||||
communityid, _ := strconv.ParseInt(r.FormValue("communityid"), 10, 64)
|
||||
state.Client.BlockCommunity(context.Background(), lemmy.BlockCommunity{
|
||||
CommunityID: communityid,
|
||||
Block: false,
|
||||
})
|
||||
case "block_user":
|
||||
personId, _ := strconv.Atoi(r.FormValue("user_id"))
|
||||
personId, _ := strconv.ParseInt(r.FormValue("user_id"), 10, 64)
|
||||
if personId == 0 {
|
||||
state.GetUser(ps.ByName("username"))
|
||||
personId = state.User.PersonView.Person.ID
|
||||
}
|
||||
state.Client.BlockPerson(context.Background(), types.BlockPerson{
|
||||
state.Client.BlockPerson(context.Background(), lemmy.BlockPerson{
|
||||
PersonID: personId,
|
||||
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, "user")
|
||||
case "login":
|
||||
login := types.Login{
|
||||
login := lemmy.Login{
|
||||
UsernameOrEmail: r.FormValue("username"),
|
||||
Password: r.FormValue("password"),
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
|
@ -1010,18 +1009,18 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
state.GetUser(r.FormValue("username"))
|
||||
if state.User != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
case "create_community":
|
||||
state.GetSite()
|
||||
community := types.CreateCommunity{
|
||||
community := lemmy.CreateCommunity{
|
||||
Name: r.FormValue("name"),
|
||||
Title: r.FormValue("title"),
|
||||
}
|
||||
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 {
|
||||
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)
|
||||
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 {
|
||||
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)
|
||||
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)
|
||||
if err == nil {
|
||||
|
@ -1055,14 +1054,14 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
return
|
||||
}
|
||||
state.GetSite()
|
||||
community := types.EditCommunity{
|
||||
community := lemmy.EditCommunity{
|
||||
CommunityID: state.Community.CommunityView.Community.ID,
|
||||
}
|
||||
if r.FormValue("title") != "" {
|
||||
community.Title = types.NewOptional(r.FormValue("title"))
|
||||
community.Title = lemmy.NewOptional(r.FormValue("title"))
|
||||
}
|
||||
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 {
|
||||
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)
|
||||
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 {
|
||||
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)
|
||||
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)
|
||||
if err == nil {
|
||||
|
@ -1100,12 +1099,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
Render(w, "index.html", state)
|
||||
return
|
||||
}
|
||||
post := types.CreatePost{
|
||||
post := lemmy.CreatePost{
|
||||
Name: r.FormValue("name"),
|
||||
CommunityID: state.Community.CommunityView.Community.ID,
|
||||
}
|
||||
if r.FormValue("url") != "" {
|
||||
post.URL = types.NewOptional(r.FormValue("url"))
|
||||
post.URL = lemmy.NewOptional(r.FormValue("url"))
|
||||
}
|
||||
file, handler, err := r.FormFile("file")
|
||||
if err == nil {
|
||||
|
@ -1115,18 +1114,18 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
Render(w, "index.html", state)
|
||||
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") != "" {
|
||||
post.Body = types.NewOptional(r.FormValue("body"))
|
||||
post.Body = lemmy.NewOptional(r.FormValue("body"))
|
||||
}
|
||||
if r.FormValue("language") != "" {
|
||||
languageid, _ := strconv.Atoi(r.FormValue("language"))
|
||||
post.LanguageID = types.NewOptional(languageid)
|
||||
languageid, _ := strconv.ParseInt(r.FormValue("language"), 10, 64)
|
||||
post.LanguageID = lemmy.NewOptional(languageid)
|
||||
}
|
||||
resp, err := state.Client.CreatePost(context.Background(), post)
|
||||
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
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
|
@ -1134,19 +1133,19 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
case "edit_post":
|
||||
r.ParseMultipartForm(10 << 20)
|
||||
state.GetSite()
|
||||
postid, _ := strconv.Atoi(ps.ByName("postid"))
|
||||
post := types.EditPost{
|
||||
postid, _ := strconv.ParseInt(ps.ByName("postid"), 10, 64)
|
||||
post := lemmy.EditPost{
|
||||
PostID: postid,
|
||||
Body: types.NewOptional(r.FormValue("body")),
|
||||
Name: types.NewOptional(r.FormValue("name")),
|
||||
URL: types.NewOptional(r.FormValue("url")),
|
||||
Body: lemmy.NewOptional(r.FormValue("body")),
|
||||
Name: lemmy.NewOptional(r.FormValue("name")),
|
||||
URL: lemmy.NewOptional(r.FormValue("url")),
|
||||
}
|
||||
if r.FormValue("url") == "" {
|
||||
post.URL = types.Optional[string]{}
|
||||
post.URL = lemmy.Optional[string]{}
|
||||
}
|
||||
if r.FormValue("language") != "" {
|
||||
languageid, _ := strconv.Atoi(r.FormValue("language"))
|
||||
post.LanguageID = types.NewOptional(languageid)
|
||||
languageid, _ := strconv.ParseInt(r.FormValue("language"), 10, 64)
|
||||
post.LanguageID = lemmy.NewOptional(languageid)
|
||||
}
|
||||
file, handler, err := r.FormFile("file")
|
||||
if err == nil {
|
||||
|
@ -1156,12 +1155,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
Render(w, "index.html", state)
|
||||
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)
|
||||
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.RawQuery = ""
|
||||
} else {
|
||||
|
@ -1170,8 +1169,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
fmt.Println(err)
|
||||
}
|
||||
case "save_post":
|
||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
||||
_, err := state.Client.SavePost(context.Background(), types.SavePost{
|
||||
postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64)
|
||||
_, err := state.Client.SavePost(context.Background(), lemmy.SavePost{
|
||||
PostID: postid,
|
||||
Save: r.FormValue("submit") == "save",
|
||||
})
|
||||
|
@ -1187,8 +1186,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
return
|
||||
}
|
||||
case "save_comment":
|
||||
commentid, _ := strconv.Atoi(r.FormValue("commentid"))
|
||||
_, err := state.Client.SaveComment(context.Background(), types.SaveComment{
|
||||
commentid, _ := strconv.ParseInt(r.FormValue("commentid"), 10, 64)
|
||||
_, err := state.Client.SaveComment(context.Background(), lemmy.SaveComment{
|
||||
CommentID: commentid,
|
||||
Save: r.FormValue("submit") == "save",
|
||||
})
|
||||
|
@ -1202,8 +1201,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
return
|
||||
}
|
||||
case "delete_post":
|
||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
||||
post := types.DeletePost{
|
||||
postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64)
|
||||
post := lemmy.DeletePost{
|
||||
PostID: postid,
|
||||
Deleted: true,
|
||||
}
|
||||
|
@ -1218,24 +1217,24 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
r.URL.RawQuery = ""
|
||||
}
|
||||
case "block_post":
|
||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
||||
postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64)
|
||||
state.GetPost(postid)
|
||||
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,
|
||||
Block: true,
|
||||
})
|
||||
}
|
||||
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,
|
||||
Block: true,
|
||||
})
|
||||
}
|
||||
case "read_post":
|
||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
||||
post := types.MarkPostAsRead{
|
||||
PostID: postid,
|
||||
postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64)
|
||||
post := lemmy.MarkPostAsRead{
|
||||
PostID: lemmy.NewOptional(postid),
|
||||
Read: true,
|
||||
}
|
||||
if r.FormValue("submit") == "mark unread" {
|
||||
|
@ -1249,7 +1248,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
return
|
||||
}
|
||||
case "vote_post":
|
||||
var score int16
|
||||
var score int64
|
||||
score = 1
|
||||
if r.FormValue("vote") != "▲" {
|
||||
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)) {
|
||||
score = 0
|
||||
}
|
||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
||||
post := types.CreatePostLike{
|
||||
postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64)
|
||||
post := lemmy.CreatePostLike{
|
||||
PostID: postid,
|
||||
Score: score,
|
||||
}
|
||||
state.Client.CreatePostLike(context.Background(), post)
|
||||
state.Client.LikePost(context.Background(), post)
|
||||
if r.FormValue("xhr") != "" {
|
||||
state.GetPost(postid)
|
||||
state.PostID = 0
|
||||
|
@ -1272,7 +1271,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
return
|
||||
}
|
||||
case "vote_comment":
|
||||
var score int16
|
||||
var score int64
|
||||
score = 1
|
||||
if r.FormValue("submit") != "▲" {
|
||||
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)) {
|
||||
score = 0
|
||||
}
|
||||
commentid, _ := strconv.Atoi(r.FormValue("commentid"))
|
||||
post := types.CreateCommentLike{
|
||||
commentid, _ := strconv.ParseInt(r.FormValue("commentid"), 10, 64)
|
||||
post := lemmy.CreateCommentLike{
|
||||
CommentID: commentid,
|
||||
Score: score,
|
||||
}
|
||||
state.Client.CreateCommentLike(context.Background(), post)
|
||||
state.Client.LikeComment(context.Background(), post)
|
||||
if r.FormValue("xhr") != "" {
|
||||
state.XHR = true
|
||||
state.GetComment(commentid)
|
||||
|
@ -1294,11 +1293,11 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
}
|
||||
case "create_comment":
|
||||
if ps.ByName("postid") != "" {
|
||||
postid, _ := strconv.Atoi(ps.ByName("postid"))
|
||||
postid, _ := strconv.ParseInt(ps.ByName("postid"), 10, 64)
|
||||
state.PostID = postid
|
||||
}
|
||||
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)
|
||||
}
|
||||
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 + ")")
|
||||
}
|
||||
if r.FormValue("submit") == "save" {
|
||||
createComment := types.CreateComment{
|
||||
createComment := lemmy.CreateComment{
|
||||
Content: content,
|
||||
PostID: state.PostID,
|
||||
}
|
||||
if state.CommentID > 0 {
|
||||
createComment.ParentID = types.NewOptional(state.CommentID)
|
||||
createComment.ParentID = lemmy.NewOptional(state.CommentID)
|
||||
}
|
||||
resp, err := state.Client.CreateComment(context.Background(), createComment)
|
||||
if err == nil {
|
||||
|
@ -1329,8 +1328,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
Render(w, "index.html", state)
|
||||
return
|
||||
}
|
||||
postid := strconv.Itoa(state.PostID)
|
||||
commentid := strconv.Itoa(resp.CommentView.Comment.ID)
|
||||
postid := strconv.FormatInt(state.PostID, 10)
|
||||
commentid := strconv.FormatInt(resp.CommentView.Comment.ID, 10)
|
||||
r.URL.Path = "/" + state.Host + "/post/" + postid
|
||||
r.URL.Fragment = "c" + commentid
|
||||
} else {
|
||||
|
@ -1360,7 +1359,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
r.URL.RawQuery = ""
|
||||
}
|
||||
case "edit_comment":
|
||||
commentid, _ := strconv.Atoi(r.FormValue("commentid"))
|
||||
commentid, _ := strconv.ParseInt(r.FormValue("commentid"), 10, 64)
|
||||
q := r.URL.Query()
|
||||
content := r.FormValue("content")
|
||||
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" {
|
||||
resp, err := state.Client.EditComment(context.Background(), types.EditComment{
|
||||
resp, err := state.Client.EditComment(context.Background(), lemmy.EditComment{
|
||||
CommentID: commentid,
|
||||
Content: types.NewOptional(content),
|
||||
Content: lemmy.NewOptional(content),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
commentid := strconv.Itoa(resp.CommentView.Comment.ID)
|
||||
commentid := strconv.FormatInt(resp.CommentView.Comment.ID, 10)
|
||||
r.URL.Fragment = "c" + commentid
|
||||
r.URL.RawQuery = ""
|
||||
}
|
||||
|
@ -1420,8 +1419,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
r.URL.RawQuery = ""
|
||||
}
|
||||
case "delete_comment":
|
||||
commentid, _ := strconv.Atoi(r.FormValue("commentid"))
|
||||
resp, err := state.Client.DeleteComment(context.Background(), types.DeleteComment{
|
||||
commentid, _ := strconv.ParseInt(r.FormValue("commentid"), 10, 64)
|
||||
resp, err := state.Client.DeleteComment(context.Background(), lemmy.DeleteComment{
|
||||
CommentID: commentid,
|
||||
Deleted: true,
|
||||
})
|
||||
|
@ -1435,7 +1434,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
Render(w, "index.html", state)
|
||||
return
|
||||
}
|
||||
commentid := strconv.Itoa(resp.CommentView.Comment.ID)
|
||||
commentid := strconv.FormatInt(resp.CommentView.Comment.ID, 10)
|
||||
r.URL.Fragment = "c" + commentid
|
||||
r.URL.RawQuery = ""
|
||||
}
|
||||
|
|
175
state.go
175
state.go
|
@ -18,12 +18,11 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rystaf/go-lemmy"
|
||||
"github.com/rystaf/go-lemmy/types"
|
||||
"go.elara.ws/go-lemmy"
|
||||
)
|
||||
|
||||
type Comment struct {
|
||||
P types.CommentView
|
||||
P lemmy.CommentView
|
||||
C []Comment
|
||||
Selected bool
|
||||
State *State
|
||||
|
@ -35,25 +34,25 @@ func (c *Comment) Submitter() bool {
|
|||
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, ".")
|
||||
id, _ := strconv.Atoi(path[len(path)-2])
|
||||
id, _ := strconv.ParseInt(path[len(path)-2], 10, 64)
|
||||
return id
|
||||
}
|
||||
|
||||
type Person struct {
|
||||
types.PersonViewSafe
|
||||
lemmy.PersonView
|
||||
}
|
||||
|
||||
type Activity struct {
|
||||
Timestamp time.Time
|
||||
Comment *Comment
|
||||
Post *Post
|
||||
Message *types.PrivateMessageView
|
||||
Message *lemmy.PrivateMessageView
|
||||
}
|
||||
|
||||
type Post struct {
|
||||
types.PostView
|
||||
lemmy.PostView
|
||||
Rank int
|
||||
State *State
|
||||
}
|
||||
|
@ -61,7 +60,7 @@ type Post struct {
|
|||
type Session struct {
|
||||
UserName string
|
||||
UserID int
|
||||
Communities []types.CommunityView
|
||||
Communities []lemmy.CommunityView
|
||||
}
|
||||
|
||||
type State struct {
|
||||
|
@ -75,9 +74,9 @@ type State struct {
|
|||
Alert string
|
||||
Host string
|
||||
CommunityName string
|
||||
Community *types.GetCommunityResponse
|
||||
TopCommunities []types.CommunityView
|
||||
Communities []types.CommunityView
|
||||
Community *lemmy.GetCommunityResponse
|
||||
TopCommunities []lemmy.CommunityView
|
||||
Communities []lemmy.CommunityView
|
||||
UnreadCount int64
|
||||
Sort string
|
||||
CommentSort string
|
||||
|
@ -88,19 +87,19 @@ type State struct {
|
|||
Comments []Comment
|
||||
Activities []Activity
|
||||
CommentCount int
|
||||
PostID int
|
||||
CommentID int
|
||||
PostID int64
|
||||
CommentID int64
|
||||
Context int
|
||||
UserName string
|
||||
User *types.GetPersonDetailsResponse
|
||||
User *lemmy.GetPersonDetailsResponse
|
||||
Now int64
|
||||
XHR bool
|
||||
Op string
|
||||
Site *types.GetSiteResponse
|
||||
Site *lemmy.GetSiteResponse
|
||||
Query string
|
||||
Content string
|
||||
SearchType string
|
||||
Captcha *types.CaptchaResponse
|
||||
Captcha *lemmy.CaptchaResponse
|
||||
Dark bool
|
||||
ShowNSFW bool
|
||||
HideInstanceNames bool
|
||||
|
@ -115,7 +114,7 @@ func (s State) UserBlocked() bool {
|
|||
if s.User == nil || s.Site == nil || !s.Site.MyUser.IsValid() {
|
||||
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 {
|
||||
return true
|
||||
}
|
||||
|
@ -261,7 +260,7 @@ func (state *State) LemmyError(domain string) error {
|
|||
}
|
||||
|
||||
func (state *State) GetCaptcha() {
|
||||
resp, err := state.Client.Captcha(context.Background(), types.GetCaptcha{})
|
||||
resp, err := state.Client.Captcha(context.Background())
|
||||
if err != nil {
|
||||
fmt.Printf("Get %v %v", err, resp)
|
||||
} else {
|
||||
|
@ -272,7 +271,7 @@ func (state *State) GetCaptcha() {
|
|||
}
|
||||
}
|
||||
func (state *State) GetSite() {
|
||||
resp, err := state.Client.Site(context.Background(), types.GetSite{})
|
||||
resp, err := state.Client.Site(context.Background())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
state.Status = http.StatusInternalServerError
|
||||
|
@ -284,8 +283,8 @@ func (state *State) GetSite() {
|
|||
if !state.Site.MyUser.IsValid() {
|
||||
return
|
||||
}
|
||||
for _, c := range state.Site.MyUser.MustValue().Follows {
|
||||
state.Session.Communities = append(state.Session.Communities, types.CommunityView{
|
||||
for _, c := range state.Site.MyUser.ValueOrZero().Follows {
|
||||
state.Session.Communities = append(state.Session.Communities, lemmy.CommunityView{
|
||||
Community: c.Community,
|
||||
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" {
|
||||
state.Sort = "Hot"
|
||||
}
|
||||
state.CommentID = commentid
|
||||
cresp, err := state.Client.Comments(context.Background(), types.GetComments{
|
||||
ParentID: types.NewOptional(state.CommentID),
|
||||
Sort: types.NewOptional(types.CommentSortType(state.CommentSort)),
|
||||
Type: types.NewOptional(types.ListingType("All")),
|
||||
Limit: types.NewOptional(int64(50)),
|
||||
cresp, err := state.Client.Comments(context.Background(), lemmy.GetComments{
|
||||
ParentID: lemmy.NewOptional(state.CommentID),
|
||||
Sort: lemmy.NewOptional(lemmy.CommentSortType(state.CommentSort)),
|
||||
Type: lemmy.NewOptional(lemmy.ListingType("All")),
|
||||
Limit: lemmy.NewOptional(int64(50)),
|
||||
})
|
||||
if err != nil {
|
||||
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 {
|
||||
return comment, nil
|
||||
}
|
||||
cresp, err := state.Client.Comment(context.Background(), types.GetComment{
|
||||
cresp, err := state.Client.Comment(context.Background(), lemmy.GetComment{
|
||||
ID: comment.ParentID(),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -358,12 +357,12 @@ func (state *State) GetComments() {
|
|||
if state.Sort != "Hot" && state.Sort != "Top" && state.Sort != "Old" && state.Sort != "New" {
|
||||
state.Sort = "Hot"
|
||||
}
|
||||
cresp, err := state.Client.Comments(context.Background(), types.GetComments{
|
||||
PostID: types.NewOptional(state.PostID),
|
||||
Sort: types.NewOptional(types.CommentSortType(state.CommentSort)),
|
||||
Type: types.NewOptional(types.ListingType("All")),
|
||||
Limit: types.NewOptional(int64(50)),
|
||||
Page: types.NewOptional(int64(state.Page)),
|
||||
cresp, err := state.Client.Comments(context.Background(), lemmy.GetComments{
|
||||
PostID: lemmy.NewOptional(state.PostID),
|
||||
Sort: lemmy.NewOptional(lemmy.CommentSortType(state.CommentSort)),
|
||||
Type: lemmy.NewOptional(lemmy.ListingType("All")),
|
||||
Limit: lemmy.NewOptional(int64(50)),
|
||||
Page: lemmy.NewOptional(int64(state.Page)),
|
||||
})
|
||||
if err != nil {
|
||||
state.Status = http.StatusInternalServerError
|
||||
|
@ -377,7 +376,7 @@ func (state *State) GetComments() {
|
|||
continue
|
||||
}
|
||||
comment := Comment{P: c, State: state}
|
||||
var postCreatorID int
|
||||
var postCreatorID int64
|
||||
if len(state.Posts) > 0 {
|
||||
postCreatorID = state.Posts[0].Post.CreatorID
|
||||
}
|
||||
|
@ -387,8 +386,8 @@ func (state *State) GetComments() {
|
|||
}
|
||||
|
||||
func (state *State) GetMessages() {
|
||||
if resp, err := state.Client.PrivateMessages(context.Background(), types.GetPrivateMessages{
|
||||
Page: types.NewOptional(int64(state.Page)),
|
||||
if resp, err := state.Client.PrivateMessages(context.Background(), lemmy.GetPrivateMessages{
|
||||
Page: lemmy.NewOptional(int64(state.Page)),
|
||||
}); err != nil {
|
||||
fmt.Println(err)
|
||||
state.Status = http.StatusInternalServerError
|
||||
|
@ -397,13 +396,13 @@ func (state *State) GetMessages() {
|
|||
for _, m := range resp.PrivateMessages {
|
||||
message := m
|
||||
state.Activities = append(state.Activities, Activity{
|
||||
Timestamp: m.PrivateMessage.Published.Time,
|
||||
Timestamp: m.PrivateMessage.Published,
|
||||
Message: &message,
|
||||
})
|
||||
}
|
||||
}
|
||||
if resp, err := state.Client.PersonMentions(context.Background(), types.GetPersonMentions{
|
||||
Page: types.NewOptional(int64(state.Page)),
|
||||
if resp, err := state.Client.PersonMentions(context.Background(), lemmy.GetPersonMentions{
|
||||
Page: lemmy.NewOptional(int64(state.Page)),
|
||||
}); err != nil {
|
||||
fmt.Println(err)
|
||||
state.Status = http.StatusInternalServerError
|
||||
|
@ -415,20 +414,20 @@ func (state *State) GetMessages() {
|
|||
unread = "unread"
|
||||
}
|
||||
comment := Comment{
|
||||
P: types.CommentView{
|
||||
P: lemmy.CommentView{
|
||||
Comment: m.Comment,
|
||||
},
|
||||
Op: unread,
|
||||
State: state,
|
||||
}
|
||||
state.Activities = append(state.Activities, Activity{
|
||||
Timestamp: m.Comment.Published.Time,
|
||||
Timestamp: m.Comment.Published,
|
||||
Comment: &comment,
|
||||
})
|
||||
}
|
||||
}
|
||||
if resp, err := state.Client.Replies(context.Background(), types.GetReplies{
|
||||
Page: types.NewOptional(int64(state.Page)),
|
||||
if resp, err := state.Client.Replies(context.Background(), lemmy.GetReplies{
|
||||
Page: lemmy.NewOptional(int64(state.Page)),
|
||||
}); err != nil {
|
||||
fmt.Println(err)
|
||||
state.Status = http.StatusInternalServerError
|
||||
|
@ -440,7 +439,7 @@ func (state *State) GetMessages() {
|
|||
unread = "unread"
|
||||
}
|
||||
comment := Comment{
|
||||
P: types.CommentView{
|
||||
P: lemmy.CommentView{
|
||||
Comment: m.Comment,
|
||||
Post: m.Post,
|
||||
Creator: m.Creator,
|
||||
|
@ -451,7 +450,7 @@ func (state *State) GetMessages() {
|
|||
State: state,
|
||||
}
|
||||
state.Activities = append(state.Activities, Activity{
|
||||
Timestamp: m.Comment.Published.Time,
|
||||
Timestamp: m.Comment.Published,
|
||||
Comment: &comment,
|
||||
})
|
||||
}
|
||||
|
@ -464,11 +463,11 @@ func (state *State) GetUser(username string) {
|
|||
if state.Op == "send_message" {
|
||||
limit = 1
|
||||
}
|
||||
resp, err := state.Client.PersonDetails(context.Background(), types.GetPersonDetails{
|
||||
Username: types.NewOptional(state.UserName),
|
||||
Page: types.NewOptional(int64(state.Page)),
|
||||
Limit: types.NewOptional(int64(limit)),
|
||||
SavedOnly: types.NewOptional(state.Op == "Saved"),
|
||||
resp, err := state.Client.PersonDetails(context.Background(), lemmy.GetPersonDetails{
|
||||
Username: lemmy.NewOptional(state.UserName),
|
||||
Page: lemmy.NewOptional(int64(state.Page)),
|
||||
Limit: lemmy.NewOptional(int64(limit)),
|
||||
SavedOnly: lemmy.NewOptional(state.Op == "Saved"),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
@ -487,14 +486,14 @@ func (state *State) GetUser(username string) {
|
|||
State: state,
|
||||
}
|
||||
state.Activities = append(state.Activities, Activity{
|
||||
Timestamp: p.Post.Published.Time,
|
||||
Timestamp: p.Post.Published,
|
||||
Post: &post,
|
||||
})
|
||||
}
|
||||
for _, c := range resp.Comments {
|
||||
comment := Comment{P: c, State: state}
|
||||
state.Activities = append(state.Activities, Activity{
|
||||
Timestamp: c.Comment.Published.Time,
|
||||
Timestamp: c.Comment.Published,
|
||||
Comment: &comment,
|
||||
})
|
||||
}
|
||||
|
@ -504,7 +503,7 @@ func (state *State) GetUser(username string) {
|
|||
}
|
||||
|
||||
func (state *State) GetUnreadCount() {
|
||||
resp, err := state.Client.UnreadCount(context.Background(), types.GetUnreadCount{})
|
||||
resp, err := state.Client.UnreadCount(context.Background())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
@ -512,9 +511,9 @@ func (state *State) GetUnreadCount() {
|
|||
state.UnreadCount = resp.PrivateMessages + resp.Mentions + resp.Replies
|
||||
}
|
||||
func (state *State) GetCommunities() {
|
||||
resp, err := state.Client.Communities(context.Background(), types.ListCommunities{
|
||||
Sort: types.NewOptional(types.SortType("TopAll")),
|
||||
Limit: types.NewOptional(int64(20)),
|
||||
resp, err := state.Client.Communities(context.Background(), lemmy.ListCommunities{
|
||||
Sort: lemmy.NewOptional(lemmy.SortType("TopAll")),
|
||||
Limit: lemmy.NewOptional(int64(20)),
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -522,7 +521,7 @@ func (state *State) GetCommunities() {
|
|||
state.TopCommunities = resp.Communities
|
||||
}
|
||||
func (state *State) MarkAllAsRead() {
|
||||
_, err := state.Client.MarkAllAsRead(context.Background(), types.MarkAllAsRead{})
|
||||
_, err := state.Client.MarkAllAsRead(context.Background())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
@ -530,14 +529,14 @@ func (state *State) MarkAllAsRead() {
|
|||
}
|
||||
|
||||
func (state *State) GetPosts() {
|
||||
posts := types.GetPosts{
|
||||
Sort: types.NewOptional(types.SortType(state.Sort)),
|
||||
Type: types.NewOptional(types.ListingType(state.Listing)),
|
||||
Limit: types.NewOptional(int64(25)),
|
||||
Page: types.NewOptional(int64(state.Page)),
|
||||
posts := lemmy.GetPosts{
|
||||
Sort: lemmy.NewOptional(lemmy.SortType(state.Sort)),
|
||||
Type: lemmy.NewOptional(lemmy.ListingType(state.Listing)),
|
||||
Limit: lemmy.NewOptional(int64(25)),
|
||||
Page: lemmy.NewOptional(int64(state.Page)),
|
||||
}
|
||||
if state.CommunityName != "" {
|
||||
posts.CommunityName = types.NewOptional(state.CommunityName)
|
||||
posts.CommunityName = lemmy.NewOptional(state.CommunityName)
|
||||
}
|
||||
resp, err := state.Client.Posts(context.Background(), posts)
|
||||
if err != nil {
|
||||
|
@ -567,11 +566,11 @@ func (state *State) Search(searchtype string) {
|
|||
state.Communities = state.Session.Communities
|
||||
return
|
||||
}
|
||||
resp, err := state.Client.Communities(context.Background(), types.ListCommunities{
|
||||
Type: types.NewOptional(types.ListingType(state.Listing)),
|
||||
Sort: types.NewOptional(types.SortType(state.Sort)),
|
||||
Limit: types.NewOptional(int64(25)),
|
||||
Page: types.NewOptional(int64(state.Page)),
|
||||
resp, err := state.Client.Communities(context.Background(), lemmy.ListCommunities{
|
||||
Type: lemmy.NewOptional(lemmy.ListingType(state.Listing)),
|
||||
Sort: lemmy.NewOptional(lemmy.SortType(state.Sort)),
|
||||
Limit: lemmy.NewOptional(int64(25)),
|
||||
Page: lemmy.NewOptional(int64(state.Page)),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
@ -580,21 +579,21 @@ func (state *State) Search(searchtype string) {
|
|||
state.Communities = resp.Communities
|
||||
return
|
||||
}
|
||||
search := types.Search{
|
||||
search := lemmy.Search{
|
||||
Q: state.Query,
|
||||
Sort: types.NewOptional(types.SortType(state.Sort)),
|
||||
ListingType: types.NewOptional(types.ListingType(state.Listing)),
|
||||
Type: types.NewOptional(types.SearchType(searchtype)),
|
||||
Limit: types.NewOptional(int64(25)),
|
||||
Page: types.NewOptional(int64(state.Page)),
|
||||
Sort: lemmy.NewOptional(lemmy.SortType(state.Sort)),
|
||||
ListingType: lemmy.NewOptional(lemmy.ListingType(state.Listing)),
|
||||
Type: lemmy.NewOptional(lemmy.SearchType(searchtype)),
|
||||
Limit: lemmy.NewOptional(int64(25)),
|
||||
Page: lemmy.NewOptional(int64(state.Page)),
|
||||
}
|
||||
|
||||
if state.CommunityName != "" {
|
||||
search.CommunityName = types.NewOptional(state.CommunityName)
|
||||
search.CommunityName = lemmy.NewOptional(state.CommunityName)
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -616,7 +615,7 @@ func (state *State) Search(searchtype string) {
|
|||
State: state,
|
||||
}
|
||||
state.Activities = append(state.Activities, Activity{
|
||||
Timestamp: c.Comment.Published.Time,
|
||||
Timestamp: c.Comment.Published,
|
||||
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 {
|
||||
return
|
||||
}
|
||||
state.PostID = postid
|
||||
// get post
|
||||
resp, err := state.Client.Post(context.Background(), types.GetPost{
|
||||
ID: types.NewOptional(state.PostID),
|
||||
resp, err := state.Client.Post(context.Background(), lemmy.GetPost{
|
||||
ID: lemmy.NewOptional(state.PostID),
|
||||
})
|
||||
if err != nil {
|
||||
state.Status = http.StatusInternalServerError
|
||||
|
@ -646,7 +645,7 @@ func (state *State) GetPost(postid int) {
|
|||
state.Posts[0].Rank = -1
|
||||
}
|
||||
state.CommunityName = resp.PostView.Community.Name
|
||||
cresp := types.GetCommunityResponse{
|
||||
cresp := lemmy.GetCommunityResponse{
|
||||
CommunityView: resp.CommunityView,
|
||||
Moderators: resp.Moderators,
|
||||
}
|
||||
|
@ -660,8 +659,8 @@ func (state *State) GetCommunity(communityName string) {
|
|||
if state.CommunityName == "" {
|
||||
return
|
||||
}
|
||||
resp, err := state.Client.Community(context.Background(), types.GetCommunity{
|
||||
Name: types.NewOptional(state.CommunityName),
|
||||
resp, err := state.Client.Community(context.Background(), lemmy.GetCommunity{
|
||||
Name: lemmy.NewOptional(state.CommunityName),
|
||||
})
|
||||
if err != nil {
|
||||
state.Error = err
|
||||
|
@ -701,13 +700,13 @@ func (state *State) UploadImage(file multipart.File, header *multipart.FileHeade
|
|||
return &pres, nil
|
||||
}
|
||||
|
||||
func getChildren(parent *Comment, pool []types.CommentView, postCreatorID int) {
|
||||
func getChildren(parent *Comment, pool []lemmy.CommentView, postCreatorID int64) {
|
||||
var children []Comment
|
||||
total := int32(0)
|
||||
var total int64
|
||||
for _, c := range pool {
|
||||
levels := strings.Split(c.Comment.Path, ".")
|
||||
for i, l := range levels {
|
||||
id, _ := strconv.Atoi(l)
|
||||
id, _ := strconv.ParseInt(l, 10, 64)
|
||||
if id == parent.P.Comment.ID {
|
||||
if i == (len(levels) - 2) {
|
||||
children = append(children, Comment{
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
{{- end -}}
|
||||
</a>
|
||||
{{end}}
|
||||
sent {{ humanize $activity.Message.PrivateMessage.Published.Time }}
|
||||
sent {{ humanize $activity.Message.PrivateMessage.Published }}
|
||||
</span>
|
||||
<div>{{ markdown "" $activity.Message.PrivateMessage.Content }}</div>
|
||||
</div>
|
||||
|
|
|
@ -21,16 +21,16 @@
|
|||
[-]
|
||||
{{- end -}}
|
||||
</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 -}}
|
||||
{{ .P.Creator.Name }}
|
||||
{{- else -}}
|
||||
{{ fullname .P.Creator }}
|
||||
{{- end -}}
|
||||
</a>
|
||||
<b>{{.P.Counts.Score}} points</b> <span title="{{.P.Comment.Published.Time}}">{{ humanize .P.Comment.Published.Time }}</span>
|
||||
{{- if gt .P.Comment.Updated.Time.Unix .P.Comment.Published.Time.Unix -}}
|
||||
* (last edited <span title="{{.P.Comment.Updated.Time}}">{{ humanize .P.Comment.Updated.Time }}</span>)
|
||||
<b>{{.P.Counts.Score}} points</b> <span title="{{.P.Comment.Published}}">{{ humanize .P.Comment.Published }}</span>
|
||||
{{- if gt .P.Comment.Updated.Unix .P.Comment.Published.Unix -}}
|
||||
* (last edited <span title="{{.P.Comment.Updated}}">{{ humanize .P.Comment.Updated }}</span>)
|
||||
{{ end }}
|
||||
</div>
|
||||
<div class="content">
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
{{ end }}
|
||||
<div class="gray">
|
||||
{{ if .Counts.Subscribers }}{{ printer .Counts.Subscribers }} subscribers,{{end}}
|
||||
a community founded {{ humanize .Community.Published.Time }}
|
||||
a community founded {{ humanize .Community.Published }}
|
||||
</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="meta">
|
||||
submitted
|
||||
<span title="{{.Post.Published.Time}}">{{ humanize .Post.Published.Time -}}</span>
|
||||
{{- if gt .Post.Updated.Time.Unix .Post.Published.Time.Unix -}}
|
||||
* (last edited <span title="{{.Post.Updated.Time}}">{{ humanize .Post.Updated.Time }}</span>)
|
||||
<span title="{{.Post.Published}}">{{ humanize .Post.Published -}}</span>
|
||||
{{- if gt .Post.Updated.Unix .Post.Published.Unix -}}
|
||||
* (last edited <span title="{{.Post.Updated}}">{{ humanize .Post.Updated }}</span>)
|
||||
{{ end }}
|
||||
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 -}}
|
||||
{{ .Creator.Name }}
|
||||
{{- else -}}
|
||||
|
@ -104,7 +104,7 @@
|
|||
{{ if .State.PostID }}
|
||||
<a id="hidechildren" class="scripting" href="">hide all child comments</a>
|
||||
{{ 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">
|
||||
<input type="hidden" name="postid" value="{{.Post.ID }}">
|
||||
<input type="hidden" name="op" value="read_post">
|
||||
|
|
|
@ -31,11 +31,9 @@
|
|||
</form>
|
||||
</div>
|
||||
{{ end }}
|
||||
<b>{{ .User.PersonView.Counts.PostScore}}</b> post score <br>
|
||||
<b>{{ .User.PersonView.Counts.CommentScore}}</b> comment score <br>
|
||||
<div class="age">
|
||||
{{ 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>
|
||||
{{ if .User.Moderates }}
|
||||
MODERATOR OF
|
||||
|
@ -49,7 +47,7 @@
|
|||
|
||||
{{ if and .PostID .Posts }}
|
||||
<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>
|
||||
{{ end }}
|
||||
|
@ -74,7 +72,7 @@
|
|||
<span class="green" title="Users active in the last day"></span>
|
||||
{{ printer .Site.SiteView.Counts.UsersActiveDay }} users here now
|
||||
{{ 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 }}
|
||||
ADMINS
|
||||
<div class="moderators">
|
||||
|
@ -112,8 +110,8 @@
|
|||
<p class="gray">you are a moderator of this community</p>
|
||||
{{ end }}
|
||||
<p>{{ markdown .Host .Community.CommunityView.Community.Description.String }}</p>
|
||||
<div class="age" title="{{ .Community.CommunityView.Counts.Published.Time}}">
|
||||
founded {{ humanize .Community.CommunityView.Counts.Published.Time }}
|
||||
<div class="age" title="{{ .Community.CommunityView.Counts.Published}}">
|
||||
founded {{ humanize .Community.CommunityView.Counts.Published }}
|
||||
</div>
|
||||
{{ if and .Session (isMod .Community .Session.UserName) }}
|
||||
MODERATOR TOOLS
|
||||
|
|
Loading…
Reference in a new issue