From 89412187d489df982c0b1a5071336b4b9e45bd10 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 9 May 2022 15:44:41 +0200 Subject: [PATCH] msgstore: rename searchMessageOptions, export fields Preparation for splitting msgstore into a separate package. --- downstream.go | 22 +++++++++++----------- msgstore.go | 16 ++++++++-------- msgstore_fs.go | 16 ++++++++-------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/downstream.go b/downstream.go index 50e64ee..1509095 100644 --- a/downstream.go +++ b/downstream.go @@ -2994,8 +2994,8 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. var uc *upstreamConn const searchMaxLimit = 100 - opts := searchOptions{ - limit: searchMaxLimit, + opts := searchMessageOptions{ + Limit: searchMaxLimit, } for name, v := range attrs { value := string(v) @@ -3010,12 +3010,12 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. } switch name { case "after": - opts.start = timestamp + opts.Start = timestamp case "before": - opts.end = timestamp + opts.End = timestamp } case "from": - opts.from = value + opts.From = value case "in": u, upstreamName, err := dc.unmarshalEntity(value) if err != nil { @@ -3025,9 +3025,9 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. }} } uc = u - opts.in = u.network.casemap(upstreamName) + opts.In = u.network.casemap(upstreamName) case "text": - opts.text = value + opts.Text = value case "limit": limit, err := strconv.Atoi(value) if err != nil || limit <= 0 { @@ -3036,7 +3036,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. Params: []string{"SEARCH", "INVALID_PARAMS", name, "Invalid limit"}, }} } - opts.limit = limit + opts.Limit = limit } } if uc == nil { @@ -3045,11 +3045,11 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. Params: []string{"SEARCH", "INVALID_PARAMS", "in", "The in parameter is mandatory"}, }} } - if opts.limit > searchMaxLimit { - opts.limit = searchMaxLimit + if opts.Limit > searchMaxLimit { + opts.Limit = searchMaxLimit } - messages, err := store.Search(ctx, &uc.network.Network, opts) + messages, err := store.Search(ctx, &uc.network.Network, &opts) if err != nil { dc.logger.Printf("failed fetching messages for search: %v", err) return ircError{&irc.Message{ diff --git a/msgstore.go b/msgstore.go index 0ae22fc..759b11c 100644 --- a/msgstore.go +++ b/msgstore.go @@ -60,13 +60,13 @@ type chatHistoryMessageStore interface { LoadAfterTime(ctx context.Context, start, end time.Time, options *loadMessageOptions) ([]*irc.Message, error) } -type searchOptions struct { - start time.Time - end time.Time - limit int - from string - in string - text string +type searchMessageOptions struct { + Start time.Time + End time.Time + Limit int + From string + In string + Text string } // searchMessageStore is a message store that supports server-side search @@ -75,7 +75,7 @@ type searchMessageStore interface { messageStore // Search returns messages matching the specified options. - Search(ctx context.Context, network *database.Network, search searchOptions) ([]*irc.Message, error) + Search(ctx context.Context, network *database.Network, options *searchMessageOptions) ([]*irc.Message, error) } type msgIDType uint diff --git a/msgstore_fs.go b/msgstore_fs.go index 086fcaf..73698c5 100644 --- a/msgstore_fs.go +++ b/msgstore_fs.go @@ -701,10 +701,10 @@ func (ms *fsMessageStore) ListTargets(ctx context.Context, network *database.Net return targets, nil } -func (ms *fsMessageStore) Search(ctx context.Context, network *database.Network, opts searchOptions) ([]*irc.Message, error) { - text := strings.ToLower(opts.text) +func (ms *fsMessageStore) Search(ctx context.Context, network *database.Network, opts *searchMessageOptions) ([]*irc.Message, error) { + text := strings.ToLower(opts.Text) selector := func(m *irc.Message) bool { - if opts.from != "" && m.User != opts.from { + if opts.From != "" && m.User != opts.From { return false } if text != "" && !strings.Contains(strings.ToLower(m.Params[1]), text) { @@ -714,13 +714,13 @@ func (ms *fsMessageStore) Search(ctx context.Context, network *database.Network, } loadOptions := loadMessageOptions{ Network: network, - Entity: opts.in, - Limit: opts.limit, + Entity: opts.In, + Limit: opts.Limit, } - if !opts.start.IsZero() { - return ms.getAfterTime(ctx, opts.start, opts.end, &loadOptions, selector) + if !opts.Start.IsZero() { + return ms.getAfterTime(ctx, opts.Start, opts.End, &loadOptions, selector) } else { - return ms.getBeforeTime(ctx, opts.end, opts.start, &loadOptions, selector) + return ms.getBeforeTime(ctx, opts.End, opts.Start, &loadOptions, selector) } }