-
Notifications
You must be signed in to change notification settings - Fork 0
/
FriendRequest.cpp
50 lines (40 loc) · 1.07 KB
/
FriendRequest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "FriendRequest.h"
#include "User.h"
#include "Date.h"
#include <string>
using namespace std;
FriendRequest::FriendRequest(User *to, User *from){
userto=to;
userfrom=from;
state="pending"; //All created friend request have a pending state, then a user decides if he wants to accept
timestamp.updateTime();
}
User* FriendRequest::getUserTo(){
return userto;
}
User* FriendRequest::getUserFrom(){
return userfrom;
}
Date FriendRequest::getTimestamp(){
return timestamp;
}
void FriendRequest::setState(string s){
if(s=="accept"||s=="decline"){ /*If a friend request gets accepted or declined
there is no need for it to exist*/
state=s;
userto->removeFriendRequest(this);
}
else{
state="pending";
}
}
string FriendRequest::toString(){
string s;
if(state == "accept"){s="accepted";}
else if(state == "decline"){s="declined";}
else {s="pending";}
return "Name: "+userfrom->getName()+"\tstate: "+ s + "\t" + timestamp.toString();
}
void FriendRequest::setTimestamp(string t){
timestamp.setTime(t);
}