mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Implement /api/friend/delete
This commit is contained in:
parent
60f8e96406
commit
608cb7654f
3 changed files with 47 additions and 6 deletions
|
@ -117,6 +117,9 @@ async fn friend_approve(req: HttpRequest, body: String) -> HttpResponse { router
|
|||
#[post("/api/friend/request/cancel")]
|
||||
async fn friend_cancel(req: HttpRequest, body: String) -> HttpResponse { router::friend::cancel(req, body) }
|
||||
|
||||
#[post("/api/friend/delete")]
|
||||
async fn friend_delete(req: HttpRequest, body: String) -> HttpResponse { router::friend::delete(req, body) }
|
||||
|
||||
#[post("/api/live/guest")]
|
||||
async fn live_guest(req: HttpRequest, body: String) -> HttpResponse { router::live::guest(req, body) }
|
||||
|
||||
|
@ -265,6 +268,7 @@ async fn main() -> std::io::Result<()> {
|
|||
.service(friend_request)
|
||||
.service(friend_approve)
|
||||
.service(friend_cancel)
|
||||
.service(friend_delete)
|
||||
.service(mission)
|
||||
.service(mission_clear)
|
||||
.service(mission_receive)
|
||||
|
|
|
@ -108,13 +108,13 @@ pub fn approve(req: HttpRequest, body: String) -> HttpResponse {
|
|||
let index = friends["pending_user_id_list"].members().into_iter().position(|r| *r.to_string() == uid.to_string());
|
||||
if !index.is_none() {
|
||||
friends["pending_user_id_list"].array_remove(index.unwrap());
|
||||
}
|
||||
if body["approve"].to_string() == "1" && ! friends["friend_user_id_list"].contains(uid) {
|
||||
friends["friend_user_id_list"].push(uid).unwrap();
|
||||
}
|
||||
|
||||
userdata::friend_request_approve(uid, user_id, body["approve"].to_string() == "1", "request_user_id_list");
|
||||
userdata::save_acc_friends(&key, friends);
|
||||
}
|
||||
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
|
@ -145,3 +145,25 @@ pub fn cancel(req: HttpRequest, body: String) -> HttpResponse {
|
|||
};
|
||||
global::send(resp)
|
||||
}
|
||||
|
||||
pub fn delete(req: HttpRequest, body: String) -> HttpResponse {
|
||||
let key = global::get_login(req.headers(), &body);
|
||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||
let user_id = userdata::get_acc(&key)["user"]["id"].as_i64().unwrap();
|
||||
let mut friends = userdata::get_acc_friends(&key);
|
||||
|
||||
let uid = body["user_id"].as_i64().unwrap();
|
||||
let index = friends["friend_user_id_list"].members().into_iter().position(|r| *r.to_string() == uid.to_string());
|
||||
if !index.is_none() {
|
||||
friends["friend_user_id_list"].array_remove(index.unwrap());
|
||||
}
|
||||
userdata::friend_remove(uid, user_id);
|
||||
userdata::save_acc_friends(&key, friends);
|
||||
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
"data": []
|
||||
};
|
||||
global::send(resp)
|
||||
}
|
||||
|
|
|
@ -362,3 +362,18 @@ pub fn friend_request_disabled(uid: i64) -> bool {
|
|||
let user = json::parse(&user.unwrap()).unwrap();
|
||||
user["user"]["friend_request_disabled"].to_string() == "1"
|
||||
}
|
||||
|
||||
pub fn friend_remove(uid: i64, requestor: i64) {
|
||||
let login_token = get_login_token(uid);
|
||||
if login_token == String::new() {
|
||||
return;
|
||||
}
|
||||
let uid = get_uid(&login_token);
|
||||
let friends = lock_and_select("SELECT friends FROM users WHERE user_id=?1", params!(uid));
|
||||
let mut friends = json::parse(&friends.unwrap()).unwrap();
|
||||
let index = friends["friend_user_id_list"].members().into_iter().position(|r| *r.to_string() == requestor.to_string());
|
||||
if !index.is_none() {
|
||||
friends["friend_user_id_list"].array_remove(index.unwrap());
|
||||
}
|
||||
lock_and_exec("UPDATE users SET friends=?1 WHERE user_id=?2", params!(json::stringify(friends), uid));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue