3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 21:39:25 +01:00

make TAGMSG storage configurable

This commit is contained in:
Shivaram Lingamneni 2020-07-09 18:36:45 -04:00
parent f2d0842453
commit bca3dd0b41
7 changed files with 74 additions and 26 deletions

View File

@ -847,3 +847,18 @@ history:
# allowing deletion of JSON export of an account's messages. this # allowing deletion of JSON export of an account's messages. this
# may be needed for compliance with data privacy regulations. # may be needed for compliance with data privacy regulations.
enable-account-indexing: false enable-account-indexing: false
# options to control storage of TAGMSG
tagmsg-storage:
# by default, should TAGMSG be stored?
default: false
# if `default` is false, store TAGMSG containing any of these tags:
whitelist:
- "+draft/react"
- "react"
# if `default` is true, don't store TAGMSG containing any of these tags:
#blacklist:
# - "+draft/typing"
# - "typing"

View File

@ -873,3 +873,18 @@ history:
# allowing deletion of JSON export of an account's messages. this # allowing deletion of JSON export of an account's messages. this
# may be needed for compliance with data privacy regulations. # may be needed for compliance with data privacy regulations.
enable-account-indexing: false enable-account-indexing: false
# options to control storage of TAGMSG
tagmsg-storage:
# by default, should TAGMSG be stored?
default: false
# if `default` is false, store TAGMSG containing any of these tags:
whitelist:
- "+draft/react"
- "react"
# if `default` is true, don't store TAGMSG containing any of these tags:
#blacklist:
# - "+draft/typing"
# - "typing"

View File

@ -646,7 +646,7 @@ func channelHistoryStatus(config *Config, registered bool, storedStatus HistoryS
} }
func (channel *Channel) AddHistoryItem(item history.Item, account string) (err error) { func (channel *Channel) AddHistoryItem(item history.Item, account string) (err error) {
if !item.IsStorable() { if !itemIsStorable(&item, channel.server.Config()) {
return return
} }

View File

@ -612,6 +612,11 @@ type Config struct {
AllowIndividualDelete bool `yaml:"allow-individual-delete"` AllowIndividualDelete bool `yaml:"allow-individual-delete"`
EnableAccountIndexing bool `yaml:"enable-account-indexing"` EnableAccountIndexing bool `yaml:"enable-account-indexing"`
} }
TagmsgStorage struct {
Default bool
Whitelist []string
Blacklist []string
} `yaml:"tagmsg-storage"`
} }
Filename string Filename string
@ -1283,6 +1288,16 @@ func (config *Config) Diff(oldConfig *Config) (addedCaps, removedCaps *caps.Set)
return return
} }
// determine whether we need to resize / create / destroy
// the in-memory history buffers:
func (config *Config) historyChangedFrom(oldConfig *Config) bool {
return config.History.Enabled != oldConfig.History.Enabled ||
config.History.ChannelLength != oldConfig.History.ChannelLength ||
config.History.ClientLength != oldConfig.History.ClientLength ||
config.History.AutoresizeWindow != oldConfig.History.AutoresizeWindow ||
config.History.Persistent != oldConfig.History.Persistent
}
func compileGuestRegexp(guestFormat string, casemapping Casemapping) (standard, folded *regexp.Regexp, err error) { func compileGuestRegexp(guestFormat string, casemapping Casemapping) (standard, folded *regexp.Regexp, err error) {
if strings.Count(guestFormat, "?") != 0 || strings.Count(guestFormat, "*") != 1 { if strings.Count(guestFormat, "?") != 0 || strings.Count(guestFormat, "*") != 1 {
err = errors.New("guest format must contain 1 '*' and no '?'s") err = errors.New("guest format must contain 1 '*' and no '?'s")

View File

@ -2113,7 +2113,7 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
AccountName: accountName, AccountName: accountName,
Tags: tags, Tags: tags,
} }
if !item.IsStorable() || !allowedPlusR { if !itemIsStorable(&item, config) || !allowedPlusR {
return return
} }
targetedItem := item targetedItem := item
@ -2136,6 +2136,32 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
} }
} }
func itemIsStorable(item *history.Item, config *Config) bool {
switch item.Type {
case history.Tagmsg:
if config.History.TagmsgStorage.Default {
for _, blacklistedTag := range config.History.TagmsgStorage.Blacklist {
if _, ok := item.Tags[blacklistedTag]; ok {
return false
}
}
return true
} else {
for _, whitelistedTag := range config.History.TagmsgStorage.Whitelist {
if _, ok := item.Tags[whitelistedTag]; ok {
return true
}
}
return false
}
case history.Privmsg, history.Notice:
// don't store CTCP other than ACTION
return !item.Message.IsRestrictedCTCPMessage()
default:
return true
}
}
// NPC <target> <sourcenick> <message> // NPC <target> <sourcenick> <message>
func npcHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool { func npcHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
target := msg.Params[0] target := msg.Params[0]

View File

@ -29,12 +29,6 @@ const (
initialAutoSize = 32 initialAutoSize = 32
) )
// a Tagmsg that consists entirely of transient tags is not stored
var transientTags = map[string]bool{
"+draft/typing": true,
"+typing": true, // future-proofing
}
// Item represents an event (e.g., a PRIVMSG or a JOIN) and its associated data // Item represents an event (e.g., a PRIVMSG or a JOIN) and its associated data
type Item struct { type Item struct {
Type ItemType Type ItemType
@ -57,23 +51,6 @@ func (item *Item) HasMsgid(msgid string) bool {
return item.Message.Msgid == msgid return item.Message.Msgid == msgid
} }
func (item *Item) IsStorable() bool {
switch item.Type {
case Tagmsg:
for name := range item.Tags {
if !transientTags[name] {
return true
}
}
return false // all tags were blacklisted
case Privmsg, Notice:
// don't store CTCP other than ACTION
return !item.Message.IsRestrictedCTCPMessage()
default:
return true
}
}
type Predicate func(item *Item) (matches bool) type Predicate func(item *Item) (matches bool)
func Reverse(results []Item) { func Reverse(results []Item) {

View File

@ -546,7 +546,7 @@ func (server *Server) applyConfig(config *Config) (err error) {
server.channels.loadRegisteredChannels(config) server.channels.loadRegisteredChannels(config)
} }
// resize history buffers as needed // resize history buffers as needed
if oldConfig.History != config.History { if config.historyChangedFrom(oldConfig) {
for _, channel := range server.channels.Channels() { for _, channel := range server.channels.Channels() {
channel.resizeHistory(config) channel.resizeHistory(config)
} }