Changeset - 7142ccb570ed
[Not reviewed]
0 3 0
Vitaly Takmazov - 13 years ago 2012-12-10 21:28:10
vitalyster@gmail.com
Use retweetID for displaying and ID everywhere else
3 files changed with 7 insertions and 4 deletions:
0 comments (0 inline, 0 general)
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -638,57 +638,57 @@ void TwitterPlugin::displayFriendlist(std::string &user, std::vector<User> &frie
 
	if(errMsg.getMessage().length() == 0) 
 
	{
 
		std::string userlist = "\n***************USER LIST****************\n";
 
		for(int i=0 ; i < friends.size() ; i++) {
 
			userlist += " - " + friends[i].getUserName() + " (" + friends[i].getScreenName() + ")\n";
 
		}	
 
		userlist += "***************************************\n";
 
		handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
							userlist, userdb[user].twitterMode == CHATROOM ? adminNickName : "");	
 
	} else handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName, 
 
							   errMsg.getMessage(), userdb[user].twitterMode == CHATROOM ? adminNickName : "");	
 
 
 
}
 

	
 
void TwitterPlugin::displayTweets(std::string &user, std::string &userRequested, std::vector<Status> &tweets , Error &errMsg)
 
{
 
	if(errMsg.getMessage().length() == 0) {
 
		
 
		std::string timeline = "";
 
		std::map<std::string, int> lastTweet;
 
		std::map<std::string, int>::iterator it;
 

	
 
		for(int i = tweets.size() - 1 ; i >= 0 ; i--) {
 
			if(userdb[user].twitterMode != CHATROOM) {
 
				std::string m = " - " + tweets[i].getUserData().getScreenName() + ": " + tweets[i].getTweet() + " (MsgId: " + tweets[i].getID() + ")\n";
 
				std::string m = " - " + tweets[i].getUserData().getScreenName() + ": " + tweets[i].getTweet() + " (MsgId: " + (tweets[i].getRetweetID().empty() ? tweets[i].getID() : tweets[i].getRetweetID()) + ")\n";
 
				handleMessage(user, adminLegacyName, m, "", "", tweets[i].getCreationTime());
 

	
 
				std::string scrname = tweets[i].getUserData().getScreenName();
 
				if(lastTweet.count(scrname) == 0 || cmp(tweets[lastTweet[scrname]].getID(), tweets[i].getID()) <= 0) lastTweet[scrname] = i;
 

	
 
			} else {
 
				handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
									tweets[i].getTweet() + " (MsgId: " + tweets[i].getID() + ")", tweets[i].getUserData().getScreenName(), "", tweets[i].getCreationTime());
 
									tweets[i].getTweet() + " (MsgId: " + (tweets[i].getRetweetID().empty() ? tweets[i].getID() : tweets[i].getRetweetID()) + ")", tweets[i].getUserData().getScreenName(), "", tweets[i].getCreationTime());
 
			}
 
		}
 
		
 
		if(userdb[user].twitterMode == MULTIPLECONTACT) {
 
			//Set as status user's last tweet
 
			for(it=lastTweet.begin() ; it!=lastTweet.end() ; it++) {
 
				int t =  it->second;
 
				handleBuddyChanged(user, tweets[t].getUserData().getScreenName(), tweets[t].getUserData().getUserName(), 
 
								   std::vector<std::string>(), pbnetwork::STATUS_ONLINE, tweets[t].getTweet());
 
			}
 
		}
 

	
 
		if((userRequested == "" || userRequested == user) && tweets.size()) {
 
			std::string tweetID = getMostRecentTweetID(user);
 
			if(tweetID != tweets[0].getID()) updateLastTweetID(user, tweets[0].getID());
 
		}
 

	
 
		if(timeline.length()) handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
												  timeline, userdb[user].twitterMode == CHATROOM ? adminNickName : "");
 
	} else handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
							   errMsg.getMessage(), userdb[user].twitterMode == CHATROOM ? adminNickName : "");	
 
}
 

	
 
void TwitterPlugin::directMessageResponse(std::string &user, std::string &username, std::vector<DirectMessage> &messages, Error &errMsg)
backends/twitter/TwitterResponseParser.cpp
Show inline comments
 
@@ -82,49 +82,49 @@ User getUser(const Swift::ParserElement::ref &element, const std::string xmlns)
 
}
 

	
 
Status getStatus(const Swift::ParserElement::ref &element, const std::string xmlns) 
 
{
 
	Status status;
 
	if(element->getName() != "status") {
 
		LOG4CXX_ERROR(logger, "Not a status element!")
 
		return status;
 
	}
 

	
 
	status.setCreationTime( toIsoTime ( std::string( element->getChild(TwitterReponseTypes::created_at, xmlns)->getText() ) ) );
 
	status.setID( std::string( element->getChild(TwitterReponseTypes::id, xmlns)->getText() ) );
 
	status.setTweet( unescape ( std::string( element->getChild(TwitterReponseTypes::text, xmlns)->getText() ) ) );
 
	status.setTruncated( std::string( element->getChild(TwitterReponseTypes::truncated, xmlns)->getText() )=="true" );
 
	status.setReplyToStatusID( std::string( element->getChild(TwitterReponseTypes::in_reply_to_status_id, xmlns)->getText() ) );
 
	status.setReplyToUserID( std::string( element->getChild(TwitterReponseTypes::in_reply_to_user_id, xmlns)->getText() ) );
 
	status.setReplyToScreenName( std::string( element->getChild(TwitterReponseTypes::in_reply_to_screen_name, xmlns)->getText() ) );
 
	status.setUserData( getUser(element->getChild(TwitterReponseTypes::user, xmlns), xmlns) );
 
	status.setRetweetCount( atoi( element->getChild(TwitterReponseTypes::retweet_count, xmlns)->getText().c_str() ) );
 
	status.setFavorited( std::string( element->getChild(TwitterReponseTypes::favorited, xmlns)->getText() )=="true" );
 
	status.setRetweeted( std::string( element->getChild(TwitterReponseTypes::retweeted, xmlns)->getText() )=="true" );
 
	Swift::ParserElement::ref rt = element->getChild(TwitterReponseTypes::retweeted_status, xmlns);
 
	if (rt != Swift::NullParserElement::element) {
 
		status.setTweet(unescape( std::string( rt->getChild(TwitterReponseTypes::text, xmlns)->getText() + " (RT by @" + status.getUserData().getScreenName() + ")") ) );
 
		status.setID( std::string ( rt->getChild(TwitterReponseTypes::id, xmlns)->getText() ) );
 
		status.setRetweetID( std::string ( rt->getChild(TwitterReponseTypes::id, xmlns)->getText() ) );
 
		status.setCreationTime( toIsoTime ( std::string (rt->getChild(TwitterReponseTypes::created_at, xmlns)->getText() ) ) );
 
		status.setUserData( getUser ( rt->getChild(TwitterReponseTypes::user, xmlns), xmlns ) );
 
	}
 
	return status;
 
}
 

	
 
DirectMessage getDirectMessage(const Swift::ParserElement::ref &element, const std::string xmlns) 
 
{
 
	DirectMessage DM;
 
	if(element->getName() != TwitterReponseTypes::direct_message) {
 
		LOG4CXX_ERROR(logger, "Not a direct_message element!")
 
		return DM;
 
	}
 

	
 
	DM.setCreationTime( toIsoTime ( std::string( element->getChild(TwitterReponseTypes::created_at, xmlns)->getText() ) ) );
 
	DM.setID( std::string( element->getChild(TwitterReponseTypes::id, xmlns)->getText() ) );
 
	DM.setMessage( unescape ( std::string( element->getChild(TwitterReponseTypes::text, xmlns)->getText() ) ) );
 
	DM.setSenderID( std::string( element->getChild(TwitterReponseTypes::sender_id, xmlns)->getText() ) );
 
	DM.setRecipientID( std::string( element->getChild(TwitterReponseTypes::recipient_id, xmlns)->getText() ) );
 
	DM.setSenderScreenName( std::string( element->getChild(TwitterReponseTypes::sender_screen_name, xmlns)->getText() ) );
 
	DM.setRecipientScreenName( std::string( element->getChild(TwitterReponseTypes::recipient_screen_name, xmlns)->getText() ) );
 
	DM.setSenderData( getUser(element->getChild(TwitterReponseTypes::sender, xmlns), xmlns) );
 
	DM.setRecipientData( getUser(element->getChild(TwitterReponseTypes::recipient, xmlns), xmlns) );
 
	return DM;
backends/twitter/TwitterResponseParser.h
Show inline comments
 
@@ -95,77 +95,80 @@ class User
 
	User():ID(""),name(""),screen_name(""),statuses_count(0){}
 

	
 
	std::string getUserID() {return ID;}
 
	std::string getUserName() {return name;}
 
	std::string getScreenName() {return screen_name;}
 
	std::string getProfileImgURL() {return profile_image_url;}
 
	unsigned int getNumberOfTweets() {return statuses_count;}
 
	EmbeddedStatus getLastStatus() {return last_status;}
 
	
 
	
 
	void setUserID(std::string _id) {ID = _id;}
 
	void setUserName(std::string _name) {name = _name;}
 
	void setScreenName(std::string _screen) {screen_name = _screen;}
 
	void setProfileImgURL(std::string _url) {profile_image_url = _url;}
 
	void setNumberOfTweets(unsigned int sc) {statuses_count  = sc;}
 
	void setLastStatus(EmbeddedStatus _last_status) {last_status = _last_status;}
 
};
 

	
 

	
 
//Class representing a status (tweet)
 
class Status
 
{
 
	std::string created_at;
 
	std::string ID;
 
	std::string retweetID;	
 
	std::string text;
 
	bool truncated;
 
	std::string in_reply_to_status_id;
 
	std::string in_reply_to_user_id;
 
	std::string in_reply_to_screen_name;
 
	User user;
 
	unsigned int retweet_count;
 
	bool favorited;
 
	bool retweeted;
 

	
 
	public:
 
	Status():created_at(""),ID(""),text(""),truncated(false),in_reply_to_status_id(""),
 
		Status():created_at(""),ID(""),retweetID(""),text(""),truncated(false),in_reply_to_status_id(""),
 
	         in_reply_to_user_id(""),in_reply_to_screen_name(""),user(User()),retweet_count(0),
 
	         favorited(false),retweeted(0){}
 
	
 
	std::string getCreationTime() {return created_at;}
 
	std::string getID() {return ID;}
 
	std::string getRetweetID() {return retweetID;}	
 
	std::string getTweet() {return text;}
 
	bool isTruncated() {return truncated;}
 
	std::string getReplyToStatusID() {return in_reply_to_status_id;}
 
	std::string getReplyToUserID() {return in_reply_to_user_id;}
 
	std::string getReplyToScreenName() {return in_reply_to_screen_name;}
 
	User getUserData() {return user;}
 
	unsigned int getRetweetCount() {return retweet_count;}
 
	bool isFavorited() {return favorited;}
 
	bool isRetweeted() {return retweeted;}
 
	
 
	void setCreationTime(std::string _created) {created_at = _created;}
 
	void setID(std::string _id) {ID = _id;}
 
	void setRetweetID(std::string _id) {retweetID = _id;}	
 
	void setTweet(std::string _text) {text = _text;}
 
	void setTruncated(bool val) {truncated = val;}
 
	void setReplyToStatusID(std::string _id) {in_reply_to_status_id = _id;}
 
	void setReplyToUserID(std::string _id) {in_reply_to_user_id = _id;}
 
	void setReplyToScreenName(std::string _name) {in_reply_to_screen_name = _name;}
 
	void setUserData(User u) {user = u;}
 
	void setRetweetCount(unsigned int rc) {retweet_count = rc;}
 
	void setFavorited(bool val) {favorited = val;}
 
	void setRetweeted(bool val) {retweeted = val;}
 
};
 

	
 
//Class representing a Direct Message
 
class DirectMessage
 
{
 
	std::string created_at;
 
	std::string ID;
 
	std::string text;
 
	std::string sender_id;
 
	std::string recipient_id;
 
	std::string sender_screen_name;
 
	std::string recipient_screen_name;
 
	User sender, recipient;
 

	
 
	public:
0 comments (0 inline, 0 general)