Browse Source

implement unfollow feature

main
ghost 3 years ago
parent
commit
128c3455f6
  1. 29
      src/application/controller/api/follow/delete.php
  2. 3
      src/bootstrap.php
  3. 27
      src/public/js/module/following.js
  4. 32
      src/system/twister.php

29
src/application/controller/api/follow/delete.php

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
<?php
$response = [
'success' => false,
'message' => _('Internal server error'),
];
if (isset($_SESSION['userName'])) {
$userName = isset($_POST['userName']) ? $_POST['userName'] : false;
$result = $_twister->unFollow($_SESSION['userName'], [$_POST['userName']]);
$response = [
'success' => true,
'message' => _('Unfollowed successfully'),
];
} else {
$response = [
'success' => false,
'message' => _('Session expired. Please, reload the page.'),
];
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode($response);

3
src/bootstrap.php

@ -79,6 +79,9 @@ if (isset($_GET['_route_'])) { @@ -79,6 +79,9 @@ if (isset($_GET['_route_'])) {
case 'api/follow/get':
require(PROJECT_DIR . '/application/controller/api/follow/get.php');
break;
case 'api/follow/delete':
require(PROJECT_DIR . '/application/controller/api/follow/delete.php');
break;
default:
require(PROJECT_DIR . '/application/controller/error/404.php');
}

27
src/public/js/module/following.js

@ -40,7 +40,7 @@ var ModuleFollowing = { @@ -40,7 +40,7 @@ var ModuleFollowing = {
$('<i/>', {
'class': 'bi bi-x-circle',
'title': 'Unfollow',
'onclick': '',
'onclick': 'ModuleFollowing.unFollow(\'' + list + '\', \'' + userName + '\', true)',
})
)
)
@ -76,4 +76,29 @@ var ModuleFollowing = { @@ -76,4 +76,29 @@ var ModuleFollowing = {
}
});
},
unFollow: function(list, userName, reFresh) {
$.ajax({
url: 'api/follow/delete',
type: 'POST',
data: {
userName: userName
},
success: function (response) {
if (response.success) {
if (reFresh) {
ModuleFollowing.load(list, reFresh);
}
} else {
alert(response.message);
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
},
}

32
src/system/twister.php

@ -180,6 +180,38 @@ class Twister { @@ -180,6 +180,38 @@ class Twister {
return false;
}
public function unFollow(string $userName, array $userNames) {
$this->_curl->prepare(
'/',
'POST',
30,
[
'jsonrpc' => '2.0',
'method' => 'unfollow',
'params' => [
$userName,
$userNames
],
'id' => time() + rand()
]
);
if ($response = $this->_curl->execute()) {
if ($response['error']) {
$this->_error = _($response['error']['message']);
} else {
return $response['result'];
}
}
return false;
}
public function getFollowing(string $userName) {
$this->_curl->prepare(

Loading…
Cancel
Save