Make chat history operations optional in messageStore

Some stores may want not to implement chat history operations.
This commit is contained in:
Simon Ser 2021-01-04 17:17:35 +01:00
parent 83a4590acc
commit ac3431ef76
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 13 additions and 5 deletions

View file

@ -1735,7 +1735,8 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
}}
}
if dc.user.msgStore == nil {
store, ok := dc.user.msgStore.(chatHistoryMessageStore)
if !ok {
return ircError{&irc.Message{
Command: irc.ERR_UNKNOWNCOMMAND,
Params: []string{dc.nick, subcommand, "Unknown command"},
@ -1775,9 +1776,9 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
var history []*irc.Message
switch subcommand {
case "BEFORE":
history, err = dc.user.msgStore.LoadBeforeTime(uc.network, entity, timestamp, limit)
history, err = store.LoadBeforeTime(uc.network, entity, timestamp, limit)
case "AFTER":
history, err = dc.user.msgStore.LoadAfterTime(uc.network, entity, timestamp, limit)
history, err = store.LoadAfterTime(uc.network, entity, timestamp, limit)
default:
// TODO: support LATEST, BETWEEN
return ircError{&irc.Message{

View file

@ -16,12 +16,19 @@ type messageStore interface {
// date. The message ID returned may not refer to a valid message, but can be
// used in history queries.
LastMsgID(network *network, entity string, t time.Time) (string, error)
LoadBeforeTime(network *network, entity string, t time.Time, limit int) ([]*irc.Message, error)
LoadAfterTime(network *network, entity string, t time.Time, limit int) ([]*irc.Message, error)
LoadLatestID(network *network, entity, id string, limit int) ([]*irc.Message, error)
Append(network *network, entity string, msg *irc.Message) (id string, err error)
}
// chatHistoryMessageStore is a message store that supports chat history
// operations.
type chatHistoryMessageStore interface {
messageStore
LoadBeforeTime(network *network, entity string, t time.Time, limit int) ([]*irc.Message, error)
LoadAfterTime(network *network, entity string, t time.Time, limit int) ([]*irc.Message, error)
}
func formatMsgID(netID int64, entity, extra string) string {
return fmt.Sprintf("%v %v %v", netID, entity, extra)
}