def add_contact(self, contactId, title, description, numbersWithDescriptions):
if self._busyReason is not None:
raise RuntimeError("Please wait for %r" % self._busyReason)
- if contactId in self._contacts:
- _moduleLogger.info("Adding duplicate contact %r" % contactId)
- # @todo Remove this evil hack to re-popup the dialog
- self.recipientsChanged.emit()
- return
+ # Allow overwriting of contacts so that the message can be updated and the SMS dialog popped back up
contactDetails = _DraftContact(title, description, numbersWithDescriptions)
self._contacts[contactId] = contactDetails
self.recipientsChanged.emit()
self.sentMessage.emit()
self._clear()
except Exception, e:
+ _moduleLogger.exception("Reporting error to user")
self.error.emit(str(e))
def _call(self, number):
self.called.emit()
self._clear()
except Exception, e:
+ _moduleLogger.exception("Reporting error to user")
self.error.emit(str(e))
def _cancel(self):
)
self.cancelled.emit()
except Exception, e:
+ _moduleLogger.exception("Reporting error to user")
self.error.emit(str(e))
contactsUpdated = QtCore.pyqtSignal()
messagesUpdated = QtCore.pyqtSignal()
+ newMessages = QtCore.pyqtSignal()
historyUpdated = QtCore.pyqtSignal()
dndStateChange = QtCore.pyqtSignal(bool)
self._contacts = {}
self._contactUpdateTime = datetime.datetime(1971, 1, 1)
self._messages = []
+ self._cleanMessages = []
self._messageUpdateTime = datetime.datetime(1971, 1, 1)
self._history = []
self._historyUpdateTime = datetime.datetime(1971, 1, 1)
def logout(self):
assert self.state != self.LOGGEDOUT_STATE, "Can only logout if logged in (currently %s" % self.state
+ _moduleLogger.info("Logging out")
self._pool.stop()
self._loggedInTime = self._LOGGEDOUT_TIME
self._backend[0].persist()
def logout_and_clear(self):
assert self.state != self.LOGGEDOUT_STATE, "Can only logout if logged in (currently %s" % self.state
+ _moduleLogger.info("Logging out and clearing the account")
self._pool.stop()
self._loggedInTime = self._LOGGEDOUT_TIME
self.clear()
le.start(dnd)
def _set_dnd(self, dnd):
- # I'm paranoid about our state geting out of sync so we set no matter
- # what but act as if we have the cannonical state
- assert self.state == self.LOGGEDIN_STATE, "DND requires being logged in (currently %s" % self.state
oldDnd = self._dnd
try:
+ assert self.state == self.LOGGEDIN_STATE, "DND requires being logged in (currently %s" % self.state
with qui_utils.notify_busy(self._errorLog, "Setting DND Status"):
yield (
self._backend[0].set_dnd,
{},
)
except Exception, e:
+ _moduleLogger.exception("Reporting error to user")
self.error.emit(str(e))
return
self._dnd = dnd
return self._dnd
def get_account_number(self):
+ if self.state != self.LOGGEDIN_STATE:
+ return ""
return self._backend[0].get_account_number()
def get_callback_numbers(self):
- # @todo Remove evilness (might call is_authed which can block)
+ if self.state != self.LOGGEDIN_STATE:
+ return {}
return self._backend[0].get_callback_numbers()
def get_callback_number(self):
le.start(callback)
def _set_callback_number(self, callback):
- # I'm paranoid about our state geting out of sync so we set no matter
- # what but act as if we have the cannonical state
- assert self.state == self.LOGGEDIN_STATE, "Callbacks configurable only when logged in (currently %s" % self.state
oldCallback = self._callback
try:
+ assert self.state == self.LOGGEDIN_STATE, "Callbacks configurable only when logged in (currently %s" % self.state
yield (
self._backend[0].set_callback_number,
(callback, ),
{},
)
except Exception, e:
+ _moduleLogger.exception("Reporting error to user")
self.error.emit(str(e))
return
self._callback = callback
self._loggedInTime = self._LOGGEDOUT_TIME
self.error.emit("Error logging in")
except Exception, e:
+ _moduleLogger.exception("Booh")
self._loggedInTime = self._LOGGEDOUT_TIME
+ _moduleLogger.exception("Reporting error to user")
self.error.emit(str(e))
finally:
if finalState is not None:
self._contacts = {}
self._messages = []
+ self._cleanMessages = []
self._history = []
self._dnd = False
self._callback = ""
try:
with open(cachePath, "rb") as f:
dumpedData = pickle.load(f)
- except (pickle.PickleError, IOError, EOFError, ValueError):
+ except (pickle.PickleError, IOError, EOFError, ValueError, ImportError):
_moduleLogger.exception("Pickle fun loading")
return False
except:
_moduleLogger.exception("Weirdness loading")
return False
- (
- version, build,
- contacts, contactUpdateTime,
- messages, messageUpdateTime,
- history, historyUpdateTime,
- dnd, callback
- ) = dumpedData
+ try:
+ (
+ version, build,
+ contacts, contactUpdateTime,
+ messages, messageUpdateTime,
+ history, historyUpdateTime,
+ dnd, callback
+ ) = dumpedData
+ except ValueError:
+ _moduleLogger.exception("Upgrade/downgrade fun")
+ return False
+ except:
+ _moduleLogger.exception("Weirdlings")
if misc_utils.compare_versions(
self._OLDEST_COMPATIBLE_FORMAT_VERSION,
self._contacts = contacts
self._contactUpdateTime = contactUpdateTime
self._messages = messages
+ self._alert_on_messages(self._messages)
self._messageUpdateTime = messageUpdateTime
self._history = history
self._historyUpdateTime = historyUpdateTime
def _update_contacts(self):
try:
+ assert self.state == self.LOGGEDIN_STATE, "Contacts requires being logged in (currently %s" % self.state
with qui_utils.notify_busy(self._errorLog, "Updating Contacts"):
self._contacts = yield (
self._backend[0].get_contacts,
{},
)
except Exception, e:
+ _moduleLogger.exception("Reporting error to user")
self.error.emit(str(e))
return
self._contactUpdateTime = datetime.datetime.now()
def _update_messages(self):
try:
+ assert self.state == self.LOGGEDIN_STATE, "Messages requires being logged in (currently %s" % self.state
with qui_utils.notify_busy(self._errorLog, "Updating Messages"):
self._messages = yield (
self._backend[0].get_messages,
{},
)
except Exception, e:
+ _moduleLogger.exception("Reporting error to user")
self.error.emit(str(e))
return
self._messageUpdateTime = datetime.datetime.now()
self.messagesUpdated.emit()
+ self._alert_on_messages(self._messages)
def _update_history(self):
try:
+ assert self.state == self.LOGGEDIN_STATE, "History requires being logged in (currently %s" % self.state
with qui_utils.notify_busy(self._errorLog, "Updating History"):
self._history = yield (
self._backend[0].get_recent,
{},
)
except Exception, e:
+ _moduleLogger.exception("Reporting error to user")
self.error.emit(str(e))
return
self._historyUpdateTime = datetime.datetime.now()
def _update_dnd(self):
oldDnd = self._dnd
try:
+ assert self.state == self.LOGGEDIN_STATE, "DND requires being logged in (currently %s" % self.state
self._dnd = yield (
self._backend[0].is_dnd,
(),
{},
)
except Exception, e:
+ _moduleLogger.exception("Reporting error to user")
self.error.emit(str(e))
return
if oldDnd != self._dnd:
_moduleLogger.info("Skipping queueing duplicate op: %r" % asyncOp)
return
self._loginOps.append(asyncOp)
+
+ def _alert_on_messages(self, messages):
+ cleanNewMessages = list(self._clean_messages(messages))
+ if self._cleanMessages:
+ if self._cleanMessages != cleanNewMessages:
+ self.newMessages.emit()
+ self._cleanMessages = cleanNewMessages
+
+ def _clean_messages(self, messages):
+ for message in messages:
+ cleaned = dict(message)
+ del cleaned["relTime"]
+ del cleaned["time"]
+ del cleaned["isArchived"]
+ del cleaned["isRead"]
+ del cleaned["isSpam"]
+ del cleaned["isTrash"]
+ cleaned["messageParts"] = [tuple(part[0:-1]) for part in cleaned["messageParts"] if part[0] != "Me:"]
+ yield cleaned