Show an IRC listener user what their session sends from other clients (closes #179)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The relay dropped every PRIVMSG, NOTICE, JOIN, PART, NICK, QUIT, TOPIC, MODE and KICK sent under the connection's own nick, so an IRC listener connection never saw what its session did from another client. The relay now drops nothing by nick. Instead, the service methods that fan out a user's own command take the client whose queue to skip: the IRC listener passes its own client, which has already written the echo, and the HTTP API passes 0. Channel messages and PARTs now also go to the sender's own session, so the HTTP handler no longer queues the channel-message echo itself and SendChannelMessage no longer returns the message's row ID. Model: opus-5-5
This commit is contained in:
+11
-8
@@ -1208,11 +1208,12 @@ func insertMessageInTx(
|
||||
return dbID, msgUUID, nil
|
||||
}
|
||||
|
||||
// EnqueueToSession adds a message to all clients of a
|
||||
// session's queues.
|
||||
// EnqueueToSession adds a message to the queues of all
|
||||
// clients of a session except client skipClientID, or of all
|
||||
// of them when skipClientID is 0.
|
||||
func (database *Database) EnqueueToSession(
|
||||
ctx context.Context,
|
||||
sessionID, messageID int64,
|
||||
sessionID, messageID, skipClientID int64,
|
||||
) error {
|
||||
transaction, err := database.conn.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
@@ -1221,7 +1222,9 @@ func (database *Database) EnqueueToSession(
|
||||
|
||||
defer func() { _ = transaction.Rollback() }()
|
||||
|
||||
err = enqueueToSessionInTx(ctx, transaction, sessionID, messageID)
|
||||
err = enqueueToSessionInTx(
|
||||
ctx, transaction, sessionID, messageID, skipClientID,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1239,15 +1242,15 @@ func (database *Database) EnqueueToSession(
|
||||
func enqueueToSessionInTx(
|
||||
ctx context.Context,
|
||||
transaction *sql.Tx,
|
||||
sessionID, messageID int64,
|
||||
sessionID, messageID, skipClientID int64,
|
||||
) error {
|
||||
_, err := transaction.ExecContext(ctx,
|
||||
`INSERT OR IGNORE INTO client_queues
|
||||
(client_id, message_id, created_at)
|
||||
SELECT c.id, ?, ?
|
||||
FROM clients c
|
||||
WHERE c.session_id = ?`,
|
||||
messageID, time.Now(), sessionID)
|
||||
WHERE c.session_id = ? AND c.id != ?`,
|
||||
messageID, time.Now(), sessionID, skipClientID)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"enqueue to session: %w", err,
|
||||
@@ -1673,7 +1676,7 @@ func quitSessionInTx(
|
||||
|
||||
for _, peerID := range peerIDs {
|
||||
err = enqueueToSessionInTx(
|
||||
ctx, transaction, peerID, messageID,
|
||||
ctx, transaction, peerID, messageID, 0,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -675,7 +675,7 @@ func TestPollMessages(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = database.EnqueueToSession(ctx, sid, dbID)
|
||||
err = database.EnqueueToSession(ctx, sid, dbID, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user