Esempio n. 1
0
        /// <summary>
        /// 动态处理程序
        /// </summary>
        /// <param name="groupMember"></param>
        /// <param name="eventArgs"></param>
        private void GroupMemberActivityModule_After(GroupMember groupMember, CommonEventArgs eventArgs)
        {
            ActivityService activityService = new ActivityService();
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                //生成动态
                if (groupMember == null)
                    return;
                var group = new GroupService().Get(groupMember.GroupId);
                if (group == null)
                    return;
                //生成Owner为群组的动态
                Activity actvityOfGroup = Activity.New();
                actvityOfGroup.ActivityItemKey = ActivityItemKeys.Instance().CreateGroupMember();
                actvityOfGroup.ApplicationId = GroupConfig.Instance().ApplicationId;
                actvityOfGroup.IsOriginalThread = true;
                actvityOfGroup.IsPrivate = !group.IsPublic;
                actvityOfGroup.UserId = groupMember.UserId;
                actvityOfGroup.ReferenceId = 0;
                actvityOfGroup.ReferenceTenantTypeId = string.Empty;
                actvityOfGroup.SourceId = groupMember.Id;
                actvityOfGroup.TenantTypeId = TenantTypeIds.Instance().User();
                actvityOfGroup.OwnerId = group.GroupId;
                actvityOfGroup.OwnerName = group.GroupName;
                actvityOfGroup.OwnerType = ActivityOwnerTypes.Instance().Group();

                activityService.Generate(actvityOfGroup, false);

                //生成Owner为用户的动态
                Activity actvityOfUser = Activity.New();
                actvityOfUser.ActivityItemKey = ActivityItemKeys.Instance().JoinGroup();
                actvityOfUser.ApplicationId = actvityOfGroup.ApplicationId;
                actvityOfUser.HasImage = actvityOfGroup.HasImage;
                actvityOfUser.HasMusic = actvityOfGroup.HasMusic;
                actvityOfUser.HasVideo = actvityOfGroup.HasVideo;
                actvityOfUser.IsOriginalThread = actvityOfGroup.IsOriginalThread;
                actvityOfUser.IsPrivate = actvityOfGroup.IsPrivate;
                actvityOfUser.UserId = actvityOfGroup.UserId;
                actvityOfUser.ReferenceId = actvityOfGroup.ReferenceId;
                actvityOfGroup.ReferenceTenantTypeId = actvityOfGroup.ReferenceTenantTypeId;
                actvityOfUser.SourceId = actvityOfGroup.SourceId;

                actvityOfUser.TenantTypeId = actvityOfGroup.TenantTypeId;
                actvityOfUser.OwnerId = groupMember.UserId;
                actvityOfUser.OwnerName = groupMember.User.DisplayName;
                actvityOfUser.OwnerType = ActivityOwnerTypes.Instance().User();
                activityService.Generate(actvityOfUser, false);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) //删除动态
            {
                activityService.DeleteSource(TenantTypeIds.Instance().User(), groupMember.UserId);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 群组成员实体
 /// </summary>
 public static GroupMember New()
 {
     GroupMember groupMember = new GroupMember()
     {
         JoinDate = DateTime.UtcNow
     };
     return groupMember;
 }
        /// <summary>
        /// 增加群组成员
        /// </summary>
        /// <param name="groupMember"></param>
        public void CreateGroupMember(GroupMember groupMember)
        {
            //设计要点:
            //1、同一个群组不允许用户重复加入
            //2、群主不允许成为群组成员
            if (IsMember(groupMember.GroupId, groupMember.UserId))
                return;
            if (IsOwner(groupMember.GroupId, groupMember.UserId))
                return;
            long id = 0;
            long.TryParse(groupMemberRepository.Insert(groupMember).ToString(), out id);

            if (id > 0)
            {
                EventBus<GroupMember>.Instance().OnAfter(groupMember, new CommonEventArgs(EventOperationType.Instance().Create()));
                //用户的参与群组数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(groupMember.UserId, OwnerDataKeys.Instance().JoinedGroupCount(), 1);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 设置/取消管理员通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void SetManagerNoticeEventModule_After(GroupMember sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType != EventOperationType.Instance().SetGroupManager() && eventArgs.EventOperationType != EventOperationType.Instance().CancelGroupManager())
                return;

            GroupService groupService = new GroupService();
            GroupEntity entity = groupService.Get(sender.GroupId);
            if (entity == null)
                return;

            User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId);
            if (senderUser == null)
                return;

            NoticeService noticeService = DIContainer.Resolve<NoticeService>();

            Notice notice = Notice.New();
            notice.UserId = sender.UserId;
            notice.ApplicationId = GroupConfig.Instance().ApplicationId;
            notice.TypeId = NoticeTypeIds.Instance().Hint();
            notice.LeadingActorUserId = 0;
            notice.LeadingActor = string.Empty;
            notice.LeadingActorUrl = string.Empty;
            notice.RelativeObjectId = sender.GroupId;
            notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64);
            notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));

            if (eventArgs.EventOperationType == EventOperationType.Instance().SetGroupManager())
            {
                notice.TemplateName = NoticeTemplateNames.Instance().SetGroupManager();
            }
            else
            {
                notice.TemplateName = NoticeTemplateNames.Instance().CannelGroupManager();
            }
            noticeService.Create(notice);
        }
Esempio n. 5
0
        /// <summary>
        /// 通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void GroupMemberNoticeModule_After(GroupMember sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType != EventOperationType.Instance().Delete() && eventArgs.EventOperationType != EventOperationType.Instance().Create() && sender != null)
                return;
            GroupService groupService = new GroupService();
            GroupEntity entity = groupService.Get(sender.GroupId);
            if (entity == null)
                return;

            User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId);
            if (senderUser == null)
                return;

            NoticeService noticeService = DIContainer.Resolve<NoticeService>();
            Notice notice;

            List<long> toUserIds = new List<long>();
            toUserIds.Add(entity.UserId);
            toUserIds.AddRange(entity.GroupManagers.Select(n => n.UserId));
            //删除群组成员通知群管理员
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                foreach (var toUserId in toUserIds)
                {
                    if (toUserId == sender.UserId)
                        continue;
                    notice = Notice.New();
                    notice.UserId = toUserId;
                    notice.ApplicationId = GroupConfig.Instance().ApplicationId;
                    notice.TypeId = NoticeTypeIds.Instance().Hint();
                    notice.LeadingActorUserId = sender.UserId;
                    notice.LeadingActor = senderUser.DisplayName;
                    notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                    notice.RelativeObjectId = sender.GroupId;
                    notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64);
                    notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));
                    notice.TemplateName = NoticeTemplateNames.Instance().MemberQuit();
                    noticeService.Create(notice);
                }
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) //添加群成员时向群管理员发送通知
            {
                foreach (var toUserId in toUserIds)
                {
                    if (toUserId == sender.UserId)
                        continue;
                    notice = Notice.New();
                    notice.UserId = toUserId;
                    notice.ApplicationId = GroupConfig.Instance().ApplicationId;
                    notice.TypeId = NoticeTypeIds.Instance().Hint();
                    notice.LeadingActorUserId = sender.UserId;
                    notice.LeadingActor = senderUser.DisplayName;
                    notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                    notice.RelativeObjectId = sender.GroupId;
                    notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64);
                    notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));
                    notice.TemplateName = NoticeTemplateNames.Instance().MemberJoin();
                    noticeService.Create(notice);
                }
                //向加入者发送通知

                //notice = Notice.New();
                //notice.UserId = sender.UserId;
                //notice.ApplicationId = GroupConfig.Instance().ApplicationId;
                //notice.TypeId = NoticeTypeIds.Instance().Hint();
                //notice.LeadingActorUserId = sender.UserId;
                //notice.LeadingActor = senderUser.DisplayName;
                //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                //notice.RelativeObjectId = sender.GroupId;
                //notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64);
                //notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));
                //notice.TemplateName = NoticeTemplateNames.Instance().MemberApplyApproved();
                //noticeService.Create(notice);
            }
        }