add new version of conversation widget and extend docs

add new version of conversation widget and extend docs

add new version of conversation widget and extend docs

add new version of conversation widget and extend docs
This commit is contained in:
Evgeny
2021-12-23 15:32:57 +03:00
parent 59f49605b8
commit 15298b5709
2 changed files with 49 additions and 5 deletions

View File

@@ -9,7 +9,7 @@ The possibilities of scripts are limited, but they can be used to expand the fun
* 4.0.0 - first version with scripts support; * 4.0.0 - first version with scripts support;
* 4.1.0 - added `weather` and `cloud` modules; * 4.1.0 - added `weather` and `cloud` modules;
* 4.1.3 - added `notify`, `files` and `utils` modules. * 4.1.3 - added `notify`, `files` and `utils` modules.
* 4.1.5 - added messages filed to `notify` module, added `folded_string` arg to `ui:show_lines` * 4.1.5 - extended `notify` module, added `folded_string` arg to `ui:show_lines`
# Lifecycle callbacks # Lifecycle callbacks
@@ -178,6 +178,8 @@ Contacts table format:
# Weather # Weather
_Avaialble from: 4.1.0_
* `weather:get_by_hour()` - performs hourly weather query. * `weather:get_by_hour()` - performs hourly weather query.
Function returns the weather data in the `on_weather_result(result)` callback, where `result` is a table of tables with the following fields: Function returns the weather data in the `on_weather_result(result)` callback, where `result` is a table of tables with the following fields:
@@ -191,6 +193,8 @@ Function returns the weather data in the `on_weather_result(result)` callback, w
# Cloud # Cloud
_Avaialble from: 4.1.0_
* `cloud:get_metadata(path)` - returns a table with file metadata; * `cloud:get_metadata(path)` - returns a table with file metadata;
* `cloud:get_file(path)` - returns the contents of the file; * `cloud:get_file(path)` - returns the contents of the file;
* `cloud:put_file(sting, path)` - writes a string to the file; * `cloud:put_file(sting, path)` - writes a string to the file;
@@ -202,9 +206,13 @@ All data are returned in `on_cloud_result(meta, content)`. The first argument is
# Notifications # Notifications
_Avaialble from: 4.1.3_
* `notify:get_current()` - requests current notifications from the launcher; * `notify:get_current()` - requests current notifications from the launcher;
* `notify:open(key)` - opens notification with specified key; * `notify:open(key)` - opens notification with specified key;
* `notify:close(key)` - removes the notification with the specified key; * `notify:close(key)` - removes the notification with the specified key;
* `notify:do_action(key, action_id)` - sends notification action (_available from: 4.1.5_);
* `notify:consumed(key)` - mark notification as consumed so built-in Notifications widget will not show it;
The `notify:get_current()` function asks for all current notifications. The Launcher returns them one by one to the `on_notify_posted(table)` callback, where table is the table representing the notification. The same callback will be called when a new notification appears. When the notification is closed, the `on_notify_removed(table)` colbeck will be called. The `notify:get_current()` function asks for all current notifications. The Launcher returns them one by one to the `on_notify_posted(table)` callback, where table is the table representing the notification. The same callback will be called when a new notification appears. When the notification is closed, the `on_notify_removed(table)` colbeck will be called.
@@ -222,12 +230,15 @@ Notification table format:
* `big_text` - extended notification text; * `big_text` - extended notification text;
* `is_clearable` - true, if the notification is clearable; * `is_clearable` - true, if the notification is clearable;
* `group_id` - notification group ID; * `group_id` - notification group ID;
* `messages` - table of tables with fields `sender` and `text` (commonly used by messenger applications). * `messages` - table of tables with fields: `sender`, `text`, `time` (_available from: 4.1.5_);
* `actions` - table notifications actions with fields: `id`, `title`, `have_input` (_available from: 4.1.5_);
Keep in mind that the AIO Launcher also calls `get_current()` every time you return to the launcher, which means that all scripts will also get notification information in the `on_notify_posted()` callback every time you return to the desktop. Keep in mind that the AIO Launcher also calls `get_current()` every time you return to the launcher, which means that all scripts will also get notification information in the `on_notify_posted()` callback every time you return to the desktop.
# Files # Files
_Avaialble from: 4.1.3_
* `files:read(file)` - returns file contents or `nil` if file does not exist; * `files:read(file)` - returns file contents or `nil` if file does not exist;
* `files:write(file, string)` - writes `string` to file (creates file if file does not exist); * `files:write(file, string)` - writes `string` to file (creates file if file does not exist);
* `files:delete(file)` - deletes the file; * `files:delete(file)` - deletes the file;
@@ -248,6 +259,8 @@ The standard edit dialog can be replaced by your own if you implement the `on_se
# Functions # Functions
_Avaialble from: 4.1.3_
* `utils:md5(string)` - returns md5-hash of string (array of bytes); * `utils:md5(string)` - returns md5-hash of string (array of bytes);
* `utils:sha256(string)` - returns sha256-hash of string (array of bytes); * `utils:sha256(string)` - returns sha256-hash of string (array of bytes);
* `utils:base64encode(string)` - returns base64 representation of string (array of bytes); * `utils:base64encode(string)` - returns base64 representation of string (array of bytes);

View File

@@ -20,6 +20,7 @@ function on_notify_posted(n)
if (n.is_clearable == false) then return end if (n.is_clearable == false) then return end
if (table_size(n.messages) == 0) then return end if (table_size(n.messages) == 0) then return end
notify:consumed(n.key)
no_tab[n.key] = n no_tab[n.key] = n
redraw() redraw()
end end
@@ -54,6 +55,25 @@ function on_click(idx)
notify:open(keys_tab[idx]) notify:open(keys_tab[idx])
end end
function on_long_click(idx)
local key = keys_tab[idx]
if (key == "NO_KEY") then
return
end
local noti = no_tab[key]
for _,action in pairs(noti.actions) do
if (action.have_input) then
notify:do_action(key, action.id)
return
end
end
ui:show_toast("Can't reply")
end
function gen_messages_tab(tab) function gen_messages_tab(tab)
tree_tab = {} tree_tab = {}
tree_keys_tab = {} tree_keys_tab = {}
@@ -66,7 +86,7 @@ function gen_messages_tab(tab)
for _,notify in pairs(tab) do for _,notify in pairs(tab) do
for _,message in pairs(notify.messages) do for _,message in pairs(notify.messages) do
local sender = format_sender(message.sender) local sender = format_sender(message.sender)
local message = format_message(message.text, notify.package) local message = format_message(message, notify.package)
if tree_tab[sender] == nil then if tree_tab[sender] == nil then
tree_tab[sender] = {} tree_tab[sender] = {}
@@ -110,15 +130,26 @@ function gen_folded_string(tab)
end end
function format_sender(sender) function format_sender(sender)
return "<b>"..sender.."</b>" local final_sender = ""
if (sender == "") then
final_sender = "Unknown"
else
final_sender = sender
end
return "<b>"..final_sender.."</b> "
end end
function format_message(message, package) function format_message(message, package)
local app_name = apps:get_name(package) local app_name = apps:get_name(package)
local app_color = apps:get_color(package) local app_color = apps:get_color(package)
local circle = "<font color=\""..app_color.."\">●</font>" local circle = "<font color=\""..app_color.."\">●</font>"
local second_color = ui:get_colors().secondary_text
local time = os.date("%H:%M", message.time)
local time_str = "<font color=\""..second_color.."\">- "..time.."</font>"
return circle.." "..html_escape(message) return circle.." "..html_escape(message.text).." "..time_str
end end
-- Utils -- -- Utils --