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


Golang Subscription.SetPublic方法代码示例

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


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

示例1: UsersForTopic

// UsersForTopic loads users subscribed to the given topic
func (a *RethinkDbAdapter) UsersForTopic(topic string) ([]t.Subscription, error) {
	// Fetch topic subscribers
	// Fetch all subscribed users. The number of users is not large
	q := rdb.DB(a.dbName).Table("subscriptions").GetAllByIndex("Topic", topic).Limit(MAX_RESULTS)
	//log.Printf("RethinkDbAdapter.UsersForTopic q: %+v", q)
	rows, err := q.Run(a.conn)
	if err != nil {
		return nil, err
	}

	// Fetch subscriptions
	var sub t.Subscription
	var subs []t.Subscription
	join := make(map[string]t.Subscription)
	usrq := make([]interface{}, 0, 16)
	for rows.Next(&sub) {
		join[sub.User] = sub
		usrq = append(usrq, sub.User)
	}

	//log.Printf("RethinkDbAdapter.UsersForTopic usrq: %+v, usrq)
	if len(usrq) > 0 {
		subs = make([]t.Subscription, 0, len(usrq))

		// Fetch users by a list of subscriptions
		rows, err = rdb.DB(a.dbName).Table("users").GetAll(usrq...).Run(a.conn)
		if err != nil {
			return nil, err
		}

		var usr t.User
		for rows.Next(&usr) {
			if sub, ok := join[usr.Id]; ok {
				sub.ObjHeader.MergeTimes(&usr.ObjHeader)
				sub.SetPublic(usr.Public)
				subs = append(subs, sub)
			}
		}

		//log.Printf("RethinkDbAdapter.UsersForTopic users: %+v", subs)
	}

	return subs, nil
}
开发者ID:ycaihua,项目名称:chat,代码行数:45,代码来源:adapter.go

示例2: SubsForTopic

// SubsForTopic fetches all subsciptions for a topic.
func (a *RethinkDbAdapter) SubsForTopic(topic string) ([]t.Subscription, error) {
	//log.Println("Loading subscriptions for topic ", topic)

	// must load User.Public for p2p topics
	var p2p []t.User
	var err error
	if t.GetTopicCat(topic) == t.TopicCat_P2P {
		uid1, uid2, _ := t.ParseP2P(topic)
		if p2p, err = a.UserGetAll(uid1, uid2); err != nil {
			return nil, err
		} else if len(p2p) != 2 {
			return nil, errors.New("failed to load two p2p users")
		}
	}

	q := rdb.DB(a.dbName).Table("subscriptions").GetAllByIndex("Topic", topic).Limit(MAX_RESULTS)
	//log.Println("Loading subscription q=", q)

	rows, err := q.Run(a.conn)
	if err != nil {
		return nil, err
	}

	var subs []t.Subscription
	var ss t.Subscription
	for rows.Next(&ss) {
		if p2p != nil {
			if p2p[0].Id == ss.User {
				ss.SetPublic(p2p[1].Public)
				ss.SetWith(p2p[1].Id)
			} else {
				ss.SetPublic(p2p[0].Public)
				ss.SetWith(p2p[0].Id)
			}
		}
		subs = append(subs, ss)
		//log.Printf("SubsForTopic: loaded sub %#+v", ss)
	}
	return subs, rows.Err()
}
开发者ID:ycaihua,项目名称:chat,代码行数:41,代码来源:adapter.go

示例3: FindSubs

// FindSubs returns a list of users who match given tags, such as "email:[email protected]" or "tel:18003287448".
// Just search the 'users.Tags' for the given tags using respective index.
func (a *RethinkDbAdapter) FindSubs(user t.Uid, query []interface{}) ([]t.Subscription, error) {
	// Query may contain redundant records, i.e. the same email twice.
	// User could be matched on multiple tags, i.e on email and phone#. Thus the query may
	// return duplicate users. Thus the need for distinct.
	if rows, err := rdb.DB(a.dbName).Table("users").GetAllByIndex("Tags", query...).Limit(MAX_RESULTS).
		Pluck("Id", "Access", "CreatedAt", "UpdatedAt", "Public", "Tags").Distinct().Run(a.conn); err != nil {
		return nil, err
	} else {
		index := make(map[string]struct{})
		for _, q := range query {
			if tag, ok := q.(string); ok {
				index[tag] = struct{}{}
			}
		}
		var user t.User
		var sub t.Subscription
		var subs []t.Subscription
		for rows.Next(&user) {
			sub.CreatedAt = user.CreatedAt
			sub.UpdatedAt = user.UpdatedAt
			sub.User = user.Id
			sub.ModeWant, sub.ModeGiven = user.Access.Auth, user.Access.Auth
			sub.SetPublic(user.Public)
			tags := make([]string, 0, 1)
			for _, tag := range user.Tags {
				if _, ok := index[tag]; ok {
					tags = append(tags, tag)
				}
			}
			sub.Private = tags
			subs = append(subs, sub)
		}
		if err = rows.Err(); err != nil {
			return nil, err
		}
		return subs, nil
	}
}
开发者ID:ycaihua,项目名称:chat,代码行数:40,代码来源:adapter.go

示例4: topicInit


//.........这里部分代码省略.........
					sub2 = &subs[0]
					user1only = true
				}
			}

			if sub1 == nil {
				if sreg.pkt.Set != nil && sreg.pkt.Set.Desc != nil && !isNullValue(sreg.pkt.Set.Desc.Private) {
					userData.private = sreg.pkt.Set.Desc.Private
					// Init.DefaultAcs and Init.Public are ignored for p2p topics
				}

				// User may set non-default access to topic, just make sure it's no higher than the default
				if sreg.pkt.Set != nil && sreg.pkt.Set.Sub != nil && sreg.pkt.Set.Sub.Mode != "" {
					if err := userData.modeWant.UnmarshalText([]byte(sreg.pkt.Set.Sub.Mode)); err != nil {
						log.Println("hub: invalid access mode for topic '" + t.name + "': '" + sreg.pkt.Set.Sub.Mode + "'")
						userData.modeWant = types.ModeP2P
					} else {
						// FIXME(gene): check for Mode.Banned
						userData.modeWant &= types.ModeP2P
					}
				} else if users[u1].Access.Auth != types.ModeNone {
					userData.modeWant = users[u1].Access.Auth
				} else {
					userData.modeWant = types.ModeP2P
				}

				sub1 = &types.Subscription{
					User:      userId1.String(),
					Topic:     t.name,
					ModeWant:  userData.modeWant,
					ModeGiven: types.ModeP2P,
					Private:   userData.private}
				// Swap Public to match swapped Public in subs returned from store.Topics.GetSubs
				sub1.SetPublic(users[u2].Public)
			}

			if sub2 == nil {
				sub2 = &types.Subscription{
					User:      userId2.String(),
					Topic:     t.name,
					ModeWant:  users[u2].Access.Auth,
					ModeGiven: types.ModeP2P,
					Private:   nil}
				// Swap Public to match swapped Public in subs returned from store.Topics.GetSubs
				sub2.SetPublic(users[u1].Public)
			}

			// Create everything
			if stopic == nil {
				if err = store.Topics.CreateP2P(sub1, sub2); err != nil {
					log.Println("hub: databse error in creating subscriptions '" + t.name + "' (" + err.Error() + ")")
					sreg.sess.queueOut(ErrUnknown(sreg.pkt.Id, t.name, timestamp))
					return
				}

				t.created = sub1.CreatedAt
				t.updated = sub1.UpdatedAt

				// t.lastId is not set (default 0) for new topics

			} else {
				// Recreate one of the subscriptions
				var subToMake *types.Subscription
				if user1only {
					subToMake = sub1
				} else {
开发者ID:ycaihua,项目名称:chat,代码行数:67,代码来源:hub.go

示例5: TopicsForUser

// TopicsForUser loads user's contact list: p2p and grp topics, except for 'me' subscription.
func (a *RethinkDbAdapter) TopicsForUser(uid t.Uid) ([]t.Subscription, error) {
	// Fetch user's subscriptions
	// Subscription have Topic.UpdatedAt denormalized into Subscription.UpdatedAt
	q := rdb.DB(a.dbName).Table("subscriptions").GetAllByIndex("User", uid.String()).Limit(MAX_RESULTS)
	//log.Printf("RethinkDbAdapter.TopicsForUser q: %+v", q)
	rows, err := q.Run(a.conn)
	if err != nil {
		return nil, err
	}

	// Fetch subscriptions. Two queries are needed: users table (me & p2p) and topics table (p2p and grp).
	// Prepare a list of Separate subscriptions to users vs topics
	var sub t.Subscription
	join := make(map[string]t.Subscription) // Keeping these to make a join with table for .private and .access
	topq := make([]interface{}, 0, 16)
	usrq := make([]interface{}, 0, 16)
	for rows.Next(&sub) {
		tcat := t.GetTopicCat(sub.Topic)

		// 'me' subscription, skip
		if tcat == t.TopicCat_Me || tcat == t.TopicCat_Fnd {
			continue

			// p2p subscription, find the other user to get user.Public
		} else if tcat == t.TopicCat_P2P {
			uid1, uid2, _ := t.ParseP2P(sub.Topic)
			if uid1 == uid {
				usrq = append(usrq, uid2.String())
			} else {
				usrq = append(usrq, uid1.String())
			}
			topq = append(topq, sub.Topic)

			// grp subscription
		} else {
			topq = append(topq, sub.Topic)
		}
		join[sub.Topic] = sub
	}

	//log.Printf("RethinkDbAdapter.TopicsForUser topq, usrq: %+v, %+v", topq, usrq)
	var subs []t.Subscription
	if len(topq) > 0 || len(usrq) > 0 {
		subs = make([]t.Subscription, 0, len(join))
	}

	if len(topq) > 0 {
		// Fetch grp & p2p topics
		rows, err = rdb.DB(a.dbName).Table("topics").GetAll(topq...).Run(a.conn)
		if err != nil {
			return nil, err
		}

		var top t.Topic
		for rows.Next(&top) {
			sub = join[top.Id]
			sub.ObjHeader.MergeTimes(&top.ObjHeader)
			sub.SetSeqId(top.SeqId)
			sub.SetHardClearId(top.ClearId)
			if t.GetTopicCat(sub.Topic) == t.TopicCat_Grp {
				// all done with a grp topic
				sub.SetPublic(top.Public)
				subs = append(subs, sub)
			} else {
				// put back the updated value of a p2p subsription, will process further below
				join[top.Id] = sub
			}
		}

		//log.Printf("RethinkDbAdapter.TopicsForUser 1: %#+v", subs)
	}

	// Fetch p2p users and join to p2p tables
	if len(usrq) > 0 {
		rows, err = rdb.DB(a.dbName).Table("users").GetAll(usrq...).Run(a.conn)
		if err != nil {
			return nil, err
		}

		var usr t.User
		for rows.Next(&usr) {
			uid2 := t.ParseUid(usr.Id)
			topic := uid.P2PName(uid2)
			if sub, ok := join[topic]; ok {
				sub.ObjHeader.MergeTimes(&usr.ObjHeader)
				sub.SetWith(uid2.UserId())
				sub.SetPublic(usr.Public)
				sub.SetLastSeenAndUA(usr.LastSeen, usr.UserAgent)
				subs = append(subs, sub)
			}
		}

		//log.Printf("RethinkDbAdapter.TopicsForUser 2: %#+v", subs)
	}

	return subs, nil
}
开发者ID:ycaihua,项目名称:chat,代码行数:98,代码来源:adapter.go


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