Browse Source

pointless refactor of stripMaskFromNick

tags/v2.5.0-rc1
Shivaram Lingamneni 3 years ago
parent
commit
15a0cda78b
4 changed files with 12 additions and 12 deletions
  1. 1
    9
      irc/channel.go
  2. 2
    2
      irc/client.go
  3. 1
    1
      irc/histserv.go
  4. 8
    0
      irc/strings.go

+ 1
- 9
irc/channel.go View File

@@ -1073,14 +1073,6 @@ func (channel *Channel) replayHistoryForResume(session *Session, after time.Time
1073 1073
 	rb.Send(true)
1074 1074
 }
1075 1075
 
1076
-func stripMaskFromNick(nickMask string) (nick string) {
1077
-	index := strings.Index(nickMask, "!")
1078
-	if index == -1 {
1079
-		return nickMask
1080
-	}
1081
-	return nickMask[0:index]
1082
-}
1083
-
1084 1076
 func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.Item, autoreplay bool) {
1085 1077
 	// send an empty batch if necessary, as per the CHATHISTORY spec
1086 1078
 	chname := channel.Name()
@@ -1103,7 +1095,7 @@ func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.I
1103 1095
 	defer rb.EndNestedBatch(batchID)
1104 1096
 
1105 1097
 	for _, item := range items {
1106
-		nick := stripMaskFromNick(item.Nick)
1098
+		nick := NUHToNick(item.Nick)
1107 1099
 		switch item.Type {
1108 1100
 		case history.Privmsg:
1109 1101
 			rb.AddSplitMessageFromClient(item.Nick, item.AccountName, item.Tags, "PRIVMSG", chname, item.Message)

+ 2
- 2
irc/client.go View File

@@ -975,7 +975,7 @@ func (session *Session) playResume() {
975 975
 	if privmsgSeq != nil {
976 976
 		privmsgs, _, _ := privmsgSeq.Between(history.Selector{}, history.Selector{}, config.History.ClientLength)
977 977
 		for _, item := range privmsgs {
978
-			sender := server.clients.Get(stripMaskFromNick(item.Nick))
978
+			sender := server.clients.Get(NUHToNick(item.Nick))
979 979
 			if sender != nil {
980 980
 				friends.Add(sender)
981 981
 			}
@@ -1079,7 +1079,7 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
1079 1079
 			if hasEventPlayback {
1080 1080
 				rb.AddFromClient(item.Message.Time, item.Message.Msgid, item.Nick, item.AccountName, nil, "INVITE", nick, item.Message.Message)
1081 1081
 			} else {
1082
-				rb.AddFromClient(item.Message.Time, utils.MungeSecretToken(item.Message.Msgid), histservService.prefix, "*", nil, "PRIVMSG", fmt.Sprintf(client.t("%[1]s invited you to channel %[2]s"), stripMaskFromNick(item.Nick), item.Message.Message))
1082
+				rb.AddFromClient(item.Message.Time, utils.MungeSecretToken(item.Message.Msgid), histservService.prefix, "*", nil, "PRIVMSG", fmt.Sprintf(client.t("%[1]s invited you to channel %[2]s"), NUHToNick(item.Nick), item.Message.Message))
1083 1083
 			}
1084 1084
 			continue
1085 1085
 		case history.Privmsg:

+ 1
- 1
irc/histserv.go View File

@@ -173,7 +173,7 @@ func histservPlayHandler(service *ircService, server *Server, client *Client, co
173 173
 	}
174 174
 
175 175
 	playMessage := func(timestamp time.Time, nick, message string) {
176
-		service.Notice(rb, fmt.Sprintf("%s <%s> %s", timestamp.Format("15:04:05"), stripMaskFromNick(nick), message))
176
+		service.Notice(rb, fmt.Sprintf("%s <%s> %s", timestamp.Format("15:04:05"), NUHToNick(nick), message))
177 177
 	}
178 178
 
179 179
 	for _, item := range items {

+ 8
- 0
irc/strings.go View File

@@ -308,3 +308,11 @@ func foldPermissive(str string) (result string, err error) {
308 308
 	str = norm.NFD.String(str)
309 309
 	return str, nil
310 310
 }
311
+
312
+// Reduce, e.g., `alice!~u@host` to `alice`
313
+func NUHToNick(nuh string) (nick string) {
314
+	if idx := strings.IndexByte(nuh, '!'); idx != -1 {
315
+		return nuh[0:idx]
316
+	}
317
+	return nuh
318
+}

Loading…
Cancel
Save