Coverage for slidge/core/mixins/recipient.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-07 05:11 +0000

1from typing import TYPE_CHECKING, Optional, Union 

2 

3from slixmpp.plugins.xep_0004 import Form 

4 

5from ...util.types import LegacyMessageType 

6 

7if TYPE_CHECKING: 

8 from ..gateway import BaseGateway 

9 

10 

11class ReactionRecipientMixin: 

12 REACTIONS_SINGLE_EMOJI = False 

13 xmpp: "BaseGateway" = NotImplemented 

14 

15 async def restricted_emoji_extended_feature(self): 

16 available = await self.available_emojis() 

17 if not self.REACTIONS_SINGLE_EMOJI and available is None: 

18 return None 

19 

20 form = Form() 

21 form["type"] = "result" 

22 form.add_field("FORM_TYPE", "hidden", value="urn:xmpp:reactions:0:restrictions") 

23 if self.REACTIONS_SINGLE_EMOJI: 

24 form.add_field("max_reactions_per_user", value="1") 

25 if available: 

26 form.add_field("allowlist", value=list(available)) 

27 return form 

28 

29 async def available_emojis( 

30 self, legacy_msg_id: Optional[LegacyMessageType] = None 

31 ) -> Optional[set[str]]: 

32 """ 

33 Override this to restrict the subset of reactions this recipient 

34 can handle. 

35 

36 :return: A set of emojis or None if any emoji is allowed 

37 """ 

38 return None 

39 

40 

41class ThreadRecipientMixin: 

42 async def create_thread(self, xmpp_id: str) -> Union[int, str]: 

43 return xmpp_id