Esempio n. 1
0
func (s *ApiServer) FetchProfile(ctx context.Context, req *pb.ProfileRequest) (*pb.Profile, error) {
	uuid1, err := uuid.FromString(req.Uuid)
	if err != nil {
		return nil, err
	}
	return store.GetProfileFromUuid(s.mdb, uuid1)
}
Esempio n. 2
0
func (s *ApiServer) LikeEntry(ctx context.Context, req *pb.LikeRequest) (*pb.Entry, error) {
	entry, err := store.GetEntry(s.rdb, req.Entry)
	if err != nil {
		return nil, err
	}

	uuid1, err := uuid.FromString(req.User)
	if err != nil {
		return nil, err
	}
	profile, err := store.GetProfileFromUuid(s.mdb, uuid1)
	if err != nil || profile == nil {
		return nil, err
	}

	if req.Like {
		var key *store.UUIDKey
		key, entry, err = store.Like(s.rdb, profile, entry)
		if err == nil {
			s.spread(key)
		}
	} else {
		entry, err = store.DeleteLike(s.rdb, profile, entry)
	}
	return entry, err
}
Esempio n. 3
0
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
}