downstream: update user realname on SETNAME
This commit is contained in:
parent
a45f9c3274
commit
29b1e6f47b
@ -1821,58 +1821,57 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the client just resets to the default, just wipe the per-network
|
if dc.realname == realname {
|
||||||
// preference
|
dc.SendMessage(&irc.Message{
|
||||||
storeRealname := realname
|
Prefix: dc.prefix(),
|
||||||
if realname == dc.user.Realname {
|
Command: "SETNAME",
|
||||||
storeRealname = ""
|
Params: []string{realname},
|
||||||
|
})
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var storeErr error
|
var err error
|
||||||
var needUpdate []Network
|
if dc.network != nil {
|
||||||
dc.forEachNetwork(func(n *network) {
|
// If the client just resets to the default, just wipe the per-network
|
||||||
// We only need to call updateNetwork for upstreams that don't
|
// preference
|
||||||
// support setname
|
record := dc.network.Network
|
||||||
if uc := n.conn; uc != nil && uc.caps.IsEnabled("setname") {
|
record.Realname = realname
|
||||||
uc.SendMessageLabeled(ctx, dc.id, &irc.Message{
|
if realname == dc.user.Realname {
|
||||||
|
record.Realname = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if uc := dc.upstream(); uc != nil && uc.caps.IsEnabled("setname") {
|
||||||
|
// Upstream will reply with a SETNAME message on success
|
||||||
|
uc.SendMessage(ctx, &irc.Message{
|
||||||
Command: "SETNAME",
|
Command: "SETNAME",
|
||||||
Params: []string{realname},
|
Params: []string{realname},
|
||||||
})
|
})
|
||||||
|
|
||||||
n.Realname = storeRealname
|
err = dc.srv.db.StoreNetwork(ctx, dc.user.ID, &record)
|
||||||
if err := dc.srv.db.StoreNetwork(ctx, dc.user.ID, &n.Network); err != nil {
|
} else {
|
||||||
dc.logger.Printf("failed to store network realname: %v", err)
|
// This will disconnect then re-connect the upstream connection
|
||||||
storeErr = err
|
_, err = dc.user.updateNetwork(ctx, &record)
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
record := n.Network // copy network record because we'll mutate it
|
|
||||||
record.Realname = storeRealname
|
|
||||||
needUpdate = append(needUpdate, record)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Walk the network list as a second step, because updateNetwork
|
|
||||||
// mutates the original list
|
|
||||||
for _, record := range needUpdate {
|
|
||||||
if _, err := dc.user.updateNetwork(ctx, &record); err != nil {
|
|
||||||
dc.logger.Printf("failed to update network realname: %v", err)
|
|
||||||
storeErr = err
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
record := dc.user.User
|
||||||
|
record.Realname = realname
|
||||||
|
err = dc.user.updateUser(ctx, &record)
|
||||||
}
|
}
|
||||||
if storeErr != nil {
|
|
||||||
|
if err != nil {
|
||||||
|
dc.logger.Printf("failed to update realname: %v", err)
|
||||||
return ircError{&irc.Message{
|
return ircError{&irc.Message{
|
||||||
Command: "FAIL",
|
Command: "FAIL",
|
||||||
Params: []string{"SETNAME", "CANNOT_CHANGE_REALNAME", "Failed to update realname"},
|
Params: []string{"SETNAME", "CANNOT_CHANGE_REALNAME", "Failed to update realname"},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
if dc.upstream() == nil {
|
if dc.network == nil {
|
||||||
dc.SendMessage(&irc.Message{
|
for _, c := range dc.user.downstreamConns {
|
||||||
Prefix: dc.prefix(),
|
if c.network == nil {
|
||||||
Command: "SETNAME",
|
c.updateRealname()
|
||||||
Params: []string{realname},
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
case "JOIN":
|
case "JOIN":
|
||||||
var namesStr string
|
var namesStr string
|
||||||
|
Loading…
Reference in New Issue
Block a user