Self-hosted, federated location sharing app and server that prioritizes user privacy and security
end-to-end-encryption location-sharing privacy self-hosted federated
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

made the friend request api symmetrical

azomDev 1e5f58e7 01598257

+21 -34
+2 -6
app/src/utils/api.ts
··· 36 36 return await post("generate-signup-key"); 37 37 } 38 38 39 - export async function createFriendRequest(friend_id: string): Promise<void> { 40 - await post("create-friend-request", friend_id); 41 - } 42 - 43 - export async function acceptFriendRequest(friend_id: string): Promise<void> { 44 - await post("accept-friend-request", friend_id); 39 + export async function requestFriendRequest(friend_id: string): Promise<void> { 40 + await post("request-friend-request", friend_id); 45 41 } 46 42 47 43 export async function isFriendRequestAccepted(friend_id: string): Promise<boolean> {
+18 -26
server/src/handlers.rs
··· 58 58 return Ok(new_signup_key); 59 59 } 60 60 61 - pub async fn create_friend_request( 61 + pub async fn request_friend_request( 62 62 State(state): State<AppState>, 63 63 Extension(user_id): Extension<String>, 64 - accepter_id: String, 64 + friend_id: String, 65 65 ) -> Result<(), SrvErr> { 66 - if accepter_id == user_id { 66 + if friend_id == user_id { 67 67 ReqBail!("Cannot friend yourself"); 68 68 } 69 69 70 70 let mut friend_requests = state.friend_requests.lock().await; 71 - let link = Link::new(accepter_id, user_id); 72 - if friend_requests.contains(&link) { 73 - ReqBail!("Friend request already exists"); 74 - } 75 - friend_requests.insert(link); 76 - return Ok(()); 77 - } 71 + let link = Link::new(friend_id, user_id); 78 72 79 - pub async fn accept_friend_request( 80 - State(state): State<AppState>, 81 - Extension(user_id): Extension<String>, 82 - sender_id: String, 83 - ) -> Result<(), SrvErr> { 84 - let link = Link::new(user_id, sender_id); 73 + // if we remove sucessfully the link, it means a request already existed 74 + // so we are making the friendship official 75 + let friend_request_accepted = friend_requests.remove(&link); 76 + if friend_request_accepted { 77 + drop(friend_requests); 85 78 86 - let friend_request_accepted = { state.friend_requests.lock().await.remove(&link) }; 79 + let mut pings_state = state.positions.lock().await; 80 + pings_state.insert(link.clone(), RingBuffer::new(state.ring_buffer_cap)); 81 + drop(pings_state); 87 82 88 - if !friend_request_accepted { 89 - ReqBail!("Friend request not found"); 83 + let mut links = state.links.lock().await; 84 + links.insert(link); 85 + drop(links); 86 + } else { 87 + friend_requests.insert(link); 88 + drop(friend_requests); 90 89 } 91 - 92 - let mut pings_state = state.positions.lock().await; 93 - pings_state.insert(link.clone(), RingBuffer::new(state.ring_buffer_cap)); 94 - drop(pings_state); 95 - 96 - let mut links = state.links.lock().await; 97 - links.insert(link); 98 90 99 91 return Ok(()); 100 92 }
+1 -2
server/src/main.rs
··· 50 50 .route("/", post(|| async { "You just sent a POST to /" })) // for testing 51 51 .route("/create-account", post(create_user)) 52 52 .route("/generate-signup-key", post(generate_signup_key)) 53 - .route("/create-friend-request", post(create_friend_request)) 54 - .route("/accept-friend-request", post(accept_friend_request)) 53 + .route("/request-friend-request", post(request_friend_request)) 55 54 .route( 56 55 "/is-friend-request-accepted", 57 56 post(is_friend_request_accepted),