コード例 #1
0
ファイル: trib-impl.go プロジェクト: karomancer/Tribbler
func (ts *Tribserver) RemoveSubscription(args *tribproto.SubscriptionArgs, reply *tribproto.SubscriptionReply) error {
	userId := args.Userid
	targetId := args.Targetuser

	//check errors for any calls to libstore
	_, userErr := ts.lstore.Get(userId)
	_, targetErr := ts.lstore.Get(targetId)

	if userErr != nil {
		reply.Status = tribproto.ENOSUCHUSER
		return nil
	}
	if targetErr != nil {
		reply.Status = tribproto.ENOSUCHTARGETUSER
		return nil
	}

	//if both exist
	//then remove from List (user:subscriptions, target)
	//then reply = OK
	//return nil
	removeErr := ts.lstore.RemoveFromList(userId+":subscriptions", targetId)
	if removeErr != nil {
		reply.Status = tribproto.ENOSUCHTARGETUSER
		return nil
	}
	reply.Status = tribproto.OK
	return nil
}
コード例 #2
0
ファイル: trib-impl.go プロジェクト: yuguess/440_P2
/**@brief add subscription to certain user
 * @param SubscriptionArgs
 * @param SubscriptionReply
 * @return error
 */
func (ts *Tribserver) AddSubscription(
	args *tribproto.SubscriptionArgs,
	reply *tribproto.SubscriptionReply) error {
	var fllw_key string
	var trib_key string
	var err error

	//check whether userid exist
	trib_key = fmt.Sprintf("%s:T", args.Userid)
	_, err = ts.Store.GetList(trib_key)
	if lsplog.CheckReport(1, err) {
		reply.Status = tribproto.ENOSUCHUSER
		return nil
	}

	//check whether target user exist
	trib_key = fmt.Sprintf("%s:T", args.Targetuser)
	_, err = ts.Store.GetList(trib_key)
	if lsplog.CheckReport(1, err) {
		reply.Status = tribproto.ENOSUCHTARGETUSER
		return nil
	}

	fllw_key = fmt.Sprintf("%s:F", args.Userid)
	err = ts.Store.AppendToList(fllw_key, args.Targetuser)

	if lsplog.CheckReport(1, err) {
		reply.Status = tribproto.EEXISTS
	} else {
		reply.Status = tribproto.OK
	}

	return nil
}
コード例 #3
0
ファイル: trib-impl.go プロジェクト: ammarar/DS-P2
func (ts *Tribserver) RemoveSubscription(args *tribproto.SubscriptionArgs, reply *tribproto.SubscriptionReply) error {
	// check that user exists
	_, err := ts.ls.Get(args.Userid)
	if err != nil {
		reply.Status = tribproto.ENOSUCHUSER
		return nil
	}
	// check if user is already subscribed to target user
	subsid := fmt.Sprintf("%s:subs", args.Userid)
	// check inside list
	err = ts.ls.RemoveFromList(subsid, args.Targetuser)
	if err != nil {
		reply.Status = tribproto.ENOSUCHTARGETUSER
		return nil
	}
	reply.Status = tribproto.OK
	return nil
}
コード例 #4
0
ファイル: trib-impl.go プロジェクト: karomancer/Tribbler
func (ts *Tribserver) AddSubscription(args *tribproto.SubscriptionArgs, reply *tribproto.SubscriptionReply) error {
	userId := args.Userid
	targetId := args.Targetuser

	//check errors for any calls to libstore
	_, userErr := ts.lstore.Get(userId)
	_, targetErr := ts.lstore.Get(targetId)

	//if userErr != nil, then user doesn't exist
	if userErr != nil {
		reply.Status = tribproto.ENOSUCHUSER
		return nil
	}
	if targetErr != nil {
		reply.Status = tribproto.ENOSUCHTARGETUSER
		return nil
	}

	subs, subErr := ts.lstore.GetList(args.Userid + ":subscriptions")
	if subErr == nil {
		for i := 0; i < len(subs); i++ {
			if subs[i] == targetId {
				reply.Status = tribproto.EEXISTS
				return nil
			}
		}
	}

	//if both exist
	//then do append to List (user:subscriptions, target)
	//then reply = OK
	//return nil
	appendErr := ts.lstore.AppendToList(userId+":subscriptions", targetId)
	if appendErr != nil {
		return appendErr
	}
	reply.Status = tribproto.OK
	return nil
}