summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoscha <joscha@plugh.de>2022-09-26 16:15:02 +0200
committerJoscha <joscha@plugh.de>2022-09-26 16:56:38 +0200
commit5ed0cd5f3f754cc1cb5c852f1dfc46868623011d (patch)
tree2f4803d50f901956832b411eaaf79dab97c8f145
parent374c4c4f799d05017d4903ca808442ec923ede65 (diff)
Update euphoxide to version with partial sessions
-rw-r--r--CHANGELOG.md3
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/euph/room.rs1
-rw-r--r--src/ui/euph/inspect.rs31
-rw-r--r--src/ui/euph/nick_list.rs63
-rw-r--r--src/ui/euph/room.rs10
-rw-r--r--src/ui/rooms.rs17
8 files changed, 100 insertions, 29 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7318d1..1dd5b1e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,9 @@ Procedure when bumping the version number:
- Session inspection popup
- Error popup when external editor fails
+### Changed
+- Use nick changes to detect sessions for nick list
+
### Fixed
- Cursor being visible through popups
- Cursor in lists when highlighted item moves off-screen
diff --git a/Cargo.lock b/Cargo.lock
index c11b6ae..4b9223a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -294,7 +294,7 @@ checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
[[package]]
name = "euphoxide"
version = "0.1.0"
-source = "git+https://github.com/Garmelon/euphoxide.git?rev=e59216809a3d372b48681061a32b0e3e5973ce85#e59216809a3d372b48681061a32b0e3e5973ce85"
+source = "git+https://github.com/Garmelon/euphoxide.git?rev=bdb17db5bf4796696d6375168abb76920ab11b87#bdb17db5bf4796696d6375168abb76920ab11b87"
dependencies = [
"futures",
"serde",
diff --git a/Cargo.toml b/Cargo.toml
index 6ba3aad..11246e1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -34,7 +34,7 @@ features = ["rustls-tls-native-roots"]
[dependencies.euphoxide]
git = "https://github.com/Garmelon/euphoxide.git"
-rev = "e59216809a3d372b48681061a32b0e3e5973ce85"
+rev = "bdb17db5bf4796696d6375168abb76920ab11b87"
# [patch."https://github.com/Garmelon/euphoxide.git"]
# euphoxide = { path = "../euphoxide/" }
diff --git a/src/euph/room.rs b/src/euph/room.rs
index 0d33e6a..530cdf5 100644
--- a/src/euph/room.rs
+++ b/src/euph/room.rs
@@ -285,7 +285,6 @@ impl State {
info!("e&{}: network event ({})", self.name, d.r#type);
}
Data::NickEvent(d) => {
- // TODO Add entry in nick list (probably in euphoxide instead of here)
info!("e&{}: {:?} renamed to {:?}", self.name, d.from, d.to);
}
Data::EditMessageEvent(_) => {
diff --git a/src/ui/euph/inspect.rs b/src/ui/euph/inspect.rs
index 70917c6..4f1f427 100644
--- a/src/ui/euph/inspect.rs
+++ b/src/ui/euph/inspect.rs
@@ -1,5 +1,6 @@
use crossterm::style::{ContentStyle, Stylize};
-use euphoxide::api::{Message, SessionView};
+use euphoxide::api::{Message, NickEvent, SessionView};
+use euphoxide::conn::SessionInfo;
use toss::styled::Styled;
use crate::ui::input::{key, InputEvent, KeyBindingsList};
@@ -38,7 +39,7 @@ macro_rules! line {
};
}
-fn session_lines(mut text: Styled, session: &SessionView) -> Styled {
+fn session_view_lines(mut text: Styled, session: &SessionView) -> Styled {
line!(text, "id", session.id);
line!(text, "name", session.name);
line!(text, "name (raw)", session.name, debug);
@@ -63,6 +64,15 @@ fn session_lines(mut text: Styled, session: &SessionView) -> Styled {
text
}
+fn nick_event_lines(mut text: Styled, event: &NickEvent) -> Styled {
+ line!(text, "id", event.id);
+ line!(text, "name", event.to);
+ line!(text, "name (raw)", event.to, debug);
+ line!(text, "session_id", event.session_id.0);
+
+ text
+}
+
fn message_lines(mut text: Styled, msg: &Message) -> Styled {
line!(text, "id", msg.id.0);
line!(text, "parent", msg.parent.map(|p| p.0), optional);
@@ -76,8 +86,19 @@ fn message_lines(mut text: Styled, msg: &Message) -> Styled {
text
}
-pub fn session_widget(session: &SessionView) -> BoxedWidget {
- let text = session_lines(Styled::default(), session);
+pub fn session_widget(session: &SessionInfo) -> BoxedWidget {
+ let heading_style = ContentStyle::default().bold();
+
+ let text = match session {
+ SessionInfo::Full(session) => {
+ let text = Styled::new("Full session", heading_style).then_plain("\n");
+ session_view_lines(text, session)
+ }
+ SessionInfo::Partial(event) => {
+ let text = Styled::new("Partial session", heading_style).then_plain("\n");
+ nick_event_lines(text, event)
+ }
+ };
Popup::new(Text::new(text)).title("Inspect session").build()
}
@@ -94,7 +115,7 @@ pub fn message_widget(msg: &Message) -> BoxedWidget {
.then("Sender", heading_style)
.then_plain("\n");
- text = session_lines(text, &msg.sender);
+ text = session_view_lines(text, &msg.sender);
Popup::new(Text::new(text)).title("Inspect message").build()
}
diff --git a/src/ui/euph/nick_list.rs b/src/ui/euph/nick_list.rs
index 78c6c67..431edb3 100644
--- a/src/ui/euph/nick_list.rs
+++ b/src/ui/euph/nick_list.rs
@@ -1,8 +1,8 @@
use std::iter;
use crossterm::style::{Color, ContentStyle, Stylize};
-use euphoxide::api::{SessionId, SessionType, SessionView};
-use euphoxide::conn::Joined;
+use euphoxide::api::{NickEvent, SessionId, SessionType, SessionView, UserId};
+use euphoxide::conn::{Joined, SessionInfo};
use toss::styled::Styled;
use crate::euph;
@@ -18,16 +18,55 @@ pub fn widget(state: &ListState<SessionId>, joined: &Joined, focused: bool) -> B
list.into()
}
+#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
+struct HalfSession {
+ name: String,
+ id: UserId,
+ session_id: SessionId,
+ is_staff: bool,
+ is_manager: bool,
+}
+
+impl HalfSession {
+ fn from_session_view(sess: &SessionView) -> Self {
+ Self {
+ name: sess.name.clone(),
+ id: sess.id.clone(),
+ session_id: sess.session_id.clone(),
+ is_staff: sess.is_staff,
+ is_manager: sess.is_manager,
+ }
+ }
+
+ fn from_nick_event(nick: &NickEvent) -> Self {
+ Self {
+ name: nick.to.clone(),
+ id: nick.id.clone(),
+ session_id: nick.session_id.clone(),
+ is_staff: false,
+ is_manager: false,
+ }
+ }
+
+ fn from_session_info(info: &SessionInfo) -> Self {
+ match info {
+ SessionInfo::Full(sess) => Self::from_session_view(sess),
+ SessionInfo::Partial(nick) => Self::from_nick_event(nick),
+ }
+ }
+}
+
fn render_rows(list: &mut List<SessionId>, joined: &Joined) {
let mut people = vec![];
let mut bots = vec![];
let mut lurkers = vec![];
let mut nurkers = vec![];
- let mut sessions = iter::once(&joined.session)
- .chain(joined.listing.values())
- .collect::<Vec<_>>();
- sessions.sort_unstable_by_key(|s| &s.name);
+ let sessions = joined
+ .listing
+ .values()
+ .map(HalfSession::from_session_info)
+ .chain(iter::once(HalfSession::from_session_view(&joined.session)));
for sess in sessions {
match sess.id.session_type() {
Some(SessionType::Bot) if sess.name.is_empty() => nurkers.push(sess),
@@ -37,10 +76,10 @@ fn render_rows(list: &mut List<SessionId>, joined: &Joined) {
}
}
- people.sort_unstable_by_key(|s| (&s.name, &s.session_id));
- bots.sort_unstable_by_key(|s| (&s.name, &s.session_id));
- lurkers.sort_unstable_by_key(|s| &s.session_id);
- nurkers.sort_unstable_by_key(|s| &s.session_id);
+ people.sort_unstable();
+ bots.sort_unstable();
+ lurkers.sort_unstable();
+ nurkers.sort_unstable();
render_section(list, "People", &people, &joined.session);
render_section(list, "Bots", &bots, &joined.session);
@@ -51,7 +90,7 @@ fn render_rows(list: &mut List<SessionId>, joined: &Joined) {
fn render_section(
list: &mut List<SessionId>,
name: &str,
- sessions: &[&SessionView],
+ sessions: &[HalfSession],
own_session: &SessionView,
) {
if sessions.is_empty() {
@@ -74,7 +113,7 @@ fn render_section(
}
}
-fn render_row(list: &mut List<SessionId>, session: &SessionView, own_session: &SessionView) {
+fn render_row(list: &mut List<SessionId>, session: &HalfSession, own_session: &SessionView) {
let (name, style, style_inv, perms_style_inv) = if session.name.is_empty() {
let name = "lurk";
let style = ContentStyle::default().grey();
diff --git a/src/ui/euph/room.rs b/src/ui/euph/room.rs
index d2007df..4418cab 100644
--- a/src/ui/euph/room.rs
+++ b/src/ui/euph/room.rs
@@ -2,8 +2,8 @@ use std::collections::VecDeque;
use std::sync::Arc;
use crossterm::style::{ContentStyle, Stylize};
-use euphoxide::api::{Data, Message, MessageId, PacketType, SessionId, SessionView};
-use euphoxide::conn::{Joined, Joining, Status};
+use euphoxide::api::{Data, Message, MessageId, PacketType, SessionId};
+use euphoxide::conn::{Joined, Joining, SessionInfo, Status};
use parking_lot::FairMutex;
use tokio::sync::oneshot::error::TryRecvError;
use tokio::sync::{mpsc, oneshot};
@@ -45,7 +45,7 @@ enum State {
Account(AccountUiState),
Links(LinksState),
InspectMessage(Message),
- InspectSession(SessionView),
+ InspectSession(SessionInfo),
}
#[allow(clippy::large_enum_variant)]
@@ -499,10 +499,10 @@ impl EuphRoom {
if let key!('i') = event {
if let RoomStatus::Connected(Status::Joined(joined)) = status {
- // TODO Fix euphoxide to use session_id as hash
if let Some(id) = self.nick_list.cursor() {
if id == joined.session.session_id {
- self.state = State::InspectSession(joined.session.clone());
+ self.state =
+ State::InspectSession(SessionInfo::Full(joined.session.clone()));
} else if let Some(session) = joined.listing.get(&id) {
self.state = State::InspectSession(session.clone());
}
diff --git a/src/ui/rooms.rs b/src/ui/rooms.rs
index aff38c5..683ef5a 100644
--- a/src/ui/rooms.rs
+++ b/src/ui/rooms.rs
@@ -191,11 +191,20 @@ impl Rooms {
let mut b = 0_usize;
let mut l = 0_usize;
let mut n = 0_usize;
- for sess in iter::once(&joined.session).chain(joined.listing.values()) {
- match sess.id.session_type() {
- Some(SessionType::Bot) if sess.name.is_empty() => n += 1,
+
+ let sessions = joined
+ .listing
+ .values()
+ .map(|s| (s.id(), s.name()))
+ .chain(iter::once((
+ &joined.session.id,
+ &joined.session.name as &str,
+ )));
+ for (user_id, name) in sessions {
+ match user_id.session_type() {
+ Some(SessionType::Bot) if name.is_empty() => n += 1,
Some(SessionType::Bot) => b += 1,
- _ if sess.name.is_empty() => l += 1,
+ _ if name.is_empty() => l += 1,
_ => p += 1,
}
}