Changeset - 761c746d1008
[Not reviewed]
0 7 0
Jan Kaluza - 13 years ago 2012-12-18 12:56:38
hanzz.k@gmail.com
Move headline sending login to backend
7 files changed with 45 insertions and 16 deletions:
0 comments (0 inline, 0 general)
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -652,22 +652,20 @@ void TwitterPlugin::displayFriendlist(std::string &user, std::vector<User> &frie
 
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].getRetweetID().empty() ? tweets[i].getID() : tweets[i].getRetweetID()) + ")\n";
 
				handleMessage(user, adminLegacyName, m, "", "", tweets[i].getCreationTime());
 
				handleMessage(user, adminLegacyName, m, "", "", tweets[i].getCreationTime(), true);
 

	
 
				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].getRetweetID().empty() ? tweets[i].getID() : tweets[i].getRetweetID()) + ")", 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(), true);
 
			}
 
		}
 
		
 
@@ -685,8 +683,6 @@ void TwitterPlugin::displayTweets(std::string &user, std::string &userRequested,
 
			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 : "");	
 
}
include/transport/networkplugin.h
Show inline comments
 
@@ -111,7 +111,7 @@ class NetworkPlugin {
 
		/// \param message Plain text message.
 
		/// \param nickname Nickname of buddy in room. Empty if it's normal chat message.
 
		/// \param xhtml XHTML message.
 
		void handleMessage(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &nickname = "", const std::string &xhtml = "", const std::string &timestamp = "");
 
		void handleMessage(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &nickname = "", const std::string &xhtml = "", const std::string &timestamp = "", bool headline = false);
 

	
 
		/// Call this function when subject in room changed.
 
		/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
plugin/cpp/networkplugin.cpp
Show inline comments
 
@@ -82,7 +82,7 @@ void NetworkPlugin::sendConfig(const PluginConfig &cfg) {
 
	send(message);
 
}
 

	
 
void NetworkPlugin::handleMessage(const std::string &user, const std::string &legacyName, const std::string &msg, const std::string &nickname, const std::string &xhtml, const std::string &timestamp) {
 
void NetworkPlugin::handleMessage(const std::string &user, const std::string &legacyName, const std::string &msg, const std::string &nickname, const std::string &xhtml, const std::string &timestamp, bool headline) {
 
	pbnetwork::ConversationMessage m;
 
	m.set_username(user);
 
	m.set_buddyname(legacyName);
 
@@ -90,6 +90,7 @@ void NetworkPlugin::handleMessage(const std::string &user, const std::string &le
 
	m.set_nickname(nickname);
 
	m.set_xhtml(xhtml);
 
	m.set_timestamp(timestamp);
 
	m.set_headline(headline);
 

	
 
	std::string message;
 
	m.SerializeToString(&message);
src/conversation.cpp
Show inline comments
 
@@ -82,14 +82,14 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
 
		message->setType(Swift::Message::Groupchat);
 
	}
 
	else {
 
		if (message->getType() != Swift::Message::Headline) {
 
			if (m_conversationManager->getUser()->getUserSetting("send_headlines") == "1") {
 
				message->setType(Swift::Message::Headline);
 
			}
 
			else {
 
		if (message->getType() == Swift::Message::Headline) {
 
			if (m_conversationManager->getUser()->getUserSetting("send_headlines") != "1") {
 
				message->setType(Swift::Message::Chat);
 
			}
 
		}
 
		else {
 
			message->setType(Swift::Message::Chat);
 
		}
 
	}
 

	
 
	std::string n = nickname;
src/settingsadhoccommand.cpp
Show inline comments
 
@@ -43,7 +43,7 @@ SettingsAdHocCommand::SettingsAdHocCommand(Component *component, UserManager *us
 

	
 
	field = Swift::BooleanFormField::create(CONFIG_STRING_DEFAULTED(component->getConfig(), "settings.send_headlines", "0") == "1");
 
	field->setName("send_headlines");
 
	field->setLabel("Send messages as headlines");
 
	field->setLabel("Allow sending messages as headlines");
 
	addFormField(field);
 
}
 

	
src/tests/conversationmanager.cpp
Show inline comments
 
@@ -215,6 +215,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 

	
 
		boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
		msg->setBody("hi there<>!");
 
		msg->setType(Swift::Message::Headline);
 

	
 
		// Forward it
 
		conv->handleMessage(msg);
 
@@ -229,19 +230,20 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 

	
 
		received.clear();
 
		user->addUserSetting("send_headlines", "0");
 
		// Forward it - Conversation should keep the Headline type, because msg->getType() is Headline
 
		// Forward it
 
		conv->handleMessage(msg);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(Swift::Message::Headline, dynamic_cast<Swift::Message *>(getStanza(received[0]))->getType());
 
		CPPUNIT_ASSERT_EQUAL(Swift::Message::Chat, dynamic_cast<Swift::Message *>(getStanza(received[0]))->getType());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40test@localhost/bot"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getFrom().toString());
 

	
 
		received.clear();
 
		msg->setType(Swift::Message::Chat);
 
		user->addUserSetting("send_headlines", "1");
 
		// Forward it
 
		conv->handleMessage(msg);
 
		loop->processEvents();
src/tests/networkpluginserver.cpp
Show inline comments
 
@@ -30,6 +30,7 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
	CPPUNIT_TEST(handleBuddyChangedPayload);
 
	CPPUNIT_TEST(handleBuddyChangedPayloadNoEscaping);
 
	CPPUNIT_TEST(handleBuddyChangedPayloadUserContactInRoster);
 
	CPPUNIT_TEST(handleMessageHeadline);
 
	CPPUNIT_TEST_SUITE_END();
 

	
 
	public:
 
@@ -104,6 +105,35 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
			serv->handleBuddyChangedPayload(message);
 
			CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		}
 

	
 
		void handleMessageHeadline() {
 
			User *user = userManager->getUser("user@localhost");
 

	
 
			pbnetwork::ConversationMessage m;
 
			m.set_username("user@localhost");
 
			m.set_buddyname("user");
 
			m.set_message("msg");
 
			m.set_nickname("");
 
			m.set_xhtml("");
 
			m.set_timestamp("");
 
			m.set_headline(true);
 

	
 
			std::string message;
 
			m.SerializeToString(&message);
 

	
 
			serv->handleConvMessagePayload(message, false);
 
			CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::Message::Chat, dynamic_cast<Swift::Message *>(getStanza(received[0]))->getType());
 

	
 
			received.clear();
 
			user->addUserSetting("send_headlines", "1");
 
			serv->handleConvMessagePayload(message, false);
 
			CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::Message::Headline, dynamic_cast<Swift::Message *>(getStanza(received[0]))->getType());
 

	
 
		}
 
};
 

	
 
CPPUNIT_TEST_SUITE_REGISTRATION (NetworkPluginServerTest);
0 comments (0 inline, 0 general)