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));
}
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);
}
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()));
}
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()));
}
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)));
}
Aggregations