Example #1
0
        /// <summary>
        /// 导入已备份在云端的消息记录
        /// </summary>
        /// <param name="import_info">导入需要的参数参考NIMLogsBackupImportInfo定义</param>
        /// <returns>false 当前有导入/导出操作正在进行中</returns>
        public static bool ImportBackupFromRemote(NIMLogsBackupImportInfo import_info)
        {
            bool ret = false;

            if (import_info != null)
            {
                //这里需增长import_info的生命周期,否则import_info被gc回收掉,会导致回调出问题
                import_info_remain = import_info;

                import_info_c.UnPackageCallback_     = ImportBackupFromRemoteUnPackageCallback;
                import_info_c.RemoteDecryptCallback_ = ImportBackupFromRemoteDecryptCallback;
                import_info_c.PathRelease_           = NewPathRelease;

                import_info_c.ProgressCallback_ = ImportLogsBackupProgressCallback;
                import_info_c.CompleteCallback_ = ImportLogsBackupCompleteCallback;

                int    nSizeOfParam = Marshal.SizeOf(import_info);
                IntPtr param_ptr    = Marshal.AllocHGlobal(nSizeOfParam);
                try
                {
                    Marshal.StructureToPtr(import_info, param_ptr, false);
                    import_info_c.user_data_ = param_ptr;
                }
                catch
                {
                }
                ret = MsglogNativeMethods.nim_import_backup_from_remote(ref import_info_c);
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        /// 在线查询消息
        /// </summary>
        /// <param name="id">会话id,对方的account id或者群组tid</param>
        /// <param name="sType">会话类型</param>
        /// <param name="limit">本次查询的消息条数上限(最多100条)</param>
        /// <param name="sTimetag">起始时间点,单位:毫秒</param>
        /// <param name="eTimetag">结束时间点,单位:毫秒</param>
        /// <param name="endMsgId">结束查询的最后一条消息的server_msg_id(不包含在查询结果中) </param>
        /// <param name="reverse">true:反向查询(按时间正序起查,正序排列),false:按时间逆序起查,逆序排列(建议默认为false)</param>
        /// <param name="saveLocal">true: 将在线查询结果保存到本地,false: 不保存</param>
        /// <param name="action"></param>
        public static void QueryMsglogOnline(string id, NIMSessionType sType, int limit, long sTimetag, long eTimetag,
                                             long endMsgId, bool reverse, bool saveLocal, QueryMsglogResultDelegate action)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_query_msg_online_async(id, sType, limit, sTimetag, eTimetag, endMsgId, reverse, saveLocal, null, QueryLogCompleted, ptr);
        }
Example #3
0
        /// <summary>
        /// 只往本地消息历史数据库里写入一条消息(如果已存在这条消息,则更新。通常是APP的本地自定义消息,并不会发给服务器)
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="sType"></param>
        /// <param name="msgId"></param>
        /// <param name="msg"></param>
        /// <param name="action"></param>
        public static void WriteMsglog(string uid, Session.NIMSessionType sType, string msgId, NIMIMMessage msg, OperateSingleLogResultDelegate action)
        {
            var ptr          = NimUtility.DelegateConverter.ConvertToIntPtr(action);
            var msgJsonValue = msg.Serialize();

            MsglogNativeMethods.nim_msglog_write_db_only_async(uid, sType, msgId, msgJsonValue, null, OperateMsglogByLogIdCompleted, ptr);
        }
Example #4
0
        /// <summary>
        /// 导入消息历史DB文件(不包括系统消息历史)。先验证是否自己的消息历史文件和DB加密密钥,如果验证不通过,则不导入。
        /// </summary>
        /// <param name="srcPath"></param>
        /// <param name="action"></param>
        /// <param name="prg"></param>
        public static void ImportDatabase(string srcPath, CommonOperationResultDelegate action, ImportProgressDelegate prg)
        {
            var ptr1 = NimUtility.DelegateConverter.ConvertToIntPtr(action);
            var ptr2 = NimUtility.DelegateConverter.ConvertToIntPtr(prg);

            MsglogNativeMethods.nim_msglog_import_db_async(srcPath, null, NormalOperationCompleted, ptr1, ReportImportDbProgress, ptr2);
        }
Example #5
0
        /// <summary>
        /// 消息是否已经被查看
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="jsonExtension"></param>
        /// <returns></returns>
        public static bool IsMessageBeReaded(NIMIMMessage msg, string jsonExtension = null)
        {
            System.Diagnostics.Debug.Assert(msg != null && !string.IsNullOrEmpty(msg.ReceiverID));
            var msgJson = msg.Serialize();

            return(MsglogNativeMethods.nim_msglog_query_be_readed(msgJson, jsonExtension));
        }
        public static void WriteMsglogOnlyForTest(string uid, bool need_update_session, NIMIMMessage msg, string json_extension, OperateSingleLogResultDelegate action)
        {
            var ptr          = DelegateConverter.ConvertToIntPtr(action);
            var msgJsonValue = msg.Serialize();

            MsglogNativeMethods.nim_msglog_insert_msglog_async(uid, msgJsonValue, need_update_session, json_extension, OperateMsglogByLogIdCompleted, ptr);
        }
Example #7
0
        /// <summary>
        /// 导出本地消息记录到云端
        /// </summary>
        /// <param name="export_info">导出需要的参数参考NIMLogsBackupExportInfo定义</param>
        /// <param name="encrypt_key_">加密秘钥</param>
        /// <returns>false 当前有导入/导出操作正在进行中</returns>
        public static bool ExportBackupToRemote(NIMLogsBackupExportInfo export_info, string encrypt_key_)
        {
            bool ret = false;

            if (export_info != null)
            {
                export_info_remain = export_info;
                export_info_c.ToRemotePackageCallback_ = ExportBackupToRemotePackageCallback;
                export_info_c.ToRemoteEncryptCallback_ = ExportBackupToRemoteEncryptCallback;
                export_info_c.encrypt_key_             = Utf8StringMarshaler.GetInstance("").MarshalManagedToNative(encrypt_key_);
                export_info_c.ProgressCallback_        = ExportLogsBackupProgressCallback;
                export_info_c.CompleteCallback_        = ExportLogsBackupCompleteCallback;
                export_info_c.ToRemoteLogFiter_        = ExportBackupToRemoteLogFiterCallback;
                export_info_c.PathRelease_             = NewPathRelease;

                //NIMLogsBackupExportInfo_Callback export_info_cb = new NIMLogsBackupExportInfo_Callback();
                int    nSizeOfParam = Marshal.SizeOf(export_info);
                IntPtr param_ptr    = Marshal.AllocHGlobal(nSizeOfParam);
                try
                {
                    Marshal.StructureToPtr(export_info, param_ptr, false);
                    export_info_c.user_data_ = param_ptr;
                }
                catch
                {
                }
                //public _ExportBackupToRemoteEncryptCallback_C ToRemoteEncryptCallback_;
                long param_value = param_ptr.ToInt64();
                Debug.WriteLine("param_value user_data:" + param_value.ToString());
                Debug.WriteLine("encrypt_key_ user_data:" + export_info_c.encrypt_key_.ToInt64().ToString());
                ret = MsglogNativeMethods.nim_export_backup_to_remote(ref export_info_c);
            }
            return(ret);
        }
        public static void QueryMsglogLocally(QueryMsglogParams args, QueryMsglogResultDelegate action)
        {
            var x        = new { direction = args.Direction, reverse = args.Reverse, endtime = args.EndTimetag };
            var json_ext = JsonParser.Serialize(x);
            var ptr      = DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_query_msg_async(args.AccountId, args.SessionType, args.CountLimit, args.MsgAnchorTimttag, json_ext, QueryLogCompleted, ptr);
        }
Example #9
0
        /// <summary>
        /// 发送已读回执
        /// </summary>
        public static void SendReceipt(NIMIMMessage msg, MsglogStatusChangedDelegate cb, string jsonExtension = null)
        {
            System.Diagnostics.Debug.Assert(msg != null && !string.IsNullOrEmpty(msg.ReceiverID));
            var msgJson = msg.Serialize();
            var ptr     = NimUtility.DelegateConverter.ConvertToIntPtr(cb);

            MsglogNativeMethods.nim_msglog_send_receipt_async(msgJson, jsonExtension, OnMsglogStatusChanged, ptr);
        }
Example #10
0
        /// <summary>
        /// 根据指定条件在一个会话中查询指定单个或多个类型的本地消息
        /// </summary>
        /// <param name="sessionType">会话类型</param>
        /// <param name="id">会话id,对方的account id或者群组tid</param>
        /// <param name="limit">本次查询的消息条数上限(默认100条)</param>
        /// <param name="fromTime">起始时间点,单位:毫秒</param>
        /// <param name="endTime">结束时间点,单位:毫秒</param>
        /// <param name="endClientMsgId">结束查询的最后一条消息的client_msg_id(不包含在查询结果中)(暂不启用)</param>
        /// <param name="reverse">true:反向查询(按时间正序起查,正序排列),false:按时间逆序起查,逆序排列(建议默认为false)</param>
        /// <param name="msgTypes">检索的消息类型</param>
        /// <param name="cb">本地查询消息的回调函数</param>
        /// <param name="jsonExt">json扩展参数(备用,目前不需要)</param>
        public static void QuerySpecifiedType(NIMSessionType sessionType, string id, int limit, long fromTime,
                                              long endTime, string endClientMsgId, bool reverse, List <NIMMessageType> msgTypes, QueryMsglogResultDelegate cb, string jsonExt = null)
        {
            var ptr         = DelegateConverter.ConvertToIntPtr(cb);
            var msgTypeJson = JsonParser.Serialize(msgTypes);

            MsglogNativeMethods.nim_msglog_query_the_message_of_the_specified_type_async(sessionType,
                                                                                         id, limit, fromTime, endTime, endClientMsgId, reverse, msgTypeJson, jsonExt, QueryLogCompleted, ptr);
        }
Example #11
0
        /// <summary>
        /// 根据指定条件查询本地消息
        /// </summary>
        /// <param name="range">消息历史的检索范围</param>
        /// <param name="ids">会话id(对方的account id或者群组tid)的集合</param>
        /// <param name="limit">本次查询的消息条数上限(默认100条)</param>
        /// <param name="sTimetag">起始时间点,单位:毫秒</param>
        /// <param name="eTimetag">结束时间点,单位:毫秒</param>
        /// <param name="endMsgId">结束查询的最后一条消息的client_msg_id(不包含在查询结果中)(暂不启用)</param>
        /// <param name="reverse">true:反向查询(按时间正序起查,正序排列),false:按时间逆序起查,逆序排列(建议默认为false)</param>
        /// <param name="msgType">检索的消息类型(目前只支持kNIMMessageTypeText、kNIMMessageTypeImage和kNIMMessageTypeFile这三种类型消息)</param>
        /// <param name="searchContent">检索文本(目前只支持kNIMMessageTypeText和kNIMMessageTypeFile这两种类型消息的文本关键字检索,
        /// 即支持文字消息和文件名的检索。
        /// 如果合并检索,需使用未知类型消息kNIMMessageTypeUnknown)</param>
        /// <param name="action"></param>
        public static void QueryMsglogByCustomCondition(NIMMsgLogQueryRange range, string[] ids, int limit,
                                                        long sTimetag, long eTimetag, string endMsgId, bool reverse,
                                                        NIMMessageType msgType, string searchContent, QueryMsglogResultDelegate action)
        {
            var    ptr    = NimUtility.DelegateConverter.ConvertToIntPtr(action);
            string idJson = NimUtility.Json.JsonParser.Serialize(ids);

            MsglogNativeMethods.nim_msglog_query_msg_by_options_async(range, idJson, limit, sTimetag, eTimetag, endMsgId,
                                                                      reverse, msgType, searchContent, null, QueryLogCompleted, ptr);
        }
Example #12
0
        /// <summary>
        ///     在线查询消息
        /// </summary>
        /// <param name="id">会话id,对方的account id或者群组tid</param>
        /// <param name="sType">会话类型</param>
        /// <param name="limit">本次查询的消息条数上限(最多100条)</param>
        /// <param name="sTimetag">起始时间点,单位:毫秒</param>
        /// <param name="eTimetag">结束时间点,单位:毫秒</param>
        /// <param name="endMsgId">结束查询的最后一条消息的server_msg_id(不包含在查询结果中) </param>
        /// <param name="reverse">true:反向查询(按时间正序起查,正序排列),false:按时间逆序起查,逆序排列(建议默认为false)</param>
        /// <param name="saveLocal">true: 将在线查询结果保存到本地,false: 不保存</param>
        /// <param name="autoDownloadAttach">查询结果回来后,是否需要sdk自动下载消息附件</param>
        /// <param name="action"></param>
        public static void QueryMsglogOnline(string id, NIMSessionType sType, int limit, long sTimetag, long eTimetag,
                                             long endMsgId, bool reverse, bool saveLocal, bool autoDownloadAttach, QueryMsglogResultDelegate action)
        {
            var ptr = DelegateConverter.ConvertToIntPtr(action);

            System.Collections.Generic.Dictionary <string, bool> dic = new System.Collections.Generic.Dictionary <string, bool>();
            dic[QueryMsglogParams.AutoDownloadAttachJsonKey] = autoDownloadAttach;
            var jsonExt = JsonParser.Serialize(dic);

            MsglogNativeMethods.nim_msglog_query_msg_online_async(id, sType, limit, sTimetag, eTimetag, endMsgId, reverse, saveLocal, jsonExt, QueryLogCompleted, ptr);
        }
        /// <summary>
        ///     导出整个消息历史DB文件(不包括系统消息历史)
        ///     android 和 ios 平台下不可用
        /// </summary>
        /// <param name="destPath">导出时保存的目标全路径</param>
        /// <param name="action"></param>
        public static void ExportDatabaseFile(string destPath, CommonOperationResultDelegate action)
        {
            var ptr = DelegateConverter.ConvertToIntPtr(action);

#if UNITY
#if UNITY_STANDALONE
            MsglogNativeMethods.nim_msglog_export_db_async(destPath, null, NormalOperationCompleted, ptr);
#endif
#else
            MsglogNativeMethods.nim_msglog_export_db_async(destPath, null, NormalOperationCompleted, ptr);
#endif
        }
        /// <summary>
        ///     导入消息历史DB文件(不包括系统消息历史)。先验证是否自己的消息历史文件和DB加密密钥,如果验证不通过,则不导入。
        ///     android 和 ios 平台下不可用
        /// </summary>
        /// <param name="srcPath"></param>
        /// <param name="action"></param>
        /// <param name="prg"></param>
        public static void ImportDatabase(string srcPath, CommonOperationResultDelegate action, ImportProgressDelegate prg)
        {
            var ptr1 = DelegateConverter.ConvertToIntPtr(action);
            var ptr2 = DelegateConverter.ConvertToIntPtr(prg);

#if UNITY
#if UNITY_STANDALONE
            MsglogNativeMethods.nim_msglog_import_db_async(srcPath, null, NormalOperationCompleted, ptr1, ImportMsglogPrgCb, ptr2);
#endif
#else
            MsglogNativeMethods.nim_msglog_import_db_async(srcPath, null, NormalOperationCompleted, ptr1, ImportMsglogPrgCb, ptr2);
#endif
        }
Example #15
0
 /// <summary>
 /// 取消导入已备份在云端的消息记录
 /// </summary>
 public static void CancelImportBackupFromRemote()
 {
     MsglogNativeMethods.nim_cancel_import_backup_from_remote();
 }
Example #16
0
 /// <summary>
 /// 取消导出本地消息记录到云端
 /// </summary>
 public static void CancelExportBackupToRemote()
 {
     MsglogNativeMethods.nim_cancel_export_backup_to_remote();
 }
Example #17
0
        /// <summary>
        /// 删除与某账号的所有云端历史记录与漫游消息
        /// </summary>
        /// <param name="accound">对方accid</param>
        /// <param name="deleteRoaming">是否同时删除与该accid的漫游消息</param>
        /// <param name="cb">操作结果的回调函数</param>
        public static void DeleteHistoryOnlineAsync(string accound, bool deleteRoaming, DeleteOnlineHistoryResultDelegate cb)
        {
            var ptr = DelegateConverter.ConvertToIntPtr(cb);

            MsglogNativeMethods.nim_msglog_delete_history_online_async(accound, deleteRoaming, null, _deleteOnlineHistoryCb, ptr);
        }
Example #18
0
        /// <summary>
        /// 导出整个消息历史DB文件(不包括系统消息历史)
        /// </summary>
        /// <param name="destPath">导出时保存的目标全路径</param>
        /// <param name="action"></param>
        public static void ExportDatabaseFile(string destPath, CommonOperationResultDelegate action)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_export_db_async(destPath, null, NormalOperationCompleted, ptr);
        }
Example #19
0
        /// <summary>
        /// 删除全部消息历史
        /// </summary>
        /// <param name="deleteSessions">是否删除所有会话列表项(即全部最近联系人)</param>
        /// <param name="action"></param>
        public static void ClearAll(bool deleteSessions, CommonOperationResultDelegate action)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_delete_all_async(deleteSessions, null, NormalOperationCompleted, ptr);
        }
Example #20
0
        /// <summary>
        /// 根据消息ID查询本地(单条)消息
        /// </summary>
        /// <param name="clientMsgId"></param>
        /// <param name="action"></param>
        public static void QuerylogById(string clientMsgId, QueryLogByMsgIdResultDelegate action)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_query_msg_by_id_async(clientMsgId, null, QuerySingleLogCompleted, ptr);
        }
Example #21
0
        /// <summary>
        /// 全部未读消息历史标记为已读
        /// </summary>
        /// <param name="cb"></param>
        public static void ReadAll(CommonOperationResultDelegate cb)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(cb);

            MsglogNativeMethods.nim_msglog_read_all_async(null, NormalOperationCompleted, ptr);
        }
Example #22
0
        /// <summary>
        /// 设置消息子状态
        /// </summary>
        /// <param name="msgId"></param>
        /// <param name="status"></param>
        /// <param name="action"></param>
        public static void SetMsglogSubStatus(string msgId, NIMMsgLogSubStatus status, OperateSingleLogResultDelegate action)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_set_sub_status_async(msgId, status, null, OperateMsglogByLogIdCompleted, ptr);
        }
Example #23
0
        /// <summary>
        /// 批量删除指定对话的消息。删除成功后,将相应会话项的最后一条消息的状态kNIMSessionMsgStatus设置为已删除状态
        /// </summary>
        /// <param name="id">会话id,对方的account id或者群组tid</param>
        /// <param name="sType">会话类型</param>
        /// <param name="action"></param>
        public static void BatchDeleteMeglog(string id, NIMSessionType sType, OperateMsglogResultDelegate action)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_batch_status_delete_async(id, sType, null, OperateMsglogByObjIdCompleted, ptr);
        }
Example #24
0
        /// <summary>
        /// 查询收到的消息是否已经发送过已读回执
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="jsonExt">json扩展参数(备用,目前不需要)</param>
        /// <returns></returns>
        public static bool IsMsgReceiptSended(NIMIMMessage msg, string jsonExt = null)
        {
            var msgJson = msg.Serialize();

            return(MsglogNativeMethods.nim_msglog_query_receipt_sent(msgJson, jsonExt));
        }
        /// <summary>
        ///     批量设置未读状态为已读消息状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="sType"></param>
        /// <param name="action"></param>
        public static void MarkMessagesStatusRead(string id, NIMSessionType sType, OperateMsglogResultDelegate action)
        {
            var ptr = DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_batch_status_read_async(id, sType, null, OperateMsglogByObjIdCompleted, ptr);
        }
Example #26
0
        /// <summary>
        /// 注册全局的消息状态变更通知(目前只支持已读状态的通知)
        /// </summary>
        /// <param name="cb"></param>
        public static void RegMsglogStatusChangedCb(MsglogStatusChangedDelegate cb)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(cb);

            MsglogNativeMethods.nim_msglog_reg_status_changed_cb(null, OnGlobalMsglogStatusChanged, ptr);
        }
Example #27
0
        /// <summary>
        /// 更新本地扩展字段内容
        /// </summary>
        /// <param name="msgId">消息Id</param>
        /// <param name="localExt">消息本地扩展字段内容</param>
        /// <param name="cb">操作结果的回调函数</param>
        public static void UpdateLocalExt(string msgId, string localExt, UpdateLocalExtDelegate cb)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(cb);

            MsglogNativeMethods.nim_msglog_update_localext_async(msgId, localExt, null, OnUpdateLocalExtCompleted, ptr);
        }
Example #28
0
        /// <summary>
        /// 删除指定会话类型的所有消息
        /// </summary>
        /// <param name="sType">会话类型</param>
        /// <param name="deleteSessions">是否删除指定会话类型的所有会话列表项</param>
        /// <param name="action"></param>
        public static void DeleteMsglogsBySessionType(NIMSessionType sType, bool deleteSessions, OperateMsglogResultDelegate action)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_delete_by_session_type_async(deleteSessions, sType, null, OperateMsglogByObjIdCompleted, ptr);
        }
Example #29
0
        /// <summary>
        /// 查询本地消息(按时间逆序起查,逆序排列)
        /// </summary>
        /// <param name="accountId">会话id,对方的account id或者群组tid</param>
        /// <param name="sType">会话类型</param>
        /// <param name="limit">一次查询数量,建议20</param>
        /// <param name="lastTimetag">上次查询最后一条消息的时间戳(按时间逆序起查,即最小的时间戳)</param>
        /// <param name="action"></param>
        public static void QueryMsglogLocally(string accountId, Session.NIMSessionType sType, int limit, long lastTimetag, QueryMsglogResultDelegate action)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_query_msg_async(accountId, sType, limit, lastTimetag, null, QueryLogCompleted, ptr);
        }
Example #30
0
        /// <summary>
        /// 删除指定一条消息
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="sType"></param>
        /// <param name="msgId"></param>
        /// <param name="action"></param>
        public static void DeleteSpecifiedMsglog(string sid, NIMSessionType sType, string msgId, OperateSingleLogResultDelegate action)
        {
            var ptr = NimUtility.DelegateConverter.ConvertToIntPtr(action);

            MsglogNativeMethods.nim_msglog_delete_async(sid, sType, msgId, null, OperateMsglogByLogIdCompleted, ptr);
        }