Commit ad93a76d authored by Philipp Hörist's avatar Philipp Hörist

Groupchat: Handle invites consistently

- Always print a status message
- Display errors on invite

Fixes #10171
parent d16eaa93
......@@ -1071,9 +1071,9 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper):
else:
self.received_history_pos = pos
def add_info_message(self, text):
def add_info_message(self, text, message_id=None):
self.conv_textview.print_conversation_line(
text, 'info', '', None, graphics=False)
text, 'info', '', None, message_id=message_id, graphics=False)
def add_status_message(self, text):
self.conv_textview.print_conversation_line(
......
......@@ -308,10 +308,9 @@ class StandardGroupChatCommands(CommandContainer):
@command(raw=True, empty=True)
@doc(_("Invite a user to a group chat for a reason"))
def invite(self, jid, reason):
self.connection.get_module('MUC').invite(self.room_jid, jid, reason)
return _("Invited %(jid)s to %(room_jid)s") % {
'jid': jid,
'room_jid': self.room_jid}
control = app.get_groupchat_control(self.account, self.room_jid)
if control is not None:
control.invite(jid)
@command(raw=True, empty=True)
@doc(_("Join a group chat given by an XMPP Address"))
......
......@@ -644,3 +644,12 @@ def get_stored_bob_data(algo_hash: str) -> Optional[bytes]:
data = file.read()
return data
return None
def get_groupchat_control(account, jid):
control = app.interface.msg_win_mgr.get_gc_control(jid, account)
if control is not None:
return control
try:
return app.interface.minimized_controls[account][jid]
except Exception:
return None
......@@ -777,7 +777,8 @@ class MUC(BaseModule):
password = app.gc_passwords.get(room, None)
self._log.info('Invite %s to %s', to, room)
self._nbxmpp('MUC').invite(room, to, reason, password, continue_, type_)
return self._nbxmpp('MUC').invite(room, to, reason, password,
continue_, type_)
@event_filter(['account'])
def _on_account_disconnected(self, _event):
......
......@@ -218,6 +218,7 @@ class GroupchatControl(ChatControlBase):
('signed-in', ged.GUI1, self._on_signed_in),
('decrypted-message-received', ged.GUI2, self._on_decrypted_message_received),
('message-sent', ged.OUT_POSTCORE, self._on_message_sent),
('message-error', ged.GUI1, self._on_message_error),
('bookmarks-received', ged.GUI2, self._on_bookmarks_received),
])
# pylint: enable=line-too-long
......@@ -512,11 +513,17 @@ class GroupchatControl(ChatControlBase):
def _on_invite_clicked(self, _button):
invitees = self._invite_box.get_invitees()
con = app.connections[self.account]
for jid in invitees:
con.get_module('MUC').invite(self.room_jid, jid)
self.invite(jid)
self._show_page('groupchat')
def invite(self, contact_jid):
con = app.connections[self.account]
message_id = con.get_module('MUC').invite(self.room_jid, contact_jid)
self.add_info_message(
_(f'{contact_jid} has been invited to this group chat'),
message_id=message_id)
def _on_destroy_room(self, _action, _param):
self.xml.destroy_reason_entry.grab_focus()
self.xml.destroy_button.grab_default()
......@@ -1757,10 +1764,7 @@ class GroupchatControl(ChatControlBase):
return
contact_jid = data
con = app.connections[self.account]
con.get_module('MUC').invite(self.room_jid, contact_jid)
self.add_info_message(_('%(jid)s has been invited to this '
'group chat') % {'jid': contact_jid})
self.invite(contact_jid)
def _jid_not_blocked(self, bare_jid: str) -> bool:
fjid = self.room_jid + '/' + bare_jid
......
......@@ -2921,24 +2921,24 @@ class RosterWindow:
app.interface.instances['file_transfers'].show_file_send_request(
account, contact)
def on_invite_to_room(self, widget, list_, room_jid, room_account,
resource=None):
def on_invite_to_room(self,
_widget,
list_,
room_jid,
room_account,
resource=None):
"""
Resource parameter MUST NOT be used if more than one contact in list
"""
for e in list_:
contact = e[0]
gc_control = app.get_groupchat_control(room_account, room_jid)
if gc_control is None:
return
for contact, _ in list_:
contact_jid = contact.jid
if resource: # we MUST have one contact only in list_
contact_jid += '/' + resource
con = app.connections[room_account]
con.get_module('MUC').invite(room_jid, contact_jid)
gc_control = app.interface.msg_win_mgr.get_gc_control(room_jid,
room_account)
if gc_control:
gc_control.add_info_message(
_('%(jid)s has been invited to this group chat') % {
'jid': contact_jid})
gc_control.invite(contact_jid)
def on_all_groupchat_maximized(self, widget, group_list):
for (contact, account) in group_list:
......@@ -4158,8 +4158,9 @@ class RosterWindow:
if type_source != 'contact':
return
contact_jid = data
con = app.connections[account_dest]
con.get_module('MUC').invite(jid_dest, contact_jid)
gc_control = app.get_groupchat_control(account_dest, jid_dest)
if gc_control is not None:
gc_control.invite(contact_jid)
return
if type_source == 'group':
......
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