Exemplo n.º 1
0
        public async Task QueryMyConversation()
        {
            LCIMConversationQuery query = new LCIMConversationQuery(client);
            ReadOnlyCollection <LCIMConversation> conversations = await query.Find();

            Assert.Greater(conversations.Count, 0);
            foreach (LCIMConversation conversation in conversations)
            {
                Assert.True(conversation.MemberIds.Contains(clientId));
            }
        }
Exemplo n.º 2
0
        public async Task QueryMemberConversation()
        {
            string memberId             = "m1";
            LCIMConversationQuery query = new LCIMConversationQuery(client);

            query.WhereEqualTo("m", memberId);
            ReadOnlyCollection <LCIMConversation> conversations = await query.Find();

            Assert.Greater(conversations.Count, 0);
            foreach (LCIMConversation conversation in conversations)
            {
                Assert.True(conversation.MemberIds.Contains(memberId));
            }
        }
Exemplo n.º 3
0
    public async void Reload()
    {
        scrollRect.ClearItemData();

        LCIMClient            client = LCManager.Instance.IMClient;
        LCIMConversationQuery query  = client.GetQuery()
                                       .WhereEqualTo("m", client.Id)
                                       .WhereEqualTo("tr", false)
                                       .OrderByDescending("updatedAt");
        ReadOnlyCollection <LCIMConversation> conversations = await query.Find();

        foreach (LCIMConversation conversation in conversations)
        {
            scrollRect.AddItemData(conversation);
        }
    }
Exemplo n.º 4
0
        public async Task QueryWithLastMessage()
        {
            string memberId             = "m1";
            LCIMConversationQuery query = new LCIMConversationQuery(client)
                                          .WhereEqualTo("m", memberId);

            query.WithLastMessageRefreshed = true;
            ReadOnlyCollection <LCIMConversation> conversations = await query.Find();

            foreach (LCIMConversation conversation in conversations)
            {
                Assert.True(!string.IsNullOrEmpty(conversation.LastMessage.Id));
                if (conversation.LastMessage is LCIMBinaryMessage binaryMessage)
                {
                    TestContext.WriteLine(System.Text.Encoding.UTF8.GetString(binaryMessage.Data));
                }
            }
        }
Exemplo n.º 5
0
        internal async Task <ReadOnlyCollection <LCIMConversation> > Find(LCIMConversationQuery query)
        {
            GenericCommand command = new GenericCommand {
                Cmd    = CommandType.Conv,
                Op     = OpType.Query,
                AppId  = LCCore.AppId,
                PeerId = Client.Id,
            };
            ConvCommand convMessage = new ConvCommand();

            string where = query.Condition.BuildWhere();
            if (!string.IsNullOrEmpty(where))
            {
                try {
                    convMessage.Where = new JsonObjectMessage {
                        Data = where
                    };
                } catch (Exception e) {
                    LCLogger.Error(e);
                }
            }
            int flag = 0;

            if (query.Compact)
            {
                flag += LCIMConversationQuery.CompactFlag;
            }
            if (query.WithLastMessageRefreshed)
            {
                flag += LCIMConversationQuery.WithLastMessageFlag;
            }
            if (flag > 0)
            {
                convMessage.Flag = flag;
            }
            convMessage.Skip  = query.Condition.Skip;
            convMessage.Limit = query.Condition.Limit;
            string orders = query.Condition.BuildOrders();

            if (!string.IsNullOrEmpty(orders))
            {
                convMessage.Sort = orders;
            }
            command.ConvMessage = convMessage;
            GenericCommand response = await Connection.SendRequest(command);

            JsonObjectMessage results = response.ConvMessage.Results;
            List <object>     convs   = JsonConvert.DeserializeObject <List <object> >(results.Data,
                                                                                       LCJsonConverter.Default);

            return(convs.Select(item => {
                Dictionary <string, object> conv = item as Dictionary <string, object>;
                string convId = conv["objectId"] as string;
                if (!Client.ConversationDict.TryGetValue(convId, out LCIMConversation conversation))
                {
                    // 解析是哪种类型的对话
                    if (conv.TryGetValue("tr", out object transient) && (bool)transient == true)
                    {
                        conversation = new LCIMChatRoom(Client);
                    }
                    else if (conv.ContainsKey("tempConv") && conv.ContainsKey("tempConvTTL"))
                    {
                        conversation = new LCIMTemporaryConversation(Client);
                    }
                    else if (conv.TryGetValue("sys", out object sys) && (bool)sys == true)
                    {
                        conversation = new LCIMServiceConversation(Client);
                    }
                    else
                    {
                        conversation = new LCIMConversation(Client);
                    }
                    Client.ConversationDict[convId] = conversation;
                }
                conversation.MergeFrom(conv);
                return conversation;
            }).ToList().AsReadOnly());
        }