diff options
Diffstat (limited to '')
| -rw-r--r-- | filamento/src/db.rs | 37 | ||||
| -rw-r--r-- | filamento/src/logic/process_stanza.rs | 2 | 
2 files changed, 22 insertions, 17 deletions
| diff --git a/filamento/src/db.rs b/filamento/src/db.rs index 51d99e6..1d3d36c 100644 --- a/filamento/src/db.rs +++ b/filamento/src/db.rs @@ -384,9 +384,10 @@ impl Db {          let id = Uuid::new_v4();          let jid = chat.correspondent();          sqlx::query!( -            "insert into chats (id, correspondent) values (?, ?)", +            "insert into chats (id, correspondent, have_chatted) values (?, ?, ?)",              id, -            jid +            jid, +            chat.have_chatted,          )          .execute(&self.db)          .await?; @@ -473,7 +474,9 @@ impl Db {              pub message: Message,          } +        // TODO: sometimes chats have no messages.          // TODO: i don't know if this will assign the right uuid to the latest message or the chat's id. should probably check but i don't think it matters as nothing ever gets called with the id of the latest message in the chats list +        // TODO: it does matter in fact, as message updates and delivery receipts need to go to the right latest_message          let chats: Vec<ChatWithMessage> = sqlx::query_as("select c.*, m.* from chats c join (select chat_id, max(timestamp) max_timestamp from messages group by chat_id) max_timestamps on c.id = max_timestamps.chat_id join messages m on max_timestamps.chat_id = m.chat_id and max_timestamps.max_timestamp = m.timestamp order by m.timestamp desc")              .fetch_all(&self.db)              .await?; @@ -569,7 +572,7 @@ impl Db {          Ok(())      } -    // create direct message from incoming +    /// create direct message from incoming. MUST upsert chat and user      pub(crate) async fn create_message_with_user_resource(          &self,          message: Message, @@ -579,20 +582,20 @@ impl Db {      ) -> Result<(), Error> {          let bare_chat = chat.as_bare();          let resource = &chat.resourcepart; -        sqlx::query!( -            "insert into users (jid) values (?) on conflict do nothing", -            bare_chat -        ) -        .execute(&self.db) -        .await?; -        let id = Uuid::new_v4(); -        sqlx::query!( -            "insert into chats (id, correspondent) values (?, ?) on conflict do nothing", -            id, -            bare_chat -        ) -        .execute(&self.db) -        .await?; +        // sqlx::query!( +        //     "insert into users (jid) values (?) on conflict do nothing", +        //     bare_chat +        // ) +        // .execute(&self.db) +        // .await?; +        // let id = Uuid::new_v4(); +        // sqlx::query!( +        //     "insert into chats (id, correspondent) values (?, ?) on conflict do nothing", +        //     id, +        //     bare_chat +        // ) +        // .execute(&self.db) +        // .await?;          if let Some(resource) = resource {              sqlx::query!(                  "insert into resources (bare_jid, resource) values (?, ?) on conflict do nothing", diff --git a/filamento/src/logic/process_stanza.rs b/filamento/src/logic/process_stanza.rs index 7142144..9c49b04 100644 --- a/filamento/src/logic/process_stanza.rs +++ b/filamento/src/logic/process_stanza.rs @@ -92,12 +92,14 @@ pub async fn recv_message<Fs: FileStore + Clone>(                          logic                              .handle_error(Error::MessageRecv(MessageRecvError::MessageHistory(e)))                              .await; +                        error!("failed to upsert chat and user")                      }                  }                  Err(e) => {                      logic                          .handle_error(Error::MessageRecv(MessageRecvError::MessageHistory(e)))                          .await; +                    error!("failed to upsert chat and user")                  }              }; | 
