msgstore: rename searchMessageOptions, export fields
Preparation for splitting msgstore into a separate package.
This commit is contained in:
parent
f508d36c38
commit
89412187d4
@ -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{
|
||||
|
16
msgstore.go
16
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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user