3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

Merge pull request #832 from slingamn/issue831_playback_direction.1

fix #831
This commit is contained in:
Shivaram Lingamneni 2020-02-27 20:11:30 -08:00 committed by GitHub
commit c414ac383c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 19 deletions

View File

@ -772,19 +772,20 @@ func (channel *Channel) autoReplayHistory(client *Client, rb *ResponseBuffer, sk
// autoreplay any messages as necessary // autoreplay any messages as necessary
var items []history.Item var items []history.Item
var after, before time.Time var start, end time.Time
if rb.session.zncPlaybackTimes.ValidFor(channel.NameCasefolded()) { if rb.session.zncPlaybackTimes.ValidFor(channel.NameCasefolded()) {
after, before = rb.session.zncPlaybackTimes.after, rb.session.zncPlaybackTimes.before start, end = rb.session.zncPlaybackTimes.start, rb.session.zncPlaybackTimes.end
} else if !rb.session.autoreplayMissedSince.IsZero() { } else if !rb.session.autoreplayMissedSince.IsZero() {
// we already checked for history caps in `playReattachMessages` // we already checked for history caps in `playReattachMessages`
after = rb.session.autoreplayMissedSince start = time.Now().UTC()
end = rb.session.autoreplayMissedSince
} }
if !after.IsZero() || !before.IsZero() { if !start.IsZero() || !end.IsZero() {
_, seq, _ := channel.server.GetHistorySequence(channel, client, "") _, seq, _ := channel.server.GetHistorySequence(channel, client, "")
if seq != nil { if seq != nil {
zncMax := channel.server.Config().History.ZNCMax zncMax := channel.server.Config().History.ZNCMax
items, _, _ = seq.Between(history.Selector{Time: after}, history.Selector{Time: before}, zncMax) items, _, _ = seq.Between(history.Selector{Time: start}, history.Selector{Time: end}, zncMax)
} }
} else if !rb.session.HasHistoryCaps() { } else if !rb.session.HasHistoryCaps() {
var replayLimit int var replayLimit int

View File

@ -668,7 +668,7 @@ func (client *Client) playReattachMessages(session *Session) {
} }
if !session.autoreplayMissedSince.IsZero() && !hasHistoryCaps { if !session.autoreplayMissedSince.IsZero() && !hasHistoryCaps {
rb := NewResponseBuffer(session) rb := NewResponseBuffer(session)
zncPlayPrivmsgs(client, rb, "*", session.autoreplayMissedSince, time.Time{}) zncPlayPrivmsgs(client, rb, "*", time.Now().UTC(), session.autoreplayMissedSince)
rb.Send(true) rb.Send(true)
} }
session.autoreplayMissedSince = time.Time{} session.autoreplayMissedSince = time.Time{}

View File

@ -54,8 +54,8 @@ func zncWireTimeToTime(str string) (result time.Time) {
} }
type zncPlaybackTimes struct { type zncPlaybackTimes struct {
after time.Time start time.Time
before time.Time end time.Time
targets StringSet // nil for "*" (everything), otherwise the channel names targets StringSet // nil for "*" (everything), otherwise the channel names
setAt time.Time setAt time.Time
} }
@ -80,19 +80,26 @@ func (z *zncPlaybackTimes) ValidFor(target string) bool {
// PRIVMSG *playback :play <target> [lower_bound] [upper_bound] // PRIVMSG *playback :play <target> [lower_bound] [upper_bound]
// e.g., PRIVMSG *playback :play * 1558374442 // e.g., PRIVMSG *playback :play * 1558374442
func zncPlaybackHandler(client *Client, command string, params []string, rb *ResponseBuffer) { func zncPlaybackHandler(client *Client, command string, params []string, rb *ResponseBuffer) {
if len(params) < 2 { if len(params) < 2 || len(params) > 4 {
return return
} else if strings.ToLower(params[0]) != "play" { } else if strings.ToLower(params[0]) != "play" {
return return
} }
targetString := params[1] targetString := params[1]
var after, before time.Time now := time.Now().UTC()
if 2 < len(params) { var start, end time.Time
after = zncWireTimeToTime(params[2]) switch len(params) {
} case 3:
if 3 < len(params) { // #831: this should have the same semantics as `LATEST timestamp=qux`,
before = zncWireTimeToTime(params[3]) // or equivalently `BETWEEN timestamp=$now timestamp=qux`, as opposed to
// `AFTER timestamp=qux` (this matters in the case where there are
// more than znc-maxmessages available)
start = now
end = zncWireTimeToTime(params[2])
case 4:
start = zncWireTimeToTime(params[2])
end = zncWireTimeToTime(params[3])
} }
var targets StringSet var targets StringSet
@ -115,7 +122,7 @@ func zncPlaybackHandler(client *Client, command string, params []string, rb *Res
// channels; redundant JOIN is a complete no-op so we won't replay twice // channels; redundant JOIN is a complete no-op so we won't replay twice
if params[1] == "*" { if params[1] == "*" {
zncPlayPrivmsgs(client, rb, "*", after, before) zncPlayPrivmsgs(client, rb, "*", start, end)
} else { } else {
targets = make(StringSet) targets = make(StringSet)
for _, targetName := range strings.Split(targetString, ",") { for _, targetName := range strings.Split(targetString, ",") {
@ -132,8 +139,8 @@ func zncPlaybackHandler(client *Client, command string, params []string, rb *Res
} }
rb.session.zncPlaybackTimes = &zncPlaybackTimes{ rb.session.zncPlaybackTimes = &zncPlaybackTimes{
after: after, start: start,
before: before, end: end,
targets: targets, targets: targets,
setAt: time.Now().UTC(), setAt: time.Now().UTC(),
} }
@ -146,7 +153,7 @@ func zncPlaybackHandler(client *Client, command string, params []string, rb *Res
} }
for _, cfNick := range nickTargets { for _, cfNick := range nickTargets {
zncPlayPrivmsgs(client, rb, cfNick, after, before) zncPlayPrivmsgs(client, rb, cfNick, start, end)
rb.Flush(true) rb.Flush(true)
} }
} }