Browse Source

是否置顶

dong_dl 1 năm trước cách đây
mục cha
commit
be1ec05b9c

+ 23 - 2
src/proto/ProtoParser.cpp

@@ -1490,16 +1490,37 @@ std::string ProtoParser::getConversationInfo(std::string requestJson)
     writer.Key("target");
     writer.String(par.target().c_str());
 
+    int64_t    timestamp = 0;
     std::string types, lines;
     types = "[" + std::to_string(par.type()) + "]";
     lines = "[" + std::to_string(par.line()) + "]";
     p->getConversation(nullptr, types.c_str(), lines.c_str(), [&](const auto &item) {
         writer.Key("lastMessage");
         toJson(writer, item);
-
-        // TODO: isTop, isSilent, draft, unreadCount, timestamp
+        timestamp = item.server_timestamp();
         return true;
     });
+
+    writer.Key("isTop");
+    writer.Bool(p->isTop(par));
+    writer.Key("isSilent");
+    writer.Bool(p->isSilent(par));
+    writer.Key("draft");
+    writer.String(""); // TODO:
+    writer.Key("timestamp");
+    writer.Int64(timestamp);
+    writer.Key("unreadCount");
+    writer.StartObject();
+    writer.Key("unread");
+    int unread = 0, unreadMention = 0, unreadMentionAll = 0;
+    p->getUnread(par, _uid, unread, unreadMention, unreadMentionAll);
+    writer.Int(unread);
+    writer.Key("unreadMention");
+    writer.Int(unreadMention);
+    writer.Key("unreadMentionAll");
+    writer.Int(unreadMentionAll);
+    writer.EndObject();
+
     writer.EndObject();
     return buffer.GetString();
 }

+ 65 - 0
src/proto/ProtoParserPrivate.cpp

@@ -302,6 +302,71 @@ int ProtoParserPrivate::getMessage(bool before, uint64_t idx, int count, int typ
 #endif
 }
 
+bool ProtoParserPrivate::isSilent(Conversation &par)
+{
+#ifdef USE_ALL_SQLITE3
+    // TODO:
+#else
+    std::string key = std::to_string(par.type()) + "-" + std::to_string(par.line()) + "-" + par.target();
+    for (auto &it : _userSettings)
+    {
+        if (it.scope() == 1 && it.key() == key)
+        {
+            return it.value() == "1";
+        }
+    }
+    return false;
+#endif
+}
+
+bool ProtoParserPrivate::isTop(Conversation &par)
+{
+#ifdef USE_ALL_SQLITE3
+    // TODO:
+#else
+    std::string key = std::to_string(par.type()) + "-" + std::to_string(par.line()) + "-" + par.target();
+    for (auto &it : _userSettings)
+    {
+        if (it.scope() == 3 && it.key() == key)
+        {
+            return it.value() == "1";
+        }
+    }
+    return false;
+#endif
+}
+
+void ProtoParserPrivate::getUnread(Conversation &par, std::string uid, int &unread, int &unreadMention, int &unreadMentionAll)
+{
+#ifdef USE_SQLITE3
+#else
+    for (auto& it : _messages)
+    {
+        if (it.conversation().type() == par.type() && it.conversation().line() == par.line() && it.conversation().target() == par.target())
+        {
+            if (true) // TODO: 判断是否已读
+                continue;
+            unread++;
+            switch (it.content().mentioned_type())
+            {
+            case 1:
+                for (int i = 0; i < it.content().mentioned_target_size(); i++)
+                {
+                    if (it.content().mentioned_target(i) == uid)
+                    {
+                        unreadMention++;
+                    }
+                }
+                break;
+            case 2:
+                unreadMentionAll++;
+                break;
+            }
+        }
+    }
+#endif
+}
+
 int ProtoParserPrivate::getConversation(const char *keyword, const char *types, const char *lines, std::function<bool(const Message &msg)> cb)
 {
 #ifdef USE_SQLITE3

+ 4 - 1
src/proto/ProtoParserPrivate.h

@@ -32,9 +32,12 @@ public:
     int update(GroupInfo &result);
     int update(PullGroupMemberResult &result);
     int update(PullMessageResult &result, uint64_t &head);
-
     void test();
 
+    bool isTop(Conversation& par);
+    bool isSilent(Conversation &par);
+    void getUnread(Conversation &par, std::string uid, int& unread, int& unreadMention, int& unreadMentionAll);
+
 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;