Ejemplo n.º 1
0
        public string Serialize(NIMIMMessage nimMsg)
        {
            var nimMsgJson = nimMsg.Serialize();
            var dic        = JsonParser.FromJson(nimMsgJson);

            if (ReceiverList == null)
            {
                dic[PushListKey] = string.Empty;
            }
            else
            {
                dic[PushListKey] = ReceiverList;
                dic[PushListKey] = JsonParser.Serialize(dic[PushListKey]);
            }
            if (!string.IsNullOrEmpty(Content))
            {
                dic[PushContentKey] = Content;
            }
            else
            {
                dic[PushContentKey] = string.Empty;
            }

            dic[ForcePushEnabledKey] = 1;
            var json = JsonParser.Serialize(dic);

            return(json);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 撤回消息
        /// </summary>
        /// <param name="message">NIMIMMessage 对象</param>
        /// <param name="notify">自定义通知</param>
        /// <param name="cb"></param>
        public static void RecallMessage(NIMIMMessage message, string notify, RecallMessageDelegate cb)
        {
            var json = message.Serialize();
            var ptr  = NimUtility.DelegateConverter.ConvertToIntPtr(cb);

            TalkNativeMethods.nim_talk_recall_msg(json, notify, null, RecallMessageCb, ptr);
        }
Ejemplo n.º 3
0
        internal static NIMIMMessage CreateMessage(Newtonsoft.Json.Linq.JObject token)
        {
            if (!token.HasValues || token.Type != Newtonsoft.Json.Linq.JTokenType.Object)
            {
                return(null);
            }
            var msgTypeToken = token.SelectToken(NIMIMMessage.MessageTypePath);

            if (msgTypeToken == null)
            {
                throw new ArgumentException("message type must be seted:" + token.ToString(Formatting.None));
            }
            var          msgType = msgTypeToken.ToObject <NIMMessageType>();
            NIMIMMessage message = null;

            ConvertAttachStringToObject(token);
            switch (msgType)
            {
            case NIMMessageType.kNIMMessageTypeAudio:
                message = token.ToObject <NIMAudioMessage>();
                break;

            case NIMMessageType.kNIMMessageTypeFile:
                message = token.ToObject <NIMFileMessage>();
                break;

            case NIMMessageType.kNIMMessageTypeImage:
                message = token.ToObject <NIMImageMessage>();
                break;

            case NIMMessageType.kNIMMessageTypeLocation:
                message = token.ToObject <NIMLocationMessage>();
                break;

            case NIMMessageType.kNIMMessageTypeText:
                message = token.ToObject <NIMTextMessage>();
                break;

            case NIMMessageType.kNIMMessageTypeVideo:
                message = token.ToObject <NIMVedioMessage>();
                break;

            case NIMMessageType.kNIMMessageTypeNotification:
                message = token.ToObject <NIMTeamNotificationMessage>();
                break;

            case NIMMessageType.kNIMMessageTypeCustom:
                message = token.ToObject <NIMCustomMessage <object> >();
                break;

            default:
                message = new NIMUnknownMessage();
                ((NIMUnknownMessage)message).RawMessage = token.ToString(Formatting.None);
                break;
            }
            return(message);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 从消息的中获取附件(图片、语音、视频等)的本地路径
        /// </summary>
        /// <param name="msg">消息对象</param>
        /// <returns>消息如果有附件,不管是否已下载,返回附件的本地路径;消息如果没有附件,返回空字符串""</returns>
        public static string GetAttachmentPathFromMsg(NIMIMMessage msg)
        {
            var jsonMsg = msg.Serialize();
            var ptr     = TalkNativeMethods.nim_talk_get_attachment_path_from_msg(jsonMsg);

            NimUtility.Utf8StringMarshaler marshaler = new NimUtility.Utf8StringMarshaler();
            var path = marshaler.MarshalNativeToManaged(ptr) as string;

            GlobalAPI.FreeBuffer(ptr);
            return(path);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 取消发送消息,目前用于取消发送文件消息
        /// </summary>
        /// <param name="message">消息体</param>
        /// <param name="action">附件上传进度回调</param>
        public static void StopSendMessage(NIMIMMessage message, ReportUploadProgressDelegate action = null)
        {
            System.Diagnostics.Debug.Assert(message != null);
            var    msg = message.Serialize();
            IntPtr ptr = IntPtr.Zero;

            if (action != null)
            {
                ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);
            }
            TalkNativeMethods.nim_talk_stop_send_msg(msg, null, UploadFileProgressChanged, ptr);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="message">消息对象</param>
        public static void SendMessage(NIMIMMessage message, ReportUploadProgressDelegate action = null)
        {
            System.Diagnostics.Debug.Assert(message != null && !string.IsNullOrEmpty(message.ReceiverID));
            var    msg = message.Serialize();
            IntPtr ptr = IntPtr.Zero;

            if (action != null)
            {
                ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);
            }
            System.Diagnostics.Debug.WriteLine("send message:" + msg);
            TalkNativeMethods.nim_talk_send_msg(msg, null, UploadFileProgressChanged, ptr);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 取消发送消息,目前用于取消发送文件消息
        /// </summary>
        /// <param name="message">消息体</param>
        /// <param name="action">附件上传进度回调</param>
        public static void StopSendMessage(NIMIMMessage message, ReportUploadProgressDelegate action = null)
        {
            var    msg = message.Serialize();
            IntPtr ptr = IntPtr.Zero;

            if (action != null)
            {
                NimUploadProgressData data = new NimUploadProgressData();
                data.Message        = message;
                data.ProgressAction = action;
                ptr = NimUtility.DelegateConverter.ConvertToIntPtr(data);
            }
            TalkNativeMethods.nim_talk_stop_send_msg(msg, null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="message">消息对象</param>
        /// <param name="action">文件类消息附件上传进度</param>
        public static void SendMessage(NIMIMMessage message, ReportUploadProgressDelegate action = null)
        {
            System.Diagnostics.Debug.Assert(message != null && !string.IsNullOrEmpty(message.ReceiverID));
            var    msg = message.Serialize();
            IntPtr ptr = IntPtr.Zero;

            if (action != null)
            {
                NimUploadProgressData data = new NimUploadProgressData();
                data.Message        = message;
                data.ProgressAction = action;
                ptr = NimUtility.DelegateConverter.ConvertToIntPtr(data);
            }
            TalkNativeMethods.nim_talk_send_msg(msg, null, _uploadFileProgressChanged, ptr);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 向群组强制推送消息
        /// </summary>
        /// <param name="message">消息对象</param>
        /// <param name="forceMsg">强制推送内容</param>
        /// <param name="action">文件类消息附件上传进度</param>
        public static void SendTeamFrocePushMessage(NIMIMMessage message, TeamForecePushMessage forceMsg, ReportUploadProgressDelegate action = null)
        {
            System.Diagnostics.Debug.Assert(message != null && message.SessionType == Session.NIMSessionType.kNIMSessionTypeTeam);
            var    msgJson = forceMsg.Serialize(message);
            IntPtr ptr     = IntPtr.Zero;

            if (action != null)
            {
                NimUploadProgressData data = new NimUploadProgressData();
                data.Message        = message;
                data.ProgressAction = action;
                ptr = NimUtility.DelegateConverter.ConvertToIntPtr(data);
            }
            TalkNativeMethods.nim_talk_send_msg(msgJson, null, _uploadFileProgressChanged, ptr);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 由其他消息生成转发消息
        /// </summary>
        /// <param name="srcMsg">原始消息</param>
        /// <param name="msgSetting">新的消息属性</param>
        /// <param name="msgId">新的客户端消息id</param>
        /// <param name="sessionId">转发目标</param>
        /// <param name="sessionType">转发目标会话类型</param>
        /// <param name="timetag">消息时间</param>
        /// <returns></returns>
        public static NIMIMMessage CreateRetweetMessage(NIMIMMessage srcMsg, NIMMessageSetting msgSetting, string msgId, string sessionId, Session.NIMSessionType sessionType, long timetag)
        {
            string srcMsgJson  = srcMsg.Serialize();
            string settingJson = string.Empty;

            if (msgSetting != null)
            {
                settingJson = msgSetting.Serialize();
            }
            var newMsgPtr = TalkNativeMethods.nim_talk_create_retweet_msg(srcMsgJson, msgId, sessionType, sessionId, settingJson, timetag);

            if (newMsgPtr != IntPtr.Zero)
            {
                NimUtility.Utf8StringMarshaler marshaler = new NimUtility.Utf8StringMarshaler();
                var newMsg     = marshaler.MarshalNativeToManaged(newMsgPtr);
                var newMsgJson = newMsg.ToString();
                var dstMsg     = MessageFactory.CreateMessage(newMsgJson);
                GlobalAPI.FreeStringBuffer(newMsgPtr);
                return(dstMsg);
            }
            return(null);
        }
Ejemplo n.º 11
0
 public ReceiveMessageArgs(NIMIMMessage msg)
 {
     Message = msg;
 }
Ejemplo n.º 12
0
        internal static NIMIMMessage CreateMessage(Newtonsoft.Json.Linq.JObject token)
        {
            if (!token.HasValues || token.Type != Newtonsoft.Json.Linq.JTokenType.Object)
            {
                return(null);
            }
            var msgTypeToken = token.SelectToken(NIMIMMessage.MessageTypePath);

            if (msgTypeToken == null)
            {
                throw new ArgumentException("message type must be seted:" + token.ToString(Formatting.None));
            }
            var          msgType = msgTypeToken.ToObject <NIMMessageType>();
            NIMIMMessage message = null;

            ConvertAttachStringToObject(token);
            var msgJsonValue = token.ToString(Formatting.None);

            switch (msgType)
            {
            case NIMMessageType.kNIMMessageTypeAudio:
                message = NimUtility.Json.JsonParser.Deserialize <NIMAudioMessage>(msgJsonValue);
                break;

            case NIMMessageType.kNIMMessageTypeFile:
                message = NimUtility.Json.JsonParser.Deserialize <NIMFileMessage>(msgJsonValue);
                break;

            case NIMMessageType.kNIMMessageTypeImage:
                message = NimUtility.Json.JsonParser.Deserialize <NIMImageMessage>(msgJsonValue);
                break;

            case NIMMessageType.kNIMMessageTypeLocation:
                message = NimUtility.Json.JsonParser.Deserialize <NIMLocationMessage>(msgJsonValue);
                break;

            case NIMMessageType.kNIMMessageTypeText:
                message = NimUtility.Json.JsonParser.Deserialize <NIMTextMessage>(msgJsonValue);
                break;

            case NIMMessageType.kNIMMessageTypeVideo:
                message = NimUtility.Json.JsonParser.Deserialize <NIMVideoMessage>(msgJsonValue);
                break;

            case NIMMessageType.kNIMMessageTypeNotification:
                message = NimUtility.Json.JsonParser.Deserialize <NIMTeamNotificationMessage>(msgJsonValue);
                break;

            case NIMMessageType.kNIMMessageTypeCustom:
                message = NimUtility.Json.JsonParser.Deserialize <NIMCustomMessage <object> >(msgJsonValue);
                break;

            case NIMMessageType.kNIMMessageTypeTips:
                ConvertAttachObjectToString(token);
                msgJsonValue = token.ToString(Formatting.None);
                message      = NimUtility.Json.JsonParser.Deserialize <NIMTipMessage>(msgJsonValue);
                break;

#if NIMAPI_UNDER_WIN_DESKTOP_ONLY
            case NIMMessageType.kNIMMessageTypeRobot:
                message = Robot.ResponseMessage.Deserialize(token);
                break;
#endif
            default:
                message = NimUtility.Json.JsonParser.Deserialize <NIMUnknownMessage>(msgJsonValue);
                ((NIMUnknownMessage)message).RawMessage = token.ToString(Formatting.None);
                break;
            }
            return(message);
        }