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

37 statements  

« prev     ^ index     » next       coverage.py v7.17.0, created at 2026-11-10 12:26 +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.stanza.roster 

8from slixmpp import Iq, Message, Presence, register_stanza_plugin 

9from slixmpp.exceptions import IqError 

10from slixmpp.plugins.xep_0050 import XEP_0050, Command 

11from slixmpp.plugins.xep_0084 import MetaData 

12from slixmpp.plugins.xep_0356.permissions import IqPermission 

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

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

15from slixmpp.plugins.xep_0469.stanza import Pinned 

16from slixmpp.plugins.xep_0492.stanza import Notify 

17from slixmpp.xmlstream import StanzaBase 

18 

19from . import ( 

20 xep_0077, 

21 xep_0100, 

22 xep_0153, 

23 xep_0292, 

24) 

25 

26Notify.interfaces = set() 

27 

28 

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

30 extensions = self.parent() 

31 if val: 

32 extensions.enable("pinned") 

33 else: 

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

35 

36 

37Pinned.set_pinned = set_pinned 

38 

39 

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

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

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

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

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

45 

46 

47XEP_0050.session_bind = session_bind # type:ignore 

48 

49 

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

51 """ 

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

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

54 we actually want to preserve the resource. 

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

56 """ 

57 new_message = StanzaBase.reply(self, clear) 

58 new_message["thread"] = self["thread"] 

59 new_message["parent_thread"] = self["parent_thread"] 

60 

61 del new_message["id"] 

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

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

64 

65 if body is not None: 

66 new_message["body"] = body 

67 return new_message 

68 

69 

70Message.reply = reply # type: ignore 

71 

72slixmpp.plugins.PLUGINS.extend( 

73 [ 

74 "xep_0292_provider", 

75 ] 

76) 

77 

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

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

80register_stanza_plugin(Presence, MetaData)