3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-11 06:29:29 +01:00

Review fixes

This commit is contained in:
Daniel Oaks 2020-04-17 16:23:18 +10:00 committed by Shivaram Lingamneni
parent 4164c643e6
commit 6bee1f6d6a
3 changed files with 11 additions and 25 deletions

View File

@ -541,25 +541,23 @@ func (channel *Channel) ClientPrefixes(client *Client, isMultiPrefix bool) strin
} }
} }
func (channel *Channel) ClientModeStrings(client *Client) []string { func (channel *Channel) ClientModeStrings(client *Client) (result []string) {
channel.stateMutex.RLock() channel.stateMutex.RLock()
defer channel.stateMutex.RUnlock() defer channel.stateMutex.RUnlock()
modes, present := channel.members[client] modes, present := channel.members[client]
if !present { if present {
return []string{} for _, mode := range modes.AllModes() {
} else { result = append(result, mode.String())
return modes.Strings() }
} }
return
} }
func (channel *Channel) ClientJoinTime(client *Client) *time.Time { func (channel *Channel) ClientJoinTime(client *Client) time.Time {
channel.stateMutex.RLock() channel.stateMutex.RLock()
defer channel.stateMutex.RUnlock() defer channel.stateMutex.RUnlock()
time, present := channel.memberJoinTimes[client] time := channel.memberJoinTimes[client]
if present { return time
return &time
}
return nil
} }
func (channel *Channel) ClientHasPrivsOver(client *Client, target *Client) bool { func (channel *Channel) ClientHasPrivsOver(client *Client, target *Client) bool {
@ -738,7 +736,7 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
defer channel.stateMutex.Unlock() defer channel.stateMutex.Unlock()
channel.members.Add(client) channel.members.Add(client)
channel.memberJoinTimes[client] = time.Now() channel.memberJoinTimes[client] = time.Now().UTC()
firstJoin := len(channel.members) == 1 firstJoin := len(channel.members) == 1
newChannel := firstJoin && channel.registeredFounder == "" newChannel := firstJoin && channel.registeredFounder == ""
if newChannel { if newChannel {

View File

@ -940,7 +940,7 @@ func extjwtHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
claims["cmodes"] = []string{} claims["cmodes"] = []string{}
if channel.hasClient(client) { if channel.hasClient(client) {
joinTime := channel.ClientJoinTime(client) joinTime := channel.ClientJoinTime(client)
if joinTime == nil { if joinTime.IsZero() {
// shouldn't happen, only in races // shouldn't happen, only in races
rb.Add(nil, server.name, "FAIL", "EXTJWT", "UNKNOWN_ERROR", client.t("Channel join time is inconsistent, JWT not generated")) rb.Add(nil, server.name, "FAIL", "EXTJWT", "UNKNOWN_ERROR", client.t("Channel join time is inconsistent, JWT not generated"))
return false return false

View File

@ -388,18 +388,6 @@ func (set *ModeSet) String() (result string) {
return buf.String() return buf.String()
} }
// Strings returns the modes in this set.
func (set *ModeSet) Strings() (result []string) {
if set == nil {
return
}
for _, mode := range set.AllModes() {
result = append(result, mode.String())
}
return
}
// Prefixes returns a list of prefixes for the given set of channel modes. // Prefixes returns a list of prefixes for the given set of channel modes.
func (set *ModeSet) Prefixes(isMultiPrefix bool) (prefixes string) { func (set *ModeSet) Prefixes(isMultiPrefix bool) (prefixes string) {
if set == nil { if set == nil {