Beispiel #1
0
        /// <summary>
        /// 新建实体时使用
        /// </summary>
        public static ActivityItem New()
        {
            ActivityItem activityItem = new ActivityItem()
            {
            };

            return(activityItem);
        }
        /// <summary>
        /// 检查用户是否接收动态
        /// </summary>
        /// <param name="userId">UserId</param>
        /// <param name="activityItemKey">动态项目标识</param>
        /// <param name="fromOwnerId">动态拥有者</param>
        /// <returns>接收动态返回true,否则返回false</returns>
        private bool IsReceiveActivity(ActivityService activityService, long userId, Activity activity)
        {
            //首先检查是否屏蔽用户
            UserBlockService userBlockService = new UserBlockService();

            if (userBlockService.IsBlockedUser(userId, activity.OwnerId))
            {
                return(false);
            }

            //被验证用户为黑名单用户
            PrivacyService privacyService = new PrivacyService();

            if (privacyService.IsStopedUser(activity.OwnerId, userId))
            {
                return(false);
            }

            //判断指定对象可见
            Dictionary <int, IEnumerable <ContentPrivacySpecifyObject> > dictionary = new ContentPrivacyService().GetPrivacySpecifyObjects(activity.TenantTypeId, activity.SourceId);

            if (dictionary != null && dictionary.Count() > 0)
            {
                foreach (var pair in dictionary)
                {
                    IPrivacySpecifyObjectValidator privacySpecifyUserGetter = DIContainer.ResolveNamed <IPrivacySpecifyObjectValidator>(pair.Key.ToString());
                    foreach (var specifyObject in pair.Value)
                    {
                        if (privacySpecifyUserGetter.Validate(activity.OwnerId, userId, specifyObject.SpecifyObjectId))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }

            //检查用户是否接收该动态项目
            Dictionary <string, bool> userSettings = activityService.GetActivityItemUserSettings(userId);

            if (userSettings.ContainsKey(activity.ActivityItemKey))
            {
                return(userSettings[activity.ActivityItemKey]);
            }
            else
            {
                //如果用户没有设置从默认设置获取
                ActivityItem activityItem = activityService.GetActivityItem(activity.ActivityItemKey);
                if (activityItem != null)
                {
                    return(activityItem.IsUserReceived);
                }
                else
                {
                    return(true);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 更新动态的私有状态
        /// </summary>
        public void UpdatePrivateStatus(long activityId, bool isPrivate, bool isPublic = true)
        {
            //仅isPrivate发生变化才执行以下操作:
            //1、从false->true:参考Generate()中创建用户收件箱、站点收件箱 (注意不要让同一用户及站点收件箱的ActivityId重复)
            //2、从true->false:移除该ActivityId对应的用户收件箱(动态拥有者的收件箱除外)、站点收件箱;

            Activity activity = activityRepository.Get(activityId);

            if (activity == null)
            {
                return;
            }

            //若没有发生变化,则返回
            if (isPrivate == activity.IsPrivate)
            {
                return;
            }

            activityRepository.UpdatePrivateStatus(activityId, isPrivate);

            if (isPrivate)
            {
                //保留动态操作者的收件箱
                activityRepository.DeleteActivityFromUserInboxAndSiteInbox(activityId, activity.UserId);
            }
            else
            {
                //创建用户收件箱、站点收件箱
                ActivityItem activityItem = GetActivityItem(activity.ActivityItemKey);
                if (activityItem == null)
                {
                    return;
                }

                if (!activityItem.IsUserReceived)
                {
                    return;
                }

                IActivityReceiverGetter receiverGetter  = DIContainer.ResolveNamed <IActivityReceiverGetter>(activity.OwnerType.ToString());
                IEnumerable <long>      receiverUserIds = receiverGetter.GetReceiverUserIds(this, activity);

                activityRepository.InsertUserInboxs(activity.ActivityId, receiverUserIds);
                if (isPublic)
                {
                    //推送给站点动态
                    if (activityItem.IsSiteReceived && activity.OwnerType == ActivityOwnerTypes.Instance().User())
                    {
                        activityRepository.InsertSiteInbox(activity.ActivityId);
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 生成动态
        /// </summary>
        /// <param name="activity">待生成的动态</param>
        /// <param name="toMyInbox">是否加入我的动态收件箱</param>
        public void Generate(Activity activity, bool toMyInbox)
        {
            ActivityItem activityItem = GetActivityItem(activity.ActivityItemKey);

            if (activityItem == null)
            {
                return;
            }
            //1、首先检查IsOnlyOnce是否为true,如果为true并且已经生成过则仅更新动态的最后更新时间
            if (activityItem.IsOnlyOnce)
            {
                //检测是否已经存在,并更新动态的最后更新时间
                if (activityRepository.CheckExistAndUpdateLastModified(activity.OwnerId, activity.OwnerType, activity.ActivityItemKey))
                {
                    return;
                }
            }

            //2、如果存在ReferenceId,更新OwnerType+TenantTypeId+ReferenceId对应动态的LastModified;
            if (activity.ReferenceId > 0)
            {
                //对应主体内容动态的最后更新时间设置为当前时间(可能有多个Owner)
                activityRepository.UpdateLastModified(activity.ReferenceTenantTypeId, activity.ReferenceId);
                //3、判断用户是否对同一主体内容产生过从属内容动态,如果产生过则替换成本次操作;  处理类似连续回复的情况
                if (activityRepository.CheckExistAndUpdateSource(activity))
                {
                    return;
                }
            }

            //生成拥有者动态
            activityRepository.Insert(activity);

            //该类操作是否需要给用户推送动态
            if (!activityItem.IsUserReceived)
            {
                return;
            }

            //4、toMyInbox = true,也会加入自己的时间线(动态收件箱)
            if (toMyInbox)
            {
                //加入自己的时间线(动态收件箱)
                activityRepository.InsertUserInboxs(activity.ActivityId, new List <long> {
                    activity.UserId
                });
            }

            //私有内容不推送给其他用户
            if (activity.IsPrivate)
            {
                return;
            }

            //5、通过IsReceiveActivity()检查,是否给该粉丝推送动态,推送时确保 ActivityId+UserId 已存在不再添加;
            IActivityReceiverGetter receiverGetter  = DIContainer.ResolveNamed <IActivityReceiverGetter>(activity.OwnerType.ToString());
            IEnumerable <long>      receiverUserIds = receiverGetter.GetReceiverUserIds(this, activity);

            activityRepository.InsertUserInboxs(activity.ActivityId, receiverUserIds);

            //推送给站点动态
            if (activityItem.IsSiteReceived && activity.OwnerType == ActivityOwnerTypes.Instance().User())
            {
                activityRepository.InsertSiteInbox(activity.ActivityId);
            }
        }
Beispiel #5
0
 /// <summary>
 /// 新建实体时使用
 /// </summary>
 public static ActivityItem New()
 {
     ActivityItem activityItem = new ActivityItem() { };
     return activityItem;
 }