daos.getUserReceivedMessageAccess().put(con, userMessage);
it.remove();
}
private void sendTwitterMessage(PartakeConnection con, IPartakeDAOs daos, DataIterator<MessageEnvelope> it, MessageEnvelope envelope) throws DAOException {
TwitterMessage message = daos.getTwitterMessageAccess().find(con, envelope.getTwitterMessageId());
if (message == null) {
Logger.warn("SendMessageEnvelopeTask.sendTwitterMessage : message was null.");
// Since the message was null, we cannot update the message status. So we silently remove this MessageEnvelope.
it.remove();
return;
}
UserEx sender = UserDAOFacade.getUserEx(con, daos, message.getUserId());
if (sender == null) {
Logger.warn("sendTwitterMessage : sender is null.");
failedSendingTwitterMessage(con, daos, it, envelope, message);
return;
}
UserTwitterLink twitterLinkage = sender.getTwitterLinkage();
if (twitterLinkage == null || !twitterLinkage.isAuthorized()) {
Logger.warn("sendTwitterMessage : envelope id " + envelope.getId() + " could not be sent : No access token");
failedSendingTwitterMessage(con, daos, it, envelope, message);
return;
}
try {
PartakeApp.getTwitterService().updateStatus(twitterLinkage.getAccessToken(), twitterLinkage.getAccessTokenSecret(), message.getMessage());
succeededSendingTwitterMessage(con, daos, it, envelope, message);
return;
} catch (TwitterException e) {
if (updateEnvelopeByTwitterException(con, daos, sender, envelope, it, e))
failedSendingTwitterMessage(con, daos, it, envelope, message);