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

Merge pull request #1961 from slingamn/readmarker

fix critical bugs in draft/read-marker
This commit is contained in:
Shivaram Lingamneni 2022-05-20 01:51:41 -04:00 committed by GitHub
commit ae55a4c660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 13 deletions

View File

@ -130,7 +130,8 @@ func (am *AccountManager) createAlwaysOnClients(config *Config) {
am.server.AddAlwaysOnClient(
account,
am.loadChannels(accountName),
am.loadLastSeen(accountName),
am.loadTimeMap(keyAccountLastSeen, accountName),
am.loadTimeMap(keyAccountReadMarkers, accountName),
am.loadModes(accountName),
am.loadRealname(accountName),
)
@ -675,8 +676,8 @@ func (am *AccountManager) saveTimeMap(account, key string, timeMap map[string]ti
}
}
func (am *AccountManager) loadLastSeen(account string) (lastSeen map[string]time.Time) {
key := fmt.Sprintf(keyAccountLastSeen, account)
func (am *AccountManager) loadTimeMap(baseKey, account string) (lastSeen map[string]time.Time) {
key := fmt.Sprintf(baseKey, account)
var lsText string
am.server.store.Update(func(tx *buntdb.Tx) error {
lsText, _ = tx.Get(key)

View File

@ -389,7 +389,7 @@ func (server *Server) RunClient(conn IRCConn) {
client.run(session)
}
func (server *Server) AddAlwaysOnClient(account ClientAccount, channelToStatus map[string]alwaysOnChannelStatus, lastSeen map[string]time.Time, uModes modes.Modes, realname string) {
func (server *Server) AddAlwaysOnClient(account ClientAccount, channelToStatus map[string]alwaysOnChannelStatus, lastSeen, readMarkers map[string]time.Time, uModes modes.Modes, realname string) {
now := time.Now().UTC()
config := server.Config()
if lastSeen == nil && account.Settings.AutoreplayMissed {
@ -407,12 +407,13 @@ func (server *Server) AddAlwaysOnClient(account ClientAccount, channelToStatus m
}
client := &Client{
lastSeen: lastSeen,
lastActive: now,
channels: make(ChannelSet),
ctime: now,
languages: server.Languages().Default(),
server: server,
lastSeen: lastSeen,
readMarkers: readMarkers,
lastActive: now,
channels: make(ChannelSet),
ctime: now,
languages: server.Languages().Default(),
server: server,
username: username,
cloakedHostname: cloakedHostname,

View File

@ -4,6 +4,7 @@
package irc
import (
"fmt"
"net"
"sync/atomic"
"time"
@ -493,7 +494,7 @@ func (client *Client) GetReadMarker(cfname string) (result string) {
t, ok := client.readMarkers[cfname]
client.stateMutex.RUnlock()
if ok {
return t.Format(IRCv3TimestampFormat)
return fmt.Sprintf("timestamp=%s", t.Format(IRCv3TimestampFormat))
}
return "*"
}

View File

@ -2770,14 +2770,14 @@ func markReadHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
}
// "MARKREAD client set command": MARKREAD <target> <timestamp>
readTimestamp := msg.Params[1]
readTimestamp := strings.TrimPrefix(msg.Params[1], "timestamp=")
readTime, err := time.Parse(IRCv3TimestampFormat, readTimestamp)
if err != nil {
rb.Add(nil, server.name, "FAIL", "MARKREAD", "INVALID_PARAMS", utils.SafeErrorParam(readTimestamp), client.t("Invalid timestamp"))
return
}
result := client.SetReadMarker(cftarget, readTime)
readTimestamp = result.Format(IRCv3TimestampFormat)
readTimestamp = fmt.Sprintf("timestamp=%s", result.Format(IRCv3TimestampFormat))
// inform the originating session whether it was a success or a no-op:
rb.Add(nil, server.name, "MARKREAD", unfoldedTarget, readTimestamp)
if result.Equal(readTime) {