# Slixmpp: The Slick XMPP Library# Copyright (C) 2012 Erik Reuterborg Larsson, Nathanael C. Fritz# This file is part of Slixmpp.# See the file LICENSE for copying permission.importloggingfromslixmpp.stanzaimportMessagefromslixmpp.xmlstreamimportregister_stanza_pluginfromslixmpp.xmlstream.handlerimportCallbackfromslixmpp.xmlstream.matcherimportStanzaPathfromslixmpp.pluginsimportBasePluginfromslixmpp.plugins.xep_0184importstanza,Request,Received
[docs]defack(self,msg):""" Acknowledge a message by sending a receipt. Arguments: msg -- The message to acknowledge. """ack=self.xmpp.Message()ack['to']=msg['from']ack['receipt']=msg['id']ack.send()
def_handle_receipt_received(self,msg):self.xmpp.event('receipt_received',msg)def_handle_receipt_request(self,msg):""" Auto-ack message receipt requests if ``self.auto_ack`` is ``True``. Arguments: msg -- The incoming message requesting a receipt. """ifself.auto_ack:ifmsg['type']inself.ack_types:ifnotmsg['receipt']:self.ack(msg)def_filter_add_receipt_request(self,stanza):""" Auto add receipt requests to outgoing messages, if: - ``self.auto_request`` is set to ``True`` - The message is not for groupchat - The message does not contain a receipt acknowledgment - The recipient is a bare JID or, if a full JID, one that has the ``urn:xmpp:receipts`` feature enabled The disco cache is checked if a full JID is specified in the outgoing message, which may mean a round-trip disco#info delay for the first message sent to the JID if entity caps are not used. """ifnotself.auto_request:returnstanzaifnotisinstance(stanza,Message):returnstanzaifstanza['request_receipt']:returnstanzaifnotstanza['type']inself.ack_types:returnstanzaifstanza['receipt']:returnstanzaifnotstanza['body']:returnstanzaifstanza['to'].resource:ifnotself.xmpp['xep_0030'].supports(stanza['to'],feature='urn:xmpp:receipts',cached=True):returnstanzastanza['request_receipt']=Truereturnstanza