Beispiel #1
0
        internal async Task <List <LCIMTemporaryConversation> > GetTemporaryConversations(IEnumerable <string> convIds)
        {
            if (convIds == null || convIds.Count() == 0)
            {
                return(null);
            }
            ConvCommand convMessage = new ConvCommand();

            convMessage.TempConvIds.AddRange(convIds);
            GenericCommand request = NewCommand(CommandType.Conv, OpType.Query);

            request.ConvMessage = convMessage;
            GenericCommand response = await Connection.SendRequest(request);

            JsonObjectMessage results = response.ConvMessage.Results;
            List <object>     convs   = JsonConvert.DeserializeObject <List <object> >(results.Data,
                                                                                       LCJsonConverter.Default);
            List <LCIMTemporaryConversation> convList = convs.Select(item => {
                LCIMTemporaryConversation temporaryConversation = new LCIMTemporaryConversation(Client);
                temporaryConversation.MergeFrom(item as Dictionary <string, object>);
                return(temporaryConversation);
            }).ToList();

            return(convList);
        }
Beispiel #2
0
        internal async Task <Dictionary <string, object> > UpdateInfo(string convId,
                                                                      Dictionary <string, object> attributes)
        {
            ConvCommand conv = new ConvCommand {
                Cid = convId,
            };

            conv.Attr = new JsonObjectMessage {
                Data = JsonConvert.SerializeObject(attributes)
            };
            GenericCommand request = NewCommand(CommandType.Conv, OpType.Update);

            request.ConvMessage = conv;
            GenericCommand response = await Connection.SendRequest(request);

            JsonObjectMessage attr = response.ConvMessage.AttrModified;

            // 更新自定义属性
            if (attr != null)
            {
                Dictionary <string, object> updatedAttr = JsonConvert.DeserializeObject <Dictionary <string, object> >(attr.Data);
                return(updatedAttr);
            }
            return(null);
        }
Beispiel #3
0
        internal async Task <bool> CheckSubscription(string convId)
        {
            ConvCommand conv = new ConvCommand();

            conv.Cids.Add(convId);
            GenericCommand request = NewCommand(CommandType.Conv, OpType.IsMember);

            request.ConvMessage = conv;
            GenericCommand response = await Connection.SendRequest(request);

            JsonObjectMessage           jsonObj = response.ConvMessage.Results;
            Dictionary <string, object> result  = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonObj.Data);

            if (result.TryGetValue(convId, out object obj))
            {
                return((bool)obj);
            }
            return(false);
        }
Beispiel #4
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());
        }