示例#1
0
func (ts *Tribserver) RemoveSubscription(args *tribproto.SubscriptionArgs, reply *tribproto.SubscriptionReply) os.Error {
	//check if user exists
	_, stat, err := ts.tm.GET(args.Userid + LAST)
	if err != nil {
		return err
	}
	if stat == storageproto.OK {
		//check if target user exists
		_, stat, err := ts.tm.GET(args.Targetuser + LAST)
		if err != nil {
			return err
		}
		if stat == storageproto.OK {
			val, err := json.Marshal(args.Targetuser)
			if err != nil {
				return err
			}

			//remove subscription from user
			ts.tm.RemoveFromList(args.Userid+SUBSCRIPTIONS, val)
		} else {
			reply.Status = tribproto.ENOSUCHTARGETUSER
		}
	} else {
		reply.Status = tribproto.ENOSUCHUSER
	}
	return nil
}
示例#2
0
func (ts *Tribserver) AddSubscription(args *tribproto.SubscriptionArgs, reply *tribproto.SubscriptionReply) os.Error {
	//check if user exists
	_, stat, err := ts.tm.GET(args.Userid + LAST)
	if err != nil {
		return err
	}
	if stat == storageproto.OK {
		//check if target user exists
		_, stat, err := ts.tm.GET(args.Targetuser + LAST)
		if err != nil {
			return err
		}
		if stat == storageproto.OK {
			val, err := json.Marshal(args.Targetuser)
			if err != nil {
				return err
			}
			//add suscription to user's list
			status, err := ts.tm.AddToList(args.Userid+SUBSCRIPTIONS, val)
			if err != nil {
				return err
			} else if status == storageproto.EITEMEXISTS {
				reply.Status = tribproto.EEXISTS
			}

		} else {
			reply.Status = tribproto.ENOSUCHTARGETUSER
		}
	} else {
		reply.Status = tribproto.ENOSUCHUSER
	}
	return nil
}