/// <summary> /// 向目标用户发送图片消息哈希报文, 在文件 IO 出错时抛出异常, 在网络发送失败时不抛出异常 /// </summary> public async Task PutImageAsync(Profile profile, string file) { var result = await this.cache.SetCacheAsync(new FileInfo(file), this.cancellation.Token); var message = new NotifyImageMessage() { ImageHash = result.Hash }; message.SetObject(result.FileInfo.FullName); var packetData = new { messageId = message.MessageId, imageHash = result.Hash, }; await this.dispatcher.InvokeAsync(() => this.InsertMessageAsync((NotifyClientProfile)profile, message)); await this.network.PutAsync((NotifyClientProfile)profile, message, "link.message.image-hash", packetData); }
NotifyPropertyMessage Convert(MessageEntry item) { if (item.Path == NotifyTextMessage.MessagePath) { var message = new NotifyTextMessage(item.MessageId, item.DateTime, AsMessageReference(item.Reference)); message.SetObject(item.Object); message.SetStatus(MessageStatus.Success); return(message); } else if (item.Path == NotifyImageMessage.MessagePath) { var message = new NotifyImageMessage(item.MessageId, item.DateTime, AsMessageReference(item.Reference)); var imageHash = item.Object; message.ImageHash = imageHash; message.SetStatus(MessageStatus.Success); if (this.cache.TryGetCache(imageHash, out var info)) { message.SetObject(info.FullName); } return(message); } return(default);