Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
if not app.account_is_available(self._account):
return
file_props = FilesProp.getFileProp(self._account, sid)
if file_props is None:
log.error('can not send iq error on failed transfer')
return
if file_props.type_ == 's':
to = file_props.receiver
else:
to = file_props.sender
iq = nbxmpp.Iq(to=to, typ='error')
iq.setAttr('id', file_props.request_id)
err = iq.setTag('error')
err.setAttr('type', error_type)
err.setTag(error, namespace=Namespace.STANZAS)
self._con.connection.send(iq)
if msg:
self.disconnect_transfer(file_props)
file_props.error = -3
app.nec.push_incoming_event(
NetworkEvent('file-request-error',
conn=self._con,
jid=app.get_jid_without_resource(to),
file_props=file_props,
error_msg=msg))
self._destroyed = False
self.account = account
self.jid = jid
self._own_affiliation = own_affiliation
self._ui = get_builder('groupchat_config.ui')
self.add(self._ui.grid)
# Activate Add button only for Admins and Owners
if self._own_affiliation in ('admin', 'owner'):
self._ui.add_button.set_sensitive(True)
self._ui.add_button.set_tooltip_text('')
disco_info = app.logger.get_last_disco_info(self.jid)
visible = disco_info.supports(Namespace.REGISTER)
self._ui.reserved_name_column.set_visible(visible)
self._ui.info_button.set_sensitive(False)
self._form = form
self._affiliations = {}
self._new_affiliations = {}
con = app.connections[self.account]
for affiliation in ('owner', 'admin', 'member', 'outcast'):
con.get_module('MUC').get_affiliation(
self.jid,
affiliation,
callback=self._on_affiliations_received,
user_data=affiliation)
if form is not None:
@event_node(Namespace.AVATAR_METADATA)
def _avatar_metadata_received(self, _con, _stanza, properties):
if properties.pubsub_event.retracted:
return
data = properties.pubsub_event.data
jid = str(properties.jid)
own_jid = self._con.get_own_jid().getBare()
if data is None:
# Remove avatar
self._log.info('Remove: %s', jid)
app.contacts.set_avatar(self._account, jid, None)
app.logger.set_avatar_sha(own_jid, jid, None)
app.interface.update_avatar(self._account, jid)
else:
if properties.is_self_message:
def get_optional_features(account):
features = []
if app.config.get_per('accounts', account, 'subscribe_mood'):
features.append(Namespace.MOOD + '+notify')
if app.config.get_per('accounts', account, 'subscribe_activity'):
features.append(Namespace.ACTIVITY + '+notify')
if app.config.get_per('accounts', account, 'subscribe_tune'):
features.append(Namespace.TUNE + '+notify')
if app.config.get_per('accounts', account, 'subscribe_nick'):
features.append(Namespace.NICK + '+notify')
if app.config.get_per('accounts', account, 'subscribe_location'):
features.append(Namespace.LOCATION + '+notify')
if app.connections[account].get_module('Bookmarks').using_bookmark_2:
features.append(Namespace.BOOKMARKS_2 + '+notify')
elif app.connections[account].get_module('Bookmarks').using_bookmark_1:
features.append(Namespace.BOOKMARKS + '+notify')
if app.is_installed('AV'):
features.append(Namespace.JINGLE_RTP)
features.append(Namespace.JINGLE_RTP_AUDIO)
features.append(Namespace.JINGLE_RTP_VIDEO)
return [
Feature('XEP-0045: Multi-User Chat',
con.get_module('MUC').supported),
Feature('XEP-0054: vcard-temp',
con.get_module('VCardTemp').supported),
Feature('XEP-0077: In-Band Registration',
con.get_module('Register').supported),
Feature('XEP-0163: Personal Eventing Protocol',
con.get_module('PEP').supported),
Feature('XEP-0163: #publish-options',
con.get_module('PubSub').publish_options),
Feature('XEP-0191: Blocking Command',
con.get_module('Blocking').supported,
Namespace.BLOCKING),
Feature('XEP-0198: Stream Management',
con.features.has_sm, Namespace.STREAM_MGMT),
Feature('XEP-0258: Security Labels in XMPP',
con.get_module('SecLabels').supported,
Namespace.SECLABEL),
Feature('XEP-0280: Message Carbons',
con.get_module('Carbons').supported,
Namespace.CARBONS),
Feature('XEP-0313: Message Archive Management',
con.get_module('MAM').available),
Feature('XEP-0363: HTTP File Upload',
con.get_module('HTTPUpload').available,
http_upload_info),
Feature('XEP-0398: Avatar Conversion',
con.avatar_conversion),
Feature('XEP-0411: Bookmarks Conversion',
con.get_module('Bookmarks').conversion)
]
@event_node(Namespace.LOCATION)
def _location_received(self, _con, _stanza, properties):
if properties.pubsub_event.retracted:
return
data = properties.pubsub_event.data
for contact in app.contacts.get_contacts(self._account,
str(properties.jid)):
if data is not None:
contact.pep[PEPEventType.LOCATION] = data
else:
contact.pep.pop(PEPEventType.LOCATION, None)
if properties.is_self_message:
if data is not None:
self._con.pep[PEPEventType.LOCATION] = data
else:
def _get_unique_id(self, properties):
if properties.is_self_message:
# Deduplicate self message with message-id
return None, properties.id
if properties.stanza_id is None:
return None, None
if properties.type.is_groupchat:
disco_info = app.logger.get_last_disco_info(
properties.jid.getBare())
if disco_info.mam_namespace != Namespace.MAM_2:
return None, None
archive = properties.jid
else:
if not self._con.get_module('MAM').available:
return None, None
archive = self._con.get_own_jid()
if archive.bareMatch(properties.stanza_id.by):
return properties.stanza_id.id, None
# stanza-id not added by the archive, ignore it.
return None, None
jid != self.jid):
# We can register this agent
registered_transports = []
jid_list = app.contacts.get_jid_list(self.account)
for jid_ in jid_list:
contact = app.contacts.get_first_contact_from_jid(
self.account, jid_)
if _('Transports') in contact.groups:
registered_transports.append(jid_)
registered_transports.append(self.jid)
if jid in registered_transports:
self.register_button.set_label(_('_Edit'))
else:
self.register_button.set_label(_('Re_gister'))
self.register_button.set_sensitive(True)
if self.join_button and Namespace.MUC in features:
self.join_button.set_sensitive(True)
self._get_action('send-file-').set_enabled(httpupload.get_enabled())
if self.is_connected and httpupload.get_enabled():
tooltip_text = _('Send File…')
max_file_size = con.get_module('HTTPUpload').max_file_size
if max_file_size is not None:
max_file_size = max_file_size / (1024 * 1024)
tooltip_text = _('Send File (max. %s MiB)…') % max_file_size
else:
tooltip_text = _('No File Transfer available')
self.xml.sendfile_button.set_tooltip_text(tooltip_text)
# Upload Avatar
vcard_support = False
if self.disco_info is not None:
vcard_support = self.disco_info.supports(Namespace.VCARD)
self._get_action('upload-avatar-').set_enabled(
self.is_connected and
vcard_support and
contact.affiliation.is_owner)
# Print join/left
join_default = app.config.get('print_join_left_default')
value = app.config.get_per('rooms', self.contact.jid,
'print_join_left', join_default)
self._get_action('print-join-left-').set_state(
GLib.Variant.new_boolean(value))
# Print join/left
status_default = app.config.get('print_status_muc_default')
value = app.config.get_per('rooms', self.contact.jid,
'print_status', status_default)
Feature('XEP-0054: vcard-temp',
con.get_module('VCardTemp').supported),
Feature('XEP-0077: In-Band Registration',
con.get_module('Register').supported),
Feature('XEP-0163: Personal Eventing Protocol',
con.get_module('PEP').supported),
Feature('XEP-0163: #publish-options',
con.get_module('PubSub').publish_options),
Feature('XEP-0191: Blocking Command',
con.get_module('Blocking').supported,
Namespace.BLOCKING),
Feature('XEP-0198: Stream Management',
con.features.has_sm, Namespace.STREAM_MGMT),
Feature('XEP-0258: Security Labels in XMPP',
con.get_module('SecLabels').supported,
Namespace.SECLABEL),
Feature('XEP-0280: Message Carbons',
con.get_module('Carbons').supported,
Namespace.CARBONS),
Feature('XEP-0313: Message Archive Management',
con.get_module('MAM').available),
Feature('XEP-0363: HTTP File Upload',
con.get_module('HTTPUpload').available,
http_upload_info),
Feature('XEP-0398: Avatar Conversion',
con.avatar_conversion),
Feature('XEP-0411: Bookmarks Conversion',
con.get_module('Bookmarks').conversion)
]