|
|
@ -5,6 +5,7 @@ import {Headers, Http} from '@angular/http';
|
|
|
|
import { User } from 'src/app/models/user';
|
|
|
|
import { User } from 'src/app/models/user';
|
|
|
|
import {environment} from 'src/environments/environment';
|
|
|
|
import {environment} from 'src/environments/environment';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
|
|
|
import { DatasharingService } from '../../services/datasharing.service';
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
selector: 'home-search',
|
|
|
|
selector: 'home-search',
|
|
|
@ -12,16 +13,22 @@ import { Router } from '@angular/router';
|
|
|
|
styleUrls: ['./search.component.sass']
|
|
|
|
styleUrls: ['./search.component.sass']
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class SearchComponent implements OnInit {
|
|
|
|
export class SearchComponent implements OnInit {
|
|
|
|
|
|
|
|
loading = false;
|
|
|
|
searchValue = ' ';
|
|
|
|
searchValue = ' ';
|
|
|
|
category = 'user';
|
|
|
|
category = 'user';
|
|
|
|
|
|
|
|
user: User;
|
|
|
|
foundUsers: Array<User>;
|
|
|
|
foundUsers: Array<User>;
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
constructor(
|
|
|
|
private searchService: SearchService,
|
|
|
|
private searchService: SearchService,
|
|
|
|
private requestService: RequestService,
|
|
|
|
private requestService: RequestService,
|
|
|
|
private http: Http,
|
|
|
|
private http: Http,
|
|
|
|
private router: Router) { }
|
|
|
|
private router: Router,
|
|
|
|
|
|
|
|
private data: DatasharingService) { }
|
|
|
|
ngOnInit() {
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
this.data.currentUserInfo.subscribe(user => {
|
|
|
|
|
|
|
|
this.user = user;
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
changeCategory(value: string) {
|
|
|
|
changeCategory(value: string) {
|
|
|
@ -34,6 +41,7 @@ export class SearchComponent implements OnInit {
|
|
|
|
this.searchValue = searchWord;
|
|
|
|
this.searchValue = searchWord;
|
|
|
|
if (searchWord) { // if not null or empty
|
|
|
|
if (searchWord) { // if not null or empty
|
|
|
|
if (this.category === 'user') {
|
|
|
|
if (this.category === 'user') {
|
|
|
|
|
|
|
|
this.loading = true;
|
|
|
|
this.findUser(searchWord);
|
|
|
|
this.findUser(searchWord);
|
|
|
|
} else if (this.category === 'groupe') {
|
|
|
|
} else if (this.category === 'groupe') {
|
|
|
|
// this.findUserByHandle(searchWord);
|
|
|
|
// this.findUserByHandle(searchWord);
|
|
|
@ -47,9 +55,28 @@ export class SearchComponent implements OnInit {
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
this.http.post(environment.graphQLUrl, this.searchService.buildJsonUser(name))
|
|
|
|
this.http.post(environment.graphQLUrl, this.searchService.buildJsonUser(name))
|
|
|
|
.subscribe(response => {
|
|
|
|
.subscribe(response => {
|
|
|
|
console.log('response received');
|
|
|
|
|
|
|
|
console.log(response);
|
|
|
|
|
|
|
|
this.foundUsers = this.searchService.renderUsers(response.json());
|
|
|
|
this.foundUsers = this.searchService.renderUsers(response.json());
|
|
|
|
|
|
|
|
for (const foundUser of this.foundUsers) {
|
|
|
|
|
|
|
|
if (!this.user.loggedIn) {foundUser.allowedToSendRequest = false; } else {
|
|
|
|
|
|
|
|
for (const receiverID of this.user.sentRequestUserIDs) {
|
|
|
|
|
|
|
|
if (foundUser.userID === receiverID ||
|
|
|
|
|
|
|
|
foundUser.userID === this.user.userID) {
|
|
|
|
|
|
|
|
foundUser.allowedToSendRequest = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const friend of this.user.friends) {
|
|
|
|
|
|
|
|
if (foundUser.userID === friend.id) {
|
|
|
|
|
|
|
|
foundUser.allowedToSendRequest = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const sender of this.user.receivedRequests) {
|
|
|
|
|
|
|
|
if (foundUser.userID === sender.senderUserID) {
|
|
|
|
|
|
|
|
foundUser.allowedToSendRequest = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -58,12 +85,11 @@ export class SearchComponent implements OnInit {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public sendFriendRequest(user: User) {
|
|
|
|
public sendFriendRequest(user: User) {
|
|
|
|
|
|
|
|
user.allowedToSendRequest = false;
|
|
|
|
const headers = new Headers();
|
|
|
|
const headers = new Headers();
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
this.http.post(environment.graphQLUrl, this.requestService.buildJsonRequest(user.userID, 'FRIENDREQUEST'))
|
|
|
|
this.http.post(environment.graphQLUrl, this.requestService.buildJsonRequest(user.userID, 'FRIENDREQUEST'))
|
|
|
|
.subscribe(response => {
|
|
|
|
.subscribe(response => {
|
|
|
|
console.log('response received');
|
|
|
|
|
|
|
|
console.log(response);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|