diff --git a/libresapi/src/api/ChatHandler.cpp b/libresapi/src/api/ChatHandler.cpp index d25b94e7e..055a8eea6 100644 --- a/libresapi/src/api/ChatHandler.cpp +++ b/libresapi/src/api/ChatHandler.cpp @@ -113,7 +113,7 @@ public: private: ChatHandler::LobbyParticipantsInfo mParticipantsInfo; protected: - virtual void gxsDoWork(Request &req, Response &resp) + virtual void gxsDoWork(Request &/*req*/, Response &resp) { resp.mDataStream.getStreamToMember(); const std::map& map = mParticipantsInfo.participants; @@ -145,6 +145,7 @@ ChatHandler::ChatHandler(StateTokenServer *sts, RsNotify *notify, RsMsgs *msgs, addResourceHandler("lobbies", this, &ChatHandler::handleLobbies); addResourceHandler("subscribe_lobby", this, &ChatHandler::handleSubscribeLobby); addResourceHandler("unsubscribe_lobby", this, &ChatHandler::handleUnsubscribeLobby); + addResourceHandler("clear_lobby", this, &ChatHandler::handleClearLobby); addResourceHandler("lobby_participants", this, &ChatHandler::handleLobbyParticipants); addResourceHandler("messages", this, &ChatHandler::handleMessages); addResourceHandler("send_message", this, &ChatHandler::handleSendMessage); @@ -167,13 +168,13 @@ void ChatHandler::notifyChatMessage(const ChatMessage &msg) mRawMsgs.push_back(msg); } -void ChatHandler::notifyChatCleared(const ChatId &chat_id) -{ - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ - std::list& msgs = mMsgs[chat_id]; - msgs.clear(); -} - +void ChatHandler::notifyChatCleared(const ChatId &chat_id) +{ + RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + std::list& msgs = mMsgs[chat_id]; + msgs.clear(); +} + void ChatHandler::notifyChatStatus(const ChatId &chat_id, const std::string &status) { RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ @@ -593,6 +594,14 @@ void ChatHandler::handleUnsubscribeLobby(Request &req, Response &resp) resp.setOk(); } +void ChatHandler::handleClearLobby(Request &req, Response &resp) +{ + ChatLobbyId id = 0; + req.mStream << makeKeyValueReference("id", id); + notifyChatCleared(ChatId(id)); + resp.setOk(); +} + ResponseTask* ChatHandler::handleLobbyParticipants(Request &req, Response &resp) { RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ diff --git a/libresapi/src/api/ChatHandler.h b/libresapi/src/api/ChatHandler.h index f92a1a47a..3068302f7 100644 --- a/libresapi/src/api/ChatHandler.h +++ b/libresapi/src/api/ChatHandler.h @@ -25,7 +25,7 @@ public: // from NotifyClient // note: this may get called from the own and from foreign threads virtual void notifyChatMessage(const ChatMessage& msg); - virtual void notifyChatCleared(const ChatId& chat_id); + virtual void notifyChatCleared(const ChatId& chat_id); // typing label for peer, broadcast and distant chat virtual void notifyChatStatus (const ChatId& /* chat_id */, const std::string& /* status_string */); @@ -119,6 +119,7 @@ private: void handleLobbies(Request& req, Response& resp); void handleSubscribeLobby(Request& req, Response& resp); void handleUnsubscribeLobby(Request& req, Response& resp); + void handleClearLobby(Request& req, Response& resp); ResponseTask* handleLobbyParticipants(Request& req, Response& resp); void handleMessages(Request& req, Response& resp); void handleSendMessage(Request& req, Response& resp); diff --git a/libresapi/src/api/Pagination.h b/libresapi/src/api/Pagination.h index 1d16b7ada..7f795fbe5 100644 --- a/libresapi/src/api/Pagination.h +++ b/libresapi/src/api/Pagination.h @@ -24,6 +24,7 @@ void handlePaginationRequest(Request& req, Response& resp, C& data) // set result type to list resp.mDataStream.getStreamToMember(); resp.mDebug << "note: list is empty" << std::endl; + resp.setOk(); return; } diff --git a/libresapi/src/webui-src/app/chat.js b/libresapi/src/webui-src/app/chat.js index 629104070..bde0494ac 100644 --- a/libresapi/src/webui-src/app/chat.js +++ b/libresapi/src/webui-src/app/chat.js @@ -115,13 +115,15 @@ function lobby(lobbyid){ } rs.request("chat/messages/" + lobbyid, reqData, function (data) { - mem.msg = mem.msg.concat(data); - if (mem.msg.length > 0) { - mem.lastKnownMsg = mem.msg[mem.msg.length -1].id; - } if (data.length > 0 ) { + mem.msg = mem.msg.concat(data); + if (mem.msg.length > 0) { + mem.lastKnownMsg = mem.msg[mem.msg.length -1].id; + } rs.request("chat/mark_chat_as_read/" + lobbyid,{}, null, {allow: "ok|not_set"}); + } else { + mem.msg = []; } }, { onmismatch: function (){}, @@ -181,12 +183,23 @@ function lobby(lobbyid){ "text-align":"center" }, onclick: function (){ - rs.request("chat/unsubscribe_lobby",{ - id:lobdt.id, - }); + rs.request("chat/unsubscribe_lobby",{ + id:lobdt.id, + }); m.route("/chat"); } },"unsubscribe"), + m("div.btn", { + style: { + "text-align":"center" + }, + onclick: function (){ + rs.request("chat/clear_lobby",{ + id:lobdt.id, + }); + m.route("/chat?lobby=" + lobbyid); + } + },"clear"), m("h3","participants:"), rs.list( "chat/lobby_participants/" + lobbyid,