示例#1
0
        //public Task MarkAsReadAsync(string conversationId = null, string messageId = null, AVIMConversation conversation = null, AVIMMessage message = null)
        //{
        //    var msgId = messageId != null ? messageId : message.Id;
        //    var convId = conversationId != null ? conversationId : conversation.ConversationId;
        //    if (convId == null && msgId == null) throw new ArgumentNullException("发送已读回执的时候,必须指定 conversation id 或者 message id");
        //    lock (mutex)
        //    {
        //        var ackCommand = new AckCommand()
        //                .ReadAck().MessageId(msgId)
        //            .ConversationId(convId)
        //            .PeerId(this.ClientId);

        //        return this.RunCommandAsync(ackCommand);
        //    }
        //}
        #region 查询对话中对方的接收状态,也就是已读回执
        private Task <Tuple <long, long> > FetchAllReceiptTimestampsAsync(string targetClientId = null, string conversationId = null, AVIMConversation conversation = null, bool queryAllMembers = false)
        {
            var convId = conversationId != null ? conversationId : conversation.ConversationId;

            if (convId == null)
            {
                throw new ArgumentNullException("conversationId 和 conversation 不可以同时为 null");
            }

            var cmd = new ConversationCommand().ConversationId(convId)
                      .TargetClientId(targetClientId)
                      .QueryAllMembers(queryAllMembers)
                      .Option("max-read")
                      .PeerId(clientId);

            return(this.RunCommandAsync(cmd).OnSuccess(t =>
            {
                var result = t.Result;
                long maxReadTimestamp = -1;
                long maxAckTimestamp = -1;

                if (result.Item2.ContainsKey("maxReadTimestamp"))
                {
                    long.TryParse(result.Item2["maxReadTimestamp"].ToString(), out maxReadTimestamp);
                }
                if (result.Item2.ContainsKey("maxAckTimestamp"))
                {
                    long.TryParse(result.Item2["maxAckTimestamp"].ToString(), out maxAckTimestamp);
                }
                return new Tuple <long, long>(maxAckTimestamp, maxReadTimestamp);
            }));
        }
        internal AVIMCommand GenerateQueryCommand()
        {
            var cmd = new ConversationCommand();

            var queryParameters = this.BuildParameters(false);

            if (queryParameters != null)
            {
                if (queryParameters.Keys.Contains("where"))
                {
                    cmd.Where(queryParameters["where"]);
                }

                if (queryParameters.Keys.Contains("skip"))
                {
                    cmd.Skip(int.Parse(queryParameters["skip"].ToString()));
                }

                if (queryParameters.Keys.Contains("limit"))
                {
                    cmd.Limit(int.Parse(queryParameters["limit"].ToString()));
                }

                if (queryParameters.Keys.Contains("sort"))
                {
                    cmd.Sort(queryParameters["order"].ToString());
                }
            }

            return(cmd.Option("query").PeerId(CurrentClient.ClientId));
        }
示例#3
0
        internal Task OperateMembersAsync(AVIMConversation conversation, string action, string member = null, IEnumerable <string> members = null)
        {
            if (string.IsNullOrEmpty(conversation.ConversationId))
            {
                throw new Exception("conversation id 不可以为空。");
            }

            var membersAsList = Concat <string>(member, members, "加人或者踢人的时候,被操作的 member(s) 不可以为空。");

            var cmd = new ConversationCommand().ConversationId(conversation.ConversationId)
                      .Members(membersAsList)
                      .Option(action)
                      .PeerId(clientId);

            return(this.LinkedRealtime.AttachSignature(cmd, LinkedRealtime.SignatureFactory.CreateConversationSignature(conversation.ConversationId, ClientId, membersAsList, ConversationSignatureAction.Add)).OnSuccess(_ =>
            {
                return this.RunCommandAsync(cmd).OnSuccess(t =>
                {
                    var result = t.Result;
                    if (!conversation.IsTransient)
                    {
                        if (conversation.MemberIds == null)
                        {
                            conversation.MemberIds = new List <string>();
                        }
                        conversation.MemberIds = conversation.MemberIds.Concat(membersAsList);
                    }
                    return result;
                });
            }).Unwrap());
        }
示例#4
0
        /// <summary>
        /// 创建对话
        /// </summary>
        /// <param name="conversation">对话</param>
        /// <param name="isUnique">是否创建唯一对话,当 isUnique 为 true 时,如果当前已经有相同成员的对话存在则返回该对话,否则会创建新的对话。该值默认为 false。</param>
        /// <returns></returns>
        internal Task <AVIMConversation> CreateConversationAsync(AVIMConversation conversation, bool isUnique = true)
        {
            var cmd = new ConversationCommand()
                      .Generate(conversation)
                      .Unique(isUnique);

            var convCmd = cmd.Option("start")
                          .PeerId(clientId);

            return(LinkedRealtime.AttachSignature(convCmd, LinkedRealtime.SignatureFactory.CreateStartConversationSignature(this.clientId, conversation.MemberIds)).OnSuccess(_ =>
            {
                return this.RunCommandAsync(convCmd).OnSuccess(t =>
                {
                    var result = t.Result;
                    if (result.Item1 < 1)
                    {
                        var members = conversation.MemberIds.ToList();
                        members.Add(ClientId);
                        conversation.MemberIds = members;
                        conversation.MergeFromPushServer(result.Item2);
                    }

                    return conversation;
                });
            }).Unwrap());
        }
示例#5
0
        private ScenarioCommand ExecuteNext()
        {
            if (mCommandList.Length <= mCursor)
            {
                return(null);
            }
            ScenarioCommand command = mCommandList[mCursor++];

            if (command is ConversationCommand)
            {
                ConversationCommand conv = command as ConversationCommand;
                mName    = conv.Name;
                mContext = conv.Context;
            }
            else if (command is CharacterCommand)
            {
                CharacterCommand crt = command as CharacterCommand;
                SetCharacterId(crt.Position, crt.Id);
            }
            else if (command is BackgroundCommand)
            {
                BackgroundCommand bg = command as BackgroundCommand;
                BG       = bg.Id;
                mBGColor = bg.BackgroundColor;
            }
            return(command);
        }
示例#6
0
        /// <summary>
        /// 创建对话
        /// </summary>
        /// <param name="conversation">对话</param>
        /// <param name="isUnique">是否创建唯一对话,当 isUnique 为 true 时,如果当前已经有相同成员的对话存在则返回该对话,否则会创建新的对话。该值默认为 false。</param>
        /// <returns></returns>
        public Task <AVIMConversation> CreateConversationAsync(AVIMConversation conversation, bool isUnique = true)
        {
            var cmd = new ConversationCommand()
                      .Attr(conversation.Attributes)
                      .Members(conversation.MemberIds)
                      .Transient(conversation.IsTransient)
                      .Unique(isUnique)
                      .Option("start")
                      .AppId(AVClient.ApplicationId)
                      .PeerId(clientId);

            return(AttachSignature(cmd, this.SignatureFactory.CreateStartConversationSignature(this.clientId, conversation.MemberIds)).OnSuccess(_ =>
            {
                return AVIMClient.AVCommandRunner.RunCommandAsync(cmd).OnSuccess(t =>
                {
                    var result = t.Result;
                    if (result.Item1 < 1)
                    {
                        conversation.ConversationId = result.Item2["cid"].ToString();
                    }

                    return conversation;
                });
            }).Unwrap());
        }
示例#7
0
        /// <summary>
        /// 当前用户对目标对话取消静音,恢复该对话的离线消息推送
        /// </summary>
        /// <param name="conversation"></param>
        /// <returns></returns>
        public Task UnmuteConversationAsync(AVIMConversation conversation)
        {
            var convCmd = new ConversationCommand()
                          .ConversationId(conversation.ConversationId)
                          .Option("unmute")
                          .PeerId(this.ClientId);

            return(this.RunCommandAsync(convCmd));
        }
        /// <summary>
        /// 当前用户对目标对话进行静音操作
        /// </summary>
        /// <param name="conversation"></param>
        /// <returns></returns>
        public Task MuteConversationAsync(AVIMConversation conversation)
        {
            var convCmd = new ConversationCommand()
                          .ConversationId(conversation.ConversationId)
                          .Option("mute")
                          .PeerId(this.ClientId);

            return(this.LinkedRealtime.AVIMCommandRunner.RunCommandAsync(convCmd));
        }
示例#9
0
        /// <summary>
        /// 将修改保存到云端
        /// </summary>
        /// <returns></returns>
        public Task SaveAsync()
        {
            var cmd = new ConversationCommand()
                      .Generate(this);

            var convCmd = cmd.Option("update")
                          .PeerId(this.CurrentClient.ClientId);

            return(this.CurrentClient.LinkedRealtime.RunCommandAsync(convCmd));
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="clientId"></param>
        /// <returns></returns>
        public Task <bool> AddMembersAsync(string clientId)
        {
            var cmd = new ConversationCommand()
                      .ConId(this.ConversationId)
                      .Member(clientId)
                      .Option("add")
                      .AppId(AVClient.ApplicationId)
                      .PeerId(clientId);
            var memberList = new List <string>()
            {
                clientId
            };

            return(CurrentClient.AttachSignature(cmd, CurrentClient.SignatureFactory.CreateConversationSignature(this.ConversationId, CurrentClient.clientId, memberList, "invite")).OnSuccess(_ =>
            {
                return AVIMClient.AVCommandRunner.RunCommandAsync(cmd).OnSuccess(t =>
                {
                    return t.Result.Item2.ContainsKey("added");
                });
            }).Unwrap());
        }