Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2023-06-07 01:02:27 +0300
committerPhilipp Hörist <philipp@hoerist.com>2023-06-07 01:02:38 +0300
commit2f6211c045e06f7f60e11539d5ba09a5af1cf08c (patch)
tree93131203d858f49440e3099bb90aae14bcff988f
parentaf23279d95c58bdb2c335b55e0e396e188d70e66 (diff)
new: MUC: Store occupant-id
-rw-r--r--gajim/common/events.py2
-rw-r--r--gajim/common/modules/contacts.py4
-rw-r--r--gajim/common/modules/mam.py20
-rw-r--r--gajim/common/modules/message.py11
-rw-r--r--gajim/common/modules/muc.py9
-rw-r--r--gajim/common/structs.py13
6 files changed, 53 insertions, 6 deletions
diff --git a/gajim/common/events.py b/gajim/common/events.py
index c9954db12..6636d1da9 100644
--- a/gajim/common/events.py
+++ b/gajim/common/events.py
@@ -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
diff --git a/gajim/common/modules/contacts.py b/gajim/common/modules/contacts.py
index 0aa0c8cf1..a63578db6 100644
--- a/gajim/common/modules/contacts.py
+++ b/gajim/common/modules/contacts.py
@@ -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
diff --git a/gajim/common/modules/mam.py b/gajim/common/modules/mam.py
index aa262394b..cc29fd174 100644
--- a/gajim/common/modules/mam.py
+++ b/gajim/common/modules/mam.py
@@ -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
diff --git a/gajim/common/modules/message.py b/gajim/common/modules/message.py
index 6e1a4c0e2..7be9ba43e 100644
--- a/gajim/common/modules/message.py
+++ b/gajim/common/modules/message.py
@@ -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
diff --git a/gajim/common/modules/muc.py b/gajim/common/modules/muc.py
index c29a632ce..832adf322 100644
--- a/gajim/common/modules/muc.py
+++ b/gajim/common/modules/muc.py
@@ -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:
diff --git a/gajim/common/structs.py b/gajim/common/structs.py
index 726726784..d3fe5dd65 100644
--- a/gajim/common/structs.py
+++ b/gajim/common/structs.py
@@ -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: