mirror of
https://github.com/element-hq/synapse.git
synced 2026-06-03 21:21:25 +00:00
Only pass field names to add_profile_updates
This commit is contained in:
@@ -112,12 +112,12 @@ class ProfileHandler:
|
||||
)
|
||||
|
||||
async def _record_profile_updates(
|
||||
self, user_id: UserID, updates: list[tuple[str, JsonValue | None]]
|
||||
self, user_id: UserID, updated_fields: list[str]
|
||||
) -> None:
|
||||
if not self._msc4429_enabled or not updates:
|
||||
if not self._msc4429_enabled or not updated_fields:
|
||||
return
|
||||
|
||||
stream_id = await self.store.add_profile_updates(user_id, updates)
|
||||
stream_id = await self.store.add_profile_updates(user_id, updated_fields)
|
||||
await self._notify_profile_update(user_id, stream_id)
|
||||
|
||||
async def get_profile(self, user_id: str, ignore_backoff: bool = True) -> JsonDict:
|
||||
@@ -275,7 +275,8 @@ class ProfileHandler:
|
||||
|
||||
await self.store.set_profile_displayname(target_user, displayname_to_set)
|
||||
await self._record_profile_updates(
|
||||
target_user, [(ProfileFields.DISPLAYNAME, displayname_to_set)]
|
||||
target_user,
|
||||
[ProfileFields.DISPLAYNAME],
|
||||
)
|
||||
|
||||
profile = await self.store.get_profileinfo(target_user)
|
||||
@@ -387,7 +388,8 @@ class ProfileHandler:
|
||||
|
||||
await self.store.set_profile_avatar_url(target_user, avatar_url_to_set)
|
||||
await self._record_profile_updates(
|
||||
target_user, [(ProfileFields.AVATAR_URL, avatar_url_to_set)]
|
||||
target_user,
|
||||
[ProfileFields.AVATAR_URL],
|
||||
)
|
||||
|
||||
profile = await self.store.get_profileinfo(target_user)
|
||||
@@ -471,7 +473,9 @@ class ProfileHandler:
|
||||
profile_updates.append((field_name, None))
|
||||
|
||||
await self.store.delete_profile(target_user)
|
||||
await self._record_profile_updates(target_user, profile_updates)
|
||||
await self._record_profile_updates(
|
||||
target_user, [field_name for field_name, _value in profile_updates]
|
||||
)
|
||||
|
||||
await self._third_party_rules.on_profile_update(
|
||||
target_user.to_string(),
|
||||
@@ -625,7 +629,7 @@ class ProfileHandler:
|
||||
raise AuthError(403, "Cannot set another user's profile")
|
||||
|
||||
await self.store.set_profile_field(target_user, field_name, new_value)
|
||||
await self._record_profile_updates(target_user, [(field_name, new_value)])
|
||||
await self._record_profile_updates(target_user, [field_name])
|
||||
|
||||
# Custom fields do not propagate into the user directory *or* rooms.
|
||||
profile = await self.store.get_profileinfo(target_user)
|
||||
@@ -661,7 +665,7 @@ class ProfileHandler:
|
||||
raise AuthError(400, "Cannot set another user's profile")
|
||||
|
||||
await self.store.delete_profile_field(target_user, field_name)
|
||||
await self._record_profile_updates(target_user, [(field_name, None)])
|
||||
await self._record_profile_updates(target_user, [field_name])
|
||||
|
||||
# Custom fields do not propagate into the user directory *or* rooms.
|
||||
profile = await self.store.get_profileinfo(target_user)
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#
|
||||
#
|
||||
import json
|
||||
from typing import TYPE_CHECKING, Collection, Iterable, Sequence, cast
|
||||
from typing import TYPE_CHECKING, Collection, Iterable, cast
|
||||
|
||||
import attr
|
||||
from canonicaljson import encode_canonical_json
|
||||
@@ -436,21 +436,23 @@ class ProfileWorkerStore(SQLBaseStore):
|
||||
return results
|
||||
|
||||
async def add_profile_updates(
|
||||
self, user_id: UserID, updates: Sequence[tuple[str, JsonValue | None]]
|
||||
self,
|
||||
user_id: UserID,
|
||||
updated_fields: list[str],
|
||||
) -> int:
|
||||
"""Persist profile update markers and return the last stream ID."""
|
||||
assert self._can_write_to_profile_updates
|
||||
|
||||
if not updates:
|
||||
if not updated_fields:
|
||||
return self._profile_updates_id_gen.get_current_token()
|
||||
|
||||
user_id_str = user_id.to_string()
|
||||
|
||||
def _add_profile_updates_txn(txn: LoggingTransaction) -> int:
|
||||
stream_ids = self._profile_updates_id_gen.get_next_mult_txn(
|
||||
txn, len(updates)
|
||||
txn, len(updated_fields)
|
||||
)
|
||||
for stream_id, (field_name, _value) in zip(stream_ids, updates):
|
||||
for stream_id, field_name in zip(stream_ids, updated_fields):
|
||||
self.db_pool.simple_insert_txn(
|
||||
txn,
|
||||
table="profile_updates",
|
||||
|
||||
Reference in New Issue
Block a user