消息内容管理

更新时间:2024-12-26 07:54:57下载pdf

本文介绍如何管理消息内容。

查询指定类型的消息列表

更新消息时,获取指定类型的消息列表。

fun requestMessageListByType(
        offset: Int,
        limit: Int,
        msgType: MessageType,
        callback: IThingDataCallback<MessageListBean>?
    )

参数说明

参数 类型 说明
offset Int 开始获取消息位置
limit Int 每页获取的消息数量
msgType MessageType 获取的消息类型
callback IThingDataCallback<MessageListBean> 查询结果的回调

调用示例

PersonalMessageCore.newThingSmartMessageCore().requestMessageListByType(10, 20, MSG_REPORT, new IThingDataCallback<MessageListBean>() {
    @Override
    public void onSuccess(MessageListBean result) {
        mBeanResult.t.postValue(change(msgType, result, null));
        mBeanResult.networkState.postValue(NetworkState.SUCCESS);
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        mBeanResult.networkState.postValue(NetworkState.falied(errorCode,
                errorMessage));
    }
})

查询消息详情列表

fun getMsgListBySrcIdSplitEncryptImageKey(
        offset: Int,
        limit: Int,
        msgType: Int,
        msgSrcId: String?,
        encryptImage: Boolean,
        splitImageKey: Boolean,
        callback: IThingDataCallback<MessageListBean>?
    )

参数说明

参数 类型 说明
offset Int 开始获取消息位置
limit Int 每页获取的消息数量
msgType Int 获取的消息类型
msgSrcId String 消息组的唯一标识符
encryptImage Boolean 是否加密图片
splitImageKey Boolean 是否需要调用解密接口
callback IThingDataCallback<MessageListBean> 查询结果的回调

调用示例

PersonalMessageCore.newThingSmartMessageCore().getMsgListBySrcIdSplitEncryptImageKey(0, 0, 0, "id", true, true, 
         mMessageCore.requestMessageListByType(offset, limit, type, new IThingDataCallback<MessageListBean>() {
            @Override
            public void onSuccess(MessageListBean result) {
                mBeanResult.t.postValue(change(msgType, result, null));
                mBeanResult.networkState.postValue(NetworkState.SUCCESS);
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                mBeanResult.networkState.postValue(NetworkState.failed(errorCode, errorMessage));
            }
        });
)

查询是否有新消息

fun requestMessageNew(callback: IThingDataCallback<MessageHasNew?>?)

参数说明

参数 类型 说明
callback IThingDataCallback<MessageListBean> 查询结果的回调

调用示例

PersonalMessageCore.newThingSmartMessageCore().requestMessageNew(object : IThingDataCallback<MessageHasNew?> {
    override fun onSuccess(messageHasNew: MessageHasNew?) {
        if (messageHasNew != null) {
            val hasNew = (messageHasNew.isAlarm || messageHasNew.isFamily || messageHasNew.isNotification)
            ThingSecurityPreferenceGlobalUtil.set(
                PreferencesContants.MESSAGE_ALARM_HAS_NEW,
                messageHasNew.isAlarm
            )
            ThingSecurityPreferenceGlobalUtil.set(
                PreferencesContants.MESSAGE_FAMILY_HAS_NEW,
                messageHasNew.isFamily
            )
            ThingSecurityPreferenceGlobalUtil.set(
                PreferencesContants.MESSAGE_NOTIFICATION_HAS_NEW,
                messageHasNew.isNotification
            )
            resultSuccess(WHAT_REFRESH, hasNew)
        }
    }

    override fun onError(errorCode: String?, errorMessage: String?) {

    }
})

标记消息为已读

fun readMessageByIds(
        msgType: Int,
        msgSrcId: String?,
        callback: IThingDataCallback<Boolean>?
    )

参数说明

参数 类型 说明
msgType Int 获取的消息类型
msgSrcId String 消息组的唯一标识符
callback IThingDataCallback<MessageListBean> 查询结果的回调

调用示例

PersonalMessageCore.newThingSmartMessageCore().readMessageByIds(0, "msgSrcId", object : IThingDataCallback<Boolean> {
                override fun onSuccess(result: Boolean?) {
                }

                override fun onError(errorCode: String?, errorMessage: String?) {
                }
            })

删除消息

fun deleteMessageByIds(
        msgType: Int,
        idList: List<String>?,
        msgSrcIdList: List<String>?,
        callback: IBooleanCallback?
    )

参数说明

参数 类型 说明
msgType Int 获取的消息类型
idList List<String> 要删除的消息 ID
msgSrcIdList List<String> 要删除的消息来源 ID
callback IThingDataCallback<MessageListBean> 查询结果的回调

调用示例

PersonalMessageCore.newThingSmartMessageCore().deleteMessageByIds(0, "id1,id2,id3", "srcId1,srcId2,srcId3", new IBooleanCallback() {
    @Override
    public void onSuccess() {
        mDeleteBeanLiveData.networkState.postValue(NetworkState.SUCCESS);
        mDeleteBeanLiveData.t.postValue(true);
    }

    @Override
    public void onError(String code, String error) {
        mDeleteBeanLiveData.networkState.postValue(NetworkState.failed(code, error));
    }
})

获取加密消息的秘钥

fun getMessageEncryptImageKeyList(
        requestList: List<MessageEncryptImageKeyRequest>,
        callback: IThingDataCallback<List<MessageEncryptImageKeyBean>>
    )

参数说明

参数 类型 说明
requestList List<MessageEncryptImageKeyRequest> 消息加密图像密钥的请求列表
callback IThingDataCallback<List<MessageEncryptImageKeyBean>> 查询结果的回调

调用示例

PersonalMessageCore.newThingSmartMessageCore().getMessageEncryptImageKeyList(requestList,
    new IThingDataCallback<List<MessageEncryptImageKeyBean>>() {
        @Override
        public void onSuccess(List<MessageEncryptImageKeyBean> keyBeans) {
            mBeanResult.t.postValue(change(0, result, keyBeans));
            mBeanResult.networkState.postValue(NetworkState.SUCCESS);
        }

        @Override
        public void onError(String errorCode, String errorMessage) {
            mBeanResult.t.postValue(change(0, result, null));
            mBeanResult.networkState.postValue(NetworkState.SUCCESS);
        }
    })