Use local url for for mentioned users
authorr <r@freesoftwareextremist.com>
Sat, 21 Dec 2019 05:48:06 +0000 (05:48 +0000)
committerr <r@freesoftwareextremist.com>
Sat, 21 Dec 2019 05:48:06 +0000 (05:48 +0000)
renderer/renderer.go
templates/notification.tmpl
templates/status.tmpl
templates/user.tmpl

index 3eb04572048b77b6a748f06175f131a2d3586016..9bbe06e0a1e0b12c76d9ef2a8a0fd350afeb740f 100644 (file)
@@ -28,7 +28,8 @@ type renderer struct {
 func NewRenderer(templateGlobPattern string) (r *renderer, err error) {
        t := template.New("default")
        t, err = t.Funcs(template.FuncMap{
-               "WithEmojis":              WithEmojis,
+               "EmojiFilter":             EmojiFilter,
+               "StatusContentFilter":     StatusContentFilter,
                "DisplayInteractionCount": DisplayInteractionCount,
                "TimeSince":               TimeSince,
                "FormatTimeRFC3339":       FormatTimeRFC3339,
@@ -70,12 +71,24 @@ func (r *renderer) RenderUserPage(ctx context.Context, writer io.Writer, data *U
        return r.template.ExecuteTemplate(writer, "user.tmpl", data)
 }
 
-func WithEmojis(content string, emojis []mastodon.Emoji) string {
-       var emojiNameContentPair []string
+
+func EmojiFilter(content string, emojis []mastodon.Emoji) string {
+       var replacements []string
+       for _, e := range emojis {
+               replacements = append(replacements, ":"+e.ShortCode+":", "<img class=\"status-emoji\" src=\""+e.URL+"\" alt=\""+e.ShortCode+"\" />")
+       }
+       return strings.NewReplacer(replacements...).Replace(content)
+}
+
+func StatusContentFilter(content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
+       var replacements []string
        for _, e := range emojis {
-               emojiNameContentPair = append(emojiNameContentPair, ":"+e.ShortCode+":", "<img class=\"status-emoji\" src=\""+e.URL+"\" alt=\""+e.ShortCode+"\" />")
+               replacements = append(replacements, ":"+e.ShortCode+":", "<img class=\"status-emoji\" src=\""+e.URL+"\" alt=\""+e.ShortCode+"\" />")
+       }
+       for _, m := range mentions {
+               replacements = append(replacements, "\""+m.URL+"\"", "\"/user/"+m.ID+"\"")
        }
-       return strings.NewReplacer(emojiNameContentPair...).Replace(content)
+       return strings.NewReplacer(replacements...).Replace(content)
 }
 
 func DisplayInteractionCount(c int64) string {
index da6164b4dc8ea56931c2d6ee589b10379ee7dd3a..271597b3c122af194d1bc9aad247b1ea428b1bc8 100644 (file)
@@ -11,7 +11,7 @@
                </a>
                <div>
                        <div>
-                               <span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span>  
+                               <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>  
                                <span class="icon dripicons-user-group"></span> 
                                followed you
                        </div>
@@ -31,7 +31,7 @@
                </a>
                <div>
                        <div>
-                               <span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span>  
+                               <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>  
                                <span class="icon dripicons-retweet retweeted"></span> 
                                retweeted your post
                        </div>
@@ -46,7 +46,7 @@
                </a>
                <div>
                        <div>
-                               <span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span>  
+                               <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>  
                                <span class="icon dripicons-star liked"></span> 
                                liked your post
                        </div>
index 618398f36a42562d91b3d71ab51a93adb3a272be..b1babf6c440b6115397f0daee33564f3d8a5e74c 100644 (file)
@@ -4,7 +4,7 @@
                <a href="/user/{{.Account.ID}}" >
                        <img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="profile-avatar" />
                </a>
-               <span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span>  
+               <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>  
                <span class="icon dripicons-retweet retweeted"></span> 
                retweeted
        </div>
@@ -22,7 +22,7 @@
                <div class="status"> 
                        {{if not .HideAccountInfo}}
                        <div class="status-name">
-                               <span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span> 
+                               <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span> 
                                <a href="/user/{{.Account.ID}}" >
                                        <span class="status-uname"> {{.Account.Acct}} </span>
                                </a>
@@ -41,7 +41,7 @@
                                {{end}}
                                {{end}}
                        </div>
-                       <div class="status-content"> {{WithEmojis .Content .Emojis}} </div>
+                       <div class="status-content"> {{StatusContentFilter .Content .Emojis .Mentions}} </div>
                        <div class="status-media-container">
                        {{range .MediaAttachments}}
                        {{if eq .Type "image"}}
index 3347f9294afe7e60aece839693ee165be71db8b1..e1a782adf368e710b00229b9901a8fa1f59c37f5 100644 (file)
@@ -9,7 +9,7 @@
        </div>
        <div class="user-profile-details-container">
                <div>
-                       <span class="status-dname"> {{WithEmojis .User.DisplayName .User.Emojis}} </span>  
+                       <span class="status-dname"> {{EmojiFilter .User.DisplayName .User.Emojis}} </span>  
                        <span class="status-uname"> {{.User.Acct}} </span>
                </div>
                <div>