feat: show amount of unread notifs in default config, add unreadCount function

notifications
sammyette 2023-07-10 18:27:00 -04:00
parent cc25effe04
commit f02d4784fb
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 9 additions and 7 deletions

View File

@ -24,14 +24,9 @@ bait.catch('hilbish.vimMode', function(mode)
end end
end) end)
--[[
hilbish.timeout(function()
hilbish.messages.send {title = 'greetings!', text = 'hello world :D'}
end, 2000)
]]--
bait.catch('hilbish.notification', function() bait.catch('hilbish.notification', function()
hilbish.prompt(lunacolors.blue('• 1 new notification'), 'right') local notif = string.format('• %s unread notification%s', hilbish.messages.unreadCount(), hilbish.messages.unreadCount() > 1 and 's' or '')
hilbish.prompt(lunacolors.blue(notif), 'right')
hilbish.timeout(function() hilbish.timeout(function()
hilbish.prompt('', 'right') hilbish.prompt('', 'right')

View File

@ -4,6 +4,7 @@ local lunacolors = require 'lunacolors'
local M = {} local M = {}
local counter = 0 local counter = 0
local unread = 0
M._messages = {} M._messages = {}
M.icons = { M.icons = {
INFO = '', INFO = '',
@ -35,6 +36,7 @@ function hilbish.messages.send(message)
expect(message, 'text') expect(message, 'text')
expect(message, 'title') expect(message, 'title')
counter = counter + 1 counter = counter + 1
unread = unread + 1
message.index = counter message.index = counter
message.read = false message.read = false
@ -46,6 +48,7 @@ function hilbish.messages.read(idx)
local msg = M._messages[idx] local msg = M._messages[idx]
if msg then if msg then
M._messages[idx].read = true M._messages[idx].read = true
unread = unread - 1
end end
end end
@ -55,6 +58,10 @@ function hilbish.messages.readAll(idx)
end end
end end
function hilbish.messages.unreadCount()
return unread
end
function hilbish.messages.delete(idx) function hilbish.messages.delete(idx)
local msg = M._messages[idx] local msg = M._messages[idx]
if not msg then if not msg then