mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Correct friend database logic
This commit is contained in:
parent
597ed7fb34
commit
d4ae8f7c5c
2 changed files with 15 additions and 8 deletions
|
@ -105,15 +105,15 @@ pub fn approve(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let mut friends = userdata::get_acc_friends(&key);
|
let mut friends = userdata::get_acc_friends(&key);
|
||||||
|
|
||||||
let uid = body["user_id"].as_i64().unwrap();
|
let uid = body["user_id"].as_i64().unwrap();
|
||||||
let index = friends["request_user_id_list"].members().into_iter().position(|r| *r.to_string() == uid.to_string());
|
let index = friends["pending_user_id_list"].members().into_iter().position(|r| *r.to_string() == uid.to_string());
|
||||||
if !index.is_none() {
|
if !index.is_none() {
|
||||||
friends["request_user_id_list"].array_remove(index.unwrap());
|
friends["pending_user_id_list"].array_remove(index.unwrap());
|
||||||
}
|
}
|
||||||
if body["approve"].to_string() == "1" && ! friends["friend_user_id_list"].contains(uid) {
|
if body["approve"].to_string() == "1" && ! friends["friend_user_id_list"].contains(uid) {
|
||||||
friends["friend_user_id_list"].push(uid).unwrap();
|
friends["friend_user_id_list"].push(uid).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
userdata::friend_request_approve(uid, user_id, body["approve"].to_string() == "1");
|
userdata::friend_request_approve(uid, user_id, body["approve"].to_string() == "1", "request_user_id_list");
|
||||||
userdata::save_acc_friends(&key, friends);
|
userdata::save_acc_friends(&key, friends);
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
|
@ -135,7 +135,7 @@ pub fn cancel(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
if !index.is_none() {
|
if !index.is_none() {
|
||||||
friends["request_user_id_list"].array_remove(index.unwrap());
|
friends["request_user_id_list"].array_remove(index.unwrap());
|
||||||
}
|
}
|
||||||
userdata::friend_request_approve(uid, user_id, false);
|
userdata::friend_request_approve(uid, user_id, false, "pending_user_id_list");
|
||||||
userdata::save_acc_friends(&key, friends);
|
userdata::save_acc_friends(&key, friends);
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
|
|
|
@ -215,7 +215,10 @@ pub fn get_acc(auth_key: &str) -> JsonValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_acc_home(auth_key: &str) -> JsonValue {
|
pub fn get_acc_home(auth_key: &str) -> JsonValue {
|
||||||
get_data(auth_key, "userhome")
|
let mut user = get_data(auth_key, "userhome");
|
||||||
|
user["home"]["pending_friend_count"] = get_acc_friends(auth_key)["pending_user_id_list"].len().into();
|
||||||
|
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
pub fn get_acc_missions(auth_key: &str) -> JsonValue {
|
pub fn get_acc_missions(auth_key: &str) -> JsonValue {
|
||||||
get_data(auth_key, "missions")
|
get_data(auth_key, "missions")
|
||||||
|
@ -327,7 +330,7 @@ pub fn friend_request(uid: i64, requestor: i64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn friend_request_approve(uid: i64, requestor: i64, accepted: bool) {
|
pub fn friend_request_approve(uid: i64, requestor: i64, accepted: bool, key: &str) {
|
||||||
let login_token = get_login_token(uid);
|
let login_token = get_login_token(uid);
|
||||||
if login_token == String::new() {
|
if login_token == String::new() {
|
||||||
return;
|
return;
|
||||||
|
@ -335,9 +338,13 @@ pub fn friend_request_approve(uid: i64, requestor: i64, accepted: bool) {
|
||||||
let uid = get_uid(&login_token);
|
let uid = get_uid(&login_token);
|
||||||
let friends = lock_and_select("SELECT friends FROM users WHERE user_id=?1", params!(uid));
|
let friends = lock_and_select("SELECT friends FROM users WHERE user_id=?1", params!(uid));
|
||||||
let mut friends = json::parse(&friends.unwrap()).unwrap();
|
let mut friends = json::parse(&friends.unwrap()).unwrap();
|
||||||
let index = friends["pending_user_id_list"].members().into_iter().position(|r| *r.to_string() == requestor.to_string());
|
let index = friends[key].members().into_iter().position(|r| *r.to_string() == requestor.to_string());
|
||||||
if !index.is_none() {
|
if !index.is_none() {
|
||||||
friends["pending_user_id_list"].array_remove(index.unwrap());
|
friends[key].array_remove(index.unwrap());
|
||||||
|
}
|
||||||
|
let index = friends["request_user_id_list"].members().into_iter().position(|r| *r.to_string() == requestor.to_string());
|
||||||
|
if !index.is_none() {
|
||||||
|
friends["request_user_id_list"].array_remove(index.unwrap());
|
||||||
}
|
}
|
||||||
if accepted && !friends["friend_user_id_list"].contains(requestor) {
|
if accepted && !friends["friend_user_id_list"].contains(requestor) {
|
||||||
friends["friend_user_id_list"].push(requestor).unwrap();
|
friends["friend_user_id_list"].push(requestor).unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue