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:
commit
ae55a4c660
@ -130,7 +130,8 @@ func (am *AccountManager) createAlwaysOnClients(config *Config) {
|
|||||||
am.server.AddAlwaysOnClient(
|
am.server.AddAlwaysOnClient(
|
||||||
account,
|
account,
|
||||||
am.loadChannels(accountName),
|
am.loadChannels(accountName),
|
||||||
am.loadLastSeen(accountName),
|
am.loadTimeMap(keyAccountLastSeen, accountName),
|
||||||
|
am.loadTimeMap(keyAccountReadMarkers, accountName),
|
||||||
am.loadModes(accountName),
|
am.loadModes(accountName),
|
||||||
am.loadRealname(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) {
|
func (am *AccountManager) loadTimeMap(baseKey, account string) (lastSeen map[string]time.Time) {
|
||||||
key := fmt.Sprintf(keyAccountLastSeen, account)
|
key := fmt.Sprintf(baseKey, account)
|
||||||
var lsText string
|
var lsText string
|
||||||
am.server.store.Update(func(tx *buntdb.Tx) error {
|
am.server.store.Update(func(tx *buntdb.Tx) error {
|
||||||
lsText, _ = tx.Get(key)
|
lsText, _ = tx.Get(key)
|
||||||
|
@ -389,7 +389,7 @@ func (server *Server) RunClient(conn IRCConn) {
|
|||||||
client.run(session)
|
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()
|
now := time.Now().UTC()
|
||||||
config := server.Config()
|
config := server.Config()
|
||||||
if lastSeen == nil && account.Settings.AutoreplayMissed {
|
if lastSeen == nil && account.Settings.AutoreplayMissed {
|
||||||
@ -407,12 +407,13 @@ func (server *Server) AddAlwaysOnClient(account ClientAccount, channelToStatus m
|
|||||||
}
|
}
|
||||||
|
|
||||||
client := &Client{
|
client := &Client{
|
||||||
lastSeen: lastSeen,
|
lastSeen: lastSeen,
|
||||||
lastActive: now,
|
readMarkers: readMarkers,
|
||||||
channels: make(ChannelSet),
|
lastActive: now,
|
||||||
ctime: now,
|
channels: make(ChannelSet),
|
||||||
languages: server.Languages().Default(),
|
ctime: now,
|
||||||
server: server,
|
languages: server.Languages().Default(),
|
||||||
|
server: server,
|
||||||
|
|
||||||
username: username,
|
username: username,
|
||||||
cloakedHostname: cloakedHostname,
|
cloakedHostname: cloakedHostname,
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -493,7 +494,7 @@ func (client *Client) GetReadMarker(cfname string) (result string) {
|
|||||||
t, ok := client.readMarkers[cfname]
|
t, ok := client.readMarkers[cfname]
|
||||||
client.stateMutex.RUnlock()
|
client.stateMutex.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
return t.Format(IRCv3TimestampFormat)
|
return fmt.Sprintf("timestamp=%s", t.Format(IRCv3TimestampFormat))
|
||||||
}
|
}
|
||||||
return "*"
|
return "*"
|
||||||
}
|
}
|
||||||
|
@ -2770,14 +2770,14 @@ func markReadHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
|
|||||||
}
|
}
|
||||||
|
|
||||||
// "MARKREAD client set command": MARKREAD <target> <timestamp>
|
// "MARKREAD client set command": MARKREAD <target> <timestamp>
|
||||||
readTimestamp := msg.Params[1]
|
readTimestamp := strings.TrimPrefix(msg.Params[1], "timestamp=")
|
||||||
readTime, err := time.Parse(IRCv3TimestampFormat, readTimestamp)
|
readTime, err := time.Parse(IRCv3TimestampFormat, readTimestamp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rb.Add(nil, server.name, "FAIL", "MARKREAD", "INVALID_PARAMS", utils.SafeErrorParam(readTimestamp), client.t("Invalid timestamp"))
|
rb.Add(nil, server.name, "FAIL", "MARKREAD", "INVALID_PARAMS", utils.SafeErrorParam(readTimestamp), client.t("Invalid timestamp"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := client.SetReadMarker(cftarget, readTime)
|
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:
|
// inform the originating session whether it was a success or a no-op:
|
||||||
rb.Add(nil, server.name, "MARKREAD", unfoldedTarget, readTimestamp)
|
rb.Add(nil, server.name, "MARKREAD", unfoldedTarget, readTimestamp)
|
||||||
if result.Equal(readTime) {
|
if result.Equal(readTime) {
|
||||||
|
Loading…
Reference in New Issue
Block a user