Просмотр исходного кода

miscellaneous review fixes

tags/v2.0.0-rc1
Shivaram Lingamneni 4 лет назад
Родитель
Сommit
8f4c14c783
4 измененных файлов: 14 добавлений и 8 удалений
  1. 6
    2
      irc/client.go
  2. 1
    1
      irc/handlers.go
  3. 6
    3
      irc/history/history.go
  4. 1
    2
      irc/mysql/history.go

+ 6
- 2
irc/client.go Просмотреть файл

@@ -871,8 +871,12 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
871 871
 		if allowTags {
872 872
 			tags = item.Tags
873 873
 		}
874
+		// XXX: Params[0] is the message target. if the source of this message is an in-memory
875
+		// buffer, then it's "" for an incoming message and the recipient's nick for an outgoing
876
+		// message. if the source of the message is mysql, then mysql only sees one copy of the
877
+		// message, and it's the version with the recipient's nick filled in. so this is an
878
+		// incoming message if Params[0] (the recipient's nick) equals the client's nick:
874 879
 		if item.Params[0] == "" || item.Params[0] == nick {
875
-			// this message was sent *to* the client from another nick
876 880
 			rb.AddSplitMessageFromClient(item.Nick, item.AccountName, tags, command, nick, item.Message)
877 881
 		} else {
878 882
 			// this message was sent *from* the client to another nick; the target is item.Params[0]
@@ -1237,9 +1241,9 @@ func (client *Client) destroy(session *Session) {
1237 1241
 		Message:     splitQuitMessage,
1238 1242
 	}
1239 1243
 	var channels []*Channel
1244
+	// use a defer here to avoid writing to mysql while holding the destroy semaphore:
1240 1245
 	defer func() {
1241 1246
 		for _, channel := range channels {
1242
-			// TODO it's dangerous to write to mysql while holding the destroy semaphore
1243 1247
 			channel.AddHistoryItem(quitItem)
1244 1248
 		}
1245 1249
 	}()

+ 1
- 1
irc/handlers.go Просмотреть файл

@@ -1914,7 +1914,7 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
1914 1914
 		var deliverySessions []*Session
1915 1915
 		// restrict messages appropriately when +R is set
1916 1916
 		// intentionally make the sending user think the message went through fine
1917
-		allowedPlusR := !user.HasMode(modes.RegisteredOnly) || details.account != ""
1917
+		allowedPlusR := details.account != "" || !user.HasMode(modes.RegisteredOnly)
1918 1918
 		if allowedPlusR {
1919 1919
 			deliverySessions = append(deliverySessions, user.Sessions()...)
1920 1920
 		}

+ 6
- 3
irc/history/history.go Просмотреть файл

@@ -42,9 +42,12 @@ type Item struct {
42 42
 	// this is the uncasefolded account name, if there's no account it should be set to "*"
43 43
 	AccountName string
44 44
 	// for non-privmsg items, we may stuff some other data in here
45
-	Message         utils.SplitMessage
46
-	Tags            map[string]string
47
-	Params          [1]string
45
+	Message utils.SplitMessage
46
+	Tags    map[string]string
47
+	Params  [1]string
48
+	// for a DM, this is the casefolded nickname of the other party (whether this is
49
+	// an incoming or outgoing message). this lets us emulate the "query buffer" functionality
50
+	// required by CHATHISTORY:
48 51
 	CfCorrespondent string
49 52
 }
50 53
 

+ 1
- 2
irc/mysql/history.go Просмотреть файл

@@ -5,7 +5,6 @@ import (
5 5
 	"database/sql"
6 6
 	"fmt"
7 7
 	"runtime/debug"
8
-	"strconv"
9 8
 	"sync"
10 9
 	"time"
11 10
 
@@ -197,7 +196,7 @@ func (mysql *MySQL) doCleanup(age time.Duration) (count int, err error) {
197 196
 		if i != 0 {
198 197
 			inBuf.WriteRune(',')
199 198
 		}
200
-		inBuf.WriteString(strconv.FormatInt(int64(id), 10))
199
+		fmt.Fprintf(&inBuf, "%d", id)
201 200
 	}
202 201
 	inBuf.WriteRune(')')
203 202
 

Загрузка…
Отмена
Сохранить