feat: render forwarded messages (#538)
This commit is contained in:
parent
662fbf4c6a
commit
5efbed2d8c
2 changed files with 26 additions and 3 deletions
|
|
@ -126,7 +126,11 @@ func (mt *MessagesText) createMsg(msg discord.Message) {
|
||||||
|
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
case discord.DefaultMessage:
|
case discord.DefaultMessage:
|
||||||
mt.createDefaultMsg(msg)
|
if msg.Reference != nil && msg.Reference.Type == discord.MessageReferenceTypeForward {
|
||||||
|
mt.createForwardedMsg(msg)
|
||||||
|
} else {
|
||||||
|
mt.createDefaultMsg(msg)
|
||||||
|
}
|
||||||
case discord.InlinedReplyMessage:
|
case discord.InlinedReplyMessage:
|
||||||
mt.createReplyMsg(msg)
|
mt.createReplyMsg(msg)
|
||||||
|
|
||||||
|
|
@ -141,9 +145,12 @@ func (mt *MessagesText) createMsg(msg discord.Message) {
|
||||||
fmt.Fprintln(mt)
|
fmt.Fprintln(mt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mt *MessagesText) formatTimestamp(ts discord.Timestamp) string {
|
||||||
|
return ts.Time().In(time.Local).Format(mt.cfg.Timestamps.Format)
|
||||||
|
}
|
||||||
|
|
||||||
func (mt *MessagesText) drawTimestamps(ts discord.Timestamp) {
|
func (mt *MessagesText) drawTimestamps(ts discord.Timestamp) {
|
||||||
time := ts.Time().In(time.Local).Format(mt.cfg.Timestamps.Format)
|
fmt.Fprintf(mt, "[::d]%s[::D] ", mt.formatTimestamp(ts))
|
||||||
fmt.Fprintf(mt, "[::d]%s[::D] ", time)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mt *MessagesText) drawAuthor(msg discord.Message) {
|
func (mt *MessagesText) drawAuthor(msg discord.Message) {
|
||||||
|
|
@ -158,6 +165,12 @@ func (mt *MessagesText) drawContent(msg discord.Message) {
|
||||||
markdown.DefaultRenderer.Render(mt, c, ast)
|
markdown.DefaultRenderer.Render(mt, c, ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mt *MessagesText) drawSnapshotContent(msg discord.MessageSnapshotMessage) {
|
||||||
|
c := []byte(tview.Escape(msg.Content))
|
||||||
|
// discordmd doesn't support MessageSnapshotMessage, so we just use write it as is. todo?
|
||||||
|
mt.Write(c)
|
||||||
|
}
|
||||||
|
|
||||||
func (mt *MessagesText) createDefaultMsg(msg discord.Message) {
|
func (mt *MessagesText) createDefaultMsg(msg discord.Message) {
|
||||||
if mt.cfg.Timestamps.Enabled {
|
if mt.cfg.Timestamps.Enabled {
|
||||||
mt.drawTimestamps(msg.Timestamp)
|
mt.drawTimestamps(msg.Timestamp)
|
||||||
|
|
@ -206,6 +219,14 @@ func (mt *MessagesText) authorName(user discord.User, gID discord.GuildID) strin
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mt *MessagesText) createForwardedMsg(msg discord.Message) {
|
||||||
|
mt.drawTimestamps(msg.Timestamp)
|
||||||
|
mt.drawAuthor(msg)
|
||||||
|
fmt.Fprintf(mt, "[::d]%s [::-]", mt.cfg.Theme.MessagesText.ForwardedIndicator)
|
||||||
|
mt.drawSnapshotContent(msg.MessageSnapshots[0].Message)
|
||||||
|
fmt.Fprintf(mt, " [::d](%s)[-:-:-] ", mt.formatTimestamp(msg.MessageSnapshots[0].Message.Timestamp))
|
||||||
|
}
|
||||||
|
|
||||||
func (mt *MessagesText) authorColor(user discord.User, gID discord.GuildID) string {
|
func (mt *MessagesText) authorColor(user discord.User, gID discord.GuildID) string {
|
||||||
color := mt.cfg.Theme.MessagesText.AuthorColor
|
color := mt.cfg.Theme.MessagesText.AuthorColor
|
||||||
if app.cfg.Theme.MessagesText.ShowUsernameColors && gID.IsValid() {
|
if app.cfg.Theme.MessagesText.ShowUsernameColors && gID.IsValid() {
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ type (
|
||||||
ShowUsernameColors bool `toml:"show_user_colors"`
|
ShowUsernameColors bool `toml:"show_user_colors"`
|
||||||
|
|
||||||
ReplyIndicator string `toml:"reply_indicator"`
|
ReplyIndicator string `toml:"reply_indicator"`
|
||||||
|
ForwardedIndicator string `toml:"forwarded_indicator"`
|
||||||
|
|
||||||
AuthorColor string `toml:"author_color"`
|
AuthorColor string `toml:"author_color"`
|
||||||
ContentColor string `toml:"content_color"`
|
ContentColor string `toml:"content_color"`
|
||||||
|
|
@ -99,6 +100,7 @@ func defaultTheme() Theme {
|
||||||
ShowUsernameColors: true,
|
ShowUsernameColors: true,
|
||||||
|
|
||||||
ReplyIndicator: ">",
|
ReplyIndicator: ">",
|
||||||
|
ForwardedIndicator: "<",
|
||||||
|
|
||||||
AuthorColor: "aqua",
|
AuthorColor: "aqua",
|
||||||
ContentColor: tview.Styles.PrimaryTextColor.String(),
|
ContentColor: tview.Styles.PrimaryTextColor.String(),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue