Beispiel #1
0
        public async Task FollowFeed(IStreamFeed feedToFollow, int activityCopyLimit = StreamClient.ActivityCopyLimitDefault)
        {
            ValidateFeedFollow(feedToFollow);
            if (activityCopyLimit < 0)
            {
                throw new ArgumentOutOfRangeException("activityCopyLimit", "Activity copy limit must be greater than or equal to 0");
            }
            if (activityCopyLimit > StreamClient.ActivityCopyLimitMax)
            {
                throw new ArgumentOutOfRangeException("activityCopyLimit", string.Format("Activity copy limit must be less than or equal to {0}", StreamClient.ActivityCopyLimitMax));
            }

            var request = _client.BuildFeedRequest(this, "/following/", HttpMethod.POST);

            request.SetJsonBody(JsonConvert.SerializeObject(new
            {
                target = feedToFollow.FeedId,
                activity_copy_limit = activityCopyLimit,
                target_token        = feedToFollow.Token
            }));

            var response = await _client.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.Created)
            {
                throw StreamException.FromResponse(response);
            }
        }
        public async Task <Model.User> Get(string userName, bool light)
        {
            if (light)
            {
                return(_database.GetInstance.QuerySingleOrDefault <Model.User>("SELECT username, pic_url FROM users where username=@user", new { user = userName }));
            }
            else
            {
                FullUser fullUser;
                fullUser = _database.GetInstance.QuerySingleOrDefault <FullUser>("SELECT username, pic_url FROM users where username=@user", new { user = userName });
                IStreamFeed userFeed     = _streamApi.StreamClient.Feed("user", userName);
                IStreamFeed userTimeline = _streamApi.StreamClient.Feed("timeline", userName);
                fullUser.Posts = await userFeed.GetActivities();

                fullUser.Followers = await userFeed.Followers();

                fullUser.Following = await userTimeline.Following();

                // Remove the user itself from the list of followers/following
                fullUser.Followers = fullUser.Followers.Where(f => f.FeedId.Split(':')[1] != userName);
                fullUser.Following = fullUser.Following.Where(f => f.TargetId.Split(':')[1] != userName);


                return(fullUser);
            }
        }
        public async Task <string> PostAsync([FromBody] UserDto userDto)
        {
            var userData = new Dictionary <string, object>()
            {
                { "profile_pic", userDto.ProfilePictureUrl }
            };

            try
            {
                // Add user to the Stream API
                await _streamApi.StreamClient.Users.Add(userDto.Username, userData);

                PasswordHasher ph = new PasswordHasher();
                // Add user to the DB
                _database.GetInstance.Execute("INSERT INTO users (username, pass, pic_url) VALUES(@user, @pass, @pic)", new { user = userDto.Username, pass = ph.Hash(userDto.Password), pic = userDto.ProfilePictureUrl });
                // Register user timeline to his profile (the user timeline will show his own posts)
                IStreamFeed userTimeline = _streamApi.StreamClient.Feed("timeline", userDto.Username);
                await userTimeline.FollowFeed("user", userDto.Username);

                // Follow the admin account with the welcome message (if the user registering is already RecYou ignore it)
                if (userDto.Username != "RecYou")
                {
                    await userTimeline.FollowFeed("user", "RecYou");
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            return(JWT.GenerateToken(userDto.Username));
        }
Beispiel #4
0
 private void ValidateFeedFollow(IStreamFeed feed)
 {
     if (feed == null)
     {
         throw new ArgumentNullException("feed", "Must have a feed to follow/unfollow");
     }
     if (((StreamFeed)feed).FeedTokenId == this.FeedTokenId)
     {
         throw new ArgumentException("Cannot follow/unfollow myself");
     }
 }
Beispiel #5
0
        public void Post([FromBody] PostDto pdto)
        {
            IStreamFeed userTimeline = _streamApi.StreamClient.Feed("user", User.Identity.Name);
            var         activityData = new Activity(User.Identity.Name, "posts", pdto.AudioUrl + "," + pdto.PictureUrl)
            {
                ForeignId = pdto.AudioUrl,
                Target    = pdto.Description,
            };


            userTimeline.AddActivity(activityData);
        }
Beispiel #6
0
        public async Task UnfollowFeed(IStreamFeed feedToUnfollow, bool keepHistory = false)
        {
            ValidateFeedFollow(feedToUnfollow);

            var request = _client.BuildFeedRequest(this, "/following/" + feedToUnfollow.FeedId + "/", HttpMethod.DELETE);

            request.AddQueryParameter("keep_history", keepHistory.ToString());

            var response = await _client.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw StreamException.FromResponse(response);
            }
        }
        public IEnumerable <Activity> Get()
        {
            IStreamFeed userTimeline = _streamApi.StreamClient.Feed("timeline", User.Identity.Name);

            return(userTimeline.GetFlatActivities().Result.Results);
        }
Beispiel #8
0
 public Follow(IStreamFeed source, IStreamFeed target)
 {
     Source = source.FeedId;
     Target = target.FeedId;
 }
 public async Task DeleteAsync([FromBody] RelationDto rdto)
 {
     IStreamFeed userTimeline = _streamApi.StreamClient.Feed("timeline", User.Identity.Name);
     await userTimeline.UnfollowFeed("user", rdto.UserToFollowUnfollow);
 }
Beispiel #10
0
 public async void Delete([FromBody] PostDto pdto)
 {
     IStreamFeed userTimeline = _streamApi.StreamClient.Feed("user", User.Identity.Name);
     await userTimeline.RemoveActivity(pdto.ForeignId);
 }