If you don't use the notion of friends between users, you can skip this section. Since the concept of friends is an MQTT chat option for dating or social networks websites.
If friends option is enabled, all MQTT chat features will be limited to the friends list else user can browse the list of all users and can chat with any one.
Add a new user to friends list
To add a new friend to a user friends list: for example adding user with userid =2 to friends list of user with userid=1.
PHP
1
require_once vendor/autoload.php;
2
$userid=1;
3
$friends=newtelifoun\mqttchat\friends($userid);
4
$result=$friends->add(2);
Copied!
1
{
2
"ok":true,
3
"data":{
4
"userid":1,
5
"friendid":2
6
}
7
}
Copied!
Remove user from friends list
To remove for example user[userid=2] from friends list of user[userid=1]:
PHP
1
require_once vendor/autoload.php;
2
$userid=1;
3
$friends=newtelifoun\mqttchat\friends($userid);
4
$result=$friends->remove(2);
Copied!
1
{
2
"ok":true,
3
"data":{}
4
}
Copied!
And to check if a user[userid=2] is friend with user[userid=1] :
PHP
1
require_once vendor/autoload.php;
2
$userid=1;
3
$friends=newtelifoun\mqttchat\friends($userid);
4
$result=$friends->is_friend(2);
Copied!
1
{
2
"ok":false,
3
"error":"not_friends"
4
}
Copied!
Get all user friends
To get user friends list :
PHP
1
require_once vendor/autoload.php;
2
$userid=1;
3
$friends=newtelifoun\mqttchat\friends($userid);
4
$offset=0;
5
$limit=20;
6
$result=$friends->getAll($offset,$limit);
Copied!
1
{
2
"ok":true,
3
"data":{
4
"query":{
5
"offset":0,
6
"limit":20
7
},
8
"friends":[
9
{
10
"userid":2,
11
"name":"user",
12
"surname":"two",
13
"profile_link":"",
14
"avatar_link":"",
15
"gender":0,
16
"status":"offline",
17
"timestamp":1607867157
18
}
19
]
20
}
21
}
Copied!
Delete all user friends
To delete all user friends use deleteAll() function like below: