requests and friends work completely now

master
Max 5 years ago
parent 8f8b95c5bd
commit cef2e80cf5

@ -57,7 +57,7 @@
</nav>
<div id="menu-button-box">
<button mat-icon-button [matMenuTriggerFor]="requestMenu" [disabled]="!loggedIn" id="menu-button">
<mat-icon [matBadge]="user.receivedRequests.length" matBadgeColor="accent">notifications</mat-icon>
<mat-icon [matBadge]="user.receivedRequests.length" [matBadgeHidden]="!user.receivedRequests.length > 0" matBadgeColor="accent">notifications</mat-icon>
</button>
<button mat-icon-button [matMenuTriggerFor]="menu" id="menu-button">
<mat-icon>more_vert</mat-icon>
@ -66,10 +66,10 @@
<mat-menu #requestMenu="matMenu">
<span mat-menu-item disableRipple="true" disabled="true">friend requests:</span>
<button mat-menu-item *ngFor = "let request of user.receivedRequests" [class.selected]="request === selectedRequest" (click)="$event.stopPropagation();" disableRipple="true">
<button mat-icon-button (click)=acceptRequest(request.id)>
<button mat-icon-button (click)=acceptRequest(request.senderUserID) (click)="$event.stopPropagation();">
<mat-icon>check</mat-icon>
</button>
<button mat-icon-button (click)=denyRequest(request.id)>
<button mat-icon-button (click)=denyRequest(request.senderUserID) (click)="$event.stopPropagation();">
<mat-icon>close</mat-icon>
</button>
<span>{{request.senderUsername}}</span>

@ -4,6 +4,7 @@ import { Observable } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators';
import { DatasharingService } from '../../services/datasharing.service';
import { SelfService } from '../../services/selfservice/self.service';
import { RequestService } from '../../services/request/request.service';
import { environment } from 'src/environments/environment';
import { Levellist } from 'src/app/models/levellist';
import { Http } from '@angular/http';
@ -22,6 +23,7 @@ export class MainNavigationComponent implements OnInit {
public overlayContainer: OverlayContainer,
private data: DatasharingService,
private selfservice: SelfService,
private requestservice: RequestService,
private breakpointObserver: BreakpointObserver,
private http: Http, private router: Router
) {
@ -115,9 +117,32 @@ export class MainNavigationComponent implements OnInit {
}
acceptRequest(id: number) {
console.log('accept request with id: ' + id);
for (let i = 0; i < this.user.receivedRequests.length; i++) {
if (this.user.receivedRequests[i].senderUserID === id) {
this.user.receivedRequests.splice(i, 1);
return;
}
}
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(environment.graphQLUrl, this.requestservice.buildJsonAcceptRequest(id))
.subscribe(response => {
console.log(response);
});
}
denyRequest(id: number) {
console.log('deny request with id: ' + id);
for (let i = 0; i < this.user.receivedRequests.length; i++) {
if (this.user.receivedRequests[i].senderUserID === id) {
this.user.receivedRequests.splice(i, 1);
return;
}
}
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(environment.graphQLUrl, this.requestservice.buildJsonDenyRequest(id))
.subscribe(response => {
console.log(response);
});
}
}

@ -55,7 +55,6 @@ export class ProfileComponent implements OnInit {
this.user.points = response.data.getUser.points;
this.user.level = response.data.getUser.level;
this.rankname = this.levellist.getLevelName(this.user.level);
this.user.friendIDs = response.data.getUser.friends;
} else {
this.profileNotFound = true;
}

@ -62,6 +62,16 @@ export class SearchComponent implements OnInit {
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;
}
}
}
}
});

@ -1,8 +1,3 @@
<!--<div id="header">
<span class="title">Friends</span>
<button id="new" type="submit"><span><i class="fa fa-plus fa-3x" aria-hidden="true"></i></span></button>
<button id="invitations" type="submit"><span><i class="fa fa-envelope-o fa-3x" aria-hidden="true"></i></span></button>
</div>-->
<mat-toolbar>
<span>Friends</span>
<div id="button-box">
@ -10,12 +5,7 @@
</div>
</mat-toolbar>
<div id="friendlist">
<!--<div class="frienditem" *ngFor="let friend of friends"
[class.selected]="friend === selectedFriend" (click)="showFriendProfile(friend)">
<div class="picture">Pic</div>
<div class="name"><span>{{friend.name}}</span></div>
</div>-->
<mat-card class="friend-card" *ngFor="let friend of friends"
<mat-card class="friend-card" *ngFor="let friend of user.friends"
[class.selected]="friend === selectedFriend" (click)="showFriendProfile(friend)"
tabindex="0"
matRipple>

@ -4,6 +4,7 @@ import { Http } from '@angular/http';
import { FriendInfo } from 'src/app/models/friendinfo';
import { Router } from '@angular/router';
import { environment } from 'src/environments/environment';
import { User } from 'src/app/models/user';
@Component({
selector: 'social-friends',
@ -11,44 +12,12 @@ import { environment } from 'src/environments/environment';
styleUrls: ['./friends.component.sass']
})
export class FriendsComponent implements OnInit {
friendIDs: number[] = [29, 27, 30, 31];
friends = new Array<FriendInfo>(); // = ["Friend 1", "Friend 2", "Friend 3", "Friend 4", "Friend 5", "Friend 6"]
user: User;
constructor(private data: DatasharingService, private http: Http, private router: Router) { }
ngOnInit() {
// this.data.currentUserInfo.subscribe(user => {
// this.friendIDs = user.friendIDs})
this.getFriendsNames();
}
getFriendsNames() {
for (const id of this.friendIDs) {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.buildJson(id))
.subscribe(response => {this.readOutFriendsNames(id, response.json()); });
}
}
readOutFriendsNames(pId: number, pResponse: any) {
this.friends.push(new FriendInfo(pId, pResponse.data.getUser.name, pResponse.data.getUser.level ));
}
buildJson(pId: number): any {
const body = {query: `query($userId: ID) {
getUser(userId:$userId) {
name
level
}
}`, variables: {
userId: pId
}};
return body;
this.data.currentUserInfo.subscribe(user => {
this.user = user; });
}
public showFriendProfile(pFriend: FriendInfo) {

@ -1,4 +1,5 @@
import { FriendRequest } from 'src/app/models/friendRequest';
import { FriendInfo } from 'src/app/models/friendinfo';
export class User {
loggedIn = false;
@ -10,7 +11,7 @@ export class User {
level: number;
profilePicture: string;
friendIDs: number[];
friends: FriendInfo[] = new Array();
groupIDs: number[];
chatIDs: number[];
receivedRequests: FriendRequest[] = new Array();

@ -6,6 +6,7 @@ import {DatasharingService} from '../datasharing.service';
import {Router} from '@angular/router';
import {environment} from 'src/environments/environment';
import { FriendRequest } from 'src/app/models/friendRequest';
import { FriendInfo } from 'src/app/models/friendinfo';
@Injectable({
providedIn: 'root'
@ -44,7 +45,9 @@ export class LoginService {
user.email = response.data.login.email;
user.points = response.data.login.points;
user.level = response.data.login.level;
user.friendIDs = response.data.login.friends;
for (const friend of response.data.login.friends) {
user.friends.push(new FriendInfo(friend.id, friend.name, friend.level));
}
user.groupIDs = response.data.login.groups;
user.chatIDs = response.data.login.chats;
for (const request of response.data.login.sentRequests) {
@ -58,7 +61,7 @@ export class LoginService {
friendRequest.senderHandle = request.sender.handle;
user.receivedRequests.push(friendRequest);
}
console.log(user.receivedRequests);
console.log(user.friends);
this.data.changeUserInfo(user);
}
@ -75,7 +78,9 @@ export class LoginService {
receivedRequests{id, sender{name, handle, id}},
sentRequests{receiver{id}},
friends {
id
id,
name,
level
},
groups {
id

@ -5,6 +5,8 @@ import {Router} from '@angular/router';
import { DatasharingService } from '../datasharing.service';
import { User } from 'src/app/models/user';
import { environment } from 'src/environments/environment';
import { FriendRequest } from 'src/app/models/friendRequest';
import { FriendInfo } from 'src/app/models/friendinfo';
@Injectable({
providedIn: 'root'
@ -38,6 +40,7 @@ export class RegisterService {
public updateUserInfo(response: any) {
const user: User = new User();
let friendRequest: FriendRequest = new FriendRequest();
user.loggedIn = true;
user.userID = response.data.register.id;
user.username = response.data.register.name;
@ -45,13 +48,22 @@ export class RegisterService {
user.email = response.data.register.email;
user.points = response.data.register.points;
user.level = response.data.register.level;
user.friendIDs = response.data.register.friends;
for (const friend of response.data.login.friends) {
user.friends.push(new FriendInfo(friend.id, friend.name, friend.level));
}
user.groupIDs = response.data.register.groups;
user.chatIDs = response.data.register.chats;
for (const request of response.data.register.sentRequests) {
user.sentRequestUserIDs.push(request.receiver.id);
}
for (const request of response.data.login.receivedRequests) {
friendRequest = new FriendRequest();
friendRequest.id = request.id;
friendRequest.senderUserID = request.sender.id;
friendRequest.senderUsername = request.sender.name;
friendRequest.senderHandle = request.sender.handle;
user.receivedRequests.push(friendRequest);
}
this.data.changeUserInfo(user);
}
@ -64,8 +76,13 @@ export class RegisterService {
handle,
points,
level,
receivedRequests{id, sender{name, handle, id}},
sentRequests{receiver{id}}
friends{id},
friends {
id,
name,
level
},
groups{id},
chats{id}
}

@ -27,4 +27,29 @@ export class RequestService {
};
return body;
}
public buildJsonAcceptRequest(id_: number): any {
const body = {
query: `mutation($id: ID!) {
acceptRequest(sender: $id, type: FRIENDREQUEST)
}`
, variables: {
id: id_
}
};
return body;
}
public buildJsonDenyRequest(id_: number): any {
const body = {
query: `mutation($id: ID!) {
denyRequest(sender: $id, type: FRIENDREQUEST)
}`
, variables: {
id: id_
}
};
return body;
}
}

@ -24,7 +24,7 @@ export class SearchService {
pUser.handle = user.handle;
pUser.points = user.points;
pUser.level = user.level;
pUser.friendIDs = user.friends;
pUser.friends = user.friends;
users.push(pUser);
}
return users;

@ -6,6 +6,8 @@ import { DatasharingService } from '../datasharing.service';
import { userInfo } from 'os';
import {Router} from '@angular/router';
import { environment } from 'src/environments/environment';
import { FriendRequest } from 'src/app/models/friendRequest';
import { FriendInfo } from 'src/app/models/friendinfo';
@Injectable({
providedIn: 'root'
@ -43,6 +45,7 @@ export class SelfService {
public updateUserInfo(response: any) {
const user: User = new User();
let friendRequest: FriendRequest = new FriendRequest();
user.loggedIn = true;
user.userID = response.data.getSelf.id;
user.username = response.data.getSelf.name;
@ -50,19 +53,48 @@ export class SelfService {
user.email = response.data.getSelf.email;
user.points = response.data.getSelf.points;
user.level = response.data.getSelf.level;
user.friendIDs = response.data.getSelf.friends;
for (const friend of response.data.login.friends) {
user.friends.push(new FriendInfo(friend.id, friend.name, friend.level));
}
user.groupIDs = response.data.getSelf.groups;
user.chatIDs = response.data.getSelf.chats;
for (const request of response.data.getSelf.sentRequests) {
user.sentRequestUserIDs.push(request.receiver.id);
}
for (const request of response.data.login.receivedRequests) {
friendRequest = new FriendRequest();
friendRequest.id = request.id;
friendRequest.senderUserID = request.sender.id;
friendRequest.senderUsername = request.sender.name;
friendRequest.senderHandle = request.sender.handle;
user.receivedRequests.push(friendRequest);
}
this.data.changeUserInfo(user);
}
public buildJson(): any {
const body = {query: `{
getSelf{id, name, email, handle, points, level, sentRequests{receiver{id}}, friends{id}, groups{id},chats{id}}
getSelf{
id,
name,
email,
handle,
points,
level,
receivedRequests{id, sender{name, handle, id}},
sentRequests{receiver{id}},
friends {
id,
name,
level
},
groups {
id
},
chats{
id
}
}
}`, variables: {
}};
return body;

Loading…
Cancel
Save