Skip to content

Commit

Permalink
Emphasize system and reaction messages (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
hloeung authored Sep 27, 2023
1 parent d1a0645 commit be85b89
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 7 additions & 4 deletions mm-go-irckit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func search(u *User, toUser *User, args []string, service string) {

if len(postlist.Posts[postlist.Order[i]].FileIds) > 0 {
for _, fname := range u.br.GetFileLinks(postlist.Posts[postlist.Order[i]].FileIds) {
u.MsgUser(toUser, "download file - "+fname)
u.MsgUser(toUser, "\x1ddownload file - "+fname+"\x1d")
}
}

Expand Down Expand Up @@ -373,7 +373,7 @@ func scrollback(u *User, toUser *User, args []string, service string) {
}

if p.Type == model.PostTypeAddToTeam || p.Type == model.PostTypeRemoveFromTeam {
nick = "system"
nick = systemUser
}

if searchPostID != "" && channelID == "" {
Expand All @@ -390,6 +390,9 @@ func scrollback(u *User, toUser *User, args []string, service string) {
}

for _, post := range strings.Split(p.Message, "\n") {
if nick == systemUser {
post = "\x1d" + post + "\x1d"
}
formatScrollbackMsg(u, channelID, search, scrollbackUser, nick, p, post)
}

Expand All @@ -398,7 +401,7 @@ func scrollback(u *User, toUser *User, args []string, service string) {
}

for _, fname := range u.br.GetFileLinks(p.FileIds) {
fileMsg := "download file - " + fname
fileMsg := "\x1ddownload file - " + fname + "\x1d"
formatScrollbackMsg(u, channelID, search, scrollbackUser, nick, p, fileMsg)
}
}
Expand All @@ -410,7 +413,7 @@ func formatScrollbackMsg(u *User, channelID string, channel string, user *User,
ts := time.Unix(0, p.CreateAt*int64(time.Millisecond))

switch {
case (u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext")) && strings.HasPrefix(channel, "#") && nick != "system":
case (u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext")) && strings.HasPrefix(channel, "#") && nick != systemUser:
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)
Expand Down
18 changes: 12 additions & 6 deletions mm-go-irckit/userbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (u *User) handleChannelAddEvent(event *bridge.ChannelAddEvent) {
ch.Join(ghost)

if event.Adder != nil && added.Nick != event.Adder.Nick && event.Adder.Nick != systemUser {
ch.SpoofMessage(systemUser, "added "+added.Nick+" to the channel by "+event.Adder.Nick)
ch.SpoofMessage(systemUser, "\x1dadded "+added.Nick+" to the channel by "+event.Adder.Nick+"\x1d")
}
}

Expand All @@ -219,7 +219,7 @@ func (u *User) handleChannelRemoveEvent(event *bridge.ChannelRemoveEvent) {
ch.Part(ghost, "")

if event.Remover != nil && removed.Nick != event.Remover.Nick && event.Remover.Nick != systemUser {
ch.SpoofMessage(systemUser, "removed "+removed.Nick+" from the channel by "+event.Remover.Nick)
ch.SpoofMessage(systemUser, "\x1dremoved "+removed.Nick+" from the channel by "+event.Remover.Nick+"\x1d")
}
}
u.saveLastViewedAt(event.ChannelID)
Expand Down Expand Up @@ -290,6 +290,8 @@ func (u *User) handleChannelMessageEvent(event *bridge.ChannelMessageEvent) {
maxlen := 440
if u.Nick != systemUser {
text, prefix, suffix, showContext, maxlen = u.handleMessageThreadContext(event.ChannelID, event.MessageID, event.ParentID, event.Event, event.Text)
} else {
text = "\x1d" + text + "\x1d"
}

lexer := ""
Expand Down Expand Up @@ -326,7 +328,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
fileMsg := "\x1ddownload file - " + fname.Name + "\x1d"
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 @@ -441,7 +443,7 @@ func (u *User) handleReactionEvent(event interface{}) {

if channelType == "D" {
e := &bridge.DirectMessageEvent{
Text: text + reaction + message,
Text: "\x1d" + text + reaction + "\x1d" + message,
ChannelID: channelID,
Receiver: u.UserInfo,
Sender: sender,
Expand All @@ -455,7 +457,7 @@ func (u *User) handleReactionEvent(event interface{}) {
}

e := &bridge.ChannelMessageEvent{
Text: text + reaction + message,
Text: "\x1d" + text + reaction + "\x1d" + message,
ChannelID: channelID,
ChannelType: channelType,
Sender: sender,
Expand Down Expand Up @@ -719,6 +721,10 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt
showReplayHdr = false
}

if nick == systemUser {
post = "\x1d" + post + "\x1d"
}

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")) && nick != systemUser {
threadMsgID := u.prefixContext(brchannel.ID, p.Id, p.RootId, "replay")
Expand All @@ -732,7 +738,7 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt
}

for _, fname := range u.br.GetFileLinks(p.FileIds) {
fileMsg := "download file - " + fname
fileMsg := "\x1ddownload file - " + fname + "\x1d"
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)
Expand Down

0 comments on commit be85b89

Please sign in to comment.