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

miscellaneous review fixes

This commit is contained in:
Shivaram Lingamneni 2020-02-20 01:45:17 -05:00
parent 82732d5b5d
commit 8f4c14c783
4 changed files with 14 additions and 8 deletions

View File

@ -871,8 +871,12 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
if allowTags { if allowTags {
tags = item.Tags tags = item.Tags
} }
// XXX: Params[0] is the message target. if the source of this message is an in-memory
// buffer, then it's "" for an incoming message and the recipient's nick for an outgoing
// message. if the source of the message is mysql, then mysql only sees one copy of the
// message, and it's the version with the recipient's nick filled in. so this is an
// incoming message if Params[0] (the recipient's nick) equals the client's nick:
if item.Params[0] == "" || item.Params[0] == nick { if item.Params[0] == "" || item.Params[0] == nick {
// this message was sent *to* the client from another nick
rb.AddSplitMessageFromClient(item.Nick, item.AccountName, tags, command, nick, item.Message) rb.AddSplitMessageFromClient(item.Nick, item.AccountName, tags, command, nick, item.Message)
} else { } else {
// this message was sent *from* the client to another nick; the target is item.Params[0] // 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) {
Message: splitQuitMessage, Message: splitQuitMessage,
} }
var channels []*Channel var channels []*Channel
// use a defer here to avoid writing to mysql while holding the destroy semaphore:
defer func() { defer func() {
for _, channel := range channels { for _, channel := range channels {
// TODO it's dangerous to write to mysql while holding the destroy semaphore
channel.AddHistoryItem(quitItem) channel.AddHistoryItem(quitItem)
} }
}() }()

View File

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

View File

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

View File

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