From 4fa67e50ff57e2fd4bff80137c59d13e70a2f4a6 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Tue, 9 Jun 2015 20:38:59 +0200 Subject: Add ability to enter rooms when offline Rooms in the recent chats list and bookmarks can be entered by double click if the user is offline. They are joined when the user goes online again. Test-Information: Tested by going offline via the presence menu and then entering rooms via recent chats and bookmarks. Change-Id: I8c3eadd29c3353c2cf5f04f53b71ef7ad67a5c05 diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index 3cd9169..30870fa 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -688,8 +688,6 @@ void ChatsManager::setOnline(bool enabled) { } } if (!enabled) { - delete mucBookmarkManager_; - mucBookmarkManager_ = NULL; chatListWindow_->setBookmarksEnabled(false); markAllRecentsOffline(); } else { @@ -775,10 +773,6 @@ void ChatsManager::rebindControllerJID(const JID& from, const JID& to) { MUC::ref ChatsManager::handleJoinMUCRequest(const JID &mucJID, const boost::optional& password, const boost::optional& nickMaybe, bool addAutoJoin, bool createAsReservedIfNew, bool isImpromptu, ChatWindow* reuseChatwindow) { MUC::ref muc; - if (!stanzaChannel_->isAvailable()) { - /* This is potentially not the optimal solution, but it will avoid consistency issues.*/ - return muc; - } if (addAutoJoin) { MUCBookmark bookmark(mucJID, mucJID.getNode()); bookmark.setAutojoin(true); @@ -793,7 +787,9 @@ MUC::ref ChatsManager::handleJoinMUCRequest(const JID &mucJID, const boost::opti std::map::iterator it = mucControllers_.find(mucJID); if (it != mucControllers_.end()) { - it->second->rejoin(); + if (stanzaChannel_->isAvailable()) { + it->second->rejoin(); + } } else { std::string nick = (nickMaybe && !(*nickMaybe).empty()) ? nickMaybe.get() : nickResolver_->jidToNick(jid_); muc = mucManager->createMUC(mucJID); @@ -825,6 +821,13 @@ MUC::ref ChatsManager::handleJoinMUCRequest(const JID &mucJID, const boost::opti controller->onUserNicknameChanged.connect(boost::bind(&ChatsManager::handleUserNicknameChanged, this, controller, _1, _2)); controller->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, mucJID.toBare(), _1, true)); controller->onUnreadCountChanged.connect(boost::bind(&ChatsManager::handleUnreadCountChanged, this, controller)); + if (!stanzaChannel_->isAvailable()) { + /* When online, the MUC is added to the registry in MUCImpl::internalJoin. This method is not + * called when Swift is offline, so we add it here as only MUCs in the registry are rejoined + * when going back online. + */ + mucRegistry_->addMUC(mucJID.toBare()); + } handleChatActivity(mucJID.toBare(), "", true); } diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index 5788465..c9936c0 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -133,11 +133,14 @@ MUCController::MUCController ( muc_->onConfigurationFormReceived.connect(boost::bind(&MUCController::handleConfigurationFormReceived, this, _1)); highlighter_->setMode(isImpromptu_ ? Highlighter::ChatMode : Highlighter::MUCMode); highlighter_->setNick(nick_); - if (timerFactory) { + if (timerFactory && stanzaChannel_->isAvailable()) { loginCheckTimer_ = boost::shared_ptr(timerFactory->createTimer(MUC_JOIN_WARNING_TIMEOUT_MILLISECONDS)); loginCheckTimer_->onTick.connect(boost::bind(&MUCController::handleJoinTimeoutTick, this)); loginCheckTimer_->start(); } + else { + chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "You are currently offline. You will enter this room when you are connected.")), ChatWindow::DefaultDirection); + } if (isImpromptu) { muc_->onUnlocked.connect(boost::bind(&MUCController::handleRoomUnlocked, this)); chatWindow_->convertToMUC(ChatWindow::ImpromptuMUC); @@ -147,7 +150,9 @@ MUCController::MUCController ( chatWindow_->convertToMUC(ChatWindow::StandardMUC); chatWindow_->setName(muc->getJID().getNode()); } - setOnline(true); + if (stanzaChannel->isAvailable()) { + setOnline(true); + } if (avatarManager_ != NULL) { avatarChangedConnection_ = (avatarManager_->onAvatarChanged.connect(boost::bind(&MUCController::handleAvatarChanged, this, _1))); } diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp index 7b40f9c..b990b84 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.cpp +++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp @@ -96,14 +96,10 @@ void QtChatListWindow::setupContextMenus() { void QtChatListWindow::handleItemActivated(const QModelIndex& index) { ChatListItem* item = model_->getItemForIndex(index); if (ChatListMUCItem* mucItem = dynamic_cast(item)) { - if (bookmarksEnabled_) { - onMUCBookmarkActivated(mucItem->getBookmark()); - } + onMUCBookmarkActivated(mucItem->getBookmark()); } else if (ChatListRecentItem* recentItem = dynamic_cast(item)) { - if (!recentItem->getChat().isMUC || bookmarksEnabled_) { - onRecentActivated(recentItem->getChat()); - } + onRecentActivated(recentItem->getChat()); } else if (ChatListWhiteboardItem* whiteboardItem = dynamic_cast(item)) { if (!whiteboardItem->getChat().isMUC || bookmarksEnabled_) { -- cgit v0.10.2-6-g49f6