Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct rooms has been Stripped #175

Closed
wants to merge 3 commits into from

Conversation

aaravlu
Copy link
Contributor

@aaravlu aaravlu commented Oct 7, 2024

1

I am back.

Sorry for my recklessness earlier. #139 #154

Here's the demo video
Screencast from 2024-10-07 19-07-14.webm

In rooms_sidebar.rs

There is a static with its fuction.

static ALL_ROOMS_COUNT: RwLock<u32> = RwLock::new(0);
pub fn apply_all_rooms_count(count: u32) {
    *ALL_ROOMS_COUNT.write().unwrap() = count
}

Let's match event and update they two.

all_rooms_count = <Label> {
    text: "None"
    draw_text: {
        color: #x0
        text_style: <TITLE_TEXT>{}
    }
}

To improve performance, Let it do nothing when app is running back.

impl MatchEvent for RoomsView {
    fn match_event(&mut self, cx: &mut Cx, event: &Event) {
        match event {
            Event::Background => {}
            Event::BackPressed => {}
            _ => self.view.label(id!(all_rooms_count)).set_text_and_redraw(
                cx,
                &format!("{} total valid rooms", *ALL_ROOMS_COUNT.read().unwrap()),
            ),
        }
    }
}

In rooms_list.rs

To distinguish the Rooms and People in the rooms_list.rs, they two were added. (Just Like Rooms two.)

static PENDING_PEOPLE_UPDATES: SegQueue<RoomsListUpdate> = SegQueue::new();
pub fn enqueue_people_list_update(update: RoomsListUpdate) {
    PENDING_PEOPLE_UPDATES.push(update);
    SignalToUI::set_ui_signal();
}

They two static and function would be shown at the end on the UI list, seperately in the Rooms and People.

pub static LOADED_ROOMS_COUNT: RwLock<usize> = RwLock::new(0);
pub static LOADED_PEOPLE_COUNT: RwLock<usize> = RwLock::new(0);

There are some types are used to check Which one is selected, People or Room.

static WHICH_IS_ACTIVE: CurrentActiveRoomIndex = RwLock::new(None);

type CurrentActiveRoomIndex = RwLock<Option<WhichIsSActive>>;

enum WhichIsSActive {
    People,
    Rooms,
}

In draw_walk of RoomsList & PeopleList, let's match the WHICH_IS_ACTIVE.

Example is RoomsList, but PeopleList is the same way.

match WHICH_IS_ACTIVE
    .read()
    .unwrap()
    .unwrap_or(WhichIsSActive::People)
{
    WhichIsSActive::People => {
        room_info.is_selected = false;
    }
    _ => {
        room_info.is_selected = self.current_active_room_index == Some(item_id)
    }
}

In handle_event of RoomsList & PeopleList,
Once the RoomPreview is clicked, WHICH_IS_ACTIVE would be set to Rooms or People.
Here view Rooms as the example, People is the same way.

if let RoomPreviewAction::Click = list_action.as_widget_action().cast() {
        *WHICH_IS_ACTIVE.write().unwrap() = Some(WhichIsSActive::Rooms);
}

In sliding_sync.rs

To distinguish the Rooms and People,
lots of code (judgements) were added, no code demo here, please review :)

Intentionally, I called apply_all_rooms_count to count all the valid rooms.

match state {
    RoomListLoadingState::NotLoaded => {}
    RoomListLoadingState::Loaded {
        maximum_number_of_rooms,
    } => {
        if let Some(all_rooms_count) = maximum_number_of_rooms {
            apply_all_rooms_count(all_rooms_count)
        }
        rooms_list::enqueue_rooms_list_update(RoomsListUpdate::LoadedRooms);
        rooms_list::enqueue_people_list_update(RoomsListUpdate::LoadedRooms)
    }
}

Copy link
Contributor Author

@aaravlu aaravlu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed : )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么修改 Cargo.toml?

@aaravlu aaravlu closed this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants