From abef7b4045ba50ce08ec973c0d6e01d14a4faafe Mon Sep 17 00:00:00 2001 From: Lawrence Vanderpool Date: Wed, 10 Jun 2015 11:04:01 -0400 Subject: [PATCH 1/2] added the ability to check for unread messages with the 'i' key --- rtv/page.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/rtv/page.py b/rtv/page.py index a69deb1..b58c192 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -412,8 +412,23 @@ class BasePage(object): s.catch = False self.refresh_content() + @BaseController.register('i') + def get_inbox(self): + """ + Checks the inbox for unread messages and displays a notification. + """ + try: + if len(list(self.reddit.get_unread(limit=1))) > 0: + show_notification(self.stdscr, ['New Messages']) + elif len(list(self.reddit.get_unread(limit=1))) == 0: + show_notification(self.stdscr, ['No New Messages']) + except praw.errors.LoginOrScopeRequired: + show_notification(self.stdscr, ['Not Logged In']) + def clear_input_queue(self): - "Clear excessive input caused by the scroll wheel or holding down a key" + """ + Clear excessive input caused by the scroll wheel or holding down a key + """ self.stdscr.nodelay(1) while self.stdscr.getch() != -1: @@ -421,7 +436,9 @@ class BasePage(object): self.stdscr.nodelay(0) def logout(self): - "Prompt to log out of the user's account." + """ + Prompt to log out of the user's account. + """ ch = prompt_input(self.stdscr, "Log out? (y/n):") if ch == 'y': From 3c83d388ccedd110cf9ca71c380e334a5d2be215 Mon Sep 17 00:00:00 2001 From: Lawrence Vanderpool Date: Thu, 11 Jun 2015 09:31:56 -0400 Subject: [PATCH 2/2] moved inbox call outside of if/else --- rtv/page.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rtv/page.py b/rtv/page.py index b58c192..e2418cb 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -417,10 +417,11 @@ class BasePage(object): """ Checks the inbox for unread messages and displays a notification. """ + inbox = len(list(self.reddit.get_unread(limit=1))) try: - if len(list(self.reddit.get_unread(limit=1))) > 0: + if inbox > 0: show_notification(self.stdscr, ['New Messages']) - elif len(list(self.reddit.get_unread(limit=1))) == 0: + elif inbox == 0: show_notification(self.stdscr, ['No New Messages']) except praw.errors.LoginOrScopeRequired: show_notification(self.stdscr, ['Not Logged In'])