Commit 108a4e5a authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Change some things

parent 6c236b0e
Pipeline #6466 passed with stages
in 3 minutes
......@@ -22,6 +22,8 @@
import time
from gajim.common import app
class Event:
"""
......@@ -130,6 +132,16 @@ def __init__(self, event):
for key, value in vars(event).items():
setattr(self, key, value)
def get_inviter_name(self):
if self.from_.bare_match(self.muc):
return self.from_.resource
contact = app.contacts.get_first_contact_from_jid(
self.account, self.from_.bare)
if contact is None:
return str(self.from_)
return contact.get_shown_name()
class FileRequestEvent(Event):
type_ = 'file-request'
def __init__(self, file_props, time_=None, show_in_roster=False, show_in_systray=True):
......
......@@ -771,12 +771,28 @@ def _on_invite_or_decline(self, _con, _stanza, properties):
self._log.info('We are already in this room')
raise nbxmpp.NodeProcessed
app.nec.push_incoming_event(
NetworkEvent('muc-invitation',
account=self._account,
**data._asdict()))
self._con.get_module('Discovery').disco_muc(
data.muc,
request_vcard=True,
callback=self._on_disco_result_after_invite,
user_data=data)
raise nbxmpp.NodeProcessed
def _on_disco_result_after_invite(self, task):
try:
result = task.finish()
except StanzaError as error:
self._log.warning(error)
return
invite_data = task.get_user_data()
app.nec.push_incoming_event(
NetworkEvent('muc-invitation',
account=self._account,
info=result.info,
**invite_data._asdict()))
def invite(self, room, to, reason=None, continue_=False):
type_ = InviteType.MEDIATED
contact = app.contacts.get_contact_from_full_jid(self._account, to)
......
......@@ -101,15 +101,23 @@ def __init__(self, account=None, options=None):
Gtk.ScrolledWindow.__init__(self)
if options is None:
options = {}
self._minimal = options.get('minimal', False)
self.set_size_request(options.get('width', 400), -1)
self.set_halign(Gtk.Align.CENTER)
self.set_vexpand(True)
self.set_min_content_height(options.get('content_height', 400))
self.set_policy(Gtk.PolicyType.NEVER,
Gtk.PolicyType.AUTOMATIC)
if self._minimal:
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)
else:
self.set_vexpand(True)
self.set_min_content_height(400)
self.set_policy(Gtk.PolicyType.NEVER,
Gtk.PolicyType.AUTOMATIC)
self._account = account
self._info = None
self._minimal = options.get('minimal', False)
self._ui = get_builder('groupchat_info_scrolled.ui')
self.add(self._ui.info_grid)
self._ui.connect_signals(self)
......
......@@ -38,29 +38,17 @@ def __init__(self, account, event):
self._from = str(event.from_)
self._password = event.password
disco_info = app.storage.cache.get_last_disco_info(event.muc)
main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
main_box.set_valign(Gtk.Align.FILL)
main_box.get_style_context().add_class('padding-18')
muc_info_box = GroupChatInfoScrolled(
account, {'minimal': True, 'content_height': 200})
muc_info_box.set_from_disco_info(disco_info)
muc_info_box = GroupChatInfoScrolled(account, {'minimal': True})
muc_info_box.set_from_disco_info(event.info)
main_box.add(muc_info_box)
if event.from_.bare_match(event.muc):
contact_text = event.from_.resource
else:
contact = app.contacts.get_first_contact_from_jid(
self.account, event.from_.bare)
if contact is None:
contact_text = str(event.from_)
else:
contact_text = contact.get_shown_name()
separator = Gtk.Separator()
contact_label = Gtk.Label(label=contact_text)
contact_label = Gtk.Label(label=event.get_inviter_name())
contact_label.get_style_context().add_class('bold16')
contact_label.set_halign(Gtk.Align.CENTER)
contact_label.set_justify(Gtk.Justification.CENTER)
......@@ -82,7 +70,7 @@ def __init__(self, account, event):
self._nick_chooser = NickChooser()
self._nick_chooser.set_text(
get_group_chat_nick(self.account, disco_info.jid))
get_group_chat_nick(self.account, event.info.jid))
join_button = Gtk.Button.new_with_mnemonic(_('_Join'))
join_button.set_halign(Gtk.Align.END)
......
......@@ -375,12 +375,8 @@ def handle_event_gc_decline(self, event):
'jid': event.from_})
def handle_event_gc_invitation(self, event):
con = app.connections[event.account]
con.get_module('Discovery').disco_muc(
event.muc,
callback=partial(self._muc_disco_info_received, event))
event = events.GcInvitationtEvent(event)
def _muc_disco_info_received(self, event, result):
if (helpers.allow_popup_window(event.account) or
not self.systray_enabled):
open_window('GroupChatInvitation',
......@@ -388,22 +384,12 @@ def _muc_disco_info_received(self, event, result):
event=event)
return
event_ = events.GcInvitationtEvent(event)
self.add_event(event.account, str(event.from_), event_)
self.add_event(event.account, str(event.from_), event)
if helpers.allow_showing_notification(event.account):
if event.from_.bare_match(event.muc):
contact_text = event.from_.resource
else:
contact = app.contacts.get_first_contact_from_jid(
event.account, event.from_.bare)
if contact is None:
contact_text = event.from_
else:
contact_text = contact.get_shown_name()
contact_name = event.get_inviter_name()
event_type = _('Group Chat Invitation')
text = _(f'{contact_text} invited you to {result.muc_name}')
text = _(f'{contact_name} invited you to {event.info.muc_name}')
app.notification.popup(event_type,
str(event.from_),
event.account,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment