using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using LeanCloud; using System.Reflection; using LeanCloud.Storage.Internal; using System.Threading; using System.Collections; using LeanCloud.Realtime.Internal; namespace LeanCloud.Realtime { /// /// 实时消息的核心基类,它是 Json schema 消息的父类 /// [AVIMMessageClassName("_AVIMMessage")] public class AVIMMessage : IAVIMMessage { /// /// 默认的构造函数 /// public AVIMMessage() { } internal readonly object mutex = new object(); /// /// 对话的Id /// public string ConversationId { get; set; } /// /// 发送消息的 ClientId /// public string FromClientId { get; set; } /// /// 消息在全局的唯一标识Id /// public string Id { get; set; } /// /// 服务器端的时间戳 /// public long ServerTimestamp { get; set; } /// /// Gets or sets the content. /// /// The content. public string Content { get; set; } /// /// 对方收到消息的时间戳,如果是多人聊天,那以最早收到消息的人回发的 ACK 为准 /// public long RcpTimestamp { get; set; } public long UpdatedAt { get; set; } internal string cmdId { get; set; } #region /// /// Gets or sets a value indicating whether this mention all. /// /// true if mention all; otherwise, false. public bool MentionAll { get; set; } /// /// Gets or sets the mention list. /// /// The mention list. public IEnumerable MentionList { get; set; } #endregion #region register convertor for custom typed message /// /// Serialize this message. /// /// The serialize. public virtual string Serialize() { return Content; } /// /// Validate the specified msgStr. /// /// The validate. /// Message string. public virtual bool Validate(string msgStr) { return true; } /// /// Deserialize the specified msgStr to message subclass instance /// /// The deserialize. /// Message string. public virtual IAVIMMessage Deserialize(string msgStr) { Content = msgStr; return this; } internal virtual MessageCommand BeforeSend(MessageCommand cmd) { return cmd; } internal static IAVIMMessage CopyMetaData(IAVIMMessage srcMsg, IAVIMMessage desMsg) { if (srcMsg == null) return desMsg; desMsg.ConversationId = srcMsg.ConversationId; desMsg.FromClientId = srcMsg.FromClientId; desMsg.Id = srcMsg.Id; desMsg.ServerTimestamp = srcMsg.ServerTimestamp; desMsg.RcpTimestamp = srcMsg.RcpTimestamp; desMsg.UpdatedAt = srcMsg.UpdatedAt; return desMsg; } #endregion } /// /// 消息的发送选项 /// public struct AVIMSendOptions { /// /// 是否需要送达回执 /// public bool Receipt; /// /// 是否是暂态消息,暂态消息不返回送达回执(ack),不保留离线消息,不触发离线推送 /// public bool Transient; /// /// 消息的优先级,默认是1,可选值还有 2|3 /// public int Priority; /// /// 是否为 Will 类型的消息,这条消息会被缓存在服务端,一旦当前客户端下线,这条消息会被发送到对话内的其他成员 /// public bool Will; /// /// 如果消息的接收者已经下线了,这个字段的内容就会被离线推送到接收者 ///例如,一张图片消息的离线消息内容可以类似于:[您收到一条图片消息,点击查看] 这样的推送内容,参照微信的做法 /// public IDictionary PushData; } }