瀏覽代碼

调试信息

dong_dl 1 年之前
父節點
當前提交
546fc36656

+ 15 - 0
inc/proto/ProtoParser.h

@@ -199,6 +199,14 @@ public:
     std::string getGroupMembers(std::string id);
     std::string searchConversation(std::string keyword, std::string types, std::string lines);
 
+    std::string getAllMessages() const;
+    std::string getAllUsers() const;
+    std::string getAllFriends() const;
+    std::string getAllFriendRequests() const;
+    std::string getAllGroups() const;
+    std::string getAllConversations() const;
+    std::string getAllUserSettings() const;
+
     void setLogLevel(int level);
     void setLogType(int type);
     int  getLogLevel() const;
@@ -412,6 +420,13 @@ EMSCRIPTEN_BINDINGS(Proto)
         .function("getRespPayload", &ProtoParser::getRespPayload)
         .function("removeResp", &ProtoParser::removeResp)
 
+        .property("conversations", &ProtoParser::getAllConversations)
+        .property("userSettings", &ProtoParser::getAllUserSettings)
+        .property("messages", &ProtoParser::getAllMessages)
+        .property("friends", &ProtoParser::getAllFriends)
+        .property("friendRequests", &ProtoParser::getAllFriendRequests)
+        .property("users", &ProtoParser::getAllUsers)
+        .property("groups", &ProtoParser::getAllGroups)
         .property("logLevel", &ProtoParser::getLogLevel, &ProtoParser::setLogLevel)
         .property("logType", &ProtoParser::getLogType, &ProtoParser::setLogType)
         .property("timeout", &ProtoParser::getTimeout, &ProtoParser::setTimeout)

+ 102 - 1
src/proto/ProtoParser.cpp

@@ -1972,7 +1972,7 @@ std::string ProtoParser::getMessages(std::string requestJson)
             valid = false;
         }
         before = doc["before"].GetBool();
-        idx    = doc["fromIndex"].GetUint64();
+        idx    = GetInt64(doc["fromIndex"]);
         count  = doc["count"].GetInt();
     }
 
@@ -1998,6 +1998,107 @@ std::string ProtoParser::getMessages(std::string requestJson)
     return ret;
 }
 
+std::string ProtoParser::getAllConversations() const
+{
+    std::list<Conversation> items;
+    p->getAllConversations(items);
+
+    rapidjson::StringBuffer                    buffer;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+    for (const auto &item : items)
+    {
+        toJson(writer, item);
+    }
+    auto ret = buffer.GetString();
+    return ret;
+}
+
+std::string ProtoParser::getAllUserSettings() const
+{
+    std::list<UserSettingEntry> items;
+    p->getAllUserSettings(items);
+
+    rapidjson::StringBuffer                    buffer;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+    for (const auto &item : items)
+    {
+        toJson(writer, item);
+    }
+    auto ret = buffer.GetString();
+    return ret;
+}
+
+std::string ProtoParser::getAllMessages() const
+{
+    std::list<Message> items;
+    p->getAllMessages(items);
+
+    rapidjson::StringBuffer                    buffer;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+    for (const auto &item : items)
+    {
+        toJson(writer, item);
+    }
+    auto ret = buffer.GetString();
+    return ret;
+}
+std::string ProtoParser::getAllUsers() const
+{
+    std::list<User> items;
+    p->getAllUsers(items);
+
+    rapidjson::StringBuffer                    buffer;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+    for (const auto &item : items)
+    {
+        toJson(writer, item);
+    }
+    auto ret = buffer.GetString();
+    return ret;
+}
+std::string ProtoParser::getAllFriends() const
+{
+    std::list<Friend> items;
+    p->getAllFriends(items);
+
+    rapidjson::StringBuffer                    buffer;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+    for (const auto &item : items)
+    {
+        toJson(writer, item);
+    }
+    auto ret = buffer.GetString();
+    return ret;
+}
+std::string ProtoParser::getAllFriendRequests() const
+{
+    std::list<FriendRequest> items;
+    p->getAllFriendRequests(items);
+
+    rapidjson::StringBuffer                    buffer;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+    for (const auto &item : items)
+    {
+        toJson(writer, item, _uid);
+    }
+    auto ret = buffer.GetString();
+    return ret;
+}
+std::string ProtoParser::getAllGroups() const
+{
+    std::list<GroupInfo> items;
+    p->getAllGroups(items);
+
+    rapidjson::StringBuffer                    buffer;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+    for (const auto &item : items)
+    {
+        toJson(writer, item);
+    }
+    auto ret = buffer.GetString();
+    return ret;
+}
+
 #ifdef USE_WASM
 
 void ProtoParser::setOnConnected(int ptr)

+ 28 - 1
src/proto/ProtoParserPrivate.cpp

@@ -1057,7 +1057,34 @@ int ProtoParserPrivate::update(PullMessageResult &result, uint64_t &head)
 #endif
     return 0;
 }
-
+void ProtoParserPrivate::getAllMessages(std::list<Message> &ret) const
+{
+    ret.insert(ret.end(), _messages.begin(), _messages.end());
+}
+void ProtoParserPrivate::getAllUsers(std::list<User> &ret) const
+{
+    ret.insert(ret.end(), _users.begin(), _users.end());
+}
+void ProtoParserPrivate::getAllFriends(std::list<Friend> &ret) const
+{
+    ret.insert(ret.end(), _friends.begin(), _friends.end());
+}
+void ProtoParserPrivate::getAllFriendRequests(std::list<FriendRequest> &ret) const
+{
+    ret.insert(ret.end(), _friendRequests.begin(), _friendRequests.end());
+}
+void ProtoParserPrivate::getAllGroups(std::list<GroupInfo> &ret) const
+{
+    ret.insert(ret.end(), _groups.begin(), _groups.end());
+}
+void ProtoParserPrivate::getAllConversations(std::list<Conversation> &ret) const
+{
+    ret.insert(ret.end(), _conversations.begin(), _conversations.end());
+}
+void ProtoParserPrivate::getAllUserSettings(std::list<UserSettingEntry> &ret) const
+{
+    ret.insert(ret.end(), _userSettings.begin(), _userSettings.end());
+}
 void ProtoParserPrivate::test()
 {
 #ifdef USE_SQLITE3

+ 8 - 0
src/proto/ProtoParserPrivate.h

@@ -46,6 +46,14 @@ public:
     void sendMessage(Message &msg, uint32_t msgId);
     void updateMessage(uint64_t msgId, uint64_t mid, uint64_t ts);
 
+    void getAllMessages(std::list<Message> &ret) const;
+    void getAllUsers(std::list<User> &ret) const;
+    void getAllFriends(std::list<Friend> &ret) const;
+    void getAllFriendRequests(std::list<FriendRequest> &ret) const;
+    void getAllGroups(std::list<GroupInfo> &ret) const;
+    void getAllConversations(std::list<Conversation> &ret) const;
+    void getAllUserSettings(std::list<UserSettingEntry> &ret) const;
+
 protected:
 #ifdef USE_SQLITE3
     int         exec(const char *sql, std::function<bool(struct sqlite3_stmt *stmt)> items, std::function<void(struct sqlite3_stmt *stmt)> pars = nullptr) const;

+ 4 - 4
src/proto/jsonUtils.cpp

@@ -246,7 +246,7 @@ void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Friend &in
     writer.EndObject();
 }
 
-void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const FriendRequest &info, std::string &uid)
+void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const FriendRequest &info, const std::string &uid)
 {
     writer.StartObject();
 
@@ -897,7 +897,7 @@ bool parseJson(std::string &str, DismissGroupRequest &par)
     return true;
 }
 
-bool parseJson(std::string &str, std::map<std::string, uint32_t>& ids, PullUserRequest &par)
+bool parseJson(std::string &str, std::map<std::string, uint32_t> &ids, PullUserRequest &par)
 {
     rapidjson::Document doc;
     if (str.length() <= 0 || doc.Parse(str.c_str()).HasParseError())
@@ -909,12 +909,12 @@ bool parseJson(std::string &str, std::map<std::string, uint32_t>& ids, PullUserR
 
     for (int i = 0; i < arr.Size(); i++)
     {
-        auto &item = arr[i];
+        auto       &item = arr[i];
         const char *uid  = item["uid"].GetString();
         if (ids.find(uid) != ids.end())
             continue;
         ids[uid] = 0;
-        auto  req  = par.add_request();
+        auto req = par.add_request();
         req->set_uid(uid);
         if (item.HasMember("update_dt"))
             req->set_update_dt(item["update_dt"].GetInt64());

+ 1 - 2
src/proto/jsonUtils.h

@@ -5,7 +5,6 @@
 #include "rapidjson/writer.h"
 #include "rapidjson/reader.h"
 
-
 int64_t GetInt64(rapidjson::Value &val);
 
 void copy(Conversation &buf, rapidjson::Value &json);
@@ -16,7 +15,7 @@ void copy(Group &group, rapidjson::Value &mem);
 void copy(Message &info, rapidjson::Value &json);
 
 void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Friend &info);
-void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const FriendRequest &info, std::string &uid);
+void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const FriendRequest &info, const std::string &uid);
 void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const GroupInfo &info);
 void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const GroupMember &info);
 void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const User &info);