dong_dl пре 1 година
родитељ
комит
2f78d753f5
3 измењених фајлова са 77 додато и 43 уклоњено
  1. 2 2
      src/proto/ProtoParser.cpp
  2. 72 41
      src/proto/jsonUtils.cpp
  3. 3 0
      src/proto/jsonUtils.h

+ 2 - 2
src/proto/ProtoParser.cpp

@@ -1059,7 +1059,7 @@ std::string ProtoParser::recallMessagePack(std::string requestJson, uint32_t &ms
         msgId = 0;
         return "";
     }
-    par.set_id(doc["id"].GetInt64());
+    par.set_id(GetInt64(doc["id"]));
 
     std::string str;
     par.SerializeToString(&str);
@@ -1129,7 +1129,7 @@ std::string ProtoParser::uploadMediaPack(std::string requestJson, uint32_t &msgI
     if (doc.HasMember("contentType"))
         par.set_contenttype(doc["contentType"].GetString());
     if (doc.HasMember("messageId"))
-        par.set_messageid(doc["messageId"].GetInt64());
+        par.set_messageid(GetInt64(doc["messageId"]));
 
     std::string str;
     par.SerializeToString(&str);

+ 72 - 41
src/proto/jsonUtils.cpp

@@ -16,6 +16,15 @@ using namespace rapidjson;
         SET_INT(x);         \
     }
 
+int64_t GetInt64(rapidjson::Value& val)
+{    
+    if (val.IsString())
+    {
+        return atoll(val.GetString());
+    }
+    return val.GetInt64();
+}
+
 void copy(Conversation &buf, rapidjson::Value &json)
 {
     buf.set_type(json["type"].GetInt());
@@ -25,37 +34,44 @@ void copy(Conversation &buf, rapidjson::Value &json)
 
 void copy(MessageContent &content, rapidjson::Value &mem)
 {
-    content.set_type(mem["type"].GetInt());
-    if (mem.HasMember("searchableContent"))
-        content.set_searchable_content(mem["searchableContent"].GetString());
-    if (mem.HasMember("pushContent"))
-        content.set_push_content(mem["pushContent"].GetString());
-    if (mem.HasMember("content"))
-        content.set_content(mem["content"].GetString());
-    if (mem.HasMember("binaryContent"))
-        content.set_data(mem["binaryContent"].GetString());
-    if (mem.HasMember("mediaType"))
-        content.set_mediatype(mem["mediaType"].GetInt());
-    if (mem.HasMember("remoteMediaUrl"))
-        content.set_remotemediaurl(mem["remoteMediaUrl"].GetString());
-    if (mem.HasMember("persist_flag"))
-        content.set_persist_flag(mem["persist_flag"].GetInt());
-    if (mem.HasMember("expire_duration"))
-        content.set_expire_duration(mem["expire_duration"].GetInt());
-    if (mem.HasMember("mentionedType"))
-        content.set_mentioned_type(mem["mentionedType"].GetInt());
-    if (mem.HasMember("mentionedTargets"))
+    if (mem.IsString())
     {
-        auto arr = mem["mentionedTargets"].GetArray();
-        for (int i = 0; i < arr.Size(); i++)
+        content.set_searchable_content(mem.GetString());
+    }
+    else if (mem.IsObject())
+    {
+        content.set_type(mem["type"].GetInt());
+        if (mem.HasMember("searchableContent"))
+            content.set_searchable_content(mem["searchableContent"].GetString());
+        if (mem.HasMember("pushContent"))
+            content.set_push_content(mem["pushContent"].GetString());
+        if (mem.HasMember("content"))
+            content.set_content(mem["content"].GetString());
+        if (mem.HasMember("binaryContent"))
+            content.set_data(mem["binaryContent"].GetString());
+        if (mem.HasMember("mediaType"))
+            content.set_mediatype(mem["mediaType"].GetInt());
+        if (mem.HasMember("remoteMediaUrl"))
+            content.set_remotemediaurl(mem["remoteMediaUrl"].GetString());
+        if (mem.HasMember("persist_flag"))
+            content.set_persist_flag(mem["persist_flag"].GetInt());
+        if (mem.HasMember("expire_duration"))
+            content.set_expire_duration(mem["expire_duration"].GetInt());
+        if (mem.HasMember("mentionedType"))
+            content.set_mentioned_type(mem["mentionedType"].GetInt());
+        if (mem.HasMember("mentionedTargets"))
         {
-            content.set_mentioned_target(i, arr[i].GetString());
+            auto arr = mem["mentionedTargets"].GetArray();
+            for (int i = 0; i < arr.Size(); i++)
+            {
+                content.set_mentioned_target(i, arr[i].GetString());
+            }
         }
+        if (mem.HasMember("extra"))
+            content.set_extra(mem["extra"].GetString());
+        if (mem.HasMember("pushData"))
+            content.set_push_data(mem["pushData"].GetString());
     }
-    if (mem.HasMember("extra"))
-        content.set_extra(mem["extra"].GetString());
-    if (mem.HasMember("pushData"))
-        content.set_push_data(mem["pushData"].GetString());
 }
 void copy(GroupInfo &group, rapidjson::Value &mem)
 {
@@ -90,17 +106,24 @@ void copy(GroupInfo &group, rapidjson::Value &mem)
 }
 void copy(GroupMember &group, rapidjson::Value &mem)
 {
-    group.set_member_id(mem["member_id"].GetString());
-    if (mem.HasMember("alias"))
-        group.set_alias(mem["alias"].GetString());
-    group.set_type(mem["type"].GetInt());
-
-    if (mem.HasMember("update_dt"))
-        group.set_update_dt(mem["update_dt"].GetInt64());
-    if (mem.HasMember("create_dt"))
-        group.set_create_dt(mem["create_dt"].GetInt64());
-    if (mem.HasMember("extra"))
-        group.set_extra(mem["extra"].GetString());
+    if (mem.IsString())
+    {
+        group.set_member_id(mem.GetString());
+    }
+    else if (mem.IsObject())
+    {
+        group.set_member_id(mem["member_id"].GetString());
+        if (mem.HasMember("alias"))
+            group.set_alias(mem["alias"].GetString());
+        group.set_type(mem["type"].GetInt());
+
+        if (mem.HasMember("update_dt"))
+            group.set_update_dt(mem["update_dt"].GetInt64());
+        if (mem.HasMember("create_dt"))
+            group.set_create_dt(mem["create_dt"].GetInt64());
+        if (mem.HasMember("extra"))
+            group.set_extra(mem["extra"].GetString());
+    }
 }
 
 void copy(Group &group, rapidjson::Value &mem)
@@ -129,7 +152,7 @@ void copy(Message &info, rapidjson::Value &json)
     info.set_allocated_content(content);
 
     if (json.HasMember("messageId"))
-        info.set_message_id(json["messageId"].GetInt64());
+        info.set_message_id(GetInt64(json["messageId"]));
     if (json.HasMember("timestamp"))
         info.set_server_timestamp(json["timestamp"].GetInt64());
     if (json.HasMember("to"))
@@ -170,11 +193,19 @@ void copy(Message &info, rapidjson::Value &json)
 #define WRITE_INT64_2(x, y) \
     writer.Key(#y);         \
     writer.Int64(info.x());
+#define WRITE_INT64_STR_2(x, y) \
+    writer.Key(#y);         \
+    writer.String(std::to_string(info.x()).c_str());
 #define WRITE_INT64(x) WRITE_INT64_2(x, x)
 #define WRITE_INT64_OPT_2(x, y) \
     if (info.has_##x())         \
     {                           \
         WRITE_INT64_2(x, y);    \
+    }                                                  
+#define WRITE_INT64_STR_OPT_2(x, y) \
+    if (info.has_##x()) \
+    { \
+        WRITE_INT64_STR_2(x, y); \
     }
 #define WRITE_INT64_OPT(x) WRITE_INT64_OPT_2(x, x)
 #define WRITE_BOOL_2(x, y) \
@@ -366,7 +397,7 @@ void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Message &i
     writer.Key("content");
     toJson(writer, info.content());
 
-    WRITE_INT64_OPT_2(message_id, messageId);
+    WRITE_INT64_STR_OPT_2(message_id, messageId);
     WRITE_INT64_OPT_2(server_timestamp, timestamp);
     WRITE_STR_OPT_2(to_user, to);
 
@@ -670,7 +701,7 @@ void toJson16(std::string &str, std::string &ret)
     {
         auto msgId = htonll(*(int64_t *)str.c_str());
         writer.Key("messageId");
-        writer.Int64(msgId);
+        writer.String(std::to_string(msgId).c_str());
         writer.Key("timestamp");
         writer.Int64(htonll(*((int64_t *)str.c_str()) + 1));
     }

+ 3 - 0
src/proto/jsonUtils.h

@@ -5,6 +5,9 @@
 #include "rapidjson/writer.h"
 #include "rapidjson/reader.h"
 
+
+int64_t GetInt64(rapidjson::Value &val);
+
 void copy(Conversation &buf, rapidjson::Value &json);
 void copy(MessageContent &content, rapidjson::Value &mem);
 void copy(GroupInfo &group, rapidjson::Value &mem);