Skip to content

Commit

Permalink
Merge pull request #167 from kevinaboos/switch_to_simplified_sync_ser…
Browse files Browse the repository at this point in the history
…vice

Switch to simplified sync service
  • Loading branch information
kevinaboos authored Oct 1, 2024
2 parents f522a1a + 571536d commit 408e40b
Show file tree
Hide file tree
Showing 9 changed files with 513 additions and 442 deletions.
181 changes: 65 additions & 116 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ futures-util = "0.3"
imbl = { version = "3.0.0", features = ["serde"] } # same as matrix-sdk-ui
imghdr = "0.7.0"
linkify = "0.10.0"
# matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk", default-features = false, features = [ "experimental-sliding-sync", "e2e-encryption", "automatic-room-key-forwarding", "markdown", "sqlite", "rustls-tls", "bundled-sqlite" ] }
matrix-sdk = { git = "https://github.com/project-robius/matrix-rust-sdk", branch = "re-export-reactions-type", default-features = false, features = [ "experimental-sliding-sync", "e2e-encryption", "automatic-room-key-forwarding", "markdown", "sqlite", "rustls-tls", "bundled-sqlite" ] }
# matrix-sdk-ui = { git = "https://github.com/matrix-org/matrix-rust-sdk", default-features = false, features = [ "e2e-encryption", "rustls-tls" ] }
matrix-sdk-ui = { git = "https://github.com/project-robius/matrix-rust-sdk", branch = "re-export-reactions-type", default-features = false, features = [ "e2e-encryption", "rustls-tls" ] }
matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk", default-features = false, features = [ "experimental-sliding-sync", "e2e-encryption", "automatic-room-key-forwarding", "markdown", "sqlite", "rustls-tls", "bundled-sqlite" ] }
matrix-sdk-ui = { git = "https://github.com/matrix-org/matrix-rust-sdk", default-features = false, features = [ "rustls-tls" ] }
rand = "0.8.5"
rangemap = "1.5.0"
serde = "1.0"
Expand Down
6 changes: 4 additions & 2 deletions src/home/room_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ live_design! {
font_size: 7.5
},
}
text: "[Timestamp unknown]"
text: "??"
}

MessagePreview = <View> {
width: Fill, height: Fit
flow: Down, spacing: 5.

latest_message = <HtmlOrPlaintext> {
padding: {top: 3.0}
html_view = { html = {
font_size: 9.3, line_spacing: 1.,
draw_normal: { text_style: { font_size: 9.3, line_spacing: 1. } },
Expand All @@ -60,7 +61,7 @@ live_design! {
draw_text: {
text_style: { font_size: 9.5, line_spacing: 1. },
}
text: "[Latest message unknown]"
text: "[Loading latest message]"
} }
}
}
Expand Down Expand Up @@ -301,6 +302,7 @@ impl RoomPreviewContent {
live!(
html_view = {
html = {
font_color: (message_text_color),
draw_normal: { color: (message_text_color) },
draw_italic: { color: (message_text_color) },
draw_bold: { color: (message_text_color) },
Expand Down
6 changes: 5 additions & 1 deletion src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,14 @@ live_design! {
visible: false,
width: Fill,
height: Fit,
padding: {top: 5.0}

html_content = <RobrixHtml> {
width: Fill,
height: Fit,
padding: { bottom: 5.0, top: 0.0 },
font_size: 10.5,
font_color: (REACTION_TEXT_COLOR),
draw_normal: { color: (REACTION_TEXT_COLOR) },
draw_italic: { color: (REACTION_TEXT_COLOR) },
draw_bold: { color: (REACTION_TEXT_COLOR) },
Expand Down Expand Up @@ -1017,7 +1019,9 @@ impl Widget for RoomScreen {
match update {
TimelineUpdate::NewItems { items, changed_indices, clear_cache } => {
if items.is_empty() {
log!("Timeline::handle_event(): timeline was cleared for room {}", tl.room_id);
if !tl.items.is_empty() {
log!("Timeline::handle_event(): timeline was cleared for room {}", tl.room_id);
}

// If the bottom of the timeline (the last event) is visible, then we should
// set the timeline to live mode.
Expand Down
66 changes: 44 additions & 22 deletions src/home/rooms_list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use crossbeam_queue::SegQueue;
use makepad_widgets::*;
use matrix_sdk::ruma::{OwnedRoomId, MilliSecondsSinceUnixEpoch};
use matrix_sdk::ruma::{MilliSecondsSinceUnixEpoch, OwnedRoomId};

use super::room_preview::RoomPreviewAction;

Expand Down Expand Up @@ -35,7 +35,7 @@ live_design! {
color: (MESSAGE_TEXT_COLOR),
text_style: <REGULAR_TEXT>{}
}
text: "Loading joined rooms..."
text: "Loading rooms..."
}
}

Expand Down Expand Up @@ -66,8 +66,15 @@ live_design! {
/// (which is called from background async tasks that receive updates from the matrix server),
/// and then dequeued by the `RoomsList` widget's `handle_event` function.
pub enum RoomsListUpdate {
/// No rooms have been loaded yet.
NotLoaded,
/// Some rooms were loaded, and the server optionally told us
/// the max number of rooms that will ever be loaded.
LoadedRooms{ max_rooms: Option<u32> },
/// Add a new room to the list of all rooms.
AddRoom(RoomPreviewEntry),
/// Clear all rooms in the list of all rooms.
ClearRooms,
/// Update the latest event content and timestamp for the given room.
UpdateLatestEvent {
room_id: OwnedRoomId,
Expand All @@ -86,7 +93,6 @@ pub enum RoomsListUpdate {
avatar: RoomPreviewAvatar,
},
/// Remove the given room from the list of all rooms.
#[allow(unused)]
RemoveRoom(OwnedRoomId),
/// Update the status label at the bottom of the list of all rooms.
Status {
Expand Down Expand Up @@ -117,10 +123,10 @@ pub enum RoomListAction {
None,
}

#[derive(Debug, Default)]
#[derive(Debug)]
pub struct RoomPreviewEntry {
/// The matrix ID of this room.
pub room_id: Option<OwnedRoomId>,
pub room_id: OwnedRoomId,
/// The displayable name of this room, if known.
pub room_name: Option<String>,
/// The timestamp and Html text content of the latest message in this room.
Expand Down Expand Up @@ -149,13 +155,27 @@ pub struct RoomsList {
#[deref] view: View,

/// The list of all known rooms and their cached preview info.
//
// TODO: change this into a hashmap keyed by room ID.
#[rust] all_rooms: Vec<RoomPreviewEntry>,
/// Maps the WidgetUid of a `RoomPreview` to that room's index in the `all_rooms` vector.
#[rust] rooms_list_map: HashMap<u64, usize>,
/// The latest status message that should be displayed in the bottom status label.
#[rust] status: String,
/// The index of the currently selected room
#[rust] current_active_room_index: Option<usize>,
/// The maximum number of rooms that will ever be loaded.
#[rust] max_known_rooms: Option<u32>,
}

impl RoomsList {
fn update_status_rooms_count(&mut self) {
self.status = if let Some(max_rooms) = self.max_known_rooms {
format!("Loaded {} of {} total rooms.", self.all_rooms.len(), max_rooms)
} else {
format!("Loaded {} rooms.", self.all_rooms.len())
};
}
}

impl Widget for RoomsList {
Expand All @@ -170,33 +190,43 @@ impl Widget for RoomsList {
self.all_rooms.push(room);
}
RoomsListUpdate::UpdateRoomAvatar { room_id, avatar } => {
if let Some(room) = self.all_rooms.iter_mut().find(|r| r.room_id.as_ref() == Some(&room_id)) {
if let Some(room) = self.all_rooms.iter_mut().find(|r| &r.room_id == &room_id) {
room.avatar = avatar;
} else {
error!("Error: couldn't find room {room_id} to update avatar");
}
}
RoomsListUpdate::UpdateLatestEvent { room_id, timestamp, latest_message_text } => {
if let Some(room) = self.all_rooms.iter_mut().find(|r| r.room_id.as_ref() == Some(&room_id)) {
if let Some(room) = self.all_rooms.iter_mut().find(|r| &r.room_id == &room_id) {
room.latest = Some((timestamp, latest_message_text));
} else {
error!("Error: couldn't find room {room_id} to update latest event");
}
}
RoomsListUpdate::UpdateRoomName { room_id, new_room_name } => {
if let Some(room) = self.all_rooms.iter_mut().find(|r| r.room_id.as_ref() == Some(&room_id)) {
if let Some(room) = self.all_rooms.iter_mut().find(|r| &r.room_id == &room_id) {
room.room_name = Some(new_room_name);
} else {
error!("Error: couldn't find room {room_id} to update room name");
}
}
RoomsListUpdate::RemoveRoom(room_id) => {
if let Some(idx) = self.all_rooms.iter().position(|r| r.room_id.as_ref() == Some(&room_id)) {
if let Some(idx) = self.all_rooms.iter().position(|r| &r.room_id == &room_id) {
self.all_rooms.remove(idx);
} else {
error!("Error: couldn't find room {room_id} to remove room");
}
}
RoomsListUpdate::ClearRooms => {
self.all_rooms.clear();
}
RoomsListUpdate::NotLoaded => {
self.status = "Loading rooms (waiting for homeserver)...".to_string();
}
RoomsListUpdate::LoadedRooms { max_rooms } => {
self.max_known_rooms = max_rooms;
self.update_status_rooms_count();
}
RoomsListUpdate::Status { status } => {
self.status = status;
}
Expand Down Expand Up @@ -226,7 +256,7 @@ impl Widget for RoomsList {
&scope.path,
RoomListAction::Selected {
room_index,
room_id: room_details.room_id.clone().unwrap(),
room_id: room_details.room_id.to_owned(),
room_name: room_details.room_name.clone(),
}
);
Expand Down Expand Up @@ -258,18 +288,10 @@ impl Widget for RoomsList {
// Draw the status label as the bottom entry.
let item = if item_id == last_item_id {
let item = list.item(cx, item_id, live_id!(status_label)).unwrap();
if count > 0 {
let text = format!("Found {count} joined rooms.");
item.as_view().apply_over(cx, live!{
height: 80.0,
label = { text: (text) }
});
} else {
item.as_view().apply_over(cx, live!{
height: Fit,
label = { text: (&self.status) }
});
}
item.as_view().apply_over(cx, live!{
height: Fit,
label = { text: (&self.status) }
});
item
}
// Draw a filler entry to take up space at the bottom of the portal list.
Expand Down
11 changes: 4 additions & 7 deletions src/persistent_state.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
//! Handles app persistence by saving and restoring client session data to/from the filesystem.
use std::{
path::PathBuf,
};
use std::path::PathBuf;
use anyhow::{anyhow, bail};
use makepad_widgets::log;
use matrix_sdk::{
matrix_auth::MatrixSession,
ruma::{OwnedUserId, UserId},
Client,
matrix_auth::MatrixSession, ruma::{OwnedUserId, UserId}, sliding_sync::VersionBuilder, Client
};
use serde::{Deserialize, Serialize};
use tokio::fs;
Expand Down Expand Up @@ -112,7 +108,8 @@ pub async fn restore_session(
let client = Client::builder()
.server_name_or_homeserver_url(client_session.homeserver)
.sqlite_store(client_session.db_path, Some(&client_session.passphrase))
.simplified_sliding_sync(false)
.sliding_sync_version_builder(VersionBuilder::DiscoverNative)
.handle_refresh_tokens()
.build()
.await?;

Expand Down
2 changes: 1 addition & 1 deletion src/shared/html_or_plaintext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ live_design! {
draw_text: {
wrap: Word,
color: (MESSAGE_TEXT_COLOR),
text_style: <MESSAGE_TEXT_STYLE> { },
text_style: <MESSAGE_TEXT_STYLE> { font_size: (MESSAGE_FONT_SIZE) },
}
text: "[plaintext message placeholder]",
}
Expand Down
Loading

0 comments on commit 408e40b

Please sign in to comment.