Query and set seen status via store
This commit is contained in:
parent
20ec6ef3b3
commit
ff4118e21d
4 changed files with 48 additions and 1 deletions
|
|
@ -94,6 +94,7 @@ pub struct SmallMessage {
|
||||||
pub time: Time,
|
pub time: Time,
|
||||||
pub nick: String,
|
pub nick: String,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
|
pub seen: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_me(content: &str) -> Option<&str> {
|
fn as_me(content: &str) -> Option<&str> {
|
||||||
|
|
@ -144,6 +145,10 @@ impl Msg for SmallMessage {
|
||||||
self.parent
|
self.parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn seen(&self) -> bool {
|
||||||
|
self.seen
|
||||||
|
}
|
||||||
|
|
||||||
fn last_possible_id() -> Self::Id {
|
fn last_possible_id() -> Self::Id {
|
||||||
Snowflake::MAX
|
Snowflake::MAX
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,10 @@ impl Msg for LogMsg {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn seen(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn last_possible_id() -> Self::Id {
|
fn last_possible_id() -> Self::Id {
|
||||||
Self::Id::MAX
|
Self::Id::MAX
|
||||||
}
|
}
|
||||||
|
|
@ -118,6 +122,8 @@ impl MsgStore<LogMsg> for Logger {
|
||||||
async fn newer_msg_id(&self, id: &usize) -> Option<usize> {
|
async fn newer_msg_id(&self, id: &usize) -> Option<usize> {
|
||||||
self.next_tree_id(id).await
|
self.next_tree_id(id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn set_seen(&self, _id: &usize, _seen: bool) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Log for Logger {
|
impl Log for Logger {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ pub trait Msg {
|
||||||
type Id: Clone + Debug + Hash + Eq + Ord;
|
type Id: Clone + Debug + Hash + Eq + Ord;
|
||||||
fn id(&self) -> Self::Id;
|
fn id(&self) -> Self::Id;
|
||||||
fn parent(&self) -> Option<Self::Id>;
|
fn parent(&self) -> Option<Self::Id>;
|
||||||
|
fn seen(&self) -> bool;
|
||||||
|
|
||||||
fn last_possible_id() -> Self::Id;
|
fn last_possible_id() -> Self::Id;
|
||||||
}
|
}
|
||||||
|
|
@ -128,4 +129,5 @@ pub trait MsgStore<M: Msg> {
|
||||||
async fn newest_msg_id(&self) -> Option<M::Id>;
|
async fn newest_msg_id(&self) -> Option<M::Id>;
|
||||||
async fn older_msg_id(&self, id: &M::Id) -> Option<M::Id>;
|
async fn older_msg_id(&self, id: &M::Id) -> Option<M::Id>;
|
||||||
async fn newer_msg_id(&self, id: &M::Id) -> Option<M::Id>;
|
async fn newer_msg_id(&self, id: &M::Id) -> Option<M::Id>;
|
||||||
|
async fn set_seen(&self, id: &M::Id, seen: bool);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,15 @@ impl MsgStore<SmallMessage> for EuphVault {
|
||||||
let _ = self.vault.tx.send(request.into());
|
let _ = self.vault.tx.send(request.into());
|
||||||
rx.await.unwrap()
|
rx.await.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn set_seen(&self, id: &Snowflake, seen: bool) {
|
||||||
|
let request = EuphRequest::SetSeen {
|
||||||
|
room: self.room.clone(),
|
||||||
|
id: *id,
|
||||||
|
seen,
|
||||||
|
};
|
||||||
|
let _ = self.vault.tx.send(request.into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) enum EuphRequest {
|
pub(super) enum EuphRequest {
|
||||||
|
|
@ -350,6 +359,11 @@ pub(super) enum EuphRequest {
|
||||||
id: Snowflake,
|
id: Snowflake,
|
||||||
result: oneshot::Sender<Option<Snowflake>>,
|
result: oneshot::Sender<Option<Snowflake>>,
|
||||||
},
|
},
|
||||||
|
SetSeen {
|
||||||
|
room: String,
|
||||||
|
id: Snowflake,
|
||||||
|
seen: bool,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EuphRequest {
|
impl EuphRequest {
|
||||||
|
|
@ -399,6 +413,7 @@ impl EuphRequest {
|
||||||
EuphRequest::GetNewerMsgId { room, id, result } => {
|
EuphRequest::GetNewerMsgId { room, id, result } => {
|
||||||
Self::get_newer_msg_id(conn, room, id, result)
|
Self::get_newer_msg_id(conn, room, id, result)
|
||||||
}
|
}
|
||||||
|
EuphRequest::SetSeen { room, id, seen } => Self::set_seen(conn, room, id, seen),
|
||||||
};
|
};
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
// If an error occurs here, the rest of the UI will likely panic and
|
// If an error occurs here, the rest of the UI will likely panic and
|
||||||
|
|
@ -778,7 +793,7 @@ impl EuphRequest {
|
||||||
ON tree.room = euph_msgs.room
|
ON tree.room = euph_msgs.room
|
||||||
AND tree.id = euph_msgs.parent
|
AND tree.id = euph_msgs.parent
|
||||||
)
|
)
|
||||||
SELECT id, parent, time, name, content
|
SELECT id, parent, time, name, content, seen
|
||||||
FROM euph_msgs
|
FROM euph_msgs
|
||||||
JOIN tree USING (room, id)
|
JOIN tree USING (room, id)
|
||||||
ORDER BY id ASC
|
ORDER BY id ASC
|
||||||
|
|
@ -791,6 +806,7 @@ impl EuphRequest {
|
||||||
time: row.get(2)?,
|
time: row.get(2)?,
|
||||||
nick: row.get(3)?,
|
nick: row.get(3)?,
|
||||||
content: row.get(4)?,
|
content: row.get(4)?,
|
||||||
|
seen: row.get(5)?,
|
||||||
})
|
})
|
||||||
})?
|
})?
|
||||||
.collect::<rusqlite::Result<_>>()?;
|
.collect::<rusqlite::Result<_>>()?;
|
||||||
|
|
@ -974,4 +990,22 @@ impl EuphRequest {
|
||||||
let _ = result.send(tree);
|
let _ = result.send(tree);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_seen(
|
||||||
|
conn: &Connection,
|
||||||
|
room: String,
|
||||||
|
id: Snowflake,
|
||||||
|
seen: bool,
|
||||||
|
) -> rusqlite::Result<()> {
|
||||||
|
conn.execute(
|
||||||
|
"
|
||||||
|
UPDATE euph_msgs
|
||||||
|
SET seen = :seen
|
||||||
|
WHERE room = :room
|
||||||
|
AND id = :id
|
||||||
|
",
|
||||||
|
named_params! {":room": room, ":id": id, ":seen": seen},
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue