• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang roster.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/twstrike/coyim/roster.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()),
	})
}
开发者ID:grayleonard,项目名称:coyim,代码行数:35,代码来源:session_test.go


示例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
	}
}
开发者ID:grayleonard,项目名称:coyim,代码行数:32,代码来源:session_test.go


示例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)
}
开发者ID:grayleonard,项目名称:coyim,代码行数:28,代码来源:session_test.go


示例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
}
开发者ID:twstrike,项目名称:coyim,代码行数:32,代码来源:session.go


示例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())
}
开发者ID:pixelrust,项目名称:coyim,代码行数:12,代码来源:account_manager.go


示例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())
}
开发者ID:tanujmathur,项目名称:coyim,代码行数:12,代码来源:account_manager.go


示例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
	}
}
开发者ID:grayleonard,项目名称:coyim,代码行数:48,代码来源:session_test.go


示例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())
}
开发者ID:0x27,项目名称:coyim,代码行数:16,代码来源:account_manager.go


示例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")
	}
}
开发者ID:grayleonard,项目名称:coyim,代码行数:18,代码来源:session_test.go


示例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
		}
	}

}
开发者ID:grayleonard,项目名称:coyim,代码行数:41,代码来源:session_test.go


示例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")
}
开发者ID:grayleonard,项目名称:coyim,代码行数:21,代码来源:session_test.go


示例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
}
开发者ID:0x27,项目名称:coyim,代码行数:22,代码来源:session.go


示例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
		}
	}
}
开发者ID:grayleonard,项目名称:coyim,代码行数:40,代码来源:session_test.go


示例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
}
开发者ID:grayleonard,项目名称:coyim,代码行数:23,代码来源:session.go


示例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
	}
}
开发者ID:twstrike,项目名称:coyim,代码行数:38,代码来源:session_test.go


示例16: Test_HandleConfirmOrDeny_handlesSendPresenceError

func (s *SessionXmppSuite) Test_HandleConfirmOrDeny_handlesSendPresenceError(c *C) {
	mockIn := &mockConnIOReaderWriter{}
	conn := xmpp.NewConn(
		xml.NewDecoder(mockIn),
		&mockConnIOReaderWriter{err: errors.New("foo bar")},
		"[email protected]/foo",
	)

	sess := &session{
		r: roster.New(),
	}
	sess.conn = conn
	sess.r.SubscribeRequest("[email protected]", "123", "")

	observer := make(chan interface{}, 1)
	sess.Subscribe(observer)

	sess.HandleConfirmOrDeny("[email protected]", true)

	for {
		select {
		case ev := <-observer:
			t := ev.(events.Log)
			if t.Level != events.Warn {
				continue
			}

			c.Assert(t.Message, Equals, "Error sending presence stanza: foo bar")
			return

		case <-time.After(1 * time.Millisecond):
			c.Errorf("did not receive event")
			return
		}
	}
}
开发者ID:grayleonard,项目名称:coyim,代码行数:36,代码来源:session_test.go


示例17: addInitialAccountsToRoster

func (u *gtkUI) addInitialAccountsToRoster() {
	for _, account := range u.accounts {
		u.roster.update(account, rosters.New())
	}
}
开发者ID:PMaynard,项目名称:coyim,代码行数:5,代码来源:ui.go



注:本文中的github.com/twstrike/coyim/roster.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang roster.Peer类代码示例发布时间:2022-05-28
下一篇:
Golang i18n.Local函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap