Commit 864f424a88

864f424a884c9119dcfd99078e05f3012dd08662

parent: 4b7c5ab287

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-07-02 21:32 UTC

room_buffer: Restore our room messages as well when restoring the buffer.

Layout: unified · split

Cargo.lock +5 −5
@@ -865,7 +865,7 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
865865[[package]]
866866name = "matrix-sdk"
867867version = "0.1.0"
868source = "git+https://github.com/matrix-org/matrix-rust-sdk/#cd9252cc3d9d46770db54a1c6317aa4a52b52cf3"
868source = "git+https://github.com/matrix-org/matrix-rust-sdk/#b092ed0a82a47f0acade7d9ee06a64f05ccace43"
869869dependencies = [
870870 "futures-timer",
871871 "http",
@@ -883,7 +883,7 @@ dependencies = [
883883[[package]]
884884name = "matrix-sdk-base"
885885version = "0.1.0"
886source = "git+https://github.com/matrix-org/matrix-rust-sdk/#cd9252cc3d9d46770db54a1c6317aa4a52b52cf3"
886source = "git+https://github.com/matrix-org/matrix-rust-sdk/#b092ed0a82a47f0acade7d9ee06a64f05ccace43"
887887dependencies = [
888888 "async-trait",
889889 "matrix-sdk-common",
@@ -899,7 +899,7 @@ dependencies = [
899899[[package]]
900900name = "matrix-sdk-common"
901901version = "0.1.0"
902source = "git+https://github.com/matrix-org/matrix-rust-sdk/#cd9252cc3d9d46770db54a1c6317aa4a52b52cf3"
902source = "git+https://github.com/matrix-org/matrix-rust-sdk/#b092ed0a82a47f0acade7d9ee06a64f05ccace43"
903903dependencies = [
904904 "futures-locks",
905905 "instant",
@@ -915,7 +915,7 @@ dependencies = [
915915[[package]]
916916name = "matrix-sdk-common-macros"
917917version = "0.1.0"
918source = "git+https://github.com/matrix-org/matrix-rust-sdk/#cd9252cc3d9d46770db54a1c6317aa4a52b52cf3"
918source = "git+https://github.com/matrix-org/matrix-rust-sdk/#b092ed0a82a47f0acade7d9ee06a64f05ccace43"
919919dependencies = [
920920 "quote",
921921 "syn",
@@ -924,7 +924,7 @@ dependencies = [
924924[[package]]
925925name = "matrix-sdk-crypto"
926926version = "0.1.0"
927source = "git+https://github.com/matrix-org/matrix-rust-sdk/#cd9252cc3d9d46770db54a1c6317aa4a52b52cf3"
927source = "git+https://github.com/matrix-org/matrix-rust-sdk/#b092ed0a82a47f0acade7d9ee06a64f05ccace43"
928928dependencies = [
929929 "async-trait",
930930 "atomic",
Cargo.toml +1 −1
@@ -28,4 +28,4 @@ weechat-sys = { git = "https://github.com/poljar/rust-weechat" }
2828[dependencies.matrix-sdk]
2929git = "https://github.com/matrix-org/matrix-rust-sdk/"
3030default-features = false
31features = ["encryption", "sqlite-cryptostore"]
31features = ["encryption", "sqlite-cryptostore", "messages"]
src/room_buffer.rs +16 −2
@@ -150,10 +150,24 @@ impl RoomBuffer {
150150
151151 room_buffer.inner.room = Rc::new(RefCell::new(room));
152152 room_buffer.update_buffer_name();
153 room_buffer.restore_messages();
153154
154155 room_buffer
155156 }
156157
158 pub fn restore_messages(&self) {
159 let room = self.room();
160 let buffer = self.weechat_buffer();
161
162 Weechat::print(&format!("HELLO WORLD RESTORING {}", buffer.name()));
163 if buffer.num_lines() == 0 {
164 for message in room.messages.iter() {
165 Weechat::print(&format!("RESTOGIN MESSAGE {:?}", message));
166 self.handle_room_message(message)
167 }
168 }
169 }
170
157171 pub fn room_mut(&mut self) -> RefMut<'_, Room> {
158172 self.inner.room.borrow_mut()
159173 }
@@ -245,7 +259,7 @@ impl RoomBuffer {
245259 }
246260
247261 pub fn handle_text_message(
248 &mut self,
262 &self,
249263 sender: &str,
250264 timestamp: u64,
251265 content: &TextMessageEventContent,
@@ -255,7 +269,7 @@ impl RoomBuffer {
255269 buffer.print_date_tags(timestamp as i64, &[], &message);
256270 }
257271
258 pub fn handle_room_message(&mut self, event: &MessageEvent) {
272 pub fn handle_room_message(&self, event: &MessageEvent) {
259273 let sender = &event.sender;
260274 let timestamp: u64 = event
261275 .origin_server_ts
src/server.rs +1
@@ -706,6 +706,7 @@ impl MatrixServer {
706706 client
707707 .sync_forever(sync_settings, async move |response| {
708708 let channel = sync_channel;
709
709710 for (room_id, room) in response.rooms.join {
710711 for event in room.state.events {
711712 if let Ok(e) = event.deserialize() {