Browse Source

Merge pull request #1189 from slingamn/tagmsg_storage.1

make TAGMSG storage configurable
tags/v2.2.0-rc1
Shivaram Lingamneni 3 years ago
parent
commit
0a6c1f7cc6
No account linked to committer's email address
7 changed files with 74 additions and 26 deletions
  1. 15
    0
      conventional.yaml
  2. 15
    0
      default.yaml
  3. 1
    1
      irc/channel.go
  4. 15
    0
      irc/config.go
  5. 27
    1
      irc/handlers.go
  6. 0
    23
      irc/history/history.go
  7. 1
    1
      irc/server.go

+ 15
- 0
conventional.yaml View File

@@ -848,3 +848,18 @@ history:
848 848
         # allowing deletion of JSON export of an account's messages. this
849 849
         # may be needed for compliance with data privacy regulations.
850 850
         enable-account-indexing: false
851
+
852
+    # options to control storage of TAGMSG
853
+    tagmsg-storage:
854
+        # by default, should TAGMSG be stored?
855
+        default: false
856
+
857
+        # if `default` is false, store TAGMSG containing any of these tags:
858
+        whitelist:
859
+            - "+draft/react"
860
+            - "react"
861
+
862
+        # if `default` is true, don't store TAGMSG containing any of these tags:
863
+        #blacklist:
864
+        #    - "+draft/typing"
865
+        #    - "typing"

+ 15
- 0
default.yaml View File

@@ -874,3 +874,18 @@ history:
874 874
         # allowing deletion of JSON export of an account's messages. this
875 875
         # may be needed for compliance with data privacy regulations.
876 876
         enable-account-indexing: false
877
+
878
+    # options to control storage of TAGMSG
879
+    tagmsg-storage:
880
+        # by default, should TAGMSG be stored?
881
+        default: false
882
+
883
+        # if `default` is false, store TAGMSG containing any of these tags:
884
+        whitelist:
885
+            - "+draft/react"
886
+            - "react"
887
+
888
+        # if `default` is true, don't store TAGMSG containing any of these tags:
889
+        #blacklist:
890
+        #    - "+draft/typing"
891
+        #    - "typing"

+ 1
- 1
irc/channel.go View File

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

+ 15
- 0
irc/config.go View File

@@ -612,6 +612,11 @@ type Config struct {
612 612
 			AllowIndividualDelete bool `yaml:"allow-individual-delete"`
613 613
 			EnableAccountIndexing bool `yaml:"enable-account-indexing"`
614 614
 		}
615
+		TagmsgStorage struct {
616
+			Default   bool
617
+			Whitelist []string
618
+			Blacklist []string
619
+		} `yaml:"tagmsg-storage"`
615 620
 	}
616 621
 
617 622
 	Filename string
@@ -1284,6 +1289,16 @@ func (config *Config) Diff(oldConfig *Config) (addedCaps, removedCaps *caps.Set)
1284 1289
 	return
1285 1290
 }
1286 1291
 
1292
+// determine whether we need to resize / create / destroy
1293
+// the in-memory history buffers:
1294
+func (config *Config) historyChangedFrom(oldConfig *Config) bool {
1295
+	return config.History.Enabled != oldConfig.History.Enabled ||
1296
+		config.History.ChannelLength != oldConfig.History.ChannelLength ||
1297
+		config.History.ClientLength != oldConfig.History.ClientLength ||
1298
+		config.History.AutoresizeWindow != oldConfig.History.AutoresizeWindow ||
1299
+		config.History.Persistent != oldConfig.History.Persistent
1300
+}
1301
+
1287 1302
 func compileGuestRegexp(guestFormat string, casemapping Casemapping) (standard, folded *regexp.Regexp, err error) {
1288 1303
 	if strings.Count(guestFormat, "?") != 0 || strings.Count(guestFormat, "*") != 1 {
1289 1304
 		err = errors.New("guest format must contain 1 '*' and no '?'s")

+ 27
- 1
irc/handlers.go View File

@@ -2132,7 +2132,7 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
2132 2132
 			AccountName: accountName,
2133 2133
 			Tags:        tags,
2134 2134
 		}
2135
-		if !item.IsStorable() || !allowedPlusR {
2135
+		if !itemIsStorable(&item, config) || !allowedPlusR {
2136 2136
 			return
2137 2137
 		}
2138 2138
 		targetedItem := item
@@ -2155,6 +2155,32 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
2155 2155
 	}
2156 2156
 }
2157 2157
 
2158
+func itemIsStorable(item *history.Item, config *Config) bool {
2159
+	switch item.Type {
2160
+	case history.Tagmsg:
2161
+		if config.History.TagmsgStorage.Default {
2162
+			for _, blacklistedTag := range config.History.TagmsgStorage.Blacklist {
2163
+				if _, ok := item.Tags[blacklistedTag]; ok {
2164
+					return false
2165
+				}
2166
+			}
2167
+			return true
2168
+		} else {
2169
+			for _, whitelistedTag := range config.History.TagmsgStorage.Whitelist {
2170
+				if _, ok := item.Tags[whitelistedTag]; ok {
2171
+					return true
2172
+				}
2173
+			}
2174
+			return false
2175
+		}
2176
+	case history.Privmsg, history.Notice:
2177
+		// don't store CTCP other than ACTION
2178
+		return !item.Message.IsRestrictedCTCPMessage()
2179
+	default:
2180
+		return true
2181
+	}
2182
+}
2183
+
2158 2184
 // NPC <target> <sourcenick> <message>
2159 2185
 func npcHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
2160 2186
 	target := msg.Params[0]

+ 0
- 23
irc/history/history.go View File

@@ -29,12 +29,6 @@ const (
29 29
 	initialAutoSize = 32
30 30
 )
31 31
 
32
-// a Tagmsg that consists entirely of transient tags is not stored
33
-var transientTags = map[string]bool{
34
-	"+draft/typing": true,
35
-	"+typing":       true, // future-proofing
36
-}
37
-
38 32
 // Item represents an event (e.g., a PRIVMSG or a JOIN) and its associated data
39 33
 type Item struct {
40 34
 	Type ItemType
@@ -57,23 +51,6 @@ func (item *Item) HasMsgid(msgid string) bool {
57 51
 	return item.Message.Msgid == msgid
58 52
 }
59 53
 
60
-func (item *Item) IsStorable() bool {
61
-	switch item.Type {
62
-	case Tagmsg:
63
-		for name := range item.Tags {
64
-			if !transientTags[name] {
65
-				return true
66
-			}
67
-		}
68
-		return false // all tags were blacklisted
69
-	case Privmsg, Notice:
70
-		// don't store CTCP other than ACTION
71
-		return !item.Message.IsRestrictedCTCPMessage()
72
-	default:
73
-		return true
74
-	}
75
-}
76
-
77 54
 type Predicate func(item *Item) (matches bool)
78 55
 
79 56
 func Reverse(results []Item) {

+ 1
- 1
irc/server.go View File

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

Loading…
Cancel
Save