memory (disco), core (main): new hasIdentity method
This commit is contained in:
parent
7216345e31
commit
7ed5c0ff9d
2 changed files with 27 additions and 1 deletions
|
|
@ -1095,6 +1095,9 @@ class SAT(service.Service):
|
|||
def checkFeatures(self, *args, **kwargs):
|
||||
return self.memory.disco.checkFeatures(*args, **kwargs)
|
||||
|
||||
def hasIdentity(self, *args, **kwargs):
|
||||
return self.memory.disco.hasIdentity(*args, **kwargs)
|
||||
|
||||
def getDiscoInfos(self, *args, **kwargs):
|
||||
return self.memory.disco.getInfos(*args, **kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from typing import Optional
|
||||
from sat.core.i18n import _
|
||||
from sat.core import exceptions
|
||||
from sat.core.log import getLogger
|
||||
from sat.core.core_types import SatXMPPEntity
|
||||
|
||||
log = getLogger(__name__)
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.words.protocols.jabber.error import StanzaError
|
||||
from twisted.internet import defer
|
||||
|
|
@ -35,6 +36,9 @@ from base64 import b64encode
|
|||
from hashlib import sha1
|
||||
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
||||
|
||||
TIMEOUT = 15
|
||||
CAP_HASH_ERROR = "ERROR"
|
||||
|
||||
|
|
@ -162,6 +166,25 @@ class Discovery(object):
|
|||
if identity is not None and identity not in disco_infos.identities:
|
||||
raise failure.Failure(exceptions.FeatureNotFound())
|
||||
|
||||
async def hasIdentity(
|
||||
self,
|
||||
client: SatXMPPEntity,
|
||||
category: str,
|
||||
type_: str,
|
||||
jid_: Optional[jid.JID] = None,
|
||||
node: str = ""
|
||||
) -> bool:
|
||||
"""Tell if an entity has the requested identity
|
||||
|
||||
@param category: identity category
|
||||
@param type_: identity type
|
||||
@param jid_: jid of the target, or None for profile's server
|
||||
@param node(unicode): optional node to use for disco request
|
||||
@return: True if the entity has the given identity
|
||||
"""
|
||||
disco_infos = await self.getInfos(client, jid_, node)
|
||||
return (category, type_) in disco_infos.identities
|
||||
|
||||
def getInfos(self, client, jid_=None, node="", use_cache=True):
|
||||
"""get disco infos from jid_, filling capability hash if needed
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue