3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

replay JOIN/PART/QUIT/KICK as PRIVMSG from HistServ

see https://github.com/ircv3/ircv3-specifications/issues/293
This commit is contained in:
Shivaram Lingamneni 2019-01-02 17:52:36 -05:00
parent f20abf414f
commit 501bb1e5c5

View File

@ -9,6 +9,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"time" "time"
"sync" "sync"
@ -469,11 +470,7 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
replayLimit := channel.server.Config().History.AutoreplayOnJoin replayLimit := channel.server.Config().History.AutoreplayOnJoin
if replayLimit > 0 { if replayLimit > 0 {
// don't replay the client's own events items := channel.history.Latest(replayLimit)
matcher := func(item history.Item) bool {
return item.Nick != details.nickMask
}
items := channel.history.Match(matcher, replayLimit)
channel.replayHistoryItems(rb, items) channel.replayHistoryItems(rb, items)
rb.Flush(true) rb.Flush(true)
} }
@ -591,10 +588,17 @@ func (channel *Channel) replayHistoryForResume(newClient *Client, after time.Tim
rb.Send(true) rb.Send(true)
} }
func stripMaskFromNick(nickMask string) (nick string) {
index := strings.Index(nickMask, "!")
if index == -1 {
return
}
return nickMask[0:index]
}
func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.Item) { func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.Item) {
chname := channel.Name() chname := channel.Name()
client := rb.target client := rb.target
extendedJoin := client.capabilities.Has(caps.ExtendedJoin)
serverTime := client.capabilities.Has(caps.ServerTime) serverTime := client.capabilities.Has(caps.ServerTime)
for _, item := range items { for _, item := range items {
@ -609,21 +613,27 @@ func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.I
case history.Notice: case history.Notice:
rb.AddSplitMessageFromClient(item.Msgid, item.Nick, item.AccountName, tags, "NOTICE", chname, item.Message) rb.AddSplitMessageFromClient(item.Msgid, item.Nick, item.AccountName, tags, "NOTICE", chname, item.Message)
case history.Join: case history.Join:
if extendedJoin { nick := stripMaskFromNick(item.Nick)
// XXX Msgid is the realname in this case var message string
rb.Add(tags, item.Nick, "JOIN", chname, item.AccountName, item.Msgid) if item.AccountName == "*" {
message = fmt.Sprintf(client.t("%s joined the channel"), nick)
} else { } else {
rb.Add(tags, item.Nick, "JOIN", chname) message = fmt.Sprintf(client.t("%s [account: %s] joined the channel"), nick, item.AccountName)
} }
case history.Quit: rb.Add(tags, "HistServ", "PRIVMSG", chname, message)
// XXX: send QUIT as PART to avoid having to correctly deduplicate and synchronize
// QUIT messages across channels
fallthrough
case history.Part: case history.Part:
rb.Add(tags, item.Nick, "PART", chname, item.Message.Original) nick := stripMaskFromNick(item.Nick)
message := fmt.Sprintf(client.t("%s left the channel (%s)"), nick, item.Message.Original)
rb.Add(tags, "HistServ", "PRIVMSG", chname, message)
case history.Quit:
nick := stripMaskFromNick(item.Nick)
message := fmt.Sprintf(client.t("%s quit (%s)"), nick, item.Message.Original)
rb.Add(tags, "HistServ", "PRIVMSG", chname, message)
case history.Kick: case history.Kick:
nick := stripMaskFromNick(item.Nick)
// XXX Msgid is the kick target // XXX Msgid is the kick target
rb.Add(tags, item.Nick, "KICK", chname, item.Msgid, item.Message.Original) message := fmt.Sprintf(client.t("%s kicked %s (%s)"), nick, item.Msgid, item.Message.Original)
rb.Add(tags, "HistServ", "PRIVMSG", chname, message)
} }
} }
} }