Software / code / prosody-modules
Comparison
mod_register_apps/mod_register_apps.lua @ 4171:85fa8c9e992a
mod_register_apps: Add support for module:provides("site-app", app_info)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 06 Oct 2020 16:03:38 +0100 |
| parent | 4114:4656a64e59be |
| child | 4178:bbd584cee042 |
comparison
equal
deleted
inserted
replaced
| 4170:2a655577fbcb | 4171:85fa8c9e992a |
|---|---|
| 111 return base_url.."/"..s; | 111 return base_url.."/"..s; |
| 112 end | 112 end |
| 113 | 113 |
| 114 local site_apps = module:shared("apps"); | 114 local site_apps = module:shared("apps"); |
| 115 | 115 |
| 116 for k, v in pairs(site_apps) do | 116 local function add_app(app_info, source) |
| 117 if v._source == module.name then | 117 local app_id = app_info.id or app_info.name:gsub("%W+", "-"):lower(); |
| 118 site_apps[k] = nil; | 118 if (not show_apps or show_apps:contains(app_id)) |
| 119 and not (hide_apps and hide_apps:contains(app_id)) | |
| 120 and not site_apps[app_id] then | |
| 121 app_info.id = app_id; | |
| 122 app_info.image = relurl(app_info.image); | |
| 123 site_apps[app_id] = app_info; | |
| 124 app_info._source = source; | |
| 125 table.insert(site_apps, app_info); | |
| 119 end | 126 end |
| 120 end | 127 end |
| 121 | 128 |
| 122 for _, app_info in ipairs(app_config) do | 129 local function remove_app(app_info) |
| 123 local app_id = app_info.id or app_info.name:gsub("%W+", "-"):lower(); | 130 local app_id = app_info.id or app_info.name:gsub("%W+", "-"):lower(); |
| 124 if (not show_apps or show_apps:contains(app_id)) | 131 site_apps[app_id] = nil; |
| 125 and not (hide_apps and hide_apps:contains(app_id)) then | 132 end |
| 126 app_info.id = app_id; | 133 |
| 127 app_info.image = relurl(app_info.image); | 134 local function add_config_apps() |
| 128 site_apps[app_id] = app_info; | 135 for _, app_info in ipairs(app_config) do |
| 129 app_info._source = module.name; | 136 add_app(app_info, module.name); |
| 130 table.insert(site_apps, app_info); | 137 end |
| 138 end | |
| 139 | |
| 140 local function module_app_added(event) | |
| 141 module:log("warn", "ADDING %s", event.item.name) | |
| 142 add_app(event.item, module.name); | |
| 143 end | |
| 144 | |
| 145 local function module_app_removed(event) | |
| 146 remove_app(event.item); | |
| 147 end | |
| 148 | |
| 149 -- Remove all apps added by this module | |
| 150 local function remove_all_apps() | |
| 151 for k, v in pairs(site_apps) do | |
| 152 if v._source == module.name then | |
| 153 remove_app(k); | |
| 154 end | |
| 131 end | 155 end |
| 132 end | 156 end |
| 133 | 157 |
| 134 local mime_map = { | 158 local mime_map = { |
| 135 png = "image/png"; | 159 png = "image/png"; |
| 142 path = module:get_directory().."/assets"; | 166 path = module:get_directory().."/assets"; |
| 143 mime_map = mime_map; | 167 mime_map = mime_map; |
| 144 }); | 168 }); |
| 145 }; | 169 }; |
| 146 }); | 170 }); |
| 171 | |
| 172 function module.load() | |
| 173 add_config_apps(); | |
| 174 module:handle_items("site-app-provider", module_app_added, module_app_removed, true); | |
| 175 end | |
| 176 | |
| 177 function module.unload() | |
| 178 remove_all_apps(); | |
| 179 end | |
| 180 |