Пример #1
0
        public void Handle(UserFollowed evt)
        {
            var user = _db.GetById <UserView>(evt.Id);

            if (user.FollowingUserIds == null)
            {
                user.FollowingUserIds = new List <Guid>();
            }

            user.FollowingUserIds.Add(evt.OtherUserId);

            _db.Update(user);


            var otherUser = _db.GetById <UserView>(evt.OtherUserId);

            if (otherUser.FollowedByUserIds == null)
            {
                otherUser.FollowedByUserIds = new List <Guid>();
            }

            otherUser.FollowedByUserIds.Add(evt.Id);

            _db.Update(otherUser);
        }
Пример #2
0
        /// <summary>
        /// “关注”指定的目标用户(异步)
        /// </summary>
        /// <param name="userId">用户编号</param>
        /// <param name="targetUserId">被关注的目标用户编号</param>
        public static async void FollowedTargetUser(int userId, int targetUserId)
        {
            await Task.Run(() =>
            {
                UserFollowed uFollowed = new UserFollowed {
                    UserId = userId, FollowedUserId = targetUserId, CreateDate = DateTime.Now
                };
                bool result = SocialData.ChangedFollowedWithTargetUser(uFollowed, 1);
                if (result)
                {
                    SocialConfig config = SocialConfigs.GetSocialConfigCache();

                    if (config.BeFollowedExpChanged != 0)
                    {
                        UserBiz.UpdateUserExp(targetUserId, config.BeFollowedExpChanged, "被关注");
                    }

                    if (config.BeFollowedCoinChanged != 0)
                    {
                        UserBiz.UpdateUserCoin(targetUserId, config.BeFollowedCoinChanged, "被关注");
                    }

                    UserBiz.SetUserCacheInfo(userId);
                    UserBiz.SetUserCacheInfo(targetUserId);

                    //发送系统消息给被关注对象,提醒该用户被“关注”
                    //Todo....
                }
            });
        }
Пример #3
0
 /// <summary>
 /// 改变和指定用户的单向“关注”关系,改变结果:成功或失败
 /// </summary>
 /// <param name="uFollowed">关注关系数据</param>
 /// <param name="action">改变类型:1-增加,0-移除</param>
 /// <returns>改变结果:成功或失败</returns>
 public static bool ChangedFollowedWithTargetUser(UserFollowed uFollowed, byte action)
 {
     using (DbCommander cmd = new DbCommander(DbConn.ReadDb, "SP_Social_ChangedFollowedWithTargetUser", CommandType.StoredProcedure))
     {
         cmd.AddInputParameters("UserId, FollowedUserId, CreateDate, Action", uFollowed.UserId, uFollowed.FollowedUserId, uFollowed.CreateDate, action);
         return(Convert.ToBoolean(cmd.ExecuteScalar()));
     }
 }
Пример #4
0
 /// <summary>
 /// 获取和指定的目标用户之间是否已存在单向“关注”关系记录
 /// </summary>
 /// <param name="uFollowed">关注关系数据</param>
 /// <returns></returns>
 public static bool BeFollowedWithTargetUser(UserFollowed uFollowed)
 {
     using (DbCommander cmd = new DbCommander(DbConn.ReadDb, "SP_Social_BeFollowedWithTargetUser", CommandType.StoredProcedure))
     {
         cmd.AddInputParameters("UserId, FollowedUserId", uFollowed.UserId, uFollowed.FollowedUserId);
         return(Convert.ToBoolean(cmd.ExecuteScalar()));
     }
 }
Пример #5
0
 public void Apply(UserFollowed @event)
 {
     if (@event == null)
     {
         throw new ArgumentNullException(nameof(@event));
     }
     Id          = Guid.NewGuid();
     FollowingId = @event.FollowingId;
     FollowerId  = @event.FollowerId;
 }
Пример #6
0
        public void ShowsOnlyMessagesFromTheFollowedUser()
        {
            var aliceFollowedBob = new UserFollowed("Alice", "Bob");
            var bobsPost         = new MessagePosted("Bob", "A message from Bob", fakeClock.HypoteticalNow);

            wallPresenter.Handle(aliceFollowedBob);
            wallPresenter.Handle(bobsPost);

            var alicesWall = GetWallFor(userName);

            Assert.That(alicesWall[0], Is.EqualTo("Bob - A message from Bob (0 seconds ago)"));
        }
        public void Follow(int userID, int userFollowedID)
        {
            using (var context = new TwitterContext())
            {
                var userFollowed = new UserFollowed
                {
                    UserID         = userID,
                    UserFollowedID = userFollowedID,
                };

                context.UserFollowed.Add(userFollowed);
                context.SaveChanges();
            }
        }
Пример #8
0
        public void AggregatesTheirMessagesToTheSourceUsersWall()
        {
            var alicesPost       = new MessagePosted("Alice", "A message from Alice", fakeClock.HypoteticalNow);
            var aliceFollowedBob = new UserFollowed("Alice", "Bob");
            var bobsPost         = new MessagePosted("Bob", "A message from Bob", fakeClock.HypoteticalNow.AddSeconds(1));

            wallPresenter.Handle(alicesPost);
            wallPresenter.Handle(aliceFollowedBob);
            wallPresenter.Handle(bobsPost);

            var alicesWall = GetWallFor(userName);

            Assert.That(alicesWall[0], Is.EqualTo("Alice - A message from Alice (0 seconds ago)"));
            Assert.That(alicesWall[1], Is.EqualTo("Bob - A message from Bob (1 second ago)"));
        }
Пример #9
0
 /// <summary>
 /// 取消“关注”指定的目标用户(异步)
 /// </summary>
 /// <param name="userId">用户编号</param>
 /// <param name="targetUserId">被关注的目标用户编号</param>
 public static async void RemoveFollowedByTargetUser(int userId, int targetUserId)
 {
     await Task.Run(() =>
     {
         UserFollowed uFollowed = new UserFollowed {
             UserId = userId, FollowedUserId = targetUserId, CreateDate = DateTime.Now
         };
         bool result = SocialData.ChangedFollowedWithTargetUser(uFollowed, 0);
         if (result)
         {
             UserBiz.SetUserCacheInfo(userId);
             UserBiz.SetUserCacheInfo(targetUserId);
         }
     });
 }
Пример #10
0
        public void ShowsMessagesFromMultipleFollowedUsers()
        {
            var aliceFollowedBob     = new UserFollowed("Alice", "Bob");
            var aliceFollowedCharlie = new UserFollowed("Alice", "Charlie");

            var bobsPost    = new MessagePosted("Bob", "A message from Bob", fakeClock.HypoteticalNow);
            var charliePost = new MessagePosted("Charlie", "A message from Charlie", fakeClock.HypoteticalNow);

            wallPresenter.Handle(aliceFollowedBob);
            wallPresenter.Handle(aliceFollowedCharlie);
            wallPresenter.Handle(bobsPost);
            wallPresenter.Handle(charliePost);

            var alicesWall = GetWallFor(userName);

            Assert.That(alicesWall[0], Is.EqualTo("Bob - A message from Bob (0 seconds ago)"));
            Assert.That(alicesWall[1], Is.EqualTo("Charlie - A message from Charlie (0 seconds ago)"));
        }
Пример #11
0
        public void Handle(UserFollowed message)
        {
            SetUpFollowersFor(message.SourceUser);

            followers[message.SourceUser].Add(message.TargetUser);
        }
            private void When(UserFollowed evt)
            {
                SubscriptionId = evt.SubscriptionId;

                _quackers.Add(evt.SubscriptionId);
            }
Пример #13
0
 public void Apply(UserFollowed evt)
 {
     FollowingUserIds.Add(evt.OtherUserId);
 }