Friends Management

Managing friends lits.

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
PHP
require_once vendor/autoload.php;
$userid=1;
$friends=new telifoun\mqttchat\friends($userid);
$result=$friends->add(2);
{
"ok": true,
"data": {
"userid": 1,
"friendid": 2
}
}

Remove user from friends list

To remove for example user[userid=2] from friends list of user[userid=1]:

PHP
PHP
require_once vendor/autoload.php;
$userid=1;
$friends=new telifoun\mqttchat\friends($userid);
$result=$friends->remove(2);
{
"ok": true,
"data": {}
}

And to check if a user[userid=2] is friend with user[userid=1] :

PHP
PHP
require_once vendor/autoload.php;
$userid=1;
$friends=new telifoun\mqttchat\friends($userid);
$result=$friends->is_friend(2);
{
"ok": false,
"error": "not_friends"
}

Get all user friends

To get user friends list :

PHP
PHP
require_once vendor/autoload.php;
$userid=1;
$friends=new telifoun\mqttchat\friends($userid);
$offset=0;
$limit=20;
$result=$friends->getAll($offset,$limit);
{
"ok": true,
"data": {
"query": {
"offset": 0,
"limit": 20
},
"friends": [
{
"userid": 2,
"name": "user",
"surname": "two",
"profile_link": "",
"avatar_link": "",
"gender": 0,
"status": "offline",
"timestamp": 1607867157
}
]
}
}

Delete all user friends

To delete all user friends use deleteAll() function like below:

PHP
PHP
require_once vendor/autoload.php;
$userid=1;
$friends=new telifoun\mqttchat\friends($userid);
$result=$friends->deleteAll();
{
"ok": true,
"data": {
"deleted records": 1
}
}