forked from chteufleur/go-xmpp
Organise code into better logical groups.
This commit is contained in:
parent
cc012762e9
commit
c1da50ce26
|
|
@ -58,12 +58,33 @@ func (x *XMPP) SendRecv(iq *Iq) (*Iq, error) {
|
||||||
return reply, nil
|
return reply, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Interface used to test if a stanza matches some application-defined
|
||||||
|
// conditions.
|
||||||
|
type Matcher interface {
|
||||||
|
// Return true if the stanza, v, matches.
|
||||||
|
Match(v interface{}) (match bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adapter to allow a plain func to be used as a Matcher.
|
||||||
|
type MatcherFunc func(v interface{}) bool
|
||||||
|
|
||||||
|
// Implement Matcher by calling the adapted func.
|
||||||
|
func (fn MatcherFunc) Match(v interface{}) bool {
|
||||||
|
return fn(v)
|
||||||
|
}
|
||||||
|
|
||||||
type FilterId int64
|
type FilterId int64
|
||||||
|
|
||||||
func (fid FilterId) Error() string {
|
func (fid FilterId) Error() string {
|
||||||
return fmt.Sprintf("Invalid filter id: %d", fid)
|
return fmt.Sprintf("Invalid filter id: %d", fid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type filter struct {
|
||||||
|
id FilterId
|
||||||
|
m Matcher
|
||||||
|
ch chan interface{}
|
||||||
|
}
|
||||||
|
|
||||||
func (x *XMPP) AddFilter(m Matcher) (FilterId, chan interface{}) {
|
func (x *XMPP) AddFilter(m Matcher) (FilterId, chan interface{}) {
|
||||||
|
|
||||||
// Protect against concurrent access.
|
// Protect against concurrent access.
|
||||||
|
|
@ -127,27 +148,6 @@ func IqResult(id string) Matcher {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface used to test if a stanza matches some application-defined
|
|
||||||
// conditions.
|
|
||||||
type Matcher interface {
|
|
||||||
// Return true if the stanza, v, matches.
|
|
||||||
Match(v interface{}) (match bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adapter to allow a plain func to be used as a Matcher.
|
|
||||||
type MatcherFunc func(v interface{}) bool
|
|
||||||
|
|
||||||
// Implement Matcher by calling the adapted func.
|
|
||||||
func (fn MatcherFunc) Match(v interface{}) bool {
|
|
||||||
return fn(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
type filter struct {
|
|
||||||
id FilterId
|
|
||||||
m Matcher
|
|
||||||
ch chan interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *XMPP) sender() {
|
func (x *XMPP) sender() {
|
||||||
for v := range x.Out {
|
for v := range x.Out {
|
||||||
x.stream.Send(v)
|
x.stream.Send(v)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue