Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 6201:b9e8f5268c97
plugins/muc/muc.lib: Move default config layout into hooks
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Tue, 01 Apr 2014 17:10:01 -0400 |
parent | 6200:57bc52f67564 |
child | 6202:64ed7f538f81 |
comparison
equal
deleted
inserted
replaced
6200:57bc52f67564 | 6201:b9e8f5268c97 |
---|---|
905 :add_child(self:get_form_layout(stanza.attr.from):form()) | 905 :add_child(self:get_form_layout(stanza.attr.from):form()) |
906 ); | 906 ); |
907 end | 907 end |
908 | 908 |
909 function room_mt:get_form_layout(actor) | 909 function room_mt:get_form_layout(actor) |
910 local whois = self:get_whois() | |
911 local form = dataform.new({ | 910 local form = dataform.new({ |
912 title = "Configuration for "..self.jid, | 911 title = "Configuration for "..self.jid, |
913 instructions = "Complete and submit this form to configure the room.", | 912 instructions = "Complete and submit this form to configure the room.", |
914 { | 913 { |
915 name = 'FORM_TYPE', | 914 name = 'FORM_TYPE', |
916 type = 'hidden', | 915 type = 'hidden', |
917 value = 'http://jabber.org/protocol/muc#roomconfig' | 916 value = 'http://jabber.org/protocol/muc#roomconfig' |
918 }, | |
919 { | |
920 name = 'muc#roomconfig_roomname', | |
921 type = 'text-single', | |
922 label = 'Name', | |
923 value = self:get_name() or "", | |
924 }, | |
925 { | |
926 name = 'muc#roomconfig_roomdesc', | |
927 type = 'text-single', | |
928 label = 'Description', | |
929 value = self:get_description() or "", | |
930 }, | |
931 { | |
932 name = 'muc#roomconfig_persistentroom', | |
933 type = 'boolean', | |
934 label = 'Make Room Persistent?', | |
935 value = self:get_persistent() | |
936 }, | |
937 { | |
938 name = 'muc#roomconfig_publicroom', | |
939 type = 'boolean', | |
940 label = 'Make Room Publicly Searchable?', | |
941 value = not self:get_hidden() | |
942 }, | |
943 { | |
944 name = 'muc#roomconfig_changesubject', | |
945 type = 'boolean', | |
946 label = 'Allow Occupants to Change Subject?', | |
947 value = self:get_changesubject() | |
948 }, | |
949 { | |
950 name = 'muc#roomconfig_whois', | |
951 type = 'list-single', | |
952 label = 'Who May Discover Real JIDs?', | |
953 value = { | |
954 { value = 'moderators', label = 'Moderators Only', default = whois == 'moderators' }, | |
955 { value = 'anyone', label = 'Anyone', default = whois == 'anyone' } | |
956 } | |
957 }, | |
958 { | |
959 name = 'muc#roomconfig_roomsecret', | |
960 type = 'text-private', | |
961 label = 'Password', | |
962 value = self:get_password() or "", | |
963 }, | |
964 { | |
965 name = 'muc#roomconfig_moderatedroom', | |
966 type = 'boolean', | |
967 label = 'Make Room Moderated?', | |
968 value = self:get_moderated() | |
969 }, | |
970 { | |
971 name = 'muc#roomconfig_membersonly', | |
972 type = 'boolean', | |
973 label = 'Make Room Members-Only?', | |
974 value = self:get_members_only() | |
975 }, | |
976 { | |
977 name = 'muc#roomconfig_historylength', | |
978 type = 'text-single', | |
979 label = 'Maximum Number of History Messages Returned by Room', | |
980 value = tostring(self:get_historylength()) | |
981 } | 917 } |
982 }); | 918 }); |
983 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; | 919 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; |
984 end | 920 end |
921 module:hook("muc-config-form", function(event) | |
922 table.insert(event.form, { | |
923 name = 'muc#roomconfig_roomname', | |
924 type = 'text-single', | |
925 label = 'Name', | |
926 value = event.room:get_name() or "", | |
927 }); | |
928 end); | |
929 module:hook("muc-config-form", function(event) | |
930 table.insert(event.form, { | |
931 name = 'muc#roomconfig_roomdesc', | |
932 type = 'text-single', | |
933 label = 'Description', | |
934 value = event.room:get_description() or "", | |
935 }); | |
936 end); | |
937 module:hook("muc-config-form", function(event) | |
938 table.insert(event.form, { | |
939 name = 'muc#roomconfig_persistentroom', | |
940 type = 'boolean', | |
941 label = 'Make Room Persistent?', | |
942 value = event.room:get_persistent() | |
943 }); | |
944 end); | |
945 module:hook("muc-config-form", function(event) | |
946 table.insert(event.form, { | |
947 name = 'muc#roomconfig_publicroom', | |
948 type = 'boolean', | |
949 label = 'Make Room Publicly Searchable?', | |
950 value = not event.room:get_hidden() | |
951 }); | |
952 end); | |
953 module:hook("muc-config-form", function(event) | |
954 table.insert(event.form, { | |
955 name = 'muc#roomconfig_changesubject', | |
956 type = 'boolean', | |
957 label = 'Allow Occupants to Change Subject?', | |
958 value = event.room:get_changesubject() | |
959 }); | |
960 end); | |
961 module:hook("muc-config-form", function(event) | |
962 local whois = event.room:get_whois(); | |
963 table.insert(event.form, { | |
964 name = 'muc#roomconfig_whois', | |
965 type = 'list-single', | |
966 label = 'Who May Discover Real JIDs?', | |
967 value = { | |
968 { value = 'moderators', label = 'Moderators Only', default = whois == 'moderators' }, | |
969 { value = 'anyone', label = 'Anyone', default = whois == 'anyone' } | |
970 } | |
971 }); | |
972 end); | |
973 module:hook("muc-config-form", function(event) | |
974 table.insert(event.form, { | |
975 name = 'muc#roomconfig_roomsecret', | |
976 type = 'text-private', | |
977 label = 'Password', | |
978 value = event.room:get_password() or "", | |
979 }); | |
980 end); | |
981 module:hook("muc-config-form", function(event) | |
982 table.insert(event.form, { | |
983 name = 'muc#roomconfig_moderatedroom', | |
984 type = 'boolean', | |
985 label = 'Make Room Moderated?', | |
986 value = event.room:get_moderated() | |
987 }); | |
988 end); | |
989 module:hook("muc-config-form", function(event) | |
990 table.insert(event.form, { | |
991 name = 'muc#roomconfig_membersonly', | |
992 type = 'boolean', | |
993 label = 'Make Room Members-Only?', | |
994 value = event.room:get_members_only() | |
995 }); | |
996 end); | |
997 module:hook("muc-config-form", function(event) | |
998 table.insert(event.form, { | |
999 name = 'muc#roomconfig_historylength', | |
1000 type = 'text-single', | |
1001 label = 'Maximum Number of History Messages Returned by Room', | |
1002 value = tostring(event.room:get_historylength()) | |
1003 }); | |
1004 end); | |
985 | 1005 |
986 function room_mt:process_form(origin, stanza) | 1006 function room_mt:process_form(origin, stanza) |
987 local query = stanza.tags[1]; | 1007 local query = stanza.tags[1]; |
988 local form = query:get_child("x", "jabber:x:data") | 1008 local form = query:get_child("x", "jabber:x:data") |
989 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end | 1009 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end |