web: improve keep unread logic in catchup, remove execess logging
This commit is contained in:
parent
a2920fde3b
commit
7c3cfec3d1
@ -72,10 +72,6 @@ fn on_url_changed(old: &Url, mut new: Url) -> Msg {
|
|||||||
if did_change {
|
if did_change {
|
||||||
messages.push(Msg::ScrollToTop)
|
messages.push(Msg::ScrollToTop)
|
||||||
}
|
}
|
||||||
info!(
|
|
||||||
"url changed\nold '{old}'\nnew '{new}', history {}",
|
|
||||||
history().length().unwrap_or(0)
|
|
||||||
);
|
|
||||||
let hpp = new.remaining_hash_path_parts();
|
let hpp = new.remaining_hash_path_parts();
|
||||||
let msg = match hpp.as_slice() {
|
let msg = match hpp.as_slice() {
|
||||||
["t", tid] => Msg::ShowThreadRequest {
|
["t", tid] => Msg::ShowThreadRequest {
|
||||||
@ -553,7 +549,6 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
Msg::ScrollToTop => {
|
Msg::ScrollToTop => {
|
||||||
info!("scrolling to the top");
|
|
||||||
web_sys::window().unwrap().scroll_to_with_x_and_y(0., 0.);
|
web_sys::window().unwrap().scroll_to_with_x_and_y(0., 0.);
|
||||||
}
|
}
|
||||||
Msg::WindowScrolled => {
|
Msg::WindowScrolled => {
|
||||||
@ -619,6 +614,36 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
orders.send_msg(Msg::CatchupRequest { query });
|
orders.send_msg(Msg::CatchupRequest { query });
|
||||||
}
|
}
|
||||||
Msg::CatchupKeepUnread => {
|
Msg::CatchupKeepUnread => {
|
||||||
|
if let Some(thread_id) = current_thread_id(&model.context) {
|
||||||
|
if let Context::ThreadResult {
|
||||||
|
thread:
|
||||||
|
ShowThreadQueryThread::EmailThread(ShowThreadQueryThreadOnEmailThread {
|
||||||
|
messages,
|
||||||
|
..
|
||||||
|
}),
|
||||||
|
..
|
||||||
|
} = &model.context
|
||||||
|
{
|
||||||
|
//orders.send_msg(Msg::SetUnread(thread_id, false));
|
||||||
|
let unread_messages: Vec<_> = messages
|
||||||
|
.iter()
|
||||||
|
.filter(|msg| msg.tags.iter().any(|t| t == "unread"))
|
||||||
|
.map(|msg| &msg.id)
|
||||||
|
.collect();
|
||||||
|
if unread_messages.is_empty() {
|
||||||
|
// All messages are read, so mark them all unread
|
||||||
|
orders.send_msg(Msg::SetUnread(thread_id, true));
|
||||||
|
} else {
|
||||||
|
// Do nothing if there are some messages unread
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// News post, not email, just mark unread
|
||||||
|
orders.send_msg(Msg::SetUnread(thread_id, true));
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// This shouldn't happen
|
||||||
|
warn!("no current thread_id");
|
||||||
|
}
|
||||||
orders.send_msg(Msg::CatchupNext);
|
orders.send_msg(Msg::CatchupNext);
|
||||||
}
|
}
|
||||||
Msg::CatchupMarkAsRead => {
|
Msg::CatchupMarkAsRead => {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use std::{collections::VecDeque, rc::Rc};
|
use std::{collections::VecDeque, rc::Rc};
|
||||||
|
|
||||||
use letterbox_shared::WebsocketMessage;
|
use letterbox_shared::WebsocketMessage;
|
||||||
use log::{error, info};
|
use log::{debug, error};
|
||||||
use seed::prelude::*;
|
use seed::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
@ -122,13 +122,13 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
match msg {
|
match msg {
|
||||||
Msg::WebSocketOpened => {
|
Msg::WebSocketOpened => {
|
||||||
model.web_socket_reconnector = None;
|
model.web_socket_reconnector = None;
|
||||||
info!("WebSocket connection is open now");
|
debug!("WebSocket connection is open now");
|
||||||
}
|
}
|
||||||
Msg::TextMessageReceived(msg) => {
|
Msg::TextMessageReceived(msg) => {
|
||||||
model.updates.push_back(msg);
|
model.updates.push_back(msg);
|
||||||
}
|
}
|
||||||
Msg::WebSocketClosed(close_event) => {
|
Msg::WebSocketClosed(close_event) => {
|
||||||
info!(
|
debug!(
|
||||||
r#"==================
|
r#"==================
|
||||||
WebSocket connection was closed:
|
WebSocket connection was closed:
|
||||||
Clean: {0}
|
Clean: {0}
|
||||||
@ -148,7 +148,7 @@ Reason: {2}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Msg::WebSocketFailed => {
|
Msg::WebSocketFailed => {
|
||||||
info!("WebSocket failed");
|
debug!("WebSocket failed");
|
||||||
if model.web_socket_reconnector.is_none() {
|
if model.web_socket_reconnector.is_none() {
|
||||||
model.web_socket_reconnector = Some(
|
model.web_socket_reconnector = Some(
|
||||||
orders.stream_with_handle(streams::backoff(None, Msg::ReconnectWebSocket)),
|
orders.stream_with_handle(streams::backoff(None, Msg::ReconnectWebSocket)),
|
||||||
@ -156,7 +156,7 @@ Reason: {2}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Msg::ReconnectWebSocket(retries) => {
|
Msg::ReconnectWebSocket(retries) => {
|
||||||
info!("Reconnect attempt: {}", retries);
|
debug!("Reconnect attempt: {}", retries);
|
||||||
model.web_socket = create_websocket(&model.ws_url, orders).unwrap();
|
model.web_socket = create_websocket(&model.ws_url, orders).unwrap();
|
||||||
}
|
}
|
||||||
Msg::SendMessage(msg) => {
|
Msg::SendMessage(msg) => {
|
||||||
@ -177,16 +177,16 @@ fn create_websocket(url: &str, orders: &impl Orders<Msg>) -> Result<EventClient,
|
|||||||
|
|
||||||
let send = msg_sender.clone();
|
let send = msg_sender.clone();
|
||||||
client.set_on_connection(Some(Box::new(move |client: &EventClient| {
|
client.set_on_connection(Some(Box::new(move |client: &EventClient| {
|
||||||
info!("{:#?}", client.status);
|
debug!("{:#?}", client.status);
|
||||||
let msg = match *client.status.borrow() {
|
let msg = match *client.status.borrow() {
|
||||||
ConnectionStatus::Connecting => {
|
ConnectionStatus::Connecting => {
|
||||||
info!("Connecting...");
|
debug!("Connecting...");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
ConnectionStatus::Connected => Some(Msg::WebSocketOpened),
|
ConnectionStatus::Connected => Some(Msg::WebSocketOpened),
|
||||||
ConnectionStatus::Error => Some(Msg::WebSocketFailed),
|
ConnectionStatus::Error => Some(Msg::WebSocketFailed),
|
||||||
ConnectionStatus::Disconnected => {
|
ConnectionStatus::Disconnected => {
|
||||||
info!("Disconnected");
|
debug!("Disconnected");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -195,7 +195,7 @@ fn create_websocket(url: &str, orders: &impl Orders<Msg>) -> Result<EventClient,
|
|||||||
|
|
||||||
let send = msg_sender.clone();
|
let send = msg_sender.clone();
|
||||||
client.set_on_close(Some(Box::new(move |ev| {
|
client.set_on_close(Some(Box::new(move |ev| {
|
||||||
info!("WS: Connection closed");
|
debug!("WS: Connection closed");
|
||||||
send(Some(Msg::WebSocketClosed(ev)));
|
send(Some(Msg::WebSocketClosed(ev)));
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user