mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-11 06:29:29 +01:00
Merge pull request #1460 from slingamn/issue1449_invite_playback
fix #1449
This commit is contained in:
commit
5b79e427b5
@ -1088,14 +1088,6 @@ func (channel *Channel) replayHistoryForResume(session *Session, after time.Time
|
|||||||
rb.Send(true)
|
rb.Send(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func stripMaskFromNick(nickMask string) (nick string) {
|
|
||||||
index := strings.Index(nickMask, "!")
|
|
||||||
if index == -1 {
|
|
||||||
return nickMask
|
|
||||||
}
|
|
||||||
return nickMask[0:index]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.Item, autoreplay bool) {
|
func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.Item, autoreplay bool) {
|
||||||
// send an empty batch if necessary, as per the CHATHISTORY spec
|
// send an empty batch if necessary, as per the CHATHISTORY spec
|
||||||
chname := channel.Name()
|
chname := channel.Name()
|
||||||
@ -1118,7 +1110,7 @@ func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.I
|
|||||||
defer rb.EndNestedBatch(batchID)
|
defer rb.EndNestedBatch(batchID)
|
||||||
|
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
nick := stripMaskFromNick(item.Nick)
|
nick := NUHToNick(item.Nick)
|
||||||
switch item.Type {
|
switch item.Type {
|
||||||
case history.Privmsg:
|
case history.Privmsg:
|
||||||
rb.AddSplitMessageFromClient(item.Nick, item.AccountName, item.Tags, "PRIVMSG", chname, item.Message)
|
rb.AddSplitMessageFromClient(item.Nick, item.AccountName, item.Tags, "PRIVMSG", chname, item.Message)
|
||||||
@ -1552,11 +1544,10 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client, rb *ResponseBuf
|
|||||||
details := inviter.Details()
|
details := inviter.Details()
|
||||||
tDetails := invitee.Details()
|
tDetails := invitee.Details()
|
||||||
tnick := invitee.Nick()
|
tnick := invitee.Nick()
|
||||||
message := utils.MakeMessage("")
|
message := utils.MakeMessage(chname)
|
||||||
item := history.Item{
|
item := history.Item{
|
||||||
Type: history.Invite,
|
Type: history.Invite,
|
||||||
Message: message,
|
Message: message,
|
||||||
Params: [1]string{chname},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, member := range channel.Members() {
|
for _, member := range channel.Members() {
|
||||||
|
@ -975,7 +975,7 @@ func (session *Session) playResume() {
|
|||||||
if privmsgSeq != nil {
|
if privmsgSeq != nil {
|
||||||
privmsgs, _, _ := privmsgSeq.Between(history.Selector{}, history.Selector{}, config.History.ClientLength)
|
privmsgs, _, _ := privmsgSeq.Between(history.Selector{}, history.Selector{}, config.History.ClientLength)
|
||||||
for _, item := range privmsgs {
|
for _, item := range privmsgs {
|
||||||
sender := server.clients.Get(stripMaskFromNick(item.Nick))
|
sender := server.clients.Get(NUHToNick(item.Nick))
|
||||||
if sender != nil {
|
if sender != nil {
|
||||||
friends.Add(sender)
|
friends.Add(sender)
|
||||||
}
|
}
|
||||||
@ -1058,16 +1058,28 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
|
|||||||
}
|
}
|
||||||
batchID = rb.StartNestedHistoryBatch(target)
|
batchID = rb.StartNestedHistoryBatch(target)
|
||||||
|
|
||||||
|
isSelfMessage := func(item *history.Item) bool {
|
||||||
|
// XXX: Params[0] is the message target. if the source of this message is an in-memory
|
||||||
|
// buffer, then it's "" for an incoming message and the recipient's nick for an outgoing
|
||||||
|
// message. if the source of the message is mysql, then mysql only sees one copy of the
|
||||||
|
// message, and it's the version with the recipient's nick filled in. so this is an
|
||||||
|
// incoming message if Params[0] (the recipient's nick) equals the client's nick:
|
||||||
|
return item.Params[0] != "" && item.Params[0] != nick
|
||||||
|
}
|
||||||
|
|
||||||
hasEventPlayback := rb.session.capabilities.Has(caps.EventPlayback)
|
hasEventPlayback := rb.session.capabilities.Has(caps.EventPlayback)
|
||||||
hasTags := rb.session.capabilities.Has(caps.MessageTags)
|
hasTags := rb.session.capabilities.Has(caps.MessageTags)
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
var command string
|
var command string
|
||||||
switch item.Type {
|
switch item.Type {
|
||||||
case history.Invite:
|
case history.Invite:
|
||||||
|
if isSelfMessage(&item) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if hasEventPlayback {
|
if hasEventPlayback {
|
||||||
rb.AddFromClient(item.Message.Time, item.Message.Msgid, item.Nick, item.AccountName, nil, "INVITE", item.Params[0])
|
rb.AddFromClient(item.Message.Time, item.Message.Msgid, item.Nick, item.AccountName, nil, "INVITE", nick, item.Message.Message)
|
||||||
} else {
|
} else {
|
||||||
rb.AddFromClient(item.Message.Time, utils.MungeSecretToken(item.Message.Msgid), histservService.prefix, "*", nil, "PRIVMSG", fmt.Sprintf(client.t("%[1]s invited you to channel %[2]s"), stripMaskFromNick(item.Nick), item.Params[0]))
|
rb.AddFromClient(item.Message.Time, utils.MungeSecretToken(item.Message.Msgid), histservService.prefix, "*", nil, "PRIVMSG", fmt.Sprintf(client.t("%[1]s invited you to channel %[2]s"), NUHToNick(item.Nick), item.Message.Message))
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
case history.Privmsg:
|
case history.Privmsg:
|
||||||
@ -1087,12 +1099,7 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
|
|||||||
if hasTags {
|
if hasTags {
|
||||||
tags = item.Tags
|
tags = item.Tags
|
||||||
}
|
}
|
||||||
// XXX: Params[0] is the message target. if the source of this message is an in-memory
|
if !isSelfMessage(&item) {
|
||||||
// buffer, then it's "" for an incoming message and the recipient's nick for an outgoing
|
|
||||||
// message. if the source of the message is mysql, then mysql only sees one copy of the
|
|
||||||
// message, and it's the version with the recipient's nick filled in. so this is an
|
|
||||||
// incoming message if Params[0] (the recipient's nick) equals the client's nick:
|
|
||||||
if item.Params[0] == "" || item.Params[0] == nick {
|
|
||||||
rb.AddSplitMessageFromClient(item.Nick, item.AccountName, tags, command, nick, item.Message)
|
rb.AddSplitMessageFromClient(item.Nick, item.AccountName, tags, command, nick, item.Message)
|
||||||
} else {
|
} else {
|
||||||
// this message was sent *from* the client to another nick; the target is item.Params[0]
|
// this message was sent *from* the client to another nick; the target is item.Params[0]
|
||||||
|
@ -173,7 +173,7 @@ func histservPlayHandler(service *ircService, server *Server, client *Client, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
playMessage := func(timestamp time.Time, nick, message string) {
|
playMessage := func(timestamp time.Time, nick, message string) {
|
||||||
service.Notice(rb, fmt.Sprintf("%s <%s> %s", timestamp.Format("15:04:05"), stripMaskFromNick(nick), message))
|
service.Notice(rb, fmt.Sprintf("%s <%s> %s", timestamp.Format("15:04:05"), NUHToNick(nick), message))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
|
@ -308,3 +308,11 @@ func foldPermissive(str string) (result string, err error) {
|
|||||||
str = norm.NFD.String(str)
|
str = norm.NFD.String(str)
|
||||||
return str, nil
|
return str, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reduce, e.g., `alice!~u@host` to `alice`
|
||||||
|
func NUHToNick(nuh string) (nick string) {
|
||||||
|
if idx := strings.IndexByte(nuh, '!'); idx != -1 {
|
||||||
|
return nuh[0:idx]
|
||||||
|
}
|
||||||
|
return nuh
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user