JMessage.retractMessage


(绝伦独舞) #24

好了,可以了 谢谢


(绝伦独舞) #25

撤回成功。但是只要发出了撤回指令,页面回退重新进入此页面app会闪退。报的依然是我上面的错误。我只有把历史消息的获取api注释才好用。
175/com.merchant E/unknown:React: Exception in native call
java.lang.NullPointerException: Attempt to invoke interface method ‘java.lang.String com.facebook.react.bridge.ReadableMap.getString(java.lang.String)’ on a null object reference
at cn.jiguang.imui.messagelist.AuroraIMUIModule.configMessage(AuroraIMUIModule.java:139)
at cn.jiguang.imui.messagelist.AuroraIMUIModule.insertMessagesToTop(AuroraIMUIModule.java:126)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:368)
at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:138)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:179)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:208)
at java.lang.Thread.run(Thread.java:818)


(绝伦独舞) #26

at cn.jiguang.imui.messagelist.AuroraIMUIModule.configMessage(AuroraIMUIModule.java:139)
这是它的定位
private RCTMessage configMessage(ReadableMap message) {
Log.d(“AuroraIMUIModule”, "configure message: " + message);
RCTMessage rctMsg = new RCTMessage(message.getString(RCTMessage.MSG_ID),
message.getString(RCTMessage.STATUS), message.getString(RCTMessage.MSG_TYPE),
message.getBoolean(RCTMessage.IS_OUTGOING));
switch (rctMsg.getType()) {
case 5:
case 6:。。。。
at cn.jiguang.imui.messagelist.AuroraIMUIModule.insertMessagesToTop(AuroraIMUIModule.java:126)
这是它的定位
@ReactMethod
public void insertMessagesToTop(ReadableArray messages) {
RCTMessage[] rctMessages = new RCTMessage[messages.size()];
for (int i = 0; i < messages.size(); i++) {
RCTMessage rctMessage = configMessage(messages.getMap(i));
rctMessages[i] = rctMessage;
}
EventBus.getDefault().post(new MessageEvent(rctMessages, ReactMsgListManager.RCT_INSERT_MESSAGES_ACTION));
}


(Josh Lipan) #27

可以贴一下你写的这块代码。
这个错误就是插入了不适配 IMUI 的消息,有些字段IMUI获取为null,从你的表述看,你并没有对撤回的消息适配成 IMUI 可以处理的消息,而是像上个问题一样直接插入了 jmessage 获取到的消息对象。


(绝伦独舞) #28

JMessage.retractMessage(msg, (success) => {
console.warn(JSON.stringify(success))
var eventMsg = {};
eventMsg.msgId = message.msgId;
eventMsg.msgType = “event”;
eventMsg.text = “你撤回了一条消息”;
eventMsg.appKey = “”;
eventMsg.username = “admin”;
eventMsg.type = “single”;
eventMsg.status = “send_going”;
eventMsg.isOutgoing = true;
eventMsg.timeString = dayjs().format(‘HH:mm’);
eventMsg.from=message.fromUser
AuroraIMUIController.updateMessage(eventMsg)
}, (error) => {
console.warn(JSON.stringify(error))

    }); @JoshLipan

这是历史消息的获取
JMessage.getHistoryMessages(parames, (messages) => {
// Alert.alert(‘messages’,JSON.stringify(messages))
console.warn(JSON.stringify(messages));
this.setState({
from: this.state.from + 10
});
var auroraMessages = messages.map((message) => {
var normalMessage = this.convertJMessageToAuroraMsgH(message);
if (normalMessage.msgType === “unknow”) {
return
}
return normalMessage
});
// AuroraIMUIController.insertMessagesToTop(auroraMessages)


(Josh Lipan) #29

这个拿到的数据是什么,打印出来看下


(绝伦独舞) #30

www[{“msgType”:“text”,“msgId”:“1”,“text”:“哈哈”,“fromUser”:{“userId”:“admin”,“displayName”:“admin”,“avatarPath”:"/data/user/0/com.merchant/files/images/small-avatar/158EDE8D029DA2FFFBC53ABC175A4DF8"},“status”:“send_succeed”,“isOutgoing”:false,“timeString”:“15:52”},null,{“msgType”:“text”,“msgId”:“3”,“text”:“你好”,“fromUser”:{“userId”:“merchant”,“displayName”:“merchant”,“avatarPath”:"/data/user/0/com.merchant/files/images/small-avatar/0F8F9EED0E55757C595DAB1AD23E4E6B"},“status”:“send_succeed”,“isOutgoing”:true,“timeString”:“15:56”},null,{“msgType”:“text”,“msgId”:“5”,“text”:“呵呵”,“fromUser”:{“userId”:“merchant”,“displayName”:“merchant”,“avatarPath”:"/data/user/0/com.merchant/files/images/small-avatar/0F8F9EED0E55757C595DAB1AD23E4E6B"},“status”:“send_succeed”,“isOutgoing”:true,“timeString”:“16:00”},null,null,null]
最后面果然三个null…这是为什么呢 。。。 @JoshLipan


(绝伦独舞) #32

我知道了 撤回的消息都变成null了, IMUI 处理不了null字段的消息。那应该怎么处理呢 我把这些nu ll变成“”行吗


(绝伦独舞) #33

JMessage.retractMessage 感觉这条消息撤回之后 直接就变成null了 我updateMessage的时候都是正确的格式,可是到了auroraMessages打印的时候刚才撤回的消息就变成null了


(绝伦独舞) #34

// if (normalMessage.msgType === “unknow”) {
// return
// }

是这句话 让撤回的消息变成了null 我注释了就好了 但是 那条消息直接变成了 asdf


(绝伦独舞) #35

因为只要是撤回 msgType 都变成了 “unknow” 这是为什么呢 @JoshLipan 大佬


(Josh Lipan) #36

你如果不显示撤回消息,直接去掉这几个model就好了;
如果要显示,你要适配成 IMUI 的消息类型啊,比如你上面执行撤回消息后适配的 IMUI 的 event 类型


(Josh Lipan) #37

Jmessage 和 IMUI 是分开的两个控件,两个是没有联系的;
就像你用其他的 IM SDK 也要适配成 IMUI 能显示的消息类型


(绝伦独舞) #38

JMessage.retractMessage(msg, (success) => {
var eventMsg = {};
eventMsg.type = “event”;
eventMsg.id = message.msgId;
eventMsg.eventType = “你撤回了一条消息”;
var a={}
a.username=message.fromUser.userId;
a.nickname=message.fromUser.displayName;
a.avatarThumbPath=message.fromUser.avatarPath;
eventMsg.from=a;
var msg = this.convertJMessageToAuroraMsg(eventMsg);
AuroraIMUIController.updateMessage(msg)
}, (error) => {
console.warn(JSON.stringify(error))

    });

我已经适配了呀。。但是获取历史消息只要是event msgType就unknow …这样还不可以吗 可以帮着看眼吗 emmm @JoshLipan


(Josh Lipan) #39

你这里适配的是撤回动作更新当前的 IMUI 显示。
第二次进入页面,你获取历史消息也要重新适配啊,你适配了最后插入 IMUI 还是 null,说明你适配逻辑不对啊,好好检查下!


(绝伦独舞) #40

好的。但是我获取历史消息的时候打印的messages 里面msgType就已经是是unknown了 难道我只要看到unknow就把msgType的类型变为event吗?这样不合理吧。。。。总感觉后台没没有合配上

JMessage.getHistoryMessages(parames, (messages) => {
               console.warn("messages"+JSON.stringify(messages));
                var auroraMessages = messages.map((message) => {
                    var normalMessage = this.convertJMessageToAuroraMsgH(message);
                    // if (normalMessage.msgType === "unknow") {
                    //     return
                    // }
                    return normalMessage

                });
                AuroraIMUIController.insertMessagesToTop(auroraMessages)
            }, (error) => {
                Alert.alert('error!', JSON.stringify(error))
            });

@JoshLipan


(Josh Lipan) #41

获取到的 messages 数据打印看下


(绝伦独舞) #42
   messages[{
			"type": "unknow",
			"unreceiptCount": 0,
			"createTime": 1543453779670,
			"target": {
				"isFriend": false,
				"isInBlackList": false,
				"isNoDisturb": false,
				"noteName": "",
				"type": "user",
				"username": "admin",
				"noteText": "",
				"region": "",
				"appKey": "",
				"nickname": "",
				"gender": "unknown",
				"address": "",
				"avatarThumbPath": "/data/user/0/com.merchant/files/images/small-avatar/81E2C9274601D4A4F3DFD8A748F428E9",
				"birthday": 0,
				"signature": ""
			},
			"from": {
				"isFriend": false,
				"isInBlackList": false,
				"isNoDisturb": false,
				"noteName": "",
				"type": "user",
				"username": "merchant",
				"noteText": "",
				"region": "",
				"appKey": "",
				"nickname": "",
				"gender": "unknown",
				"address": "",
				"avatarThumbPath": "/data/user/0/com.merchant/files/images/small-avatar/78BCB2BB7B7044171B397A8980C0430C",
				"birthday": 0,
				"signature": ""
			},
			"serverMessageId": "2117315242",
			"id": "8"
		}, {
			"type": "unknow",
			"unreceiptCount": 0,
			"createTime": 1543453925754,
			"target": {
				"isFriend": false,
				"isInBlackList": false,
				"isNoDisturb": false,
				"noteName": "",
				"type": "user",
				"username": "admin",
				"noteText": "",
				"region": "",
				"appKey": "",
				"nickname": "",
				"gender": "unknown",
				"address": "",
				"avatarThumbPath": "/data/user/0/com.merchant/files/images/small-avatar/81E2C9274601D4A4F3DFD8A748F428E9",
				"birthday": 0,
				"signature": ""
			},
			"from": {
				"isFriend": false,
				"isInBlackList": false,
				"isNoDisturb": false,
				"noteName": "",
				"type": "user",
				"username": "merchant",
				"noteText": "",
				"region": "",
				"appKey": "",
				"nickname": "",
				"gender": "unknown",
				"address": "",
				"avatarThumbPath": "/data/user/0/com.merchant/files/images/small-avatar/78BCB2BB7B7044171B397A8980C0430C",
				"birthday": 0,
				"signature": ""
			},
			"serverMessageId": "2115414073",
			"id": "9"
		},
		 ]

@JoshLipan


(Josh Lipan) #43

被撤回的消息消息类型就是 unknown


(绝伦独舞) #44

这样啊。。。那我知道了 :joy: