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 /client.go | |
parent | 2af4a39ac16c6245f0e87ddf3cc137339f6c604f (diff) |
fix for parsing reply link and showing images in static folder
Diffstat (limited to 'client.go')
-rw-r--r-- | client.go | 51 |
1 files changed, 6 insertions, 45 deletions
@@ -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 -} |