Properly handle chatrooms on external servers

This commit is contained in:
Adrian Moennich 2014-10-08 17:42:29 +02:00
parent 1fc1de771d
commit 3d976f6b1c
5 changed files with 39 additions and 12 deletions

View File

@ -71,9 +71,10 @@ class RHChatManageEvent(RHChatManageEventBase):
_eager='chatroom.events').all()
chatroom_filter = (~Chatroom.id.in_(x.chatroom_id for x in chatrooms)) if chatrooms else True
available_chatrooms = Chatroom.find_all(Chatroom.created_by_id == int(session.user.id), chatroom_filter)
logs_enabled = current_plugin.settings.get('log_url')
return WPChatEventMgmt.render_template('manage_event.html', self._conf, event_chatrooms=chatrooms,
event=self.event, chat_links=current_plugin.settings.get('chat_links'),
available_chatrooms=available_chatrooms)
available_chatrooms=available_chatrooms, logs_enabled=logs_enabled)
class RHChatManageEventModify(RHEventChatroomMixin, RHChatManageEventBase):
@ -108,16 +109,21 @@ class RHChatManageEventRefresh(RHEventChatroomMixin, RHChatManageEventBase):
RHEventChatroomMixin._checkParams(self)
def _process(self):
if self.chatroom.custom_server:
return jsonify(result='')
config = get_room_config(self.chatroom.jid)
if config is None:
if not room_exists(self.chatroom.jid):
return jsonify(result='not-found')
raise IndicoError(_('Unexpected result from Jabber server'))
changed = False
for key, value in config.iteritems():
if getattr(self.chatroom, key) != value:
changed = True
setattr(self.chatroom, key, value)
return jsonify(result='changed' if changed else '')

View File

@ -58,11 +58,12 @@ class AddChatroomForm(EditChatroomForm):
raise ValidationError(_('Could not convert name to a jabber ID'))
if Chatroom.find_first(jid_node=jid, custom_server=self.custom_server.data):
raise ValidationError(_('A room with this name already exists'))
tmp_room = Chatroom(jid_node=jid, custom_server=self.custom_server.data)
if room_exists(tmp_room.jid):
raise ValidationError(_('A room with this name/JID already exists on the Jabber server ({0})').format(
tmp_room.jid
))
if not self.custom_server.data:
tmp_room = Chatroom(jid_node=jid)
if room_exists(tmp_room.jid):
raise ValidationError(_('A room with this name/JID already exists on the Jabber server ({0})').format(
tmp_room.jid
))
@generated_data
def jid_node(self):

View File

@ -58,7 +58,12 @@
var $this = $(this);
var msg = $T('Do you really want to remove this chatroom from the event?');
if ($this.data('numEvents') == 1) {
msg += '<br>' + $T('Since it is only used in this event, it will be deleted from the Jabber server, too!');
msg += '<br>';
if ($this.data('customServer')) {
msg += $T('Since it is on an external server, it will not be deleted on that server.');
} else {
msg += $T('Since it is only used in this event, it will be deleted from the Jabber server, too!');
}
}
new ConfirmPopup($T('Delete this chatroom?'), msg, function(confirmed) {
if (!confirmed) {

View File

@ -10,14 +10,20 @@
<span><strong>{{ chatroom.name }}</strong></span>
-
<a class="chat-toggle-details" href="#">{% trans %}Show Details{% endtrans %}</a>
-
<a href="{{ url_for_plugin('.manage_rooms_logs', event_chatroom) }}">{% trans %}Logs{% endtrans %}</a>
{% if logs_enabled and not chatroom.custom_server %}
-
<a href="{{ url_for_plugin('.manage_rooms_logs', event_chatroom) }}">{% trans %}Logs{% endtrans %}</a>
{% endif %}
-
<a href="{{ url_for_plugin('.manage_rooms_modify', event_chatroom) }}">{% trans %}Edit{% endtrans %}</a>
{% if not chatroom.custom_server %}
-
<a class="js-chat-refresh-room" href="#" data-href="{{ url_for_plugin('.manage_rooms_refresh', event_chatroom) }}">{% trans %}Refresh{% endtrans %}</a>
{% endif %}
-
<a class="js-chat-refresh-room" href="#" data-href="{{ url_for_plugin('.manage_rooms_refresh', event_chatroom) }}">{% trans %}Refresh{% endtrans %}</a>
-
<a class="js-chat-remove-room" href="#" data-href="{{ url_for_plugin('.manage_rooms_remove', event_chatroom) }}" data-num-events="{{ chatroom.events | count }}">{% trans %}Remove{% endtrans %}</a>
<a class="js-chat-remove-room" href="#" data-href="{{ url_for_plugin('.manage_rooms_remove', event_chatroom) }}" data-num-events="{{ chatroom.events | count }}" data-custom-server="{{ 1 if chatroom.custom_server else 0 }}">
{%- trans %}Remove{% endtrans -%}
</a>
{% if chat_links %}
-
<strong><a class="dropDownMenu highlight js-chat-join" href="#" data-server="{{ server }}" data-room="{{ chatroom.jid_node }}">{% trans %}Join now!{% endtrans %}</a></strong>

View File

@ -37,6 +37,9 @@ WHITESPACE = re.compile(r'\s+')
def create_room(room):
"""Creates a MUC room on the XMPP server."""
if room.custom_server:
return
def _create_room(xmpp):
muc = xmpp.plugin['xep_0045']
muc.joinMUC(room.jid, xmpp.requested_jid.user)
@ -49,6 +52,9 @@ def create_room(room):
def update_room(room):
"""Updates a MUC room on the XMPP server."""
if room.custom_server:
return
def _update_room(xmpp):
muc = xmpp.plugin['xep_0045']
muc.joinMUC(room.jid, xmpp.requested_jid.user)
@ -61,6 +67,9 @@ def update_room(room):
def delete_room(room, reason=''):
"""Deletes a MUC room from the XMPP server."""
if room.custom_server:
return
def _delete_room(xmpp):
muc = xmpp.plugin['xep_0045']
muc.destroy(room.jid, reason=reason)