Skip to content

Commit

Permalink
inbox: return message ids
Browse files Browse the repository at this point in the history
  • Loading branch information
caolan committed Jul 29, 2024
1 parent 9529c7b commit 51ece1a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface JsonArray extends Array<JsonValue> { }
type JsonValue = (null | boolean | number | string | JsonObject | JsonArray);

export type Message = {
id: number,
peer: string,
uuid: string,
message: Uint8Array,
Expand Down
1 change: 1 addition & 0 deletions mutinyd/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub enum ResponseBody {

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Message {
pub id: usize,
pub peer: String,
pub uuid: String,
#[serde(with = "serde_bytes")]
Expand Down
9 changes: 5 additions & 4 deletions mutinyd/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl<'a> StoreTransaction<'a> {

pub fn read_message(&self, app_id: i64) -> Result<Option<Message>> {
let mut stmt = self.tx.prepare_cached(
"SELECT peer.peer_id, app.uuid, data
"SELECT message_inbox.id, peer.peer_id, app.uuid, data
FROM message_inbox
JOIN message_data ON message_data.id = message_id
JOIN app ON app.id = from_app_id
Expand All @@ -339,9 +339,10 @@ impl<'a> StoreTransaction<'a> {
)?;
stmt.query_row([app_id], |row| {
Ok(Message {
peer: row.get::<_, String>(0)?,
uuid: row.get::<_, String>(1)?,
message: row.get::<_, Vec<u8>>(2)?,
id: row.get::<_, usize>(0)?,
peer: row.get::<_, String>(1)?,
uuid: row.get::<_, String>(2)?,
message: row.get::<_, Vec<u8>>(3)?,
})
}).optional()
}
Expand Down

0 comments on commit 51ece1a

Please sign in to comment.