Skip to content
Snippets Groups Projects
Verified Commit 2f6211c0 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

new: MUC: Store occupant-id

parent af23279d
No related branches found
No related tags found
No related merge requests found
......@@ -398,6 +398,7 @@ class MamMessageReceived(ApplicationEvent):
stanza_id: str
archive_jid: str
kind: KindConstant
occupant_id: str | None
@dataclass
......@@ -423,6 +424,7 @@ class MessageReceived(ApplicationEvent):
class GcMessageReceived(MessageReceived):
name: str = field(init=False, default='gc-message-received')
room_jid: str
occupant_id: str | None
@dataclass
......
......@@ -971,6 +971,10 @@ class GroupchatParticipant(CommonContact):
def type_string(self) -> str:
return 'pm'
@property
def occupant_id(self) -> str | None:
return self._presence.occupant_id
def can_add_to_roster(
contact: BareContact | GroupchatContact | GroupchatParticipant
......
......@@ -299,6 +299,8 @@ class MAM(BaseModule):
return
stanza_id = message_id
occupant_id = self._get_occupant_id(properties)
event_attr: dict[str, Any] = {
'account': self._account,
'jid': jid,
......@@ -309,6 +311,7 @@ class MAM(BaseModule):
'stanza_id': stanza_id,
'archive_jid': properties.mam.archive,
'kind': kind,
'occupant_id': occupant_id,
}
if check_if_message_correction(properties,
......@@ -320,6 +323,7 @@ class MAM(BaseModule):
self._log):
return
app.storage.archive.insert_into_logs(
self._account,
jid,
......@@ -329,10 +333,24 @@ class MAM(BaseModule):
contact_name=properties.muc_nickname,
additional_data=additional_data,
stanza_id=stanza_id,
message_id=properties.id)
message_id=properties.id,
occupant_id=occupant_id)
app.ged.raise_event(MamMessageReceived(**event_attr))
def _get_occupant_id(self, properties: MessageProperties) -> str | None:
if not properties.type.is_groupchat:
return None
if properties.occupant_id is None:
return None
contact = self._client.get_module('Contacts').get_contact(
properties.jid.bare, groupchat=True)
if contact.supports(Namespace.OCCUPANT_ID):
return properties.occupant_id
return None
def _is_valid_request(self, properties: MessageProperties) -> bool:
valid_id = self._mam_query_ids.get(properties.mam.archive, None)
return valid_id == properties.mam.query_id
......
......@@ -192,8 +192,16 @@ class Message(BaseModule):
if not msgtxt:
return
occupant_id = None
group_contact = self._client.get_module('Contacts').get_contact(
jid, groupchat=True)
if group_contact.supports(Namespace.OCCUPANT_ID):
# Only store occupant-id if MUC announces support
occupant_id = properties.occupant_id
event_attr.update({
'room_jid': jid,
'occupant_id': occupant_id,
})
event = GcMessageReceived(**event_attr)
......@@ -260,7 +268,8 @@ class Message(BaseModule):
contact_name=event.properties.muc_nickname,
additional_data=event.additional_data,
stanza_id=event.stanza_id,
message_id=event.properties.id)
message_id=event.properties.id,
occupant_id=event.occupant_id)
return msg_log_id
return None
......
......@@ -759,8 +759,15 @@ class MUC(BaseModule):
def _process_user_presence(self,
properties: PresenceProperties
) -> MUCPresenceData:
jid = properties.jid
muc_presence = MUCPresenceData.from_presence(properties)
group_contact = self._client.get_module('Contacts').get_contact(
jid.bare, groupchat=True)
occupant_id = None
if group_contact.supports(Namespace.OCCUPANT_ID):
occupant_id = properties.occupant_id
muc_presence = MUCPresenceData.from_presence(properties, occupant_id)
if not muc_presence.available:
self._joined_users[jid.bare].pop(jid.resource)
else:
......
......@@ -237,16 +237,22 @@ class MUCPresenceData:
affiliation: Affiliation
role: Role
real_jid: JID | None
occupant_id: str | None
@classmethod
def from_presence(cls, properties: PresenceProperties) -> MUCPresenceData:
def from_presence(cls,
properties: PresenceProperties,
occupant_id: str | None
) -> MUCPresenceData:
return cls(show=properties.show,
status=properties.status,
idle_time=properties.idle_timestamp,
available=properties.type.is_available,
affiliation=properties.muc_user.affiliation,
role=properties.muc_user.role,
real_jid=properties.muc_user.jid)
real_jid=properties.muc_user.jid,
occupant_id=occupant_id)
UNKNOWN_MUC_PRESENCE = MUCPresenceData(show=PresenceShowExt.OFFLINE,
......@@ -255,7 +261,8 @@ UNKNOWN_MUC_PRESENCE = MUCPresenceData(show=PresenceShowExt.OFFLINE,
available=False,
affiliation=Affiliation.NONE,
role=Role.NONE,
real_jid=None)
real_jid=None,
occupant_id=None)
class VariantMixin:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment