Philipp Hörist pushed to branch master at gajim / gajim
Commits:
4d4dcabe by Philipp Hörist at 2025-05-10T21:09:27+02:00
cfix: Database: Use always bare remote jid for occupants
- - - - -
5 changed files:
- gajim/common/modules/message.py
- gajim/common/modules/message_util.py
- gajim/common/modules/moderations.py
- gajim/common/storage/archive/models.py
- gajim/common/storage/archive/storage.py
Changes:
=====================================
gajim/common/modules/message.py
=====================================
@@ -376,7 +376,7 @@ def store_message(self, message: OutgoingMessage) -> None:
occupant = mod.Occupant(
account_=self._account,
- remote_jid_=remote_jid,
+ remote_jid_=muc_jid,
id=str(occupant_id),
real_remote_jid_=real_jid,
nickname=resource,
=====================================
gajim/common/modules/message_util.py
=====================================
@@ -110,7 +110,7 @@ def get_occupant_info(
return mod.Occupant(
account_=account,
- remote_jid_=remote_jid,
+ remote_jid_=remote_jid.new_as_bare(),
id=str(occupant_id),
real_remote_jid_=real_jid or VALUE_MISSING,
nickname=resource,
=====================================
gajim/common/modules/moderations.py
=====================================
@@ -134,7 +134,7 @@ def _insert_moderation_message(
if moderator_occupant_id is not None:
occupant_data = mod.Occupant(
account_=self._account,
- remote_jid_=remote_jid,
+ remote_jid_=remote_jid.new_as_bare(),
id=moderator_occupant_id,
nickname=moderator_nickname,
updated_at=properties.moderation.stamp,
@@ -185,7 +185,7 @@ def _insert_tombstone(
if message_occupant_id is not None:
occupant_data = mod.Occupant(
account_=self._account,
- remote_jid_=remote_jid,
+ remote_jid_=remote_jid.new_as_bare(),
id=message_occupant_id,
nickname=properties.jid.resource,
updated_at=timestamp,
=====================================
gajim/common/storage/archive/models.py
=====================================
@@ -43,6 +43,9 @@ class Base(DeclarativeBase):
int: types.INTEGER(),
}
+ def validate(self) -> None:
+ pass
+
class UtilMixin:
def get_upsert_values(self) -> dict[str, str]:
@@ -152,6 +155,12 @@ class Occupant(MappedAsDataclass, Base, UtilMixin,
kw_only=True):
)
updated_at: Mapped[datetime.datetime] = mapped_column(EpochTimestampType)
+ def validate(self) -> None:
+ if self.remote_jid_ is None:
+ return
+ if not self.remote_jid_.is_bare:
+ raise ValueError("Remote JID must be a bare jid")
+
def needs_update(self, existing: Occupant) -> bool:
return existing.updated_at < self.updated_at
=====================================
gajim/common/storage/archive/storage.py
=====================================
@@ -209,6 +209,8 @@ def _set_foreign_keys(self, session: Session, row: Any) ->
None:
def insert_object(
self, session: Session, obj: Any, ignore_on_conflict: bool = True
) -> int:
+
+ obj.validate()
self._set_foreign_keys(session, obj)
self._log_row(obj)
session.add(obj)
@@ -248,6 +250,8 @@ def _insert_row(
return_pk_on_conflict: bool = False,
ignore_on_conflict: bool = False,
) -> int:
+
+ row.validate()
self._set_foreign_keys(session, row)
self._log_row(row)
table = row.__class__
@@ -278,6 +282,8 @@ def _upsert_row(
session: Session,
row: Any,
) -> int:
+
+ row.validate()
self._set_foreign_keys(session, row)
self._log_row(row)
table = row.__class__
@@ -313,6 +319,8 @@ def _upsert_row2(
session: Session,
row: Any,
) -> int | None:
+
+ row.validate()
self._set_foreign_keys(session, row)
self._log_row(row)
table = row.__class__
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/4d4dcabeecbf6f822603e398d0aea9ee85b41d55
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/4d4dcabeecbf6f822603e398d0aea9ee85b41d55
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]