Beispiel #1
0
        /// <summary>
        /// 更换群主
        /// </summary>
        /// <param name="groupId">群组Id</param>
        /// <param name="newOwnerUserId">新群主UserId</param>
        public void ChangeGroupOwner(long groupId, long newOwnerUserId)
        {
            //更换群主后,原群主转换成群组成员,如果新群主是群组成员则从成员中移除
            GroupEntity group          = groupRepository.Get(groupId);
            long        oldOwnerUserId = group.UserId;

            group.UserId = newOwnerUserId;
            groupRepository.ChangeGroupOwner(groupId, newOwnerUserId);

            //原群主的群组数-1,加入群组数+1
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().CreatedGroupCount(), -1);
            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().JoinedGroupCount(), 1);

            //原群主转换成群组成员
            GroupMember groupMember = GroupMember.New();

            groupMember.GroupId = groupId;
            groupMember.UserId  = oldOwnerUserId;
            groupMemberRepository.Insert(groupMember);

            //新群主的群组数+1,加入群组数-1
            ownerDataService.Change(newOwnerUserId, OwnerDataKeys.Instance().CreatedGroupCount(), 1);

            //如果新群主是群组成员则从成员中移除
            if (IsMember(groupId, newOwnerUserId))
            {
                DeleteGroupMember(groupId, newOwnerUserId);
            }
        }
 void SetStatusInvitationnForJoinGroupEventModule_After(Invitation sender, CommonEventArgs eventArgs)
 {
     if (eventArgs.EventOperationType == EventOperationType.Instance().Update())
     {
         InvitationService invitationService = DIContainer.Resolve <InvitationService>();
         Invitation        invitation        = invitationService.Get(sender.Id);
         if (invitation != null && invitation.InvitationTypeKey == InvitationTypeKeys.Instance().InviteJoinGroup() && invitation.Status == InvitationStatus.Accept)
         {
             GroupService groupService = new GroupService();
             GroupMember  member       = GroupMember.New();
             member.GroupId   = sender.RelativeObjectId;
             member.UserId    = sender.UserId;
             member.IsManager = false;
             groupService.CreateGroupMember(member);
         }
         else if (invitation != null && invitation.InvitationTypeKey == InvitationTypeKeys.Instance().ApplyJoinGroup() && invitation.Status == InvitationStatus.Accept)
         {
             GroupService groupService = new GroupService();
             GroupMember  member       = GroupMember.New();
             member.GroupId   = sender.RelativeObjectId;
             member.UserId    = sender.SenderUserId;
             member.IsManager = false;
             groupService.CreateGroupMember(member);
             IEnumerable <long> a = groupService.GetGroupMemberApplies(sender.RelativeObjectId, GroupMemberApplyStatus.Pending, 20, 1).Where(n => n.UserId == sender.SenderUserId).Select(m => m.Id);
             groupService.ApproveGroupMemberApply(a, true);
         }
         else if (invitation != null && invitation.InvitationTypeKey == InvitationTypeKeys.Instance().ApplyJoinGroup() && invitation.Status == InvitationStatus.Refuse)
         {
             GroupService       groupService = new GroupService();
             IEnumerable <long> a            = groupService.GetGroupMemberApplies(sender.RelativeObjectId, GroupMemberApplyStatus.Pending, 20, 1).Where(n => n.UserId == sender.SenderUserId).Select(m => m.Id);
             groupService.ApproveGroupMemberApply(a, false);
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// 接受/拒绝群组加入申请
        /// </summary>
        /// <param name="groupIds">申请Id列表</param>
        /// <param name="isApproved">是否接受</param>
        public void ApproveGroupMemberApply(IEnumerable <long> applyIds, bool isApproved)
        {
            //设计要点:
            //1、仅允许对待处理状态的申请变更状态;
            //2、通过批准的申请,直接创建GroupMember
            IEnumerable <GroupMemberApply> groupMemberApplies = groupMemberApplyRepository.PopulateEntitiesByEntityIds(applyIds);
            GroupMemberApplyStatus         applyStatus        = isApproved ? GroupMemberApplyStatus.Approved : GroupMemberApplyStatus.Disapproved;
            string operationType = isApproved ? EventOperationType.Instance().Approved() : EventOperationType.Instance().Disapproved();

            foreach (var apply in groupMemberApplies)
            {
                if (apply.ApplyStatus != GroupMemberApplyStatus.Pending)
                {
                    continue;
                }



                apply.ApplyStatus = applyStatus;
                groupMemberApplyRepository.Update(apply);



                EventBus <GroupMemberApply> .Instance().OnAfter(apply, new CommonEventArgs(operationType));

                if (isApproved)
                {
                    GroupMember member = GroupMember.New();
                    member.UserId  = apply.UserId;
                    member.GroupId = apply.GroupId;
                    CreateGroupMember(member);
                }
            }
        }
Beispiel #4
0
 void SetStatusInvitationnForJoinGroupEventModule_After(Invitation sender, CommonEventArgs eventArgs)
 {
     if (eventArgs.EventOperationType == EventOperationType.Instance().Update())
     {
         InvitationService invitationService = DIContainer.Resolve <InvitationService>();
         Invitation        invitation        = invitationService.Get(sender.Id);
         if (invitation != null && invitation.InvitationTypeKey == InvitationTypeKeys.Instance().InviteJoinGroup() && invitation.Status == InvitationStatus.Accept)
         {
             GroupService groupService = new GroupService();
             GroupMember  member       = GroupMember.New();
             member.GroupId   = sender.RelativeObjectId;
             member.UserId    = sender.UserId;
             member.IsManager = false;
             groupService.CreateGroupMember(member);
         }
         else if (invitation != null && invitation.InvitationTypeKey == InvitationTypeKeys.Instance().ApplyJoinGroup() && invitation.Status == InvitationStatus.Accept)
         {
             GroupService groupService = new GroupService();
             GroupMember  member       = GroupMember.New();
             member.GroupId   = sender.RelativeObjectId;
             member.UserId    = sender.SenderUserId;
             member.IsManager = false;
             groupService.CreateGroupMember(member);
         }
     }
 }