/** * This slot is called when fetching mentions is finished (see fetchLastTweets()) */ void MentionsQmlListModel::finishedFetchTweets(const QList<QTweetStatus> &statuses) { QTweetMentions *mentions = qobject_cast<QTweetMentions*>(sender()); if (mentions) { if (!statuses.isEmpty()) { qDebug() << "Fetch mentions: " << statuses.count(); QSqlQuery query; query.exec("BEGIN;"); query.prepare("INSERT OR REPLACE INTO status " "(id, text, screenName, profileImageUrl, userId, mention, created, replyToStatusId) " "VALUES " "(:id, :text, :screenName, :profileImageUrl, :userId, :mention, :created, :replyToStatusId);"); QListIterator<QTweetStatus> i(statuses); i.toBack(); while (i.hasPrevious()) { QString text; QTweetStatus s = i.previous(); query.bindValue(":id", s.id()); query.bindValue(":replyToStatusId", s.inReplyToStatusId()); query.bindValue(":userId", s.user().id()); query.bindValue(":screenName", s.user().screenName()); query.bindValue(":profileImageUrl", s.user().profileImageUrl()); query.bindValue(":mention", 1); query.bindValue(":created", s.createdAt()); if (s.isRetweet()) { QString retweetedText = s.retweetedStatus().text(); text = "RT @" + s.retweetedStatus().user().screenName() + ": " + retweetedText; } else { text = s.text(); } query.bindValue(":text", text); query.exec(); m_newStatuses.prepend(s); } query.exec("COMMIT;"); m_numNewTweets = m_newStatuses.count(); emit numNewTweetsChanged(); } mentions->deleteLater(); } }
/** * This slot is connected to user stream object. * Called when new tweet arrives in the user stream */ void MentionsQmlListModel::onStatusesStream(const QTweetStatus &status) { QList<QTweetEntityUserMentions> entityUserMentions = status.userMentionsEntities(); for (int i = 0; i < entityUserMentions.count(); ++i) { if (entityUserMentions.at(i).userid() == userID()) { //check if is mention QSqlQuery query; QString text; query.prepare("INSERT OR REPLACE INTO status " "(id, text, screenName, profileImageUrl, userId, mention, created, replyToStatusId) " "VALUES " "(:id, :text, :screenName, :profileImageUrl, :userId, :mention, :created, :replyToStatusId);"); query.bindValue(":id", status.id()); query.bindValue(":userId", status.user().id()); query.bindValue(":screenName", status.user().screenName()); query.bindValue(":profileImageUrl", status.user().profileImageUrl()); query.bindValue(":mention", 1); query.bindValue(":created", status.createdAt()); query.bindValue(":replyToStatusId", status.inReplyToStatusId()); if (status.isRetweet()) { QString retweetedText = status.retweetedStatus().text(); text = "RT @" + status.retweetedStatus().user().screenName() + ": " + retweetedText; } else { text = status.text(); } query.bindValue(":text", text); query.exec(); m_newStatuses.prepend(status); m_numNewTweets = m_newStatuses.count(); emit numNewTweetsChanged(); break; } } }