本文整理汇总了Golang中github.com/twstrike/coyim/roster.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_WatchStanzas_iq_set_roster_setsExistingRosterItem
func (s *SessionXmppSuite) Test_WatchStanzas_iq_set_roster_setsExistingRosterItem(c *C) {
mockIn := &mockConnIOReaderWriter{read: []byte("<client:iq xmlns:client='jabber:client' type='set' to='cde'><query xmlns='jabber:iq:roster'>" +
"<item jid='[email protected]' name='Romeo' subscription='both'>" +
"<group>Friends</group>" +
"</item>" +
"</query></client:iq>")}
conn := xmpp.NewConn(
xml.NewDecoder(mockIn),
mockIn,
"[email protected]/foo",
)
called := 0
sess := &session{
config: &config.ApplicationConfig{},
accountConfig: &config.Account{
Account: "[email protected]",
},
r: roster.New(),
connStatus: DISCONNECTED,
}
sess.conn = conn
sess.r.AddOrReplace(peerFrom(data.RosterEntry{Jid: "[email protected]", Subscription: "both", Name: "Jill", Group: []string{"Foes"}}, sess.GetConfig()))
sess.r.AddOrReplace(peerFrom(data.RosterEntry{Jid: "[email protected]", Subscription: "both", Name: "Mo", Group: []string{"Foes"}}, sess.GetConfig()))
sess.watchStanzas()
c.Assert(called, Equals, 0)
c.Assert(sess.r.ToSlice(), DeepEquals, []*roster.Peer{
peerFrom(data.RosterEntry{Jid: "[email protected]", Subscription: "both", Name: "Jill", Group: []string{"Foes"}}, sess.GetConfig()),
peerFrom(data.RosterEntry{Jid: "[email protected]", Subscription: "both", Name: "Romeo", Group: []string{"Friends"}}, sess.GetConfig()),
})
}
示例2: Test_WatchStanzas_presence_unavailable_forNoneKnownUser
func (s *SessionXmppSuite) Test_WatchStanzas_presence_unavailable_forNoneKnownUser(c *C) {
mockIn := &mockConnIOReaderWriter{read: []byte("<client:presence xmlns:client='jabber:client' from='[email protected]/balcony' to='[email protected]' type='unavailable'><client:status>going on vacation</client:status></client:presence>")}
conn := xmpp.NewConn(
xml.NewDecoder(mockIn),
mockIn,
"[email protected]/foo",
)
sess := &session{
r: roster.New(),
connStatus: DISCONNECTED,
}
sess.conn = conn
observer := make(chan interface{}, 1)
sess.Subscribe(observer)
sess.watchStanzas()
select {
case ev := <-observer:
switch ev.(type) {
case events.Presence:
c.Error("Received presence event")
return
default:
// ignore
}
case <-time.After(1 * time.Millisecond):
return
}
}
示例3: Test_HandleConfirmOrDeny_succeedsOnAllowedAndAskBack
func (s *SessionXmppSuite) Test_HandleConfirmOrDeny_succeedsOnAllowedAndAskBack(c *C) {
mockIn := &mockConnIOReaderWriter{}
conn := xmpp.NewConn(
xml.NewDecoder(mockIn),
mockIn,
"[email protected]/foo",
)
called := 0
sess := &session{
r: roster.New(),
sessionEventHandler: &mockSessionEventHandler{
//warn: func(v string) {
// called++
//},
},
}
sess.conn = conn
sess.r.SubscribeRequest("[email protected]", "123", "")
sess.HandleConfirmOrDeny("[email protected]", true)
c.Assert(called, Equals, 0)
c.Assert(string(mockIn.write), Matches, "<presence id='123' to='[email protected]' type='subscribed'/><presence id='[0-9]+' to='[email protected]' type='subscribe'/>")
_, inMap := sess.r.GetPendingSubscribe("[email protected]")
c.Assert(inMap, Equals, false)
}
示例4: Factory
// Factory creates a new session from the given config
func Factory(c *config.ApplicationConfig, cu *config.Account, df func(tls.Verifier) xi.Dialer) access.Session {
// Make xmppLogger go to in memory STRING and/or the log file
inMemoryLog, xmppLogger := createXMPPLogger(c.RawLogFile)
s := &session{
config: c,
accountConfig: cu,
r: roster.New(),
otrEventHandler: make(map[string]*event.OtrEventHandler),
lastActionTime: time.Now(),
timeouts: make(map[data.Cookie]time.Time),
autoApproves: make(map[string]bool),
inMemoryLog: inMemoryLog,
xmppLogger: xmppLogger,
connectionLogger: logToDebugLog(),
dialerFactory: df,
}
s.ReloadKeys()
s.convManager = client.NewConversationManager(s, s)
go observe(s)
go checkReconnect(s)
return s
}
示例5: addAccount
func (m *accountManager) addAccount(appConfig *config.ApplicationConfig, account *config.Account, sf access.Factory, df func() interfaces.Dialer) {
m.Lock()
defer m.Unlock()
acc := newAccount(appConfig, account, sf, df)
acc.session.Subscribe(m.events)
acc.session.SetCommandManager(m)
acc.session.SetConnector(acc)
m.accounts = append(m.accounts, acc)
m.setContacts(acc, rosters.New())
}
示例6: addAccount
func (m *accountManager) addAccount(appConfig *config.ApplicationConfig, account *config.Account) {
m.Lock()
defer m.Unlock()
acc := newAccount(appConfig, account)
acc.session.Subscribe(m.events)
acc.session.CommandManager = m
acc.session.Connector = acc
m.accounts = append(m.accounts, acc)
m.setContacts(acc, rosters.New())
}
示例7: Test_WatchStanzas_iq_set_roster_removesRosterItems
func (s *SessionXmppSuite) Test_WatchStanzas_iq_set_roster_removesRosterItems(c *C) {
mockIn := &mockConnIOReaderWriter{read: []byte("<client:iq xmlns:client='jabber:client' type='set' to='cde'><query xmlns='jabber:iq:roster'>" +
"<item jid='[email protected]' name='Romeo' subscription='remove'>" +
"<group>Friends</group>" +
"</item>" +
"</query></client:iq>")}
conn := xmpp.NewConn(
xml.NewDecoder(mockIn),
mockIn,
"[email protected]/foo",
)
sess := &session{
config: &config.ApplicationConfig{},
accountConfig: &config.Account{
Account: "[email protected]",
},
r: roster.New(),
connStatus: DISCONNECTED,
}
sess.conn = conn
sess.r.AddOrReplace(peerFrom(data.RosterEntry{Jid: "[email protected]", Subscription: "both", Name: "Mo", Group: []string{"Foes"}}, sess.GetConfig()))
sess.r.AddOrReplace(peerFrom(data.RosterEntry{Jid: "[email protected]", Subscription: "both", Name: "Jill", Group: []string{"Foes"}}, sess.GetConfig()))
sess.r.AddOrReplace(peerFrom(data.RosterEntry{Jid: "[email protected]", Subscription: "both", Name: "Mo", Group: []string{"Foes"}}, sess.GetConfig()))
observer := make(chan interface{}, 1)
sess.Subscribe(observer)
sess.watchStanzas()
c.Assert(sess.r.ToSlice(), DeepEquals, []*roster.Peer{
peerFrom(data.RosterEntry{Jid: "[email protected]", Subscription: "both", Name: "Jill", Group: []string{"Foes"}}, sess.GetConfig()),
})
select {
case ev := <-observer:
switch ev.(type) {
case events.Peer:
c.Error("Received peer event")
return
default:
// ignore
}
case <-time.After(1 * time.Millisecond):
return
}
}
示例8: addAccount
func (m *accountManager) addAccount(appConfig *config.ApplicationConfig, account *config.Account) {
m.Lock()
defer m.Unlock()
acc, err := newAccount(appConfig, account)
if err != nil {
//TODO error
return
}
acc.session.Subscribe(m.events)
acc.session.CommandManager = m
m.accounts = append(m.accounts, acc)
m.setContacts(acc, rosters.New())
}
示例9: Test_HandleConfirmOrDeny_failsWhenNoPendingSubscribeIsWaiting
func (s *SessionXmppSuite) Test_HandleConfirmOrDeny_failsWhenNoPendingSubscribeIsWaiting(c *C) {
sess := &session{
r: roster.New(),
}
observer := make(chan interface{}, 1)
sess.Subscribe(observer)
sess.HandleConfirmOrDeny("[email protected]", true)
select {
case ev := <-observer:
t := ev.(events.Log)
c.Assert(t.Level, Equals, events.Warn)
case <-time.After(1 * time.Millisecond):
c.Errorf("did not receive event")
}
}
示例10: Test_WatchStanzas_presence_unavailable_forKnownUser
func (s *SessionXmppSuite) Test_WatchStanzas_presence_unavailable_forKnownUser(c *C) {
mockIn := &mockConnIOReaderWriter{read: []byte("<client:presence xmlns:client='jabber:client' from='[email protected]/balcony' to='[email protected]' type='unavailable'><client:status>going on vacation</client:status></client:presence>")}
conn := xmpp.NewConn(
xml.NewDecoder(mockIn),
mockIn,
"[email protected]/foo",
)
sess := &session{
config: &config.ApplicationConfig{},
accountConfig: &config.Account{},
r: roster.New(),
connStatus: DISCONNECTED,
}
sess.conn = conn
sess.r.AddOrReplace(roster.PeerWithState("[email protected]", "somewhere", "", ""))
observer := make(chan interface{}, 1)
sess.Subscribe(observer)
sess.watchStanzas()
p, _ := sess.r.Get("[email protected]")
c.Assert(p.Online, Equals, false)
for {
select {
case ev := <-observer:
switch t := ev.(type) {
case events.Presence:
c.Assert(t.Gone, Equals, true)
return
default:
//ignore
}
case <-time.After(1 * time.Millisecond):
c.Errorf("did not receive event")
return
}
}
}
示例11: Test_WatchStanzas_presence_subscribe
func (s *SessionXmppSuite) Test_WatchStanzas_presence_subscribe(c *C) {
mockIn := &mockConnIOReaderWriter{read: []byte("<client:presence xmlns:client='jabber:client' from='[email protected]/balcony' to='[email protected]' type='subscribe' id='adf12112'/>")}
conn := xmpp.NewConn(
xml.NewDecoder(mockIn),
mockIn,
"[email protected]/foo",
)
sess := &session{
config: &config.ApplicationConfig{},
accountConfig: &config.Account{},
r: roster.New(),
connStatus: DISCONNECTED,
}
sess.conn = conn
sess.watchStanzas()
v, _ := sess.r.GetPendingSubscribe("[email protected]")
c.Assert(v, Equals, "adf12112")
}
示例12: NewSession
// NewSession creates a new session from the given config
func NewSession(c *config.ApplicationConfig, cu *config.Account) *Session {
s := &Session{
Config: c,
accountConfig: cu,
R: roster.New(),
OtrEventHandler: make(map[string]*event.OtrEventHandler),
LastActionTime: time.Now(),
timeouts: make(map[xmpp.Cookie]time.Time),
xmppLogger: openLogFile(c.RawLogFile),
}
s.PrivateKeys = parseFromConfig(cu)
s.ConversationManager = client.NewConversationManager(s, s)
go observe(s)
return s
}
示例13: Test_WatchStanzas_presence_regularPresenceIsAdded
func (s *SessionXmppSuite) Test_WatchStanzas_presence_regularPresenceIsAdded(c *C) {
mockIn := &mockConnIOReaderWriter{read: []byte("<client:presence xmlns:client='jabber:client' from='[email protected]/balcony' to='[email protected]'><client:show>dnd</client:show></client:presence>")}
conn := xmpp.NewConn(
xml.NewDecoder(mockIn),
mockIn,
"[email protected]/foo",
)
sess := &session{
config: &config.ApplicationConfig{},
accountConfig: &config.Account{},
r: roster.New(),
connStatus: DISCONNECTED,
}
sess.conn = conn
observer := make(chan interface{}, 1)
sess.Subscribe(observer)
sess.watchStanzas()
st, _, _ := sess.r.StateOf("[email protected]")
c.Assert(st, Equals, "dnd")
for {
select {
case ev := <-observer:
switch t := ev.(type) {
case events.Presence:
c.Assert(t.Gone, Equals, false)
default:
//ignore
}
return
case <-time.After(1 * time.Millisecond):
c.Errorf("did not receive event")
return
}
}
}
示例14: Factory
// Factory creates a new session from the given config
func Factory(c *config.ApplicationConfig, cu *config.Account) access.Session {
s := &session{
config: c,
accountConfig: cu,
r: roster.New(),
otrEventHandler: make(map[string]*event.OtrEventHandler),
lastActionTime: time.Now(),
timeouts: make(map[xmpp.Cookie]time.Time),
xmppLogger: openLogFile(c.RawLogFile),
}
s.ReloadKeys()
s.convManager = client.NewConversationManager(s, s)
go observe(s)
go checkReconnect(s)
return s
}
示例15: Test_WatchStanzas_presence_ignoresSameState
func (s *SessionSuite) Test_WatchStanzas_presence_ignoresSameState(c *C) {
mockIn := &mockConnIOReaderWriter{read: []byte("<client:presence xmlns:client='jabber:client' from='[email protected]/balcony' to='[email protected]'><client:show>dnd</client:show></client:presence>")}
conn := xmpp.NewConn(
xml.NewDecoder(mockIn),
mockIn,
"[email protected]/foo",
)
sess := &session{
config: &config.ApplicationConfig{},
accountConfig: &config.Account{},
r: roster.New(),
connStatus: DISCONNECTED,
}
sess.conn = conn
sess.r.AddOrReplace(roster.PeerWithState("[email protected]", "dnd", "", "", ""))
observer := make(chan interface{}, 1)
sess.Subscribe(observer)
sess.watchStanzas()
st, _, _ := sess.r.StateOf("[email protected]")
c.Assert(st, Equals, "dnd")
select {
case ev := <-observer:
switch ev.(type) {
case events.Presence:
c.Error("Received presence event")
return
default:
// ignore
}
case <-time.After(1 * time.Millisecond):
return
}
}