Search in sources :

Example 1 with SocialRelation

use of com.faforever.server.entity.SocialRelation in project faf-java-server by FAForever.

the class SocialService method addFriend.

@Transactional
public void addFriend(Player requester, int friendId) {
    removeFoe(requester, friendId);
    log.debug("Adding '{}' as a friend of player '{}'", friendId, requester);
    socialRelationRepository.save(new SocialRelation(requester.getId(), requester, friendId, SocialRelationStatus.FRIEND));
}
Also used : SocialRelation(com.faforever.server.entity.SocialRelation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SocialRelation

use of com.faforever.server.entity.SocialRelation in project faf-java-server by FAForever.

the class SocialService method onPlayerOnlineEvent.

@EventListener
public void onPlayerOnlineEvent(PlayerOnlineEvent event) {
    Player player = event.getPlayer();
    List<SocialRelation> socialRelations = player.getSocialRelations();
    if (socialRelations == null) {
        return;
    }
    clientService.sendSocialRelations(new SocialRelationListResponse(socialRelations.stream().map(socialRelation -> new SocialRelationResponse(socialRelation.getSubjectId(), RelationType.valueOf(socialRelation.getStatus().toString()))).collect(Collectors.toList())), player);
}
Also used : SocialRelation(com.faforever.server.entity.SocialRelation) SocialRelationStatus(com.faforever.server.entity.SocialRelationStatus) EventListener(org.springframework.context.event.EventListener) RelationType(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse.RelationType) Collectors(java.util.stream.Collectors) Player(com.faforever.server.entity.Player) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SocialRelation(com.faforever.server.entity.SocialRelation) Service(org.springframework.stereotype.Service) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) ClientService(com.faforever.server.client.ClientService) Transactional(org.springframework.transaction.annotation.Transactional) Player(com.faforever.server.entity.Player) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) EventListener(org.springframework.context.event.EventListener)

Example 3 with SocialRelation

use of com.faforever.server.entity.SocialRelation in project faf-java-server by FAForever.

the class SocialServiceTest method addFriend.

@Test
public void addFriend() throws Exception {
    instance.addFriend(requester, 5);
    verify(socialRelationRepository).deleteByPlayerIdAndSubjectIdAndStatus(requester.getId(), 5, SocialRelationStatus.FOE);
    verify(socialRelationRepository).save(captor.capture());
    SocialRelation socialRelation = captor.getValue();
    assertThat(socialRelation.getStatus(), is(SocialRelationStatus.FRIEND));
    assertThat(socialRelation.getSubjectId(), is(5));
    assertThat(socialRelation.getPlayerId(), is(requester.getId()));
}
Also used : SocialRelation(com.faforever.server.entity.SocialRelation) Test(org.junit.Test)

Example 4 with SocialRelation

use of com.faforever.server.entity.SocialRelation in project faf-java-server by FAForever.

the class SocialServiceTest method addFoe.

@Test
public void addFoe() throws Exception {
    instance.addFoe(requester, 5);
    verify(socialRelationRepository).deleteByPlayerIdAndSubjectIdAndStatus(requester.getId(), 5, SocialRelationStatus.FRIEND);
    verify(socialRelationRepository).save(captor.capture());
    SocialRelation socialRelation = captor.getValue();
    assertThat(socialRelation.getStatus(), is(SocialRelationStatus.FOE));
    assertThat(socialRelation.getSubjectId(), is(5));
    assertThat(socialRelation.getPlayerId(), is(requester.getId()));
}
Also used : SocialRelation(com.faforever.server.entity.SocialRelation) Test(org.junit.Test)

Example 5 with SocialRelation

use of com.faforever.server.entity.SocialRelation in project faf-java-server by FAForever.

the class SocialServiceTest method onAuthenticationSuccess.

@Test
public void onAuthenticationSuccess() throws Exception {
    User user = (User) new User().setPlayer(new Player().setSocialRelations(Arrays.asList(new SocialRelation(1, null, 10, SocialRelationStatus.FRIEND), new SocialRelation(2, null, 11, SocialRelationStatus.FOE)))).setPassword("pw").setLogin("junit");
    FafUserDetails userDetails = new FafUserDetails(user);
    instance.onPlayerOnlineEvent(new PlayerOnlineEvent(this, userDetails.getPlayer()));
    ArgumentCaptor<SocialRelationListResponse> captor = ArgumentCaptor.forClass(SocialRelationListResponse.class);
    verify(clientService).sendSocialRelations(captor.capture(), any());
    SocialRelationListResponse response = captor.getValue();
    assertThat(response, instanceOf(SocialRelationListResponse.class));
    assertThat(response.getSocialRelations(), hasSize(2));
    assertThat(response.getSocialRelations().get(0), is(new SocialRelationResponse(10, RelationType.FRIEND)));
    assertThat(response.getSocialRelations().get(1), is(new SocialRelationResponse(11, RelationType.FOE)));
}
Also used : SocialRelation(com.faforever.server.entity.SocialRelation) Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) FafUserDetails(com.faforever.server.security.FafUserDetails) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) Test(org.junit.Test)

Aggregations

SocialRelation (com.faforever.server.entity.SocialRelation)6 Test (org.junit.Test)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Player (com.faforever.server.entity.Player)2 PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)2 SocialRelationResponse (com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse)2 ClientService (com.faforever.server.client.ClientService)1 SocialRelationStatus (com.faforever.server.entity.SocialRelationStatus)1 User (com.faforever.server.entity.User)1 FafUserDetails (com.faforever.server.security.FafUserDetails)1 RelationType (com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse.RelationType)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 EventListener (org.springframework.context.event.EventListener)1 Service (org.springframework.stereotype.Service)1