From 215137df0f574ebc98a6574ab7f0fee453d65790 Mon Sep 17 00:00:00 2001 From: Janne Koschinski <janne@kuschku.de> Date: Thu, 14 Feb 2019 13:18:54 +0100 Subject: [PATCH] Improve compatibility with the IRCCloud Slack gateway --- main.go | 58 +++++++++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/main.go b/main.go index 99a05fa..a0f411a 100644 --- a/main.go +++ b/main.go @@ -136,21 +136,20 @@ type DataField struct { } type Data struct { - Color string `json:"color"` - AuthorName string `json:"author_name"` - AuthorLink string `json:"author_link"` - AuthorIcon string `json:"author_icon"` - Title string `json:"title"` - TitleLink string `json:"title_link"` - Text string `json:"text"` - Fields []DataField `json:"fields"` - ImageUrl string `json:"image_url"` - Type string `json:"type"` - Player string `json:"player"` - ThumbUrl string `json:"thumb_url"` - Footer string `json:"footer"` - FooterIcon string `json:"footer_icon"` - Ts int `json:"ts"` + Color string `json:"color"` + AuthorName string `json:"author_name"` + AuthorLink string `json:"author_link"` + AuthorIcon string `json:"author_icon"` + Title string `json:"title"` + TitleLink string `json:"title_link"` + Text string `json:"text"` + Fields []DataField `json:"fields"` + ImageUrl string `json:"image_url"` + Type string `json:"type"` + Player string `json:"player"` + Service string `json:"service"` + ServiceIcon string `json:"service_icon"` + Ts int `json:"ts"` } func coalesce(list []string) string { @@ -209,31 +208,23 @@ func buildData(in InternalData, oEmbed OEmbed, providerFallbacks []func(*Interna for _, fallback := range providerFallbacks { out.Color = coalesce([]string{in.metaThemeColor, in.urlProviderMetaThemeColor}) - out.Footer = coalesce([]string{oEmbed.ProviderName, in.ogSiteName, in.urlProviderOgSiteName, in.urlProviderMetaTitle, in.urlProviderTitle}) - out.FooterIcon = resolve(in.url, coalesce([]string{in.linkFavicon, in.urlProviderLinkFavicon, in.urlProviderIconPng, in.urlProviderIconIco})) - if out.Footer != "" && out.FooterIcon != "" { + out.Service = coalesce([]string{oEmbed.ProviderName, in.ogSiteName, in.urlProviderOgSiteName, in.urlProviderMetaTitle, in.urlProviderTitle}) + out.ServiceIcon = resolve(in.url, coalesce([]string{in.linkFavicon, in.urlProviderLinkFavicon, in.urlProviderIconPng, in.urlProviderIconIco})) + if out.Service != "" && out.ServiceIcon != "" { break } fallback(&in) } - var largeImages []string - var smallImages []string - if in.twitterCard == "summary" || in.twitterCard == "summary_large_image" { - largeImages = append(largeImages, in.twitterImage) - } else { - smallImages = append(smallImages, in.twitterImage) - } - largeImages = append(largeImages, in.ogImage) - smallImages = append(smallImages, in.ogImage) + var images []string + images = append(images, in.twitterImage) + images = append(images, in.ogImage) if in.rawType == "image" { - largeImages = append(largeImages, in.url.String()) - } - // Only use favicon as thumbnail icon if we don’t already use it for the footer - if out.Footer == "" { - smallImages = append(smallImages, in.linkFavicon) + images = append(images, in.url.String()) } + out.ImageUrl = resolve(in.url, coalesce(images)) + hasType := func(formats []string, types []string) bool { for _, format := range formats { for _, t := range types { @@ -265,9 +256,6 @@ func buildData(in InternalData, oEmbed OEmbed, providerFallbacks []func(*Interna out.Type = "article" } - out.ThumbUrl = resolve(in.url, coalesce(smallImages)) - out.ImageUrl = resolve(in.url, coalesce(largeImages)) - buildField := func(title string, value string) { const MaxShortFieldLength = 32 value = strings.TrimSpace(value) -- GitLab