Retrieve individual messages from store
This commit is contained in:
parent
7e086258b6
commit
bb542ae08e
3 changed files with 54 additions and 0 deletions
|
|
@ -79,6 +79,10 @@ impl MsgStore<LogMsg> for Logger {
|
||||||
Path::new(vec![*id])
|
Path::new(vec![*id])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn msg(&self, id: &usize) -> Option<LogMsg> {
|
||||||
|
self.messages.lock().get(*id).cloned()
|
||||||
|
}
|
||||||
|
|
||||||
async fn tree(&self, tree_id: &usize) -> Tree<LogMsg> {
|
async fn tree(&self, tree_id: &usize) -> Tree<LogMsg> {
|
||||||
let msgs = self
|
let msgs = self
|
||||||
.messages
|
.messages
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,7 @@ impl<M: Msg> Tree<M> {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait MsgStore<M: Msg> {
|
pub trait MsgStore<M: Msg> {
|
||||||
async fn path(&self, id: &M::Id) -> Path<M::Id>;
|
async fn path(&self, id: &M::Id) -> Path<M::Id>;
|
||||||
|
async fn msg(&self, id: &M::Id) -> Option<M>;
|
||||||
async fn tree(&self, tree_id: &M::Id) -> Tree<M>;
|
async fn tree(&self, tree_id: &M::Id) -> Tree<M>;
|
||||||
async fn first_tree_id(&self) -> Option<M::Id>;
|
async fn first_tree_id(&self) -> Option<M::Id>;
|
||||||
async fn last_tree_id(&self) -> Option<M::Id>;
|
async fn last_tree_id(&self) -> Option<M::Id>;
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,18 @@ impl MsgStore<SmallMessage> for EuphVault {
|
||||||
rx.await.unwrap()
|
rx.await.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn msg(&self, id: &Snowflake) -> Option<SmallMessage> {
|
||||||
|
// TODO vault::Error
|
||||||
|
let (tx, rx) = oneshot::channel();
|
||||||
|
let request = EuphRequest::GetMsg {
|
||||||
|
room: self.room.clone(),
|
||||||
|
id: *id,
|
||||||
|
result: tx,
|
||||||
|
};
|
||||||
|
let _ = self.vault.tx.send(request.into());
|
||||||
|
rx.await.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
async fn tree(&self, tree_id: &Snowflake) -> Tree<SmallMessage> {
|
async fn tree(&self, tree_id: &Snowflake) -> Tree<SmallMessage> {
|
||||||
// TODO vault::Error
|
// TODO vault::Error
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
|
|
@ -403,6 +415,11 @@ pub(super) enum EuphRequest {
|
||||||
id: Snowflake,
|
id: Snowflake,
|
||||||
result: oneshot::Sender<Path<Snowflake>>,
|
result: oneshot::Sender<Path<Snowflake>>,
|
||||||
},
|
},
|
||||||
|
GetMsg {
|
||||||
|
room: String,
|
||||||
|
id: Snowflake,
|
||||||
|
result: oneshot::Sender<Option<SmallMessage>>,
|
||||||
|
},
|
||||||
GetTree {
|
GetTree {
|
||||||
room: String,
|
room: String,
|
||||||
root: Snowflake,
|
root: Snowflake,
|
||||||
|
|
@ -506,6 +523,7 @@ impl EuphRequest {
|
||||||
} => Self::add_msgs(conn, room, msgs, next_msg, own_user_id),
|
} => Self::add_msgs(conn, room, msgs, next_msg, own_user_id),
|
||||||
Self::GetLastSpan { room, result } => Self::get_last_span(conn, room, result),
|
Self::GetLastSpan { room, result } => Self::get_last_span(conn, room, result),
|
||||||
Self::GetPath { room, id, result } => Self::get_path(conn, room, id, result),
|
Self::GetPath { room, id, result } => Self::get_path(conn, room, id, result),
|
||||||
|
Self::GetMsg { room, id, result } => Self::get_msg(conn, room, id, result),
|
||||||
Self::GetTree { room, root, result } => Self::get_tree(conn, room, root, result),
|
Self::GetTree { room, root, result } => Self::get_tree(conn, room, root, result),
|
||||||
Self::GetFirstTreeId { room, result } => Self::get_first_tree_id(conn, room, result),
|
Self::GetFirstTreeId { room, result } => Self::get_first_tree_id(conn, room, result),
|
||||||
Self::GetLastTreeId { room, result } => Self::get_last_tree_id(conn, room, result),
|
Self::GetLastTreeId { room, result } => Self::get_last_tree_id(conn, room, result),
|
||||||
|
|
@ -900,6 +918,37 @@ impl EuphRequest {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_msg(
|
||||||
|
conn: &Connection,
|
||||||
|
room: String,
|
||||||
|
id: Snowflake,
|
||||||
|
result: oneshot::Sender<Option<SmallMessage>>,
|
||||||
|
) -> rusqlite::Result<()> {
|
||||||
|
let msg = conn
|
||||||
|
.query_row(
|
||||||
|
"
|
||||||
|
SELECT id, parent, time, name, content, seen
|
||||||
|
FROM euph_msgs
|
||||||
|
WHERE room = ?
|
||||||
|
AND id = ?
|
||||||
|
",
|
||||||
|
params![room, WSnowflake(id)],
|
||||||
|
|row| {
|
||||||
|
Ok(SmallMessage {
|
||||||
|
id: row.get::<_, WSnowflake>(0)?.0,
|
||||||
|
parent: row.get::<_, Option<WSnowflake>>(1)?.map(|s| s.0),
|
||||||
|
time: row.get::<_, WTime>(2)?.0,
|
||||||
|
nick: row.get(3)?,
|
||||||
|
content: row.get(4)?,
|
||||||
|
seen: row.get(5)?,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.optional()?;
|
||||||
|
let _ = result.send(msg);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn get_tree(
|
fn get_tree(
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
room: String,
|
room: String,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue