diff options
author | FChannel <> | 2022-05-01 12:13:25 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | e80fe14f7985f9e85bfb9582926acd7891455786 (patch) | |
tree | 80f4fb97c3299d94cb590a23be2eb531ec66c3db | |
parent | 2af4a39ac16c6245f0e87ddf3cc137339f6c604f (diff) |
fix for parsing reply link and showing images in static folder
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | activitypub/actor.go | 2 | ||||
-rw-r--r-- | client.go | 51 | ||||
-rw-r--r-- | main.go | 13 | ||||
-rw-r--r-- | post/util.go | 39 | ||||
-rw-r--r-- | views/js/posts.js | 2 | ||||
-rw-r--r-- | views/partials/posts.html | 4 |
7 files changed, 54 insertions, 59 deletions
@@ -14,7 +14,7 @@ Current things that will be implemented first are: - Other improvements will be made over time, first it needs to be as easy as possible for new instances to come online and connect with others reliably. Try and run your own instances and federate with one of the instances above. -Any contributions or suggestions are appreciated. Best way to give immediate feedback is the XMPP: `general@rooms.fchannel.org` or Matrix: `#fchan:matrix.org` +Any contributions or suggestions are appreciated. Best way to give immediate feedback is the XMPP: `xmpp:general@rooms.fchannel.org` or Matrix: `#fchan:matrix.org` ## Development To get started on hacking the code of FChannel, it is recommended you setup your diff --git a/activitypub/actor.go b/activitypub/actor.go index 70681d1..e837df5 100644 --- a/activitypub/actor.go +++ b/activitypub/actor.go @@ -484,7 +484,7 @@ func GetActorInstance(path string) (string, string) { } } - re = regexp.MustCompile(`(https?://)?(www)?([\w\d-_.:]+)(/|\s+|\r|\r\n)?$`) + re = regexp.MustCompile(`(https?://)(www)?([\w\d-_.:]+)(/|\s+|\r|\r\n)?$`) mainActor := re.MatchString(path) if mainActor { match := re.FindStringSubmatch(path) @@ -8,6 +8,7 @@ import ( "github.com/FChannel0/FChannel-Server/activitypub" "github.com/FChannel0/FChannel-Server/config" "github.com/FChannel0/FChannel-Server/db" + "github.com/FChannel0/FChannel-Server/post" "github.com/FChannel0/FChannel-Server/util" "github.com/FChannel0/FChannel-Server/webfinger" _ "github.com/lib/pq" @@ -138,7 +139,7 @@ func ParseLinkComments(board activitypub.Actor, op string, content string, threa isOP = " (OP)" } - parsedLink := ConvertHashLink(domain, link) + parsedLink := post.ConvertHashLink(domain, link) //formate the hover title text var quoteTitle string @@ -146,11 +147,11 @@ func ParseLinkComments(board activitypub.Actor, op string, content string, threa // if the quoted content is local get it // else get it from the database if thread.Id == link { - quoteTitle = ParseLinkTitle(board.Outbox, op, thread.Content) + quoteTitle = post.ParseLinkTitle(board.Outbox, op, thread.Content) } else { for _, e := range thread.Replies.OrderedItems { if e.Id == parsedLink { - quoteTitle = ParseLinkTitle(board.Outbox, op, e.Content) + quoteTitle = post.ParseLinkTitle(board.Outbox, op, e.Content) break } } @@ -162,9 +163,9 @@ func ParseLinkComments(board activitypub.Actor, op string, content string, threa } if len(obj.OrderedItems) > 0 { - quoteTitle = ParseLinkTitle(board.Outbox, op, obj.OrderedItems[0].Content) + quoteTitle = post.ParseLinkTitle(board.Outbox, op, obj.OrderedItems[0].Content) } else { - quoteTitle = ParseLinkTitle(board.Outbox, op, parsedLink) + quoteTitle = post.ParseLinkTitle(board.Outbox, op, parsedLink) } } } @@ -191,32 +192,6 @@ func ParseLinkComments(board activitypub.Actor, op string, content string, threa return content, nil } -func ParseLinkTitle(actorName string, op string, content string) string { - re := regexp.MustCompile(`(>>(https?://[A-Za-z0-9_.:\-~]+\/[A-Za-z0-9_.\-~]+\/)\w+(#.+)?)`) - match := re.FindAllStringSubmatch(content, -1) - - for i, _ := range match { - link := strings.Replace(match[i][0], ">>", "", 1) - isOP := "" - - domain := match[i][2] - - if link == op { - isOP = " (OP)" - } - - link = ConvertHashLink(domain, link) - content = strings.Replace(content, match[i][0], ">>"+util.ShortURL(actorName, link)+isOP, 1) - } - - // TODO: this drops more than we need to - content = strings.ReplaceAll(content, "'", "") - content = strings.ReplaceAll(content, "\"", "") - content = strings.ReplaceAll(content, ">", `/\<`) - - return content -} - func ParseCommentQuotes(content string) string { // replace quotes re := regexp.MustCompile(`((\r\n|\r|\n|^)>(.+)?[^\r\n])`) @@ -233,17 +208,3 @@ func ParseCommentQuotes(content string) string { return re.ReplaceAllString(content, "\r\n<span class=\"quote\">></span>") } - -func ConvertHashLink(domain string, link string) string { - re := regexp.MustCompile(`(#.+)`) - parsedLink := re.FindString(link) - - if parsedLink != "" { - parsedLink = domain + "" + strings.Replace(parsedLink, "#", "", 1) - parsedLink = strings.Replace(parsedLink, "\r", "", -1) - } else { - parsedLink = link - } - - return parsedLink -} @@ -7,6 +7,7 @@ import ( "github.com/FChannel0/FChannel-Server/activitypub" "github.com/FChannel0/FChannel-Server/config" "github.com/FChannel0/FChannel-Server/db" + "github.com/FChannel0/FChannel-Server/post" "github.com/FChannel0/FChannel-Server/routes" "github.com/FChannel0/FChannel-Server/util" "github.com/FChannel0/FChannel-Server/webfinger" @@ -112,6 +113,7 @@ func main() { app.Use(logger.New()) app.Static("/static", "./views") + app.Static("/static", "./static") app.Static("/public", "./public") /* @@ -636,14 +638,9 @@ func TemplateFunctions(engine *html.Engine) { engine.AddFunc("isOnion", util.IsOnion) engine.AddFunc("parseReplyLink", func(actorId string, op string, id string, content string) template.HTML { - actor, err := webfinger.FingerActor(actorId) - if err != nil { - // TODO: figure out what to do here - panic(err) - } - - title := strings.ReplaceAll(ParseLinkTitle(actor.Id, op, content), `/\<`, ">") - link := fmt.Sprintf("<a href=\"%s/%s#%s\" title=\"%s\" class=\"replyLink\">>>%s</a>", actor.Name, util.ShortURL(actor.Outbox, op), util.ShortURL(actor.Outbox, id), title, util.ShortURL(actor.Outbox, id)) + actor, _ := webfinger.FingerActor(actorId) + title := strings.ReplaceAll(post.ParseLinkTitle(actor.Id+"/", op, content), `/\<`, ">") + link := "<a href=\"/" + actor.Name + "/" + util.ShortURL(actor.Outbox, op) + "#" + util.ShortURL(actor.Outbox, id) + "\" title=\"" + title + "\" class=\"replyLink\">>>" + util.ShortURL(actor.Outbox, id) + "</a>" return template.HTML(link) }) diff --git a/post/util.go b/post/util.go index 0b87d42..a9d326a 100644 --- a/post/util.go +++ b/post/util.go @@ -17,6 +17,20 @@ import ( "github.com/gofiber/fiber/v2" ) +func ConvertHashLink(domain string, link string) string { + re := regexp.MustCompile(`(#.+)`) + parsedLink := re.FindString(link) + + if parsedLink != "" { + parsedLink = domain + "" + strings.Replace(parsedLink, "#", "", 1) + parsedLink = strings.Replace(parsedLink, "\r", "", -1) + } else { + parsedLink = link + } + + return parsedLink +} + func ParseCommentForReplies(comment string, op string) ([]activitypub.ObjectBase, error) { re := regexp.MustCompile(`(>>(https?://[A-Za-z0-9_.:\-~]+\/[A-Za-z0-9_.\-~]+\/)(f[A-Za-z0-9_.\-~]+-)?([A-Za-z0-9_.\-~]+)?#?([A-Za-z0-9_.\-~]+)?)`) match := re.FindAllStringSubmatch(comment, -1) @@ -82,6 +96,31 @@ func ParseCommentForReply(comment string) (string, error) { return "", nil } +func ParseLinkTitle(actorName string, op string, content string) string { + re := regexp.MustCompile(`(>>(https?://[A-Za-z0-9_.:\-~]+\/[A-Za-z0-9_.\-~]+\/)\w+(#.+)?)`) + match := re.FindAllStringSubmatch(content, -1) + + for i, _ := range match { + link := strings.Replace(match[i][0], ">>", "", 1) + isOP := "" + + domain := match[i][2] + + if link == op { + isOP = " (OP)" + } + + link = ConvertHashLink(domain, link) + content = strings.Replace(content, match[i][0], ">>"+util.ShortURL(actorName, link)+isOP, 1) + } + + content = strings.ReplaceAll(content, "'", "'") + content = strings.ReplaceAll(content, "\"", """) + content = strings.ReplaceAll(content, ">", `/\<`) + + return content +} + func ParseOptions(ctx *fiber.Ctx, obj activitypub.ObjectBase) activitypub.ObjectBase { options := util.EscapeString(ctx.FormValue("options")) if options != "" { diff --git a/views/js/posts.js b/views/js/posts.js index 87f6228..5a9ab50 100644 --- a/views/js/posts.js +++ b/views/js/posts.js @@ -3,7 +3,7 @@ function startNewPost(){ el.style="display:none;"; el.setAttribute("state", "1"); document.getElementById("newpost").style = ""; - document.getElementById("stopTablePost").style = "display:unset;"; + document.getElementById("stopTablePost").style = "cursor: pointer; display:unset;"; sessionStorage.setItem("newpostState", true); } diff --git a/views/partials/posts.html b/views/partials/posts.html index a248650..14d4878 100644 --- a/views/partials/posts.html +++ b/views/partials/posts.html @@ -106,9 +106,7 @@ {{ $parentId := .Id }} {{ if .Replies.OrderedItems }} {{ range .Replies.OrderedItems }} - - <!--TODO: fix parse reply link function with other routes mainly getactor--> - <span id="{{$parentId}}-replyto-{{.Id}}"><!-- fix \{\{ parseReplyLink $board.Actor.Id $opId .Id .Content }} --></span> + <span id="{{$parentId}}-replyto-{{.Id}}">{{ parseReplyLink $board.Actor.Id $opId .Id .Content }}</span> {{ end }} {{ end }} <p id="{{ .Id }}-content" style="white-space: pre-wrap; margin: 10px 30px 10px 30px;">{{ parseContent $board.Actor $opId .Content $thread }}</p> |