Esempio n. 1
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);
        }
Esempio n. 2
0
 static TalkAPI()
 {
     ReceivedMessageCallback   = new IMReceiveMessageCallback(OnReceiveIMMessage);
     MessageArcCallback        = new IMMessageArcCallback(OnReceiveMessageAck);
     UploadFileProgressChanged = new UploadFileCallback(OnUploadFileProgressChanged);
     TalkNativeMethods.nim_talk_reg_ack_cb("", MessageArcCallback, IntPtr.Zero);
     TalkNativeMethods.nim_talk_reg_receive_cb("", ReceivedMessageCallback, IntPtr.Zero);
 }
Esempio n. 3
0
 internal static void RegisterCallbacks()
 {
     _receivedMessageCallback   = new IMReceiveMessageCallback(OnReceiveIMMessage);
     _messageArcCallback        = new IMMessageArcCallback(OnReceiveMessageAck);
     _uploadFileProgressChanged = new UploadFileCallback(OnUploadFileProgressChanged);
     TalkNativeMethods.nim_talk_reg_ack_cb("", _messageArcCallback, IntPtr.Zero);
     TalkNativeMethods.nim_talk_reg_receive_cb("", _receivedMessageCallback, IntPtr.Zero);
 }
Esempio n. 4
0
        /// <summary>
        /// 撤回消息
        /// </summary>
        /// <param name="msgId">消息 id</param>
        /// <param name="notify">自定义通知</param>
        /// <param name="cb"></param>
        public static void RecallMessage(string msgId, string notify, RecallMessageDelegate cb)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(cb);
            Dictionary <string, object> paramDic = new Dictionary <string, object>();

            paramDic[NIMIMMessage.ClientMessageId] = msgId;
            var json = NimUtility.Json.JsonParser.Serialize(paramDic);

            TalkNativeMethods.nim_talk_recall_msg(json, notify, null, RecallMessageCb, ptr);
        }
Esempio n. 5
0
        /// <summary>
        /// 注册接收群通知是否需要过滤的回调
        /// </summary>
        /// <param name="action"></param>
        public static void RegTeamNotificationFilterCb(TeamNotificationFilterDelegate action)
        {
            IntPtr ptr = IntPtr.Zero;

            if (action != null)
            {
                ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);
            }
            TalkNativeMethods.nim_talk_reg_notification_filter_cb(null, TeamNotificationFilter, ptr);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        /// <summary>
        /// 注册接收批量广播消息回调 (如果在注册了接收消息回调的同时也注册了该批量接口,当有批量消息时,会改走这个接口通知应用层,例如登录后接收到的离线消息等)
        /// </summary>
        /// <param name="cb"></param>
        public static void RegReceiveBroadcastMsgsCb(ReceiveBroadcastMsgsDelegate cb)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(cb);

            TalkNativeMethods.nim_talk_reg_receive_broadcast_msgs_cb(null, _receiveBroadcastMsgsCallback, ptr);
        }
Esempio n. 14
0
        /// <summary>
        /// 注册接收消息撤回通知的回调
        /// </summary>
        /// <param name="cb"></param>
        public static void RegRecallMessageCallback(RecallMessageDelegate cb)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(cb);

            TalkNativeMethods.nim_talk_reg_recall_msg_cb(null, GlobalRecallMessageCb, ptr);
        }
Esempio n. 15
0
        /// <summary>
        /// 注册接收批量消息回调 (如果在注册了接收消息回调的同时也注册了该批量接口,当有批量消息时,会改走这个接口通知应用层,例如登录后接收到的离线消息等)
        /// </summary>
        /// <param name="cb"></param>
        public static void RegReceiveBatchMessagesCb(ReceiveBatchMesaagesDelegate cb)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(cb);

            TalkNativeMethods.nim_talk_reg_receive_msgs_cb(null, OnReceivedBatchMessages, ptr);
        }