Threads, Get Messages Since

This commit is contained in:
2024-08-23 16:39:15 -04:00
Unverified
parent a0ccdb1def
commit 68b7ba6809
3 changed files with 72 additions and 24 deletions

View File

@@ -21,6 +21,7 @@ pub trait RealmChat {
async fn get_message_from_id(stoken: String, id: i64) -> Result<Message, ErrorCode>;
async fn get_messages_since(stoken: String, time: DateTime<Utc>) -> Result<Vec<Message>, ErrorCode>;
async fn get_all_direct_replies(stoken: String, head: i64) -> Result<Vec<Message>, ErrorCode>;
async fn get_reply_chain(stoken: String, head: Message, depth: u8) -> Result<ReplyChain, ErrorCode>;
async fn get_rooms(stoken: String) -> Result<Vec<Room>, ErrorCode>;
async fn get_room(stoken: String, roomid: String) -> Result<Room, ErrorCode>;
async fn get_user(userid: String) -> Result<User, ErrorCode>;
@@ -46,6 +47,22 @@ pub struct Message {
pub data: MessageData,
}
pub trait FromRows<R: Row>: Sized {
fn from_rows(rows: Vec<R>) -> Result<Vec<Self>, sqlx::Error>;
}
impl FromRows<SqliteRow> for Message {
fn from_rows(rows: Vec<SqliteRow>) -> sqlx::Result<Vec<Self>> {
let mut messages = Vec::new();
for row in rows {
messages.push(Message::from_row(&row)?);
}
Ok(messages)
}
}
impl FromRow<'_, SqliteRow> for Message {
fn from_row(row: &SqliteRow) -> sqlx::Result<Self> {
Ok(Self {
@@ -146,3 +163,9 @@ pub struct Room {
pub admin_only_view: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplyChain {
pub message: Message,
pub replies: Option<Vec<ReplyChain>>,
}