|
@@ -40,6 +40,7 @@ class Puppet(DBPuppet, BasePuppet):
|
|
|
hs_domain: str
|
|
|
mxid_template: SimpleTemplate[int]
|
|
|
|
|
|
+ bridge: InstagramBridge
|
|
|
config: Config
|
|
|
|
|
|
default_mxid_intent: IntentAPI
|
|
@@ -84,6 +85,7 @@ class Puppet(DBPuppet, BasePuppet):
|
|
|
|
|
|
@classmethod
|
|
|
def init_cls(cls, bridge: "InstagramBridge") -> AsyncIterable[Awaitable[None]]:
|
|
|
+ cls.bridge = bridge
|
|
|
cls.config = bridge.config
|
|
|
cls.loop = bridge.loop
|
|
|
cls.mx = bridge.matrix
|
|
@@ -126,12 +128,37 @@ class Puppet(DBPuppet, BasePuppet):
|
|
|
)
|
|
|
|
|
|
async def update_info(self, info: BaseResponseUser, source: u.User) -> None:
|
|
|
- update = False
|
|
|
+ update = await self._update_contact_info(info)
|
|
|
update = await self._update_name(info) or update
|
|
|
update = await self._update_avatar(info, source) or update
|
|
|
if update:
|
|
|
await self.update()
|
|
|
|
|
|
+ async def _update_contact_info(self, info: BaseResponseUser | None = None) -> bool:
|
|
|
+ if not self.bridge.homeserver_software.is_hungry:
|
|
|
+ return False
|
|
|
+
|
|
|
+ if self.contact_info_set:
|
|
|
+ return False
|
|
|
+
|
|
|
+ try:
|
|
|
+ identifiers = []
|
|
|
+ if info and info.username:
|
|
|
+ identifiers.append(f"instagram:{info.username}")
|
|
|
+ await self.default_mxid_intent.beeper_update_profile(
|
|
|
+ {
|
|
|
+ "com.beeper.bridge.identifiers": identifiers,
|
|
|
+ "com.beeper.bridge.remote_id": str(self.fbid),
|
|
|
+ "com.beeper.bridge.service": self.bridge.beeper_service_name,
|
|
|
+ "com.beeper.bridge.network": self.bridge.beeper_network_name,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ self.contact_info_set = True
|
|
|
+ except Exception:
|
|
|
+ self.log.exception("Error updating contact info")
|
|
|
+ self.contact_info_set = False
|
|
|
+ return True
|
|
|
+
|
|
|
@classmethod
|
|
|
def _get_displayname(cls, info: BaseResponseUser) -> str:
|
|
|
return cls.config["bridge.displayname_template"].format(
|