Browse Source

fix query messages not being put in right target.

master
Gisle Aune 1 year ago
parent
commit
e06199c378
  1. 19
      client.go
  2. 20
      client_test.go
  3. 32
      internal/irctest/eventlog.go

19
client.go

@ -11,6 +11,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"log"
mathRand "math/rand"
"net"
"sort"
@ -1362,8 +1363,8 @@ func (client *Client) handleEvent(event *Event) {
target := Target(client.status)
targetName := event.Arg(0)
if targetName == client.nick {
target := client.Target("query", targetName)
if target == nil {
queryTarget := client.Target("query", targetName)
if queryTarget == nil {
query := &Query{
id: client.id,
user: list.User{
@ -1379,8 +1380,10 @@ func (client *Client) handleEvent(event *Event) {
_ = client.AddTarget(query)
event.RenderTags["spawned"] = query.id
target = query
queryTarget = query
}
target = queryTarget
} else {
channel := client.Channel(targetName)
if channel != nil {
@ -1389,11 +1392,10 @@ func (client *Client) handleEvent(event *Event) {
}
target = channel
} else {
target = client.status
}
}
log.Println(targetName == client.nick)
client.handleInTarget(target, event)
}
@ -1540,13 +1542,8 @@ func (client *Client) handleInTarget(target Target, event *Event) {
return
}
client.mutex.RLock()
target.Handle(event, client)
event.targets = append(event.targets, target)
client.mutex.RUnlock()
target.Handle(event, client)
}
func generateClientID(prefix string) string {

20
client_test.go

@ -21,8 +21,12 @@ func TestClient(t *testing.T) {
AutoJoinInvites: true,
})
logger := irctest.EventLog{}
client.AddHandler(handlers.Input)
client.AddHandler(handlers.MRoleplay)
client.AddHandler(handlers.CTCP)
client.AddHandler(logger.Handler)
t.Logf("Client.ID = %#+v", client.ID())
if client.ID() == "" {
@ -188,6 +192,14 @@ func TestClient(t *testing.T) {
return errors.New("Hunter2 should have changed the host: " + userHunter2.Host)
}
event := logger.Last("packet", "PRIVMSG")
if event == nil {
return errors.New("did not find last channel message")
}
if event.ChannelTarget() == nil {
return errors.New("event lacks channel target")
}
return nil
}},
{Server: ":Hunter2!~test2@172.17.37.1 PRIVMSG Test768 :Hello, World"},
@ -199,6 +211,14 @@ func TestClient(t *testing.T) {
return errors.New("Did not find query")
}
event := logger.Last("packet", "PRIVMSG")
if event == nil {
return errors.New("did not find last query message")
}
if event.QueryTarget() == nil {
return errors.New("event lacks query target")
}
return nil
}},
{Server: ":Hunter2!~test2@172.17.37.1 NICK SevenAsterisks"},

32
internal/irctest/eventlog.go

@ -0,0 +1,32 @@
package irctest
import "github.com/gissleh/irc"
type EventLog struct {
events []*irc.Event
}
func (l *EventLog) First(kind, verb string) *irc.Event {
for _, e := range l.events {
if e.Verb() == verb && e.Kind() == kind {
return e
}
}
return nil
}
func (l *EventLog) Last(kind, verb string) *irc.Event {
for i := len(l.events) - 1; i >= 0; i-- {
e := l.events[i]
if e.Verb() == verb && e.Kind() == kind {
return e
}
}
return nil
}
func (l *EventLog) Handler(event *irc.Event, _ *irc.Client) {
l.events = append(l.events, event)
}
Loading…
Cancel
Save