예제 #1
0
파일: auth.go 프로젝트: hi-trust/friendfeed
func (s *ApiServer) DeleteService(ctx context.Context, req *pb.ServiceRequest) (*pb.Feedinfo, error) {
	feedinfo, err := store.GetFeedinfo(s.rdb, req.User)
	if err != nil {
		return nil, err
	}

	for i, item := range feedinfo.Services {
		if item.Id == req.Service {
			feedinfo.Services = append(feedinfo.Services[:i], feedinfo.Services[i+1:]...)
		}
	}
	if err := store.SaveFeedinfo(s.rdb, feedinfo.Uuid, feedinfo); err != nil {
		return nil, err
	}
	return feedinfo, nil
}
예제 #2
0
파일: auth.go 프로젝트: hi-trust/friendfeed
func (s *ApiServer) PutOAuth(ctx context.Context, authinfo *pb.OAuthUser) (*pb.Profile, error) {
	// TODO: create profile on oauth?
	user, err := store.PutOAuthUser(s.mdb, authinfo)
	if err != nil {
		return nil, err
	}

	// exists user
	if user.Uuid != "" {
		uuid1, err := uuid.FromString(user.Uuid)
		if err != nil {
			return nil, err
		}
		profile, err := store.GetProfileFromUuid(s.mdb, uuid1)
		if err != nil {
			return nil, err
		}

		// build services if profile present
		if authinfo.Provider == "twitter" {
			feedinfo, err := store.GetFeedinfo(s.rdb, profile.Uuid)
			if err != nil {
				return nil, err
			}
			// WARN: goth user.NickName == screen_name which is twitter id
			service := &pb.Service{
				Id:       "twitter",
				Name:     "Twitter",
				Icon:     "/static/images/icons/twitter.png",
				Profile:  "https://twitter.com/" + user.NickName,
				Username: user.Name,
				Oauth:    user,
				Created:  time.Now().Unix(),
				Updated:  time.Now().Unix(),
			}
			feedinfo.Services = append(feedinfo.Services, service)
			err = store.SaveFeedinfo(s.rdb, profile.Uuid, feedinfo)
			if err != nil {
				return nil, err
			}
		}
		return profile, nil
	}

	return new(pb.Profile), nil
}
예제 #3
0
func (s *ApiServer) PostFeedinfo(ctx context.Context, in *pb.Feedinfo) (*pb.Profile, error) {
	profile := &pb.Profile{
		Uuid:        in.Uuid,
		Id:          in.Id,
		Name:        in.Name,
		Type:        in.Type,
		Private:     in.Private,
		SupId:       in.SupId,
		Description: in.Description,
	}
	// remote key only present when id == target_id
	if in.RemoteKey != "" {
		// record remote key
		profile.RemoteKey = in.RemoteKey
	}

	// profile.Picture = s.ArchiveProfilePicture(profile.Id)
	// log.Println("profile pic:", profile.Picture)

	if err := store.UpdateProfile(s.mdb, profile); err != nil {
		return nil, err
	}

	// save all feed info in one key for simplicity
	// TODO: refactor?
	in.Entries = []*pb.Entry{}
	if err := store.SaveFeedinfo(s.rdb, profile.Uuid, in); err != nil {
		return nil, err
	}

	// TODO: server overload, disable friends of feed
	// There is no way we can handle this much jobs in a short time.
	// remote key only present when id == target_id
	// if in.RemoteKey != "" {
	// 	for _, sub := range in.Subscriptions {
	// 		// enqueue user subscriptons
	// 		oldjob, err := store.GetArchiveHistory(s.mdb, sub.Id)
	// 		if err != nil || oldjob.Status == "done" {
	// 			// no aggressive archiving for friends of feed
	// 			log.Printf("%s previous archived.", sub.Id)
	// 			continue
	// 		}

	// 		ctx := context.Background()
	// 		key := store.NewFlakeKey(store.TableJobFeed, s.mdb.NextId())
	// 		job := &pb.FeedJob{
	// 			Key:       key.String(),
	// 			Id:        in.Id,
	// 			RemoteKey: in.RemoteKey,
	// 			TargetId:  sub.Id,
	// 			Start:     0,
	// 			PageSize:  100,
	// 			Created:   time.Now().Unix(),
	// 			Updated:   time.Now().Unix(),
	// 		}
	// 		s.EnqueJob(ctx, job)
	// 	}
	// }

	return profile, nil
}