Skip to content

Commit

Permalink
add some missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Mar 28, 2024
1 parent 68e084e commit 8469c37
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/viewer/renderer/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ var (
figure = element("figure", true)
blockquote = element("blockquote", true)
strong = element("strong", true)
pre = element("pre", true)
)

func element(el string, close bool) func(class string, s string) string {
Expand Down
42 changes: 42 additions & 0 deletions internal/viewer/renderer/slack_action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package renderer

import (
"fmt"
"strings"

"github.com/rusq/slack"
)

/*
{
"type": "actions",
"block_id": "{\"task_id\":\"1209021\",\"id\":\"........\"}",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View",
"emoji": true
},
"action_id": "jira_view_modal",
"value": "jira_view_modal"
},
*/

func (*Slack) mbtAction(ib slack.Block) (string, error) {
b, ok := ib.(*slack.ActionBlock)
if !ok {
return "", NewErrIncorrectType(&slack.ActionBlock{}, ib)
}
var buf strings.Builder
for _, e := range b.Elements.ElementSet {
switch e := e.(type) {
case *slack.ButtonBlockElement:
fmt.Fprintf(&buf, `[BUTTON: %s: %s]`, e.ActionID, e.Text.Text)
default:
fmt.Fprintf(&buf, "[ELEMENT: %T]", e)
}
}
return div("slack-actions", buf.String()), nil
}
24 changes: 24 additions & 0 deletions internal/viewer/renderer/slack_section.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package renderer

import (
"github.com/rusq/slack"
)

/*
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Meeting passcode: yyyyy"
},
"block_id": "swSOO"
}
*/

func (*Slack) mbtSection(ib slack.Block) (string, error) {
b, ok := ib.(*slack.SectionBlock)
if !ok {
return "", NewErrIncorrectType(&slack.SectionBlock{}, ib)
}
return pre("slack-section-text", b.Text.Text), nil
}
13 changes: 13 additions & 0 deletions internal/viewer/renderer/slack_sundry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package renderer

import "github.com/rusq/slack"

/*
{
"type": "call",
"block_id": "35d6f"
},
*/
func (*Slack) mbtCall(slack.Block) (string, error) {
return div("slack-call", "(Call)"), nil
}
10 changes: 10 additions & 0 deletions internal/viewer/renderer/slack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@ var (
slack.MBTRichText: (*Slack).mbtRichText,
slack.MBTImage: (*Slack).mbtImage,
slack.MBTContext: (*Slack).mbtContext,
slack.MBTSection: (*Slack).mbtSection,
slack.MBTAction: (*Slack).mbtAction,
"call": (*Slack).mbtCall,
}

blockTypeClass = map[slack.MessageBlockType]string{
slack.MBTRichText: "slack-rich-text-block",
slack.MBTImage: "slack-image-block",
slack.MBTContext: "slack-context-block",
slack.MBTSection: "slack-section-block",
slack.MBTAction: "slack-action-block",
"call": "slack-call-block",
}
)

func mbtTODO(s *Slack, b slack.Block) (string, error) {
return "", nil
}

// rte - rich text element
var (
rteTypeHandlers = map[slack.RichTextElementType]func(*Slack, slack.RichTextElement) (string, error){}
Expand Down
3 changes: 1 addition & 2 deletions internal/viewer/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ func epoch(ts json.Number) string {
}
t, err := ts.Int64()
if err != nil {
slog.Debug("epoch Int64 error, trying float", "err", err, "ts", ts)
tf, err := ts.Float64()
if err != nil {
slog.Debug("epoch Float64 error", "err", err, "ts", ts)
slog.Debug("epoch Float64 error, out of conversion options", "err", err, "ts", ts)
return ts.String()
}
t = int64(tf)
Expand Down

0 comments on commit 8469c37

Please sign in to comment.