diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-05-16 18:30:56 +0100 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-05-16 18:30:56 +0100 |
commit | 6ff9e1a08d0a3c24e68cb1b65289eb95e7060359 (patch) | |
tree | 4ab553a0fdb6be13ffa2064f0bb4a0e5e7c93dd7 | |
parent | a66b3c0c7ded54ca407439871d87b7fbd20535e8 (diff) |
room-config: flicker CanUpdateConfiguration but keep MutableProperties stable
I had misunderstood these two properties before, yet again. This is
better and easier. I added more tests.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | src/idle-muc-channel.c | 22 | ||||
-rw-r--r-- | src/room-config.c | 32 | ||||
-rw-r--r-- | tests/twisted/messages/room-config.py | 32 |
3 files changed, 59 insertions, 27 deletions
diff --git a/src/idle-muc-channel.c b/src/idle-muc-channel.c index 09b487f..1ee5748 100644 --- a/src/idle-muc-channel.c +++ b/src/idle-muc-channel.c @@ -243,11 +243,6 @@ idle_muc_channel_constructed (GObject *obj) priv->room_config = (TpBaseRoomConfig *) idle_room_config_new ((TpBaseChannel *) self); - - tp_base_room_config_set_can_update_configuration ( - priv->room_config, TRUE); - /* Just to get CanUpdateConfiguration out there. */ - tp_base_room_config_emit_properties_changed (priv->room_config); } static void @@ -572,31 +567,18 @@ static void change_mode_state(IdleMUCChannel *obj, guint add, guint remove) { } if (combined & (MODE_FLAG_OPERATOR_PRIVILEGE | MODE_FLAG_HALFOP_PRIVILEGE)) { - static const TpBaseRoomConfigProperty prop_helper[] = { - TP_BASE_ROOM_CONFIG_INVITE_ONLY, - TP_BASE_ROOM_CONFIG_LIMIT, - TP_BASE_ROOM_CONFIG_MODERATED, - TP_BASE_ROOM_CONFIG_PASSWORD, - TP_BASE_ROOM_CONFIG_PASSWORD_PROTECTED, - TP_BASE_ROOM_CONFIG_PRIVATE, - TP_NUM_BASE_ROOM_CONFIG_PROPERTIES - }; if (add & (MODE_FLAG_OPERATOR_PRIVILEGE | MODE_FLAG_HALFOP_PRIVILEGE)) { group_add |= TP_CHANNEL_GROUP_FLAG_CAN_ADD | TP_CHANNEL_GROUP_FLAG_CAN_REMOVE | TP_CHANNEL_GROUP_FLAG_MESSAGE_REMOVE; - for (int i = 0; prop_helper[i] != TP_NUM_BASE_ROOM_CONFIG_PROPERTIES; ++i) { - tp_base_room_config_set_property_mutable (priv->room_config, prop_helper[i], TRUE); - } + tp_base_room_config_set_can_update_configuration (priv->room_config, TRUE); if (flags & MODE_FLAG_TOPIC_ONLY_SETTABLE_BY_OPS) idle_muc_channel_update_can_set_topic (obj, TRUE); } else if (remove & (MODE_FLAG_OPERATOR_PRIVILEGE | MODE_FLAG_HALFOP_PRIVILEGE)) { group_remove |= TP_CHANNEL_GROUP_FLAG_CAN_REMOVE | TP_CHANNEL_GROUP_FLAG_MESSAGE_REMOVE; - for (int i = 0; prop_helper[i] != TP_NUM_BASE_ROOM_CONFIG_PROPERTIES; ++i) { - tp_base_room_config_set_property_mutable (priv->room_config, prop_helper[i], FALSE); - } + tp_base_room_config_set_can_update_configuration (priv->room_config, FALSE); if (flags & MODE_FLAG_INVITE_ONLY) group_remove |= TP_CHANNEL_GROUP_FLAG_CAN_ADD; diff --git a/src/room-config.c b/src/room-config.c index 10d994d..27f0c9b 100644 --- a/src/room-config.c +++ b/src/room-config.c @@ -61,6 +61,35 @@ idle_room_config_init (IdleRoomConfig *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, IDLE_TYPE_ROOM_CONFIG, IdleRoomConfigPrivate); +} + +static void +idle_room_config_constructed (GObject *object) +{ + TpBaseRoomConfig *self = TP_BASE_ROOM_CONFIG (object); + static const TpBaseRoomConfigProperty prop_helper[] = { + TP_BASE_ROOM_CONFIG_INVITE_ONLY, + TP_BASE_ROOM_CONFIG_LIMIT, + TP_BASE_ROOM_CONFIG_MODERATED, + TP_BASE_ROOM_CONFIG_PASSWORD, + TP_BASE_ROOM_CONFIG_PASSWORD_PROTECTED, + TP_BASE_ROOM_CONFIG_PRIVATE, + TP_NUM_BASE_ROOM_CONFIG_PROPERTIES + }; + guint i; + void (*chain_up)(GObject *) = + G_OBJECT_CLASS (idle_room_config_parent_class)->constructed; + + if (chain_up != NULL) + chain_up (object); + + for (i = 0; prop_helper[i] != TP_NUM_BASE_ROOM_CONFIG_PROPERTIES; ++i) + { + tp_base_room_config_set_property_mutable (self, prop_helper[i], TRUE); + } + + /* Just to get the mutable properties out there. */ + tp_base_room_config_emit_properties_changed (self); /* Let's reset the password back to the empty string when * password-protected is set to False. */ @@ -71,8 +100,11 @@ idle_room_config_init (IdleRoomConfig *self) static void idle_room_config_class_init (IdleRoomConfigClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); TpBaseRoomConfigClass *parent_class = TP_BASE_ROOM_CONFIG_CLASS (klass); + object_class->constructed = idle_room_config_constructed; + parent_class->update_async = idle_room_config_update_configuration_async; g_type_class_add_private (klass, sizeof (IdleRoomConfigPrivate)); } diff --git a/tests/twisted/messages/room-config.py b/tests/twisted/messages/room-config.py index e18687d..12f2d0f 100644 --- a/tests/twisted/messages/room-config.py +++ b/tests/twisted/messages/room-config.py @@ -43,12 +43,7 @@ def setup(q, bus, conn, stream, op_user=True): args=[cs.GF_MESSAGE_REMOVE | cs.GF_CAN_REMOVE, 0]), EventPattern('dbus-signal', signal='PropertiesChanged', args=[cs.CHANNEL_IFACE_ROOM_CONFIG, - {'MutableProperties': ['InviteOnly', - 'Limit', - 'Moderated', - 'Private', - 'PasswordProtected', - 'Password']}, + {'CanUpdateConfiguration': True}, []])) return chan @@ -80,6 +75,15 @@ def test_props_present(q, bus, conn, stream): sync_stream(q, stream) q.unforbid_events(forbidden) + # we should have these mutable ones + mutable_props = ['InviteOnly', + 'Limit', + 'Moderated', + 'Private', + 'PasswordProtected', + 'Password'] + assertEquals(mutable_props, props['MutableProperties']) + def test_simple_bools(q, bus, conn, stream): chan = setup(q, bus, conn, stream) @@ -336,7 +340,21 @@ def test_mode_no_op(q, bus, conn, stream): {key: val}) q.expect('dbus-error', method='UpdateConfiguration', - name=cs.NOT_IMPLEMENTED) + name=cs.PERMISSION_DENIED) + + # op the user + change_channel_mode(stream, '+o test') + q.expect('dbus-signal', signal='PropertiesChanged', + args=[cs.CHANNEL_IFACE_ROOM_CONFIG, + {'CanUpdateConfiguration': True}, + []]) + + # remove ops again + change_channel_mode(stream, '-o test') + q.expect('dbus-signal', signal='PropertiesChanged', + args=[cs.CHANNEL_IFACE_ROOM_CONFIG, + {'CanUpdateConfiguration': False}, + []]) if __name__ == '__main__': exec_test(test_props_present) |