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{ return ircError{&irc.Message{
Command: irc.ERR_UNKNOWNCOMMAND, Command: irc.ERR_UNKNOWNCOMMAND,
Params: []string{dc.nick, subcommand, "Unknown command"}, Params: []string{dc.nick, subcommand, "Unknown command"},
@ -1775,9 +1776,9 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
var history []*irc.Message var history []*irc.Message
switch subcommand { switch subcommand {
case "BEFORE": case "BEFORE":
history, err = dc.user.msgStore.LoadBeforeTime(uc.network, entity, timestamp, limit) history, err = store.LoadBeforeTime(uc.network, entity, timestamp, limit)
case "AFTER": case "AFTER":
history, err = dc.user.msgStore.LoadAfterTime(uc.network, entity, timestamp, limit) history, err = store.LoadAfterTime(uc.network, entity, timestamp, limit)
default: default:
// TODO: support LATEST, BETWEEN // TODO: support LATEST, BETWEEN
return ircError{&irc.Message{ 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 // date. The message ID returned may not refer to a valid message, but can be
// used in history queries. // used in history queries.
LastMsgID(network *network, entity string, t time.Time) (string, error) 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) LoadLatestID(network *network, entity, id string, limit int) ([]*irc.Message, error)
Append(network *network, entity string, msg *irc.Message) (id string, err 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 { func formatMsgID(netID int64, entity, extra string) string {
return fmt.Sprintf("%v %v %v", netID, entity, extra) return fmt.Sprintf("%v %v %v", netID, entity, extra)
} }