aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src/db.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-04-08 11:29:31 +0100
committerLibravatar cel 🌸 <cel@bunny.garden>2025-04-08 11:29:31 +0100
commit0b19cb38183929d3f242cfd11c34426d9302697c (patch)
treef03a20b1b85d677c182a9d7a2c34c77a29ac6df7 /filamento/src/db.rs
parent5b644e2dc8712d56931b410b9c46dae1ef36e691 (diff)
downloadluz-0b19cb38183929d3f242cfd11c34426d9302697c.tar.gz
luz-0b19cb38183929d3f242cfd11c34426d9302697c.tar.bz2
luz-0b19cb38183929d3f242cfd11c34426d9302697c.zip
fix(filamento): check if nick and avatar were actually changed
Diffstat (limited to '')
-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?