From 00081de61040ab178c832ca1e8abee1a56136c96 Mon Sep 17 00:00:00 2001 From: Smok1e Date: Tue, 12 Sep 2023 20:33:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BD=D0=B4=D0=B8=D0=BA=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=20=D0=BD=D0=B5=D0=BF=D1=80=D0=BE=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications/App Market.app/Main.lua | 62 ++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/Applications/App Market.app/Main.lua b/Applications/App Market.app/Main.lua index 7a871ef0..02708bf9 100644 --- a/Applications/App Market.app/Main.lua +++ b/Applications/App Market.app/Main.lua @@ -1,4 +1,3 @@ - local internet = require("Internet") local GUI = require("GUI") local screen = require("Screen") @@ -105,7 +104,7 @@ local leftList = window:addChild(GUI.list(1, 4, leftListPanel.width, 1, 3, 0, ni local contentContainer = window:addChild(GUI.container(1, 1, 1, 1)) -local sponsoredLabel = window:addChild(GUI.text(2, 1, 0x3C3C3C, "Sponsored by McModder")) +local sponsoredLabel = window:addChild(GUI.text(2, 1, 0x3C3C3C, "Sponsored by Smok1e")) local progressIndicator = window:addChild(GUI.progressIndicator(math.floor(leftListPanel.width / 2 - 1), 1, 0x3C3C3C, 0x00B640, 0x99FF80)) @@ -187,7 +186,6 @@ local function RawAPIRequest(script, postData, notUnserialize) progressIndicator.active = false workspace:draw() - if success then if not notUnserialize then local unserializeResult, unserializeReason = text.deserialize(data) @@ -415,6 +413,27 @@ local function deletePublication(publication) end end +local function checkForUnreadMessages() + if not user.token then + return + end + + local dialogs = fieldAPIRequest("result", "dialogs", { + token = user.token + }) + + if dialogs then + messagesItem.has_unread_messages = false + + for _, dialog in pairs(dialogs) do + if dialog.last_message_user_id ~= user.id and dialog.last_message_is_read == 0 then + messagesItem.has_unread_messages = true + break + end + end + end +end + -------------------------------------------------------------------------------- local function getApplicationPathFromVersions(versionsPath) @@ -684,6 +703,29 @@ local function containerScrollEventHandler(workspace, object, e1, e2, e3, e4, e5 end end +local function messagesButtonDraw(pressable) + local backgroundColor = pressable.pressed and pressable.colors.pressed.background or pressable.disabled and pressable.colors.disabled.background or pressable.colors.default.background + local textColor = pressable.pressed and pressable.colors.pressed.text or pressable.disabled and pressable.colors.disabled.text or pressable.colors.default.text + + if backgroundColor then + screen.drawRectangle(pressable.x, pressable.y, pressable.width, pressable.height, backgroundColor, textColor, " ") + end + + -- Рисуем синюю писечку, просящую прочитать сообщения + if pressable.has_unread_messages then + local x = math.floor(pressable.x + 2) + local y = math.floor(pressable.y + pressable.height / 2) + local backgroundColor, _, _ = screen.get(x, y) + + screen.set(x, y, backgroundColor, 0x005EFF, "●") + end + + screen.drawText( + math.floor(pressable.x + pressable.width / 2 - unicode.len(pressable.text) / 2), + math.floor(pressable.y + pressable.height / 2), textColor, pressable.text + ) +end + local newApplicationPreview, newPublicationInfo local function applicationWidgetEventHandler(workspace, object, e1) @@ -1049,7 +1091,10 @@ local function dialogGUI(to_user_name) if result then messages = result end + + checkForUnreadMessages() end + messages = messages or {} contentContainer:removeChildren() @@ -1147,7 +1192,7 @@ end local function dialogs() local dialogs = fieldAPIRequest("result", "dialogs", { - token = user.token, + token = user.token }) if dialogs then @@ -1162,10 +1207,15 @@ local function dialogs() dialogGUI() end + messagesItem.has_unread_messages = false if #dialogs > 0 then local y = sendMessageButton.localY + 2 for i = 1, #dialogs do + if not messagesItem.has_unread_messages then + messagesItem.has_unread_messages = dialogs[i].last_message_is_read == 0 and dialogs[i].last_message_user_id ~= user.id + end + local backgroundColor, nicknameColor, timestampColor, textColor = 0xFFFFFF, 0x0, 0xD2D2D2, 0x969696 if dialogs[i].last_message_is_read == 0 and dialogs[i].last_message_user_name ~= user.name then backgroundColor, nicknameColor, timestampColor, textColor = 0xCCDBFF, 0x0, 0xB4B4B4, 0x878787 @@ -1967,6 +2017,7 @@ end messagesItem = leftList:addItem(localization.messages) messagesItem.onTouch = dialogs +messagesItem.draw = messagesButtonDraw leftList:addItem(localization.settings).onTouch = settings @@ -2000,6 +2051,9 @@ end loadConfig() +-- Рисуем синюю писечку если надо +checkForUnreadMessages() + lastMethod = loadCategory if select(1, ...) == "updates" then