Update euphoxide to version with id newtype wrappers

This commit is contained in:
Joscha 2022-09-26 10:20:47 +02:00
parent 2d88513a28
commit 374c4c4f79
10 changed files with 131 additions and 114 deletions

View file

@ -7,7 +7,7 @@ use anyhow::bail;
use cookie::{Cookie, CookieJar};
use euphoxide::api::packet::ParsedPacket;
use euphoxide::api::{
Auth, AuthOption, Data, Log, Login, Logout, Nick, Send, Snowflake, Time, UserId,
Auth, AuthOption, Data, Log, Login, Logout, MessageId, Nick, Send, Time, UserId,
};
use euphoxide::conn::{ConnRx, ConnTx, Joining, Status};
use log::{error, info, warn};
@ -50,7 +50,7 @@ enum Event {
RequestLogs,
Auth(String),
Nick(String),
Send(Option<Snowflake>, String, oneshot::Sender<Snowflake>),
Send(Option<MessageId>, String, oneshot::Sender<MessageId>),
Login { email: String, password: String },
Logout,
}
@ -66,7 +66,7 @@ struct State {
conn_tx: Option<ConnTx>,
/// `None` before any `snapshot-event`, then either `Some(None)` or
/// `Some(Some(id))`.
last_msg_id: Option<Option<Snowflake>>,
last_msg_id: Option<Option<MessageId>>,
requesting_logs: Arc<Mutex<bool>>,
}
@ -419,9 +419,9 @@ impl State {
fn on_send(
&self,
parent: Option<Snowflake>,
parent: Option<MessageId>,
content: String,
id_tx: oneshot::Sender<Snowflake>,
id_tx: oneshot::Sender<MessageId>,
) {
if let Some(conn_tx) = &self.conn_tx {
let conn_tx = conn_tx.clone();
@ -527,9 +527,9 @@ impl Room {
pub fn send(
&self,
parent: Option<Snowflake>,
parent: Option<MessageId>,
content: String,
) -> Result<oneshot::Receiver<Snowflake>, Error> {
) -> Result<oneshot::Receiver<MessageId>, Error> {
let (id_tx, id_rx) = oneshot::channel();
self.event_tx
.send(Event::Send(parent, content, id_tx))

View file

@ -1,5 +1,5 @@
use crossterm::style::{Color, ContentStyle, Stylize};
use euphoxide::api::{Snowflake, Time};
use euphoxide::api::{MessageId, Snowflake, Time};
use time::OffsetDateTime;
use toss::styled::Styled;
@ -89,8 +89,8 @@ fn highlight_content(content: &str, base_style: ContentStyle) -> Styled {
#[derive(Debug, Clone)]
pub struct SmallMessage {
pub id: Snowflake,
pub parent: Option<Snowflake>,
pub id: MessageId,
pub parent: Option<MessageId>,
pub time: Time,
pub nick: String,
pub content: String,
@ -135,7 +135,7 @@ fn styled_editor_content(content: &str) -> Styled {
}
impl Msg for SmallMessage {
type Id = Snowflake;
type Id = MessageId;
fn id(&self) -> Self::Id {
self.id
@ -150,7 +150,7 @@ impl Msg for SmallMessage {
}
fn last_possible_id() -> Self::Id {
Snowflake::MAX
MessageId(Snowflake::MAX)
}
}