|
1 |
| -use crate::components::app::freenet_api::freenet_synchronizer::SynchronizerMessage; |
2 |
| -use crate::components::app::{PENDING_INVITES, ROOMS, SYNCHRONIZER}; |
| 1 | +use crate::components::app::freenet_api::{ |
| 2 | + freenet_synchronizer::SynchronizerMessage, FreenetSynchronizer, |
| 3 | +}; |
| 4 | +use crate::components::app::{PENDING_INVITES, ROOMS, SYNCHRONIZER, WEB_API}; |
3 | 5 | use crate::components::members::Invitation;
|
4 |
| -use crate::invites::{PendingRoomJoin, PendingRoomStatus}; |
| 6 | +use crate::invites::{PendingInvites, PendingRoomJoin, PendingRoomStatus}; |
5 | 7 | use crate::room_data::Rooms;
|
6 | 8 | use dioxus::logger::tracing::{error, info};
|
7 | 9 | use dioxus::prelude::*;
|
@@ -100,7 +102,15 @@ pub fn ReceiveInvitationModal(invitation: Signal<Option<Invitation>>) -> Element
|
100 | 102 | }
|
101 | 103 | }
|
102 | 104 |
|
103 |
| - // In Dioxus 0.6, we don't need to return a cleanup function |
| 105 | + // Return cleanup function to remove event listener |
| 106 | + (move || { |
| 107 | + window |
| 108 | + .remove_event_listener_with_callback( |
| 109 | + "river-invitation-accepted", |
| 110 | + closure.as_ref().unchecked_ref(), |
| 111 | + ) |
| 112 | + .expect("Failed to remove event listener"); |
| 113 | + })() |
104 | 114 | });
|
105 | 115 |
|
106 | 116 | rsx! {
|
@@ -206,54 +216,11 @@ fn render_error_state(
|
206 | 216 |
|
207 | 217 | /// Renders the state when room is successfully subscribed and retrieved
|
208 | 218 | fn render_subscribed_state(
|
209 |
| - room_key: &VerifyingKey, |
210 |
| - mut invitation: Signal<Option<Invitation>>, |
| 219 | + _room_key: &VerifyingKey, |
| 220 | + _invitation: Signal<Option<Invitation>>, |
211 | 221 | ) -> Element {
|
212 |
| - // Get the room data to display confirmation |
213 |
| - let room_name = ROOMS.read() |
214 |
| - .map.get(room_key) |
215 |
| - .map(|r| r.room_state.configuration.configuration.name.clone()) |
216 |
| - .unwrap_or_else(|| "the room".to_string()); |
217 |
| - |
218 |
| - // Trigger a synchronization to ensure the new member is propagated |
219 |
| - let _ = SYNCHRONIZER |
220 |
| - .write() |
221 |
| - .get_message_sender() |
222 |
| - .unbounded_send(SynchronizerMessage::ProcessRooms); |
223 |
| - |
224 |
| - // Clone values needed for the closure |
225 |
| - let room_key_owned = room_key.clone(); |
226 |
| - let room_name_for_closure = room_name.clone(); |
227 |
| - |
228 |
| - // Close the modal after a short delay |
229 |
| - use_effect(move || { |
230 |
| - // Clone again for the inner closure |
231 |
| - let room_name_inner = room_name_for_closure.clone(); |
232 |
| - |
233 |
| - wasm_bindgen_futures::spawn_local(async move { |
234 |
| - // Wait a moment to show the success message |
235 |
| - futures_timer::Delay::new(std::time::Duration::from_millis(1500)).await; |
236 |
| - invitation.set(None); |
237 |
| - |
238 |
| - // Remove from pending invites after successful join |
239 |
| - PENDING_INVITES.with_mut(|pending| { |
240 |
| - pending.map.remove(&room_key_owned); |
241 |
| - }); |
242 |
| - |
243 |
| - info!("Successfully joined room: {}", room_name_inner); |
244 |
| - }); |
245 |
| - }); |
246 |
| - |
247 |
| - rsx! { |
248 |
| - div { |
249 |
| - class: "has-text-centered p-4", |
250 |
| - p { class: "mb-4 has-text-success is-size-5", |
251 |
| - i { class: "fas fa-check-circle mr-2" } |
252 |
| - "Successfully joined \"{room_name}\"!" |
253 |
| - } |
254 |
| - p { "You'll be redirected to the room shortly..." } |
255 |
| - } |
256 |
| - } |
| 222 | + // Just return an empty element - the cleanup is now handled in the main component |
| 223 | + rsx! { "" } |
257 | 224 | }
|
258 | 225 |
|
259 | 226 | /// Renders the invitation options based on the user's membership status
|
@@ -431,37 +398,7 @@ fn accept_invitation(inv: Invitation, nickname: String) {
|
431 | 398 |
|
432 | 399 | info!("Requesting room state for invitation");
|
433 | 400 |
|
434 |
| - // First, check if we already have this room in our ROOMS |
435 |
| - let room_exists = ROOMS.read().map.contains_key(&room_owner); |
436 |
| - |
437 |
| - if room_exists { |
438 |
| - info!("Room already exists, adding member directly"); |
439 |
| - |
440 |
| - // If the room already exists, add the member directly to the room |
441 |
| - ROOMS.with_mut(|rooms| { |
442 |
| - if let Some(room_data) = rooms.map.get_mut(&room_owner) { |
443 |
| - // Add the member to the room |
444 |
| - room_data.room_state.members.members.push(authorized_member.clone()); |
445 |
| - |
446 |
| - // Add member info with the nickname |
447 |
| - let member_id = authorized_member.member.id(); |
448 |
| - let member_info = river_common::room_state::member_info::MemberInfo { |
449 |
| - member_id, |
450 |
| - version: 0, |
451 |
| - preferred_nickname: nickname.clone(), |
452 |
| - }; |
453 |
| - let authorized_member_info = river_common::room_state::member_info::AuthorizedMemberInfo::new( |
454 |
| - member_info, |
455 |
| - &invitee_signing_key, |
456 |
| - ); |
457 |
| - room_data.room_state.member_info.member_info.push(authorized_member_info); |
458 |
| - |
459 |
| - info!("Added member {:?} to room {:?}", member_id, MemberId::from(room_owner)); |
460 |
| - } |
461 |
| - }); |
462 |
| - } |
463 |
| - |
464 |
| - // Send the AcceptInvitation message to synchronize with the network |
| 401 | + // Send the AcceptInvitation message directly without spawn_local |
465 | 402 | let result = SYNCHRONIZER
|
466 | 403 | .write()
|
467 | 404 | .get_message_sender()
|
|
0 commit comments