aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src
diff options
context:
space:
mode:
Diffstat (limited to 'filamento/src')
-rw-r--r--filamento/src/db.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/filamento/src/db.rs b/filamento/src/db.rs
index cdc7520..51d99e6 100644
--- a/filamento/src/db.rs
+++ b/filamento/src/db.rs
@@ -78,10 +78,11 @@ impl Db {
/// returns whether or not the nickname was updated
pub(crate) async fn delete_user_nick(&self, jid: JID) -> Result<bool, Error> {
if sqlx::query!(
- "insert into users (jid, nick) values (?, ?) on conflict do update set nick = ?",
+ "insert into users (jid, nick) values (?, ?) on conflict do update set nick = ? where nick is not ?",
jid,
None::<String>,
None::<String>,
+ None::<String>,
)
.execute(&self.db)
.await?
@@ -96,17 +97,18 @@ impl Db {
/// returns whether or not the nickname was updated
pub(crate) async fn upsert_user_nick(&self, jid: JID, nick: String) -> Result<bool, Error> {
- if sqlx::query!(
- "insert into users (jid, nick) values (?, ?) on conflict do update set nick = ?",
+ let rows_affected = sqlx::query!(
+ "insert into users (jid, nick) values (?, ?) on conflict do update set nick = ? where nick is not ?",
jid,
nick,
+ nick,
nick
)
.execute(&self.db)
.await?
- .rows_affected()
- > 0
- {
+ .rows_affected();
+ tracing::debug!("rows affected: {}", rows_affected);
+ if rows_affected > 0 {
Ok(true)
} else {
Ok(false)
@@ -129,10 +131,11 @@ impl Db {
.map(|row: AvatarRow| row.avatar)
.unwrap_or(None);
if sqlx::query!(
- "insert into users (jid, avatar) values (?, ?) on conflict do update set avatar = ?",
+ "insert into users (jid, avatar) values (?, ?) on conflict do update set avatar = ? where avatar is not ?",
jid,
None::<String>,
None::<String>,
+ None::<String>,
)
.execute(&self.db)
.await?
@@ -162,10 +165,11 @@ impl Db {
.map(|row: AvatarRow| row.avatar)
.unwrap_or(None);
if sqlx::query!(
- "insert into users (jid, avatar) values (?, ?) on conflict do update set avatar = ?",
+ "insert into users (jid, avatar) values (?, ?) on conflict do update set avatar = ? where avatar is not ?",
jid,
avatar,
- avatar
+ avatar,
+ avatar,
)
.execute(&self.db)
.await?