back interdiff of round #12 and #11

appview/notify: notify users mentioned on PR comments #739

merged
opened by boltless.me targeting master from feat/mentions
files
appview
notify
pages
markup
pulls
ERROR
appview/notify/db/db.go

Failed to calculate interdiff for this file.

ERROR
appview/notify/merged_notifier.go

Failed to calculate interdiff for this file.

ERROR
appview/notify/notifier.go

Failed to calculate interdiff for this file.

ERROR
appview/notify/posthog/notifier.go

Failed to calculate interdiff for this file.

ERROR
appview/pulls/pulls.go

Failed to calculate interdiff for this file.

NEW
appview/pages/markup/extension/atlink.go
··· 16 16 17 17 // An AtNode struct represents an AtNode 18 18 type AtNode struct { 19 - handle string 19 + Handle string 20 20 ast.BaseInline 21 21 } 22 22 ··· 59 59 block.Advance(m[1]) 60 60 node := &AtNode{} 61 61 node.AppendChild(node, ast.NewTextSegment(atSegment)) 62 - node.handle = string(atSegment.Value(block.Source())[1:]) 62 + node.Handle = string(atSegment.Value(block.Source())[1:]) 63 63 return node 64 64 } 65 65 ··· 88 88 func (r *atHtmlRenderer) renderAt(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) { 89 89 if entering { 90 90 w.WriteString(`<a href="/@`) 91 - w.WriteString(n.(*AtNode).handle) 91 + w.WriteString(n.(*AtNode).Handle) 92 92 w.WriteString(`" class="mention">`) 93 93 } else { 94 94 w.WriteString("</a>")
NEW
appview/pages/markup/markdown.go
··· 302 302 return path.Join(rctx.CurrentDir, dst) 303 303 } 304 304 305 + // FindUserMentions returns Set of user handles from given markup soruce. 306 + // It doesn't guarntee unique DIDs 307 + func FindUserMentions(source string) []string { 308 + var ( 309 + mentions []string 310 + mentionsSet = make(map[string]struct{}) 311 + md = NewMarkdown() 312 + sourceBytes = []byte(source) 313 + root = md.Parser().Parse(text.NewReader(sourceBytes)) 314 + ) 315 + ast.Walk(root, func(n ast.Node, entering bool) (ast.WalkStatus, error) { 316 + if entering && n.Kind() == textension.KindAt { 317 + handle := n.(*textension.AtNode).Handle 318 + mentionsSet[handle] = struct{}{} 319 + return ast.WalkSkipChildren, nil 320 + } 321 + return ast.WalkContinue, nil 322 + }) 323 + for handle := range mentionsSet { 324 + mentions = append(mentions, handle) 325 + } 326 + return mentions 327 + } 328 + 305 329 func isAbsoluteUrl(link string) bool { 306 330 parsed, err := url.Parse(link) 307 331 if err != nil {