/// <summary> /// Recalls the async. /// </summary> /// <returns>The async.</returns> /// <param name="message">Message.</param> public Task <AVIMRecalledMessage> RecallAsync(IAVIMMessage message) { var tcs = new TaskCompletionSource <AVIMRecalledMessage>(); var patchCmd = new PatchCommand().Recall(message); RunCommandAsync(patchCmd) .OnSuccess(t => { var recalledMsg = new AVIMRecalledMessage(); AVIMMessage.CopyMetaData(message, recalledMsg); tcs.SetResult(recalledMsg); }); return(tcs.Task); }
/// <summary> /// Modifies the aysnc. /// </summary> /// <returns>The aysnc.</returns> /// <param name="oldMessage">要修改的消息对象</param> /// <param name="newMessage">新的消息对象</param> public Task <IAVIMMessage> UpdateAsync(IAVIMMessage oldMessage, IAVIMMessage newMessage) { var tcs = new TaskCompletionSource <IAVIMMessage>(); var patchCmd = new PatchCommand().Modify(oldMessage, newMessage); this.RunCommandAsync(patchCmd) .OnSuccess(t => { // 从旧消息对象中拷贝数据 AVIMMessage.CopyMetaData(oldMessage, newMessage); // 获取更新时间戳 var response = t.Result.Item2; if (response.TryGetValue("lastPatchTime", out object updatedAtObj) && long.TryParse(updatedAtObj.ToString(), out long updatedAt)) { newMessage.UpdatedAt = updatedAt; } tcs.SetResult(newMessage); }); return(tcs.Task); }
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.LinkedRealtime.AVIMCommandRunner.RunCommandAsync(ackCommand)); } }
internal Task <AVIMMessage> SendMessageAsync(AVIMClient client, AVIMConversation conversation, AVIMMessage message) { var tcs = new TaskCompletionSource <AVIMMessage>(); var sendMsg = new DirectCommand { // TODO 完善消息体 Cid = conversation.convId, Msg = message.ToString() }; var cmd = commandFactory.NewRequest(client.ClientId, CommandType.Direct); cmd.directMessage = sendMsg; SendRequest(cmd).ContinueWith(t => { if (t.IsFaulted) { tcs.SetException(t.Exception.InnerException); } else { tcs.SetResult(message); } }); return(tcs.Task); }
internal void HandleReceiveMessage(AVIMConversation conversation, AVIMMessage message) { message.Conversation = conversation; OnReceivedMessage?.Invoke(message); }
internal Task <AVIMMessage> SendMessageAsync(AVIMConversation conversation, AVIMMessage message) { return(connection.SendMessageAsync(this, conversation, message)); }
public Task <AVIMMessage> SendMessageAsync(AVIMMessage message) { return(Client.SendMessageAsync(this, message)); }