Turn CHATHISTORY and backlog limits into constants

This commit is contained in:
Simon Ser 2021-11-03 18:29:21 +01:00
parent 0b6b687d70
commit abe5f362db
2 changed files with 5 additions and 6 deletions

View File

@ -1161,7 +1161,7 @@ func (dc *downstreamConn) welcome() error {
}
isupport := []string{
fmt.Sprintf("CHATHISTORY=%v", dc.srv.HistoryLimit),
fmt.Sprintf("CHATHISTORY=%v", chatHistoryLimit),
"CASEMAPPING=ascii",
}
@ -1331,9 +1331,8 @@ func (dc *downstreamConn) sendTargetBacklog(net *network, target, msgID string)
ctx, cancel := context.WithTimeout(context.TODO(), messageStoreTimeout)
defer cancel()
limit := 4000
targetCM := net.casemap(target)
history, err := dc.user.msgStore.LoadLatestID(ctx, &net.Network, targetCM, msgID, limit)
history, err := dc.user.msgStore.LoadLatestID(ctx, &net.Network, targetCM, msgID, backlogLimit)
if err != nil {
dc.logger.Printf("failed to send backlog for %q: %v", target, err)
return
@ -2328,7 +2327,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
}
limit, err := strconv.Atoi(limitStr)
if err != nil || limit < 0 || limit > dc.srv.HistoryLimit {
if err != nil || limit < 0 || limit > chatHistoryLimit {
return ircError{&irc.Message{
Command: "FAIL",
Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, limitStr, "Invalid limit"},

View File

@ -26,6 +26,8 @@ var writeTimeout = 10 * time.Second
var upstreamMessageDelay = 2 * time.Second
var upstreamMessageBurst = 10
var messageStoreTimeout = 10 * time.Second
var chatHistoryLimit = 1000
var backlogLimit = 4000
type Logger interface {
Print(v ...interface{})
@ -53,7 +55,6 @@ type Server struct {
Hostname string
Title string
Logger Logger
HistoryLimit int
LogPath string
Debug bool
HTTPOrigins []string
@ -75,7 +76,6 @@ type Server struct {
func NewServer(db Database) *Server {
srv := &Server{
Logger: log.New(log.Writer(), "", log.LstdFlags),
HistoryLimit: 1000,
MaxUserNetworks: -1,
db: db,
listeners: make(map[net.Listener]struct{}),