# Slixmpp: The Slick XMPP Library# Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net># This file is part of Slixmpp.# See the file LICENSE for copying permission.fromtypingimport(Dict,Optional,Set,Tuple,)fromslixmppimportJID,Message,Iqfromslixmpp.exceptionsimportIqError,IqTimeoutfromslixmpp.pluginsimportBasePluginfromslixmpp.xmlstreamimportregister_stanza_pluginfromslixmpp.xmlstream.matcherimportMatchXPathfromslixmpp.xmlstream.handlerimportCallbackfromslixmpp.plugins.xep_0404importstanzafromslixmpp.plugins.xep_0004.stanzaimportFormNODES=['urn:xmpp:mix:nodes:jidmap',]
[docs]asyncdefget_anon_raw(self,channel:JID,*,ifrom:Optional[JID]=None,**pubsubkwargs)->Iq:""" Get the jid-participant mapping result (raw). :param JID channel: MIX channel JID """returnawaitself.xmpp['xep_0030'].get_items(channel.bare,ifrom=ifrom,**pubsubkwargs)
[docs]asyncdefget_anon_by_jid(self,channel:JID,*,ifrom:Optional[JID]=None,**pubsubkwargs)->Dict[JID,str]:""" Get the jid-participant mapping, by JID :param JID channel: MIX channel JID """raw=awaitself.get_anon_raw(channel,ifrom=ifrom,**pubsubkwargs)mapping={}foriteminraw['pubsub']['items']:mapping[item['anon_participant']['jid']]=item['id']returnmapping
[docs]asyncdefget_anon_by_id(self,channel:JID,*,ifrom:Optional[JID]=None,**pubsubkwargs)->Dict[str,JID]:""" Get the jid-participant mapping, by participant id :param JID channel: MIX channel JID """raw=awaitself.get_anon_raw(channel,ifrom=ifrom,**pubsubkwargs)mapping={}foriteminraw['pubsub']['items']:mapping[item['id']]=item['anon_participant']['jid']returnmapping
[docs]asyncdefget_preferences(self,channel:JID,*,ifrom:Optional[JID]=None,**iqkwargs)->Form:""" Get channel preferences with default values. :param JID channel: MIX channel JID """iq=self.xmpp.make_iq_get(ito=channel.bare,ifrom=ifrom)iq.enable('user_preference')prefs_stanza=awaitiq.send(**iqkwargs)returnprefs_stanza['user_preference']['form']
[docs]asyncdefset_preferences(self,channel:JID,form:Form,*,ifrom:Optional[JID]=None,**iqkwargs)->Form:""" Set channel preferences :param JID channel: MIX channel JID :param Form form: A 0004 form with updated preferences """iq=self.xmpp.make_iq_set(ito=channel.bare,ifrom=ifrom)iq['user_preference']['form']=formprefs_result=awaitiq.send(**iqkwargs)returnprefs_result['user_preference']['form']