summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2017-02-19 19:55:46 (GMT)
committerTobias Markmann <tm@ayena.de>2017-03-03 11:26:38 (GMT)
commit5fa6933f9cc3e6d0df8c6896871cbe6cc09a9492 (patch)
tree96854d1b7c2b85f959aa2e1bab215e9fcdabd94d /Swift/Controllers/Chat/MUCController.cpp
parent901ca8337c983f098394c7d4889f74aad452b1d0 (diff)
downloadswift-5fa6933f9cc3e6d0df8c6896871cbe6cc09a9492.zip
swift-5fa6933f9cc3e6d0df8c6896871cbe6cc09a9492.tar.bz2
Do not clear join/leave queue for MUC rooms on CSN messages
Previously chat-state notification messages would cause the join/leave queue of a MUC room to be cleared, resulting in taking up more vertical space than it had to. Test-Information: Compared two Swift builds (one with this patch and one without) in a room where some occupants would send CSN messages from time to time. With this patch, a CSN message clearly does not cause the join/leave queue to be cleared. Added unit test to verify new behaviour. Tested on macOS 10.12.3 with Qt 5.7.1. Change-Id: I0aee733fa5d16bbfb497a17b3d7a3ffe3fea8f26
Diffstat (limited to 'Swift/Controllers/Chat/MUCController.cpp')
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 8fa98f6..545eab5 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -512,62 +512,68 @@ std::string MUCController::roleToFriendlyName(MUCOccupant::Role role) {
}
assert(false);
return "";
}
std::string MUCController::roleToSortName(MUCOccupant::Role role) {
switch (role) {
case MUCOccupant::Moderator: return "1";
case MUCOccupant::Participant: return "2";
case MUCOccupant::Visitor: return "3";
case MUCOccupant::NoRole: return "4";
}
assert(false);
return "5";
}
JID MUCController::nickToJID(const std::string& nick) {
return muc_->getJID().withResource(nick);
}
bool MUCController::messageTargetsMe(std::shared_ptr<Message> message) {
std::string stringRegexp(".*\\b" + boost::to_lower_copy(nick_) + "\\b.*");
boost::regex myRegexp(stringRegexp);
return boost::regex_match(boost::to_lower_copy(message->getBody().get_value_or("")), myRegexp);
}
void MUCController::preHandleIncomingMessage(std::shared_ptr<MessageEvent> messageEvent) {
if (messageEvent->getStanza()->getType() == Message::Groupchat) {
lastActivity_ = boost::posix_time::microsec_clock::universal_time();
}
- clearPresenceQueue();
std::shared_ptr<Message> message = messageEvent->getStanza();
+
+ // This avoids clearing join/leave queue for chat state notification messages
+ // which are not readable (e.g. have no body content).
+ if (!(!messageEvent->isReadable() && message->getPayload<ChatState>())) {
+ clearPresenceQueue();
+ }
+
if (joined_ && messageEvent->getStanza()->getFrom().getResource() != nick_ && messageTargetsMe(message) && !message->getPayload<Delay>() && messageEvent->isReadable()) {
chatWindow_->flash();
}
else {
messageEvent->setTargetsMe(false);
}
if (messageEvent->isReadable() && isImpromptu_) {
chatWindow_->flash(); /* behave like a regular char*/
}
if (joined_) {
std::string nick = message->getFrom().getResource();
if (nick != nick_ && currentOccupants_.find(nick) != currentOccupants_.end()) {
completer_->addWord(nick);
}
}
/*Buggy implementations never send the status code, so use an incoming message as a hint that joining's done (e.g. the old ejabberd on psi-im.org).*/
receivedActivity();
joined_ = true;
if (message->hasSubject() && !message->getPayload<Body>() && !message->getPayload<Thread>()) {
if (!isInitialJoin_) {
displaySubjectIfChanged(message->getSubject());
}
isInitialJoin_ = false;
chatWindow_->setSubject(message->getSubject());
doneGettingHistory_ = true;
subject_ = message->getSubject();
}
if (!doneGettingHistory_ && !message->getPayload<Delay>()) {