public async Task Success_Refuse_Pending_Friend_Invitation() { await _relationService.RelationInviteAsync(SenderId, TargetId, CharacterRelationType.Friend); IEnumerable <RelationInvitationDto> invitations = await _relationService.GetPendingInvitationByCharacterIdAsync(TargetId); Assert.IsNotNull(invitations); RelationInvitationDto invitation = invitations.FirstOrDefault(s => s.OwnerId == SenderId); Assert.IsNotNull(invitation); // refuse the invitation List <RelationDto> relation = await _relationService.RelationInviteProcessAsync(invitation.Id, RelationInvitationProcessType.Refuse); IEnumerable <RelationDto> relations = await _relationService.GetRelationListByCharacterIdAsync(SenderId); Assert.IsFalse(relations.Any(s => s.OwnerId == SenderId && s.TargetId == TargetId && s.Type == CharacterRelationType.Friend && relation.Any(c => c.Id == s.Id))); // invitations should be clear IEnumerable <RelationInvitationDto> invitationsEmpty = await _relationService.GetPendingInvitationByCharacterIdAsync(TargetId); Assert.IsTrue(!invitationsEmpty.Any()); await _relationService.RelationRemoveAsync(relations); }
public async Task <RelationInvitationDto> RelationInviteAsync(long senderId, long targetId, CharacterRelationType relationType) { var tmp = new RelationInvitationDto { Id = Guid.NewGuid(), OwnerId = senderId, TargetId = targetId, RelationType = relationType }; await RelationInviteAsync(tmp); return(tmp); }
protected override async Task Handle(RelationInvitationProcessEvent e, CancellationToken cancellation) { IEnumerable <RelationInvitationDto> invitations = await _relationService.GetPendingInvitationByCharacterIdAsync(e.Sender.Id); RelationInvitationDto invitation = invitations.FirstOrDefault(s => s.TargetId == e.Sender.Id && s.OwnerId == e.TargetCharacterId); if (invitation == null) { // no invitation to process return; } await _relationService.RelationInviteProcessAsync(invitation.Id, e.Type); }
protected override async Task <ProcessInvitation.Response> Handle(ProcessInvitation request) { RelationInvitationDto tmp = await _repository.GetByIdAsync(request.InvitationId); if (tmp == null) { return(new ProcessInvitation.Response { Relation = new List <RelationDto>() }); } await _repository.DeleteByIdAsync(request.InvitationId); CharacterDto owner = await _characterService.GetByIdAsync(tmp.OwnerId); CharacterDto target = await _characterService.GetByIdAsync(tmp.TargetId); RelationDto[] relations = { new RelationDto { Id = Guid.NewGuid(), OwnerId = tmp.OwnerId, TargetId = tmp.TargetId, Type = tmp.RelationType, Name = target?.Name ?? tmp.TargetId.ToString() }, new RelationDto { Id = Guid.NewGuid(), OwnerId = tmp.TargetId, TargetId = tmp.OwnerId, Type = tmp.RelationType, Name = owner?.Name ?? tmp.OwnerId.ToString() }, }; if (request.ProcessType == RelationInvitationProcessType.Accept) { await _relations.SaveAsync(relations); } return(new ProcessInvitation.Response { Relation = request.ProcessType == RelationInvitationProcessType.Accept ? new List <RelationDto>(relations) : new List <RelationDto>() }); }
public Task RelationInviteAsync(RelationInvitationDto invitation) { return(BroadcastAsync(new SendInvitation { Invitation = invitation })); }