1
0
Fork 0
mirror of https://github.com/fluffle/goirc synced 2025-05-12 10:41:42 +00:00

Merge branch 'state-copy'. Fixes #49, #35.

Overhaul the state tracker to return copies of data that should be correct
at the time of the response. Subsequent changes to tracked IRC state will not
be reflected in the copies. For people fixing up their code because this merge
broke everything, you probably want to be paying particular attention to the
use of conn.Me() instead of conn.cfg.Me.

Sorry if this causes you hassle, it's for the best.

Lastly, if kballard is watching: sorry dude, you were mostly right ;-)
This commit is contained in:
Alex Bramley 2015-02-27 19:56:41 +00:00
commit 0cac69d2ee
12 changed files with 958 additions and 576 deletions

View file

@ -90,7 +90,7 @@ type Config struct {
func NewConfig(nick string, args ...string) *Config {
cfg := &Config{
Me: state.NewNick(nick),
Me: &state.Nick{Nick: nick},
PingFreq: 3 * time.Minute,
NewNick: func(s string) string { return s + "_" },
Recover: (*Conn).LogPanic, // in dispatch.go
@ -122,7 +122,7 @@ func Client(cfg *Config) *Conn {
cfg = NewConfig("__idiot__")
}
if cfg.Me == nil || cfg.Me.Nick == "" || cfg.Me.Ident == "" {
cfg.Me = state.NewNick("__idiot__")
cfg.Me = &state.Nick{Nick: "__idiot__"}
cfg.Me.Ident = "goirc"
cfg.Me.Name = "Powered by GoIRC"
}
@ -169,6 +169,11 @@ func (conn *Conn) Config() *Config {
}
func (conn *Conn) Me() *state.Nick {
conn.mu.RLock()
defer conn.mu.RUnlock()
if conn.st != nil {
conn.cfg.Me = conn.st.Me()
}
return conn.cfg.Me
}
@ -177,6 +182,8 @@ func (conn *Conn) StateTracker() state.Tracker {
}
func (conn *Conn) EnableStateTracking() {
conn.mu.Lock()
defer conn.mu.Unlock()
if conn.st == nil {
n := conn.cfg.Me
conn.st = state.NewTracker(n.Nick)
@ -188,7 +195,10 @@ func (conn *Conn) EnableStateTracking() {
}
func (conn *Conn) DisableStateTracking() {
conn.mu.Lock()
defer conn.mu.Unlock()
if conn.st != nil {
conn.cfg.Me = conn.st.Me()
conn.delSTHandlers()
conn.st.Wipe()
conn.st = nil