Skip to content

Commit

Permalink
Include thread context for matterircd style hex numbers for replay an…
Browse files Browse the repository at this point in the history
…d scrollback

Also fix counters by doing the looking for all events, not just
post_edited, post_deleted, or reaction.
  • Loading branch information
hloeung committed Sep 14, 2023
1 parent 38f89c4 commit 4bf8059
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
8 changes: 4 additions & 4 deletions mm-go-irckit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,15 @@ func formatScrollbackMsg(u *User, channelID string, channel string, user *User,
ts := time.Unix(0, p.CreateAt*int64(time.Millisecond))

switch {
case (u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post") && strings.HasPrefix(channel, "#") && nick != "system": //nolint:goconst
threadMsgID := u.prefixContext("", p.Id, p.RootId, "scrollback")
case (u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext")) && strings.HasPrefix(channel, "#") && nick != "system": //nolint:goconst
threadMsgID := u.prefixContext(channelID, p.Id, p.RootId, "scrollback")
msg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, msgText)
u.Srv.Channel(channelID).SpoofMessage(nick, msg)
case strings.HasPrefix(channel, "#"):
msg := "[" + ts.Format("2006-01-02 15:04") + "] " + msgText
u.Srv.Channel(channelID).SpoofMessage(nick, msg)
case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post":
threadMsgID := u.prefixContext("", p.Id, p.RootId, "scrollback")
case u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext"):
threadMsgID := u.prefixContext(channelID, p.Id, p.RootId, "scrollback")
msg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, msgText)
u.MsgSpoofUser(user, nick, msg)
default:
Expand Down
16 changes: 6 additions & 10 deletions mm-go-irckit/userbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (u *User) handleChannelMessageEvent(event *bridge.ChannelMessageEvent) {
func (u *User) handleFileEvent(event *bridge.FileEvent) {
for _, fname := range event.Files {
fileMsg := "download file - " + fname.Name
if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post" {
if u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext") {
threadMsgID := u.prefixContext(event.ChannelID, event.MessageID, event.ParentID, "posted_file")
fileMsg = u.formatContextMessage("", threadMsgID, fileMsg)
}
Expand Down Expand Up @@ -720,8 +720,8 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt
}

replayMsg := fmt.Sprintf("[%s] %s", ts.Format("15:04"), post)
if (u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext")) && (u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post") && nick != systemUser {
threadMsgID := u.prefixContext("", p.Id, p.RootId, "replay")
if (u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext")) && nick != systemUser {
threadMsgID := u.prefixContext(brchannel.ID, p.Id, p.RootId, "replay")
replayMsg = u.formatContextMessage(ts.Format("15:04"), threadMsgID, post)
}
spoof(nick, replayMsg)
Expand All @@ -733,8 +733,8 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt

for _, fname := range u.br.GetFileLinks(p.FileIds) {
fileMsg := "download file - " + fname
if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post" {
threadMsgID := u.prefixContext("", p.Id, p.RootId, "replay_file")
if u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext") {
threadMsgID := u.prefixContext(brchannel.ID, p.Id, p.RootId, "replay_file")
fileMsg = u.formatContextMessage(ts.Format("15:04"), threadMsgID, fileMsg)
}
spoof(nick, fileMsg)
Expand Down Expand Up @@ -1018,11 +1018,7 @@ func (u *User) prefixContext(channelID, messageID, parentID, event string) strin
u.updateMsgMapIndex(channelID, parentcount, parentID)
}

if event == "post_edited" || event == "post_deleted" || event == "reaction" {
if _, ok = u.msgMap[channelID][messageID]; !ok {
u.msgMap[channelID][messageID] = u.increaseMsgCounter(channelID, parentcount)
}
} else {
if _, ok = u.msgMap[channelID][messageID]; !ok {
u.msgMap[channelID][messageID] = u.increaseMsgCounter(channelID, parentcount)
}

Expand Down

0 comments on commit 4bf8059

Please sign in to comment.