diff --git a/blocks.go b/blocks.go index e32a445..e217fa9 100644 --- a/blocks.go +++ b/blocks.go @@ -8,6 +8,7 @@ import ( "path" "strconv" "strings" + "time" "github.com/slack-go/slack" "github.com/yuin/goldmark" @@ -174,18 +175,45 @@ func (portal *Portal) renderSlackBlock(block slack.Block, userTeam *database.Use case *slack.DividerBlock: return "
%s | ", portal.mrkdwnToMatrixHtml(field.Text))) + if i%2 != 0 || i == len(b.Fields)-1 { + fieldTable.WriteString("
%s", attachment.AuthorName, renderedAttachment, attachment.FromURL, attachment.Footer)) } + } else if len(attachment.Blocks.BlockSet) > 0 { + for _, message_block := range attachment.Blocks.BlockSet { + renderedAttachment, _ := portal.renderSlackBlock(message_block, userTeam) + htmlText.WriteString(fmt.Sprintf("
%s%s
%s", renderedAttachment)) + } + } else { + if len(attachment.Pretext) > 0 { + htmlText.WriteString(fmt.Sprintf("
%s
", portal.mrkdwnToMatrixHtml(attachment.Pretext))) + } + var attachParts []string + if len(attachment.AuthorName) > 0 { + if len(attachment.AuthorLink) > 0 { + attachParts = append(attachParts, fmt.Sprintf("%s", + attachment.AuthorLink, attachment.AuthorName)) + } else { + attachParts = append(attachParts, fmt.Sprintf("%s", attachment.AuthorName)) + } + } + if len(attachment.Title) > 0 { + if len(attachment.TitleLink) > 0 { + attachParts = append(attachParts, fmt.Sprintf("%s", + attachment.TitleLink, portal.mrkdwnToMatrixHtml(attachment.Title))) + } else { + attachParts = append(attachParts, fmt.Sprintf("%s", portal.mrkdwnToMatrixHtml(attachment.Title))) + } + } + if len(attachment.Text) > 0 { + attachParts = append(attachParts, portal.mrkdwnToMatrixHtml(attachment.Text)) + } else if len(attachment.Fallback) > 0 { + attachParts = append(attachParts, portal.mrkdwnToMatrixHtml(attachment.Fallback)) + } + htmlText.WriteString(fmt.Sprintf("%s", strings.Join(attachParts, "") } }
"))) + if len(attachment.Fields) > 0 { + var fieldBody string + var short = false + for _, field := range attachment.Fields { + if !short { + fieldBody += "" + } + fieldBody += fmt.Sprintf(" " + } + } + htmlText.WriteString(fmt.Sprintf("%s ", + field.Title, portal.mrkdwnToMatrixHtml(field.Value)) + short = !short && field.Short + if !short { + fieldBody += "
%s%s
", fieldBody)) + } else { + htmlText.WriteString("
") + } + var footerParts []string + if len(attachment.Footer) > 0 { + footerParts = append(footerParts, portal.mrkdwnToMatrixHtml(attachment.Footer)) + } + if len(attachment.Ts) > 0 { + ts, _ := attachment.Ts.Int64() + t := time.Unix(ts, 0) + footerParts = append(footerParts, t.Local().Format("Jan 02, 2006 15:04:05 MST")) + } + if len(footerParts) > 0 { + htmlText.WriteString(fmt.Sprintf("%s", strings.Join(footerParts, " | "))) + } + htmlText.WriteString("