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

Merge pull request #1164 from slingamn/updateidle

fix #1155
This commit is contained in:
Shivaram Lingamneni 2020-06-30 17:43:03 -07:00 committed by GitHub
commit a8476f4e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 30 deletions

View File

@ -723,16 +723,11 @@ func (client *Client) playReattachMessages(session *Session) {
// //
// Touch indicates that we received a line from the client (so the connection is healthy // Touch indicates that we received a line from the client (so the connection is healthy
// at this time, modulo network latency and fakelag). `active` means not a PING or suchlike // at this time, modulo network latency and fakelag).
// (i.e. the user should be sitting in front of their client). func (client *Client) Touch(session *Session) {
func (client *Client) Touch(active bool, session *Session) {
var markDirty bool var markDirty bool
now := time.Now().UTC() now := time.Now().UTC()
client.stateMutex.Lock() client.stateMutex.Lock()
if active {
client.lastActive = now
session.lastActive = now
}
if client.accountSettings.AutoreplayMissed || session.deviceID != "" { if client.accountSettings.AutoreplayMissed || session.deviceID != "" {
client.setLastSeen(now, session.deviceID) client.setLastSeen(now, session.deviceID)
if now.Sub(client.lastSeenLastWrite) > lastSeenWriteInterval { if now.Sub(client.lastSeenLastWrite) > lastSeenWriteInterval {

View File

@ -15,7 +15,6 @@ type Command struct {
handler func(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool handler func(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool
oper bool oper bool
usablePreReg bool usablePreReg bool
leaveClientIdle bool // if true, leaves the client active time alone
allowedInBatch bool // allowed in client-to-server batches allowedInBatch bool // allowed in client-to-server batches
minParams int minParams int
capabs []string capabs []string
@ -67,7 +66,7 @@ func (cmd *Command) Run(server *Server, client *Client, session *Session, msg ir
// TODO: eliminate idletimer entirely in favor of this measurement // TODO: eliminate idletimer entirely in favor of this measurement
if client.registered { if client.registered {
client.Touch(!cmd.leaveClientIdle, session) client.Touch(session)
} }
return exiting return exiting
@ -161,7 +160,6 @@ func init() {
"ISON": { "ISON": {
handler: isonHandler, handler: isonHandler,
minParams: 1, minParams: 1,
leaveClientIdle: true,
}, },
"JOIN": { "JOIN": {
handler: joinHandler, handler: joinHandler,
@ -246,13 +244,11 @@ func init() {
handler: pingHandler, handler: pingHandler,
usablePreReg: true, usablePreReg: true,
minParams: 1, minParams: 1,
leaveClientIdle: true,
}, },
"PONG": { "PONG": {
handler: pongHandler, handler: pongHandler,
usablePreReg: true, usablePreReg: true,
minParams: 1, minParams: 1,
leaveClientIdle: true,
}, },
"PRIVMSG": { "PRIVMSG": {
handler: messageHandler, handler: messageHandler,
@ -351,7 +347,6 @@ func init() {
"WHO": { "WHO": {
handler: whoHandler, handler: whoHandler,
minParams: 1, minParams: 1,
leaveClientIdle: true,
}, },
"WHOIS": { "WHOIS": {
handler: whoisHandler, handler: whoisHandler,

View File

@ -418,6 +418,14 @@ func (client *Client) detailsNoMutex() (result ClientDetails) {
return return
} }
func (client *Client) UpdateActive(session *Session) {
now := time.Now().UTC()
client.stateMutex.Lock()
defer client.stateMutex.Unlock()
client.lastActive = now
session.lastActive = now
}
func (channel *Channel) Name() string { func (channel *Channel) Name() string {
channel.stateMutex.RLock() channel.stateMutex.RLock()
defer channel.stateMutex.RUnlock() defer channel.stateMutex.RUnlock()

View File

@ -1955,7 +1955,12 @@ func messageHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R
return false return false
} }
if rb.session.isTor && utils.IsRestrictedCTCPMessage(message) { isCTCP := utils.IsRestrictedCTCPMessage(message)
if histType == history.Privmsg && !isCTCP {
client.UpdateActive(rb.session)
}
if rb.session.isTor && isCTCP {
// note that error replies are never sent for NOTICE // note that error replies are never sent for NOTICE
if histType != history.Notice { if histType != history.Notice {
rb.Notice(client.t("CTCP messages are disabled over Tor")) rb.Notice(client.t("CTCP messages are disabled over Tor"))