dong_dl 1 рік тому
батько
коміт
c0a4957134
3 змінених файлів з 26 додано та 23 видалено
  1. 9 9
      src/proto/ProtoParser.cpp
  2. 12 9
      src/proto/jsonUtils.cpp
  3. 5 5
      src/proto/jsonUtils.h

+ 9 - 9
src/proto/ProtoParser.cpp

@@ -413,7 +413,7 @@ std::string ProtoParser::searchConversation(std::string keyword, std::string typ
         con.set_type(item.conversation().type());
         con.set_target(item.conversation().target());
         con.set_line(item.conversation().line());
-        toJson(writer, con, item);
+        toJson(writer, con, item, _uid.c_str());
         return true;
     });
     writer.EndArray();
@@ -686,7 +686,7 @@ unsigned char ProtoParser::parsePayload(std::string &payload, bool pub)
 
                 p->update(r, _msgCurrent);
                 std::list<Message> messages;
-                toJson(r, _payload, messages);
+                toJson(r, _payload, messages, _uid.c_str());
             }
             else
             {
@@ -700,7 +700,7 @@ unsigned char ProtoParser::parsePayload(std::string &payload, bool pub)
             {
                 p->update(r, _msgCurrent);
                 std::list<Message> messages;
-                toJson(r, _payload, messages);
+                toJson(r, _payload, messages, _uid.c_str());
             }
         }
         else if (_topic.compare("GMUT") == 0) // uploadMedia
@@ -736,7 +736,7 @@ unsigned char ProtoParser::parsePayload(std::string &payload, bool pub)
                 {
                     p->update(r, _uid, _msgCurrent);
                 }
-                toJson(r, _payload);
+                toJson(r, _payload, _uid.c_str());
             }
             else
             {
@@ -1698,7 +1698,7 @@ std::string ProtoParser::getConversationInfos(std::string types, std::string lin
         con.set_type(item.conversation().type());
         con.set_target(item.conversation().target());
         con.set_line(item.conversation().line());
-        toJson(writer, con, item);
+        toJson(writer, con, item, _uid.c_str());
         return true;
     });
     writer.EndArray();
@@ -1886,7 +1886,7 @@ std::string ProtoParser::getConversationInfo(std::string requestJson)
     lines = "[" + std::to_string(par.line()) + "]";
     p->getConversation(nullptr, types.c_str(), lines.c_str(), [&](const auto &item) {
         writer.Key("lastMessage");
-        toJson(writer, item);
+        toJson(writer, item, _uid.c_str());
         timestamp = item.server_timestamp();
         return true;
     });
@@ -1936,7 +1936,7 @@ std::string ProtoParser::getMessage(std::string str)
     rapidjson::StringBuffer                    buffer;
     rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
     p->getMessage(id, [&](const auto &item) {
-        toJson(writer, item);
+        toJson(writer, item, _uid.c_str());
         return false;
     });
     auto ret = buffer.GetString();
@@ -1990,7 +1990,7 @@ std::string ProtoParser::getMessages(std::string requestJson)
             count = 100;
         int cnt = 0;
         p->getMessage(before, idx, count, par.type(), par.line(), par.target().c_str(), [&](const auto &item) {
-            toJson(writer, item);
+            toJson(writer, item, _uid.c_str());
             return true;
         });
     }
@@ -2041,7 +2041,7 @@ std::string ProtoParser::getAllMessages() const
     rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
     for (const auto &item : items)
     {
-        toJson(writer, item);
+        toJson(writer, item, _uid.c_str());
     }
     auto ret = buffer.GetString();
     return ret;

+ 12 - 9
src/proto/jsonUtils.cpp

@@ -400,7 +400,7 @@ void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const MessageCon
     writer.EndObject();
 }
 
-void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Message &info)
+void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Message &info, const char* uid)
 {
     writer.StartObject();
 
@@ -410,6 +410,9 @@ void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Message &i
     writer.Key("content");
     toJson(writer, info.content());
 
+    writer.Key("direction");
+    writer.Int(info.from_user() == uid ? 0 : 1);
+
     WRITE_INT64_STR_OPT_2(message_id, messageId);
     WRITE_INT64_OPT_2(server_timestamp, timestamp);
     WRITE_STR_OPT_2(to_user, to);
@@ -425,7 +428,7 @@ void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Message &i
     writer.EndObject();
 }
 
-void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Conversation &info, const Message &msg)
+void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Conversation &info, const Message &msg, const char* uid)
 {
     writer.StartObject();
     WRITE_INT(type);
@@ -433,7 +436,7 @@ void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Conversati
     WRITE_INT(line);
 
     writer.Key("lastMessage");
-    toJson(writer, msg);
+    toJson(writer, msg, uid);
 
     writer.EndObject();
 }
@@ -459,7 +462,7 @@ void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const GetUploadT
     writer.EndObject();
 }
 
-void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const NotifyMessage &info)
+void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const NotifyMessage &info, const char *uid)
 {
     writer.StartObject();
     WRITE_INT(type);
@@ -468,7 +471,7 @@ void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const NotifyMess
     if (info.has_message())
     {
         writer.Key("message");
-        toJson(writer, info.message());
+        toJson(writer, info.message(), uid);
     }
     writer.EndObject();
 }
@@ -630,7 +633,7 @@ void toJson(GetUserSettingResult &r, std::string &ret)
     ret = buffer.GetString();
 }
 
-void toJson(PullMessageResult &r, std::string &ret, std::list<Message> &messages)
+void toJson(PullMessageResult &r, std::string &ret, std::list<Message> &messages, const char *uid)
 {
     rapidjson::StringBuffer                    buffer;
     rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
@@ -641,7 +644,7 @@ void toJson(PullMessageResult &r, std::string &ret, std::list<Message> &messages
     for (int i = 0; i < r.message_size(); i++)
     {
         auto info = r.message(i);
-        toJson(writer, info);
+        toJson(writer, info, uid);
         messages.emplace_back(info);
     }
     writer.EndArray();
@@ -681,12 +684,12 @@ void toJson(SearchUserResult &r, std::string &ret)
     ret = buffer.GetString();
 }
 
-void toJson(NotifyMessage &r, std::string &ret)
+void toJson(NotifyMessage &r, std::string &ret, const char *uid)
 {
     rapidjson::StringBuffer                    buffer;
     rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
 
-    toJson(writer, r);
+    toJson(writer, r, uid);
 
     ret = buffer.GetString();
 }

+ 5 - 5
src/proto/jsonUtils.h

@@ -23,10 +23,10 @@ void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const UserResult
 void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const UserSettingEntry &info);
 void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Conversation &info);
 void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const MessageContent &info);
-void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Message &info);
-void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Conversation &info, const Message &msg);
+void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Message &info, const char *uid);
+void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const Conversation &info, const Message &msg, const char *uid);
 void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const GetUploadTokenResult &info);
-void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const NotifyMessage &info);
+void toJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, const NotifyMessage &info, const char *uid);
 void toJson(ConnectAckPayload &p, std::string &ret, uint64_t &msgHead, uint64_t &friendHead, uint64_t &friendRqHead, uint64_t &settingHead);
 void toJson(GetFriendsResult &r, std::string &ret);
 void toJson(GroupInfo &r, std::string &ret);
@@ -35,10 +35,10 @@ void toJson(PullGroupInfoResult &r, std::string &ret);
 void toJson(PullGroupMemberResult &r, std::string &ret);
 void toJson(PullUserResult &r, std::string &ret);
 void toJson(GetUserSettingResult &r, std::string &ret);
-void toJson(PullMessageResult &r, std::string &ret, std::list<Message> &messages);
+void toJson(PullMessageResult &r, std::string &ret, std::list<Message> &messages, const char *uid);
 void toJson(GetUploadTokenResult &r, std::string &ret);
 void toJson(SearchUserResult &r, std::string &ret);
-void toJson(NotifyMessage &r, std::string &ret);
+void toJson(NotifyMessage &r, std::string &ret, const char *uid);
 void toJson8(std::string &str, std::string &ret);
 void toJson16(std::string &str, std::string &ret);
 void toJson(RouteResponse &r, std::string &ret);