Coverage for slidge/slixfix/__init__.py: 95%

39 statements  

« prev     ^ index     » next       coverage.py v7.17.0, created at 2026-12-01 19:36 +0000

1# This module contains patches for slixmpp; some have pending requests upstream 

2# and should be removed on the next slixmpp release. 

3import uuid 

4 

5# ruff: noqa: F401 

6import slixmpp.plugins 

7import slixmpp.plugins.xep_0060.stanza 

8import slixmpp.stanza.roster 

9from slixmpp import Iq, Message, Presence, register_stanza_plugin 

10from slixmpp.exceptions import IqError 

11from slixmpp.plugins.xep_0050 import XEP_0050, Command 

12from slixmpp.plugins.xep_0084 import MetaData 

13from slixmpp.plugins.xep_0356.permissions import IqPermission 

14from slixmpp.plugins.xep_0356.privilege import XEP_0356, PrivilegedIqError 

15from slixmpp.plugins.xep_0469.stanza import NS as PINNED_NS 

16from slixmpp.plugins.xep_0469.stanza import Pinned 

17from slixmpp.plugins.xep_0492.stanza import Notify 

18from slixmpp.xmlstream import StanzaBase 

19 

20from . import ( 

21 xep_0077, 

22 xep_0100, 

23 xep_0153, 

24 xep_0292, 

25) 

26 

27Notify.interfaces = set() 

28 

29 

30def set_pinned(self, val: bool) -> None: # noqa 

31 extensions = self.parent() 

32 if val: 

33 extensions.enable("pinned") 

34 else: 

35 extensions._del_sub(f"{{{PINNED_NS}}}pinned") 

36 

37 

38Pinned.set_pinned = set_pinned 

39 

40 

41def session_bind(self, jid) -> None: # noqa 

42 self.xmpp.plugin["xep_0030"].add_feature(Command.namespace) 

43 # awful hack to for the disco items: we need to comment this line 

44 # related issue: https://todo.sr.ht/~nicoco/slidge/131 

45 # self.xmpp['xep_0030'].set_items(node=Command.namespace, items=tuple()) 

46 

47 

48XEP_0050.session_bind = session_bind # type:ignore 

49 

50 

51def reply(self, body=None, clear: bool = True): # noqa 

52 """ 

53 Overrides slixmpp's Message.reply(), since it strips to sender's resource 

54 for mtype=groupchat, and we do not want that, because when we raise an XMPPError, 

55 we actually want to preserve the resource. 

56 (this is called in RootStanza.exception() to handle XMPPErrors) 

57 """ 

58 new_message = StanzaBase.reply(self, clear) 

59 new_message["thread"] = self["thread"] 

60 new_message["parent_thread"] = self["parent_thread"] 

61 

62 del new_message["id"] 

63 if self.stream is not None and self.stream.use_message_ids: 

64 new_message["id"] = self.stream.new_id() 

65 

66 if body is not None: 

67 new_message["body"] = body 

68 return new_message 

69 

70 

71Message.reply = reply # type: ignore 

72 

73slixmpp.plugins.PLUGINS.extend( 

74 [ 

75 "xep_0292_provider", 

76 ] 

77) 

78 

79# Even if this is non-standard, we include a XEP-0084 avatar metadata element 

80# in the presence of participants when the avatar is available via HTTP 

81register_stanza_plugin(Presence, MetaData) 

82register_stanza_plugin(slixmpp.plugins.xep_0060.stanza.Item, MetaData)