mirror of
https://github.com/twisterarmy/cloud-server.git
synced 2025-03-12 13:31:04 +00:00
implement unfollow feature
This commit is contained in:
parent
e788102b9a
commit
128c3455f6
@ -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);
|
@ -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');
|
||||
}
|
||||
|
@ -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 = {
|
||||
}
|
||||
});
|
||||
},
|
||||
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);
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
@ -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…
x
Reference in New Issue
Block a user