Browse Source

Add replies to messages

master
Gregory Rudolph 4 years ago
parent
commit
fc48ad5c4a
  1. 2
      kbtui.toml
  2. 21
      main.go

2
kbtui.toml

@ -8,7 +8,7 @@ cmd_prefix = "/" @@ -8,7 +8,7 @@ cmd_prefix = "/"
[formatting]
# BASH-like PS1 variable equivalent
output_format = "┌──[$USER@$DEVICE$TAGS] [$ID] [$DATE - $TIME]\n└╼ $MSG"
output_format = "$REPL┌──[$USER@$DEVICE$TAGS] [$ID] [$DATE - $TIME]\n└╼ $MSG"
output_stream_format = "┌──[$USER@$DEVICE$TAGS] [$ID] [$DATE - $TIME]\n└╼ $MSG"
output_mention_format = "┌──[$USER@$DEVICE$TAGS] [$ID] [$DATE - $TIME]\n└╼ $MSG"
pm_format = "PM from $USER@$DEVICE: $MSG"

21
main.go

@ -537,14 +537,29 @@ func formatMessage(api keybase.ChatAPI, formatString string) StyledString { @@ -537,14 +537,29 @@ func formatMessage(api keybase.ChatAPI, formatString string) StyledString {
body = body.replaceString("$TITLE", attachment.Object.Title)
body = body.replace("$FILE", config.Colors.Message.Attachment.stylize(fmt.Sprintf("[Attachment: %s]", attachment.Object.Filename)))
}
reply := ""
if msg.Content.Text.ReplyTo != 0 {
chat := k.NewChat(channel)
replyMsg, replErr := chat.ReadMessage(msg.Content.Text.ReplyTo)
if replErr == nil {
replyUser := replyMsg.Result.Messages[0].Msg.Sender.Username
replyBody := ""
if replyMsg.Result.Messages[0].Msg.Content.Type == "text" {
replyBody = replyMsg.Result.Messages[0].Msg.Content.Text.Body
}
reply = fmt.Sprintf("\nReplyTo> %s: %s\n", replyUser, replyBody)
}
}
//printInfo(fmt.Sprintf("%d", msg.Content.Text.ReplyTo))
user := colorUsername(msg.Sender.Username)
device := config.Colors.Message.SenderDevice.stylize(msg.Sender.DeviceName)
msgID := config.Colors.Message.ID.stylize(fmt.Sprintf("%d", msg.ID))
date := config.Colors.Message.Time.stylize(tm.Format(config.Formatting.DateFormat))
msgTime := config.Colors.Message.Time.stylize(tm.Format(config.Formatting.TimeFormat))
c0ck := config.Colors.Message.Quote.stylize(reply)
channelName := config.Colors.Message.ID.stylize(fmt.Sprintf("@%s#%s", msg.Channel.Name, msg.Channel.TopicName))
ret = ret.replace("$REPL", c0ck)
ret = ret.replace("$MSG", body)
ret = ret.replace("$USER", user)
ret = ret.replace("$DEVICE", device)
@ -569,8 +584,8 @@ func formatOutput(api keybase.ChatAPI) StyledString { @@ -569,8 +584,8 @@ func formatOutput(api keybase.ChatAPI) StyledString {
// Input handling
func handleMessage(api keybase.ChatAPI) {
if api.Error != nil {
printError(fmt.Sprintf("%+v", api.Error))
if api.ErrorListen != nil {
printError(fmt.Sprintf("%+v", api.ErrorListen))
return
}
if _, ok := typeCommands[api.Msg.Content.Type]; ok {

Loading…
Cancel
Save