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 19:19:23 +0300
committerPhilipp Hörist <philipp@hoerist.com>2023-06-07 19:19:23 +0300
commite09866e4eb0b1ddf3f32a129e75172e275de3df0 (patch)
tree0f77e5d8fb49c0656c5c6b535b2f05807f6ead68
parent8d6181cb82f2f449bf7e54f56c7527af6ebbf42e (diff)
new: MUC: Store real jid for messages
-rw-r--r--gajim/common/events.py2
-rw-r--r--gajim/common/modules/mam.py16
-rw-r--r--gajim/common/modules/message.py20
3 files changed, 35 insertions, 3 deletions
diff --git a/gajim/common/events.py b/gajim/common/events.py
index 6636d1da9..59ea378af 100644
--- a/gajim/common/events.py
+++ b/gajim/common/events.py
@@ -399,6 +399,7 @@ class MamMessageReceived(ApplicationEvent):
archive_jid: str
kind: KindConstant
occupant_id: str | None
+ real_jid: JID | None
@dataclass
@@ -424,6 +425,7 @@ class MessageReceived(ApplicationEvent):
class GcMessageReceived(MessageReceived):
name: str = field(init=False, default='gc-message-received')
room_jid: str
+ real_jid: JID | None
occupant_id: str | None
diff --git a/gajim/common/modules/mam.py b/gajim/common/modules/mam.py
index cc29fd174..acd8e3710 100644
--- a/gajim/common/modules/mam.py
+++ b/gajim/common/modules/mam.py
@@ -300,6 +300,7 @@ class MAM(BaseModule):
stanza_id = message_id
occupant_id = self._get_occupant_id(properties)
+ real_jid = self._get_real_jid(properties)
event_attr: dict[str, Any] = {
'account': self._account,
@@ -312,6 +313,7 @@ class MAM(BaseModule):
'archive_jid': properties.mam.archive,
'kind': kind,
'occupant_id': occupant_id,
+ 'real_jid': real_jid,
}
if check_if_message_correction(properties,
@@ -323,7 +325,6 @@ class MAM(BaseModule):
self._log):
return
-
app.storage.archive.insert_into_logs(
self._account,
jid,
@@ -334,10 +335,21 @@ class MAM(BaseModule):
additional_data=additional_data,
stanza_id=stanza_id,
message_id=properties.id,
- occupant_id=occupant_id)
+ occupant_id=occupant_id,
+ real_jid=real_jid,
+ )
app.ged.raise_event(MamMessageReceived(**event_attr))
+ def _get_real_jid(self, properties: MessageProperties) -> JID | None:
+ if not properties.type.is_groupchat:
+ return None
+
+ if properties.muc_user is None:
+ return None
+
+ return properties.muc_user.jid
+
def _get_occupant_id(self, properties: MessageProperties) -> str | None:
if not properties.type.is_groupchat:
return None
diff --git a/gajim/common/modules/message.py b/gajim/common/modules/message.py
index 7be9ba43e..dff03c1d6 100644
--- a/gajim/common/modules/message.py
+++ b/gajim/common/modules/message.py
@@ -22,6 +22,7 @@ import time
import nbxmpp
from nbxmpp.namespaces import Namespace
+from nbxmpp.protocol import JID
from nbxmpp.structs import MessageProperties
from nbxmpp.structs import StanzaHandler
from nbxmpp.util import generate_id
@@ -35,6 +36,7 @@ from gajim.common.events import MessageReceived
from gajim.common.events import RawMessageReceived
from gajim.common.helpers import AdditionalDataDict
from gajim.common.modules.base import BaseModule
+from gajim.common.modules.contacts import GroupchatParticipant
from gajim.common.modules.misc import parse_oob
from gajim.common.modules.misc import parse_xhtml
from gajim.common.modules.util import check_if_message_correction
@@ -199,8 +201,11 @@ class Message(BaseModule):
# Only store occupant-id if MUC announces support
occupant_id = properties.occupant_id
+ real_jid = self._get_real_jid(properties)
+
event_attr.update({
'room_jid': jid,
+ 'real_jid': real_jid,
'occupant_id': occupant_id,
})
@@ -269,7 +274,8 @@ class Message(BaseModule):
additional_data=event.additional_data,
stanza_id=event.stanza_id,
message_id=event.properties.id,
- occupant_id=event.occupant_id)
+ occupant_id=event.occupant_id,
+ real_Jid=event.real_jid)
return msg_log_id
return None
@@ -279,6 +285,18 @@ class Message(BaseModule):
if stanza_id is None and disco_info.mam_namespace == Namespace.MAM_2:
self._log.warning('%s announces mam:2 without stanza-id', room_jid)
+ def _get_real_jid(self, properties: MessageProperties) -> JID | None:
+ if not properties.type.is_groupchat:
+ return None
+
+ if not properties.jid.is_full:
+ return None
+
+ participant = self._client.get_module('Contacts').get_contact(
+ properties.jid, groupchat=True)
+ assert isinstance(participant, GroupchatParticipant)
+ return participant.real_jid
+
def _get_unique_id(self,
properties: MessageProperties
) -> tuple[str | None, str | None]: