diff --git a/src/endpoints/users/getUser.cr b/src/endpoints/users/getUser.cr index 3c02ae4..d0e95dd 100644 --- a/src/endpoints/users/getUser.cr +++ b/src/endpoints/users/getUser.cr @@ -10,6 +10,12 @@ CrystalGauntlet.endpoints["/getGJUserInfo20.php"] = ->(context : HTTP::Server::C id, username, is_admin, messages_enabled, friend_requests_enabled, comments_enabled, youtube_url, twitter_url, twitch_url, created_at, user_id, stars, demons, coins, user_coins, diamonds, orbs, creator_points, icon_type, color1, color2, glow, cube, ship, ball, ufo, wave, robot, spider, explosion = DATABASE.query_one("select accounts.id, accounts.username, is_admin, messages_enabled, friend_requests_enabled, comments_enabled, youtube_url, twitter_url, twitch_url, accounts.created_at, users.id, stars, demons, coins, user_coins, diamonds, orbs, creator_points, icon_type, color1, color2, glow, cube, ship, ball, ufo, wave, robot, spider, explosion from accounts join users on accounts.id = users.account_id where accounts.id = ?", params["targetAccountID"], as: {Int32, String, Int32, Int32, Int32, Int32, String?, String?, String?, String, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32}) + is_friend = DATABASE.scalar("select count(*) from friend_links where (account_id_1 = ? and account_id_2 = ?) or (account_id_2 = ? and account_id_1 = ?)", account_id, id, account_id, id).as(Int64) > 0 + begin + friend_request_id, friend_request_body, friend_request_created_at, from = DATABASE.query_one("select id, body, created_at, from_account_id from friend_requests where from_account_id = ? or to_account_id = ?", id, id, as: {Int32, String, String, Int32}) + rescue + end + return CrystalGauntlet::Format.fmt_hash({ 1 => username, 2 => user_id, @@ -35,13 +41,11 @@ CrystalGauntlet.endpoints["/getGJUserInfo20.php"] = ->(context : HTTP::Server::C # registered or not; always 1 here 29 => 1, 30 => 1, # rank; todo - # 31 = isnt (0) or is (1) friend or (3) incoming request or (4) outgoing request - # todo - 31 => 0, - # also w/ friend requests: - # 32 => id, - # 35 => comment, - # 37 => date, + # isnt (0) or is (1) friend or (3) incoming request or (4) outgoing request + 31 => friend_request_id ? (from == account_id ? 4 : 3) : (is_friend ? 1 : 0), + 32 => friend_request_id, + 35 => friend_request_body, + 37 => friend_request_created_at ? Time.parse(friend_request_created_at, Format::TIME_FORMAT, Time::Location::UTC) : "", 38 => account_id == id ? DATABASE.scalar("select count(*) from messages where (to_account_id = ? and read_at is null)", id).as(Int64) : 0, 39 => account_id == id ? DATABASE.scalar("select count(*) from friend_requests where (to_account_id = ? and read_at is null)", id).as(Int64) : 0, 40 => account_id == id ? DATABASE.scalar("select count(*) from friend_links where (account_id_1 = ? and read_at_1 is null) or (account_id_2 = ? and read_at_2 is null)", id, id).as(Int64) : 0,