diff --git a/mm-go-irckit/userbridge.go b/mm-go-irckit/userbridge.go index bcc12361..29166eaf 100644 --- a/mm-go-irckit/userbridge.go +++ b/mm-go-irckit/userbridge.go @@ -149,7 +149,7 @@ func (u *User) handleDirectMessageEvent(event *bridge.DirectMessageEvent) { text = wordwrap.String(text, maxlen) lines := strings.Split(text, "\n") for _, text := range lines { - if text == "```" { + if strings.HasPrefix(text, "```") { codeBlock = !codeBlock } // skip empty lines for anything not part of a code block. @@ -293,7 +293,7 @@ func (u *User) handleChannelMessageEvent(event *bridge.ChannelMessageEvent) { text = wordwrap.String(text, maxlen) lines := strings.Split(text, "\n") for _, text := range lines { - if text == "```" { + if strings.HasPrefix(text, "```") { codeBlock = !codeBlock } // skip empty lines for anything not part of a code block. @@ -1198,6 +1198,10 @@ func (u *User) loadLastViewedAt() map[string]int64 { } func (u *User) saveLastViewedAt(channelID string) { + if channelID == "" { + return + } + currentTime := make([]byte, 8) binary.LittleEndian.PutUint64(currentTime, uint64(model.GetMillis())) @@ -1291,7 +1295,7 @@ func (u *User) handleMessageThreadContext(channelID, messageID, parentID, event, case u.v.GetBool(u.br.Protocol()+".prefixcontext") && strings.HasPrefix(text, "\x01"): prefix = u.prefixContext(channelID, messageID, parentID, event) + " " newText = strings.Replace(text, "\x01ACTION ", "\x01ACTION "+prefix, 1) - maxlen = len(text) + maxlen = len(newText) case u.v.GetBool(u.br.Protocol()+".prefixcontext") && u.v.GetBool(u.br.Protocol()+".showcontextmulti"): prefix = u.prefixContext(channelID, messageID, parentID, event) + " " newText = text @@ -1303,6 +1307,7 @@ func (u *User) handleMessageThreadContext(channelID, messageID, parentID, event, case u.v.GetBool(u.br.Protocol()+".suffixcontext") && strings.HasSuffix(text, "\x01"): suffix = " " + u.prefixContext(channelID, messageID, parentID, event) newText = strings.Replace(text, " \x01", suffix+" \x01", 1) + maxlen = len(newText) case u.v.GetBool(u.br.Protocol()+".suffixcontext") && u.v.GetBool(u.br.Protocol()+".showcontextmulti"): suffix = " " + u.prefixContext(channelID, messageID, parentID, event) newText = text