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

Merge pull request #1415 from slingamn/issue1409_invite_history.1

fix #1409
This commit is contained in:
Shivaram Lingamneni 2020-11-29 19:47:22 -08:00 committed by GitHub
commit 5edfcced0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 32 deletions

View File

@ -1507,24 +1507,33 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client, rb *ResponseBuf
invitee.Invite(chcfname, createdAt)
}
details := inviter.Details()
tDetails := invitee.Details()
tnick := invitee.Nick()
message := utils.MakeMessage("")
item := history.Item{
Type: history.Invite,
Message: message,
Params: [1]string{chname},
}
for _, member := range channel.Members() {
if member == inviter || member == invitee || !channel.ClientIsAtLeast(member, modes.Halfop) {
continue
}
for _, session := range member.Sessions() {
if session.capabilities.Has(caps.InviteNotify) {
session.Send(nil, inviter.NickMaskString(), "INVITE", invitee.Nick(), chname)
session.sendFromClientInternal(false, message.Time, message.Msgid, details.nickMask, details.accountName, nil, "INVITE", tnick, chname)
}
}
}
cnick := inviter.Nick()
tnick := invitee.Nick()
rb.Add(nil, inviter.server.name, RPL_INVITING, cnick, tnick, chname)
invitee.Send(nil, inviter.NickMaskString(), "INVITE", tnick, chname)
rb.Add(nil, inviter.server.name, RPL_INVITING, details.nick, tnick, chname)
invitee.sendFromClientInternal(false, message.Time, message.Msgid, details.nickMask, details.accountName, nil, "INVITE", tnick, chname)
if away, awayMessage := invitee.Away(); away {
rb.Add(nil, inviter.server.name, RPL_AWAY, cnick, tnick, awayMessage)
rb.Add(nil, inviter.server.name, RPL_AWAY, details.nick, tnick, awayMessage)
}
inviter.addHistoryItem(invitee, item, &details, &tDetails, channel.server.Config())
}
// Uninvite rescinds a channel invitation, if the inviter can do so.

View File

@ -1055,6 +1055,13 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
for _, item := range items {
var command string
switch item.Type {
case history.Invite:
if hasEventPlayback {
rb.AddFromClient(item.Message.Time, item.Message.Msgid, item.Nick, item.AccountName, nil, "INVITE", item.Params[0])
} 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]))
}
continue
case history.Privmsg:
command = "PRIVMSG"
case history.Notice:
@ -1088,7 +1095,7 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
rb.EndNestedBatch(batchID)
if !complete {
rb.Add(nil, "HistServ", "NOTICE", nick, client.t("Some additional message history may have been lost"))
rb.Add(nil, histservService.prefix, "NOTICE", nick, client.t("Some additional message history may have been lost"))
}
}
@ -1862,6 +1869,34 @@ func (client *Client) historyStatus(config *Config) (status HistoryStatus, targe
return
}
func (client *Client) addHistoryItem(target *Client, item history.Item, details, tDetails *ClientDetails, config *Config) (err error) {
if !itemIsStorable(&item, config) {
return
}
item.Nick = details.nickMask
item.AccountName = details.accountName
targetedItem := item
targetedItem.Params[0] = tDetails.nick
cStatus, _ := client.historyStatus(config)
tStatus, _ := target.historyStatus(config)
// add to ephemeral history
if cStatus == HistoryEphemeral {
targetedItem.CfCorrespondent = tDetails.nickCasefolded
client.history.Add(targetedItem)
}
if tStatus == HistoryEphemeral && client != target {
item.CfCorrespondent = details.nickCasefolded
target.history.Add(item)
}
if cStatus == HistoryPersistent || tStatus == HistoryPersistent {
targetedItem.CfCorrespondent = ""
client.server.historyDB.AddDirectMessage(details.nickCasefolded, details.account, tDetails.nickCasefolded, tDetails.account, targetedItem)
}
return nil
}
func (client *Client) handleRegisterTimeout() {
client.Quit(fmt.Sprintf("Registration timeout: %v", RegisterTimeout), nil)
client.destroy(nil)

View File

@ -2143,37 +2143,20 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
}
}
if !allowedPlusR {
return
}
config := server.Config()
if !config.History.Enabled {
return
}
item := history.Item{
Type: histType,
Message: message,
Nick: nickMaskString,
AccountName: accountName,
Tags: tags,
}
if !itemIsStorable(&item, config) || !allowedPlusR {
return
}
targetedItem := item
targetedItem.Params[0] = tnick
cStatus, _ := client.historyStatus(config)
tStatus, _ := user.historyStatus(config)
// add to ephemeral history
if cStatus == HistoryEphemeral {
targetedItem.CfCorrespondent = tDetails.nickCasefolded
client.history.Add(targetedItem)
}
if tStatus == HistoryEphemeral && client != user {
item.CfCorrespondent = details.nickCasefolded
user.history.Add(item)
}
if cStatus == HistoryPersistent || tStatus == HistoryPersistent {
targetedItem.CfCorrespondent = ""
server.historyDB.AddDirectMessage(details.nickCasefolded, details.account, tDetails.nickCasefolded, tDetails.account, targetedItem)
Type: histType,
Message: message,
Tags: tags,
}
client.addHistoryItem(user, item, &details, &tDetails, config)
}
}

View File

@ -23,6 +23,7 @@ const (
Tagmsg
Nick
Topic
Invite
)
const (