当前位置: 首页>>代码示例>>Golang>>正文


Golang Subscription.GetPublic方法代码示例

本文整理汇总了Golang中github.com/tinode/chat/server/store/types.Subscription.GetPublic方法的典型用法代码示例。如果您正苦于以下问题:Golang Subscription.GetPublic方法的具体用法?Golang Subscription.GetPublic怎么用?Golang Subscription.GetPublic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/tinode/chat/server/store/types.Subscription的用法示例。


在下文中一共展示了Subscription.GetPublic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: topicInit


//.........这里部分代码省略.........
			if len(subs) == 0 {
				log.Println("hub: missing both subscriptions for '" + t.name + "' (SHOULD NEVER HAPPEN!)")
				sreg.sess.queueOut(ErrUnknown(sreg.pkt.Id, t.name, timestamp))
				return
			}

			t.created = stopic.CreatedAt
			t.updated = stopic.UpdatedAt

			t.lastId = stopic.SeqId
		}

		// t.owner is blank for p2p topics

		// Ensure that other users are automatically rejected
		t.accessAuth = types.ModeP2P
		t.accessAnon = types.ModeBanned

		// t.public is not used for p2p topics since each user get a different public

		// Custom default access levels set in sreg.pkt.Init.DefaultAcs are ignored

		if stopic != nil && len(subs) == 2 {
			// Case 4.

			log.Println("hub: existing p2p topic")

			// t.clearId is not used in P2P topics, may change later

			for i := 0; i < 2; i++ {
				uid := types.ParseUid(subs[i].User)
				t.perUser[uid] = perUserData{
					// Adapter already swapped the public values
					public:  subs[i].GetPublic(),
					private: subs[i].Private,
					// lastSeenTag: subs[i].LastSeen,
					modeWant:  subs[i].ModeWant,
					modeGiven: subs[i].ModeGiven}
			}

		} else {
			// Cases 1, 2

			log.Println("hub: p2p new topic or one of the subs missing")

			var userData perUserData

			// Fetching records for both users.
			// Requester.
			userId1 := sreg.sess.uid
			// The other user.
			userId2 := types.ParseUserId(t.original)
			var u1, u2 int
			users, err := store.Users.GetAll(userId1, userId2)
			if err != nil {
				log.Println("hub: failed to load users for '" + t.name + "' (" + err.Error() + ")")
				sreg.sess.queueOut(ErrUnknown(sreg.pkt.Id, t.name, timestamp))
				return
			} else if len(users) != 2 {
				// Invited user does not exist
				log.Println("hub: missing user for '" + t.name + "'")
				sreg.sess.queueOut(ErrUserNotFound(sreg.pkt.Id, t.name, timestamp))
				return
			} else {
				// User records are unsorted, make sure we know who is who.
				if users[0].Uid() == userId1 {
开发者ID:ycaihua,项目名称:chat,代码行数:67,代码来源:hub.go


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