|
|
@ -124,13 +124,18 @@ impl PrivateMessage {
|
|
|
|
conn: &PgConnection,
|
|
|
|
conn: &PgConnection,
|
|
|
|
private_message_form: &PrivateMessageForm,
|
|
|
|
private_message_form: &PrivateMessageForm,
|
|
|
|
) -> Result<Self, Error> {
|
|
|
|
) -> Result<Self, Error> {
|
|
|
|
use crate::schema::private_message::dsl::*;
|
|
|
|
let existing = Self::read_from_apub_id(
|
|
|
|
insert_into(private_message)
|
|
|
|
conn,
|
|
|
|
.values(private_message_form)
|
|
|
|
private_message_form
|
|
|
|
.on_conflict(ap_id)
|
|
|
|
.ap_id
|
|
|
|
.do_update()
|
|
|
|
.as_ref()
|
|
|
|
.set(private_message_form)
|
|
|
|
.unwrap_or(&"none".to_string()),
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
);
|
|
|
|
|
|
|
|
match existing {
|
|
|
|
|
|
|
|
Err(NotFound {}) => Ok(Self::create(conn, &private_message_form)?),
|
|
|
|
|
|
|
|
Ok(p) => Ok(Self::update(conn, p.id, &private_message_form)?),
|
|
|
|
|
|
|
|
Err(e) => Err(e),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|