Modify the issue where sending failed messages cannot be displayed

This commit is contained in:
SL 2023-10-27 21:33:55 +08:00
parent c038944238
commit 922f23abe2
4 changed files with 106 additions and 42 deletions

View File

@ -25,6 +25,7 @@ import com.xinbida.wukongim.interfaces.IGetOrSyncHistoryMsgBack;
import com.xinbida.wukongim.manager.MsgManager; import com.xinbida.wukongim.manager.MsgManager;
import com.xinbida.wukongim.message.type.WKSendMsgResult; import com.xinbida.wukongim.message.type.WKSendMsgResult;
import com.xinbida.wukongim.msgmodel.WKMessageContent; import com.xinbida.wukongim.msgmodel.WKMessageContent;
import com.xinbida.wukongim.utils.WKLoggerUtils;
import com.xinbida.wukongim.utils.WKTypeUtils; import com.xinbida.wukongim.utils.WKTypeUtils;
import org.json.JSONException; import org.json.JSONException;
@ -516,7 +517,9 @@ public class MsgDbManager {
saveList.add(list.get(i)); saveList.add(list.get(i));
} }
List<String> clientMsgNos = new ArrayList<>(); List<String> clientMsgNos = new ArrayList<>();
List<String> msgIds = new ArrayList<>();
List<WKMsg> existMsgList = new ArrayList<>(); List<WKMsg> existMsgList = new ArrayList<>();
List<WKMsg> msgIdExistMsgList = new ArrayList<>();
for (int i = 0, size = saveList.size(); i < size; i++) { for (int i = 0, size = saveList.size(); i < size; i++) {
boolean isSave = WKIM.getInstance().getMsgManager().setMessageStoreBeforeIntercept(saveList.get(i)); boolean isSave = WKIM.getInstance().getMsgManager().setMessageStoreBeforeIntercept(saveList.get(i));
if (!isSave) { if (!isSave) {
@ -525,36 +528,78 @@ public class MsgDbManager {
if (saveList.get(i).setting == null) { if (saveList.get(i).setting == null) {
saveList.get(i).setting = new WKMsgSetting(); saveList.get(i).setting = new WKMsgSetting();
} }
if (msgIds.size() == 200) {
List<WKMsg> tempList = queryWithMsgIds(msgIds);
if (tempList != null && tempList.size() > 0) {
msgIdExistMsgList.addAll(tempList);
}
msgIds.clear();
}
if (clientMsgNos.size() == 200) { if (clientMsgNos.size() == 200) {
List<WKMsg> tempList = queryWithClientMsgNos(clientMsgNos); List<WKMsg> tempList = queryWithClientMsgNos(clientMsgNos);
if (tempList != null && tempList.size() > 0) if (tempList != null && tempList.size() > 0)
existMsgList.addAll(tempList); existMsgList.addAll(tempList);
clientMsgNos.clear(); clientMsgNos.clear();
} }
if (!TextUtils.isEmpty(saveList.get(i).messageID)) {
msgIds.add(saveList.get(i).messageID);
}
if (!TextUtils.isEmpty(saveList.get(i).clientMsgNO)) if (!TextUtils.isEmpty(saveList.get(i).clientMsgNO))
clientMsgNos.add(saveList.get(i).clientMsgNO); clientMsgNos.add(saveList.get(i).clientMsgNO);
} }
if (msgIds.size() > 0) {
List<WKMsg> tempList = queryWithMsgIds(msgIds);
if (tempList != null && tempList.size() > 0) {
msgIdExistMsgList.addAll(tempList);
}
msgIds.clear();
}
if (clientMsgNos.size() > 0) { if (clientMsgNos.size() > 0) {
List<WKMsg> tempList = queryWithClientMsgNos(clientMsgNos); List<WKMsg> tempList = queryWithClientMsgNos(clientMsgNos);
if (tempList != null && tempList.size() > 0) if (tempList != null && tempList.size() > 0) {
existMsgList.addAll(tempList); existMsgList.addAll(tempList);
}
clientMsgNos.clear(); clientMsgNos.clear();
} }
List<WKMsg> insertMsgList = new ArrayList<>();
for (WKMsg msg : saveList) { for (WKMsg msg : saveList) {
if (TextUtils.isEmpty(msg.clientMsgNO) || TextUtils.isEmpty(msg.messageID)) {
continue;
}
boolean isAdd = true;
for (WKMsg tempMsg : existMsgList) { for (WKMsg tempMsg : existMsgList) {
if (tempMsg != null && !TextUtils.isEmpty(tempMsg.clientMsgNO) if (tempMsg == null || TextUtils.isEmpty(tempMsg.clientMsgNO)) {
&& !TextUtils.isEmpty(msg.clientMsgNO) && tempMsg.clientMsgNO.equals(msg.clientMsgNO)) { continue;
}
if (tempMsg.clientMsgNO.equals(msg.clientMsgNO)) {
if (msg.isDeleted == tempMsg.isDeleted && tempMsg.isDeleted == 1) {
isAdd = false;
}
msg.isDeleted = 1; msg.isDeleted = 1;
msg.clientMsgNO = WKIM.getInstance().getMsgManager().createClientMsgNO(); msg.clientMsgNO = WKIM.getInstance().getMsgManager().createClientMsgNO();
break; break;
} }
} }
if (isAdd) {
for (WKMsg tempMsg : msgIdExistMsgList) {
if (tempMsg == null || TextUtils.isEmpty(tempMsg.messageID)) {
continue;
}
if (msg.messageID.equals(tempMsg.messageID)) {
isAdd = false;
break;
}
}
}
if (isAdd) {
insertMsgList.add(msg);
}
} }
// insertMsgList(saveList); // insertMsgList(insertMsgList);
List<ContentValues> cvList = new ArrayList<>(); List<ContentValues> cvList = new ArrayList<>();
for (WKMsg wkMsg : saveList) { for (WKMsg wkMsg : insertMsgList) {
WKLoggerUtils.getInstance().e("插入数据" + wkMsg.messageID);
ContentValues cv = WKSqlContentValues.getContentValuesWithMsg(wkMsg); ContentValues cv = WKSqlContentValues.getContentValuesWithMsg(wkMsg);
cvList.add(cv); cvList.add(cv);
} }
@ -1183,8 +1228,8 @@ public class MsgDbManager {
return orderSeq; return orderSeq;
} }
public int queryMaxMessageSeqNotDeletedWithChannel(String channelID,byte channelType){ public int queryMaxMessageSeqNotDeletedWithChannel(String channelID, byte channelType) {
String sql = "SELECT max(message_seq) message_seq FROM " + message + " WHERE channel_id='" + channelID + "' AND channel_type=" + channelType +" AND is_deleted=0"; String sql = "SELECT max(message_seq) message_seq FROM " + message + " WHERE channel_id='" + channelID + "' AND channel_type=" + channelType + " AND is_deleted=0";
int messageSeq = 0; int messageSeq = 0;
try (Cursor cursor = WKIMApplication try (Cursor cursor = WKIMApplication
.getInstance() .getInstance()
@ -1253,14 +1298,15 @@ public class MsgDbManager {
} }
public List<WKMsg> queryWithMsgIds(List<String> messageIds) { public List<WKMsg> queryWithMsgIds(List<String> messageIds) {
StringBuffer stringBuffer = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (int i = 0, size = messageIds.size(); i < size; i++) { for (int i = 0, size = messageIds.size(); i < size; i++) {
if (!TextUtils.isEmpty(stringBuffer)) { if (!TextUtils.isEmpty(sb)) {
stringBuffer.append(","); sb.append(",");
} }
stringBuffer.append(messageIds.get(i)); sb.append("'").append(messageIds.get(i)).append("'");
} }
String sql = "select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id where " + message + ".message_id in (" + stringBuffer + ")"; String sql = "select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id where " + message + ".message_id in (" + sb + ")";
WKLoggerUtils.getInstance().e("查询sql" + sql);
List<WKMsg> list = new ArrayList<>(); List<WKMsg> list = new ArrayList<>();
List<String> gChannelIds = new ArrayList<>(); List<String> gChannelIds = new ArrayList<>();
List<String> pChannelIds = new ArrayList<>(); List<String> pChannelIds = new ArrayList<>();

View File

@ -199,7 +199,6 @@ class MsgReactionDBManager {
WKMsgReaction reaction = new WKMsgReaction(); WKMsgReaction reaction = new WKMsgReaction();
reaction.channelID = WKCursor.readString(cursor, "channel_id"); reaction.channelID = WKCursor.readString(cursor, "channel_id");
reaction.channelType = (byte) WKCursor.readInt(cursor, "channel_type"); reaction.channelType = (byte) WKCursor.readInt(cursor, "channel_type");
reaction.isDeleted = WKCursor.readInt(cursor, "is_deleted");
reaction.uid = WKCursor.readString(cursor, "uid"); reaction.uid = WKCursor.readString(cursor, "uid");
reaction.name = WKCursor.readString(cursor, "name"); reaction.name = WKCursor.readString(cursor, "name");
reaction.messageID = WKCursor.readString(cursor, "message_id"); reaction.messageID = WKCursor.readString(cursor, "message_id");

View File

@ -40,6 +40,7 @@ import com.xinbida.wukongim.interfaces.IUploadAttachmentListener;
import com.xinbida.wukongim.interfaces.IUploadMsgExtraListener; import com.xinbida.wukongim.interfaces.IUploadMsgExtraListener;
import com.xinbida.wukongim.message.WKConnection; import com.xinbida.wukongim.message.WKConnection;
import com.xinbida.wukongim.message.MessageHandler; import com.xinbida.wukongim.message.MessageHandler;
import com.xinbida.wukongim.message.WKRead;
import com.xinbida.wukongim.message.type.WKMsgContentType; import com.xinbida.wukongim.message.type.WKMsgContentType;
import com.xinbida.wukongim.message.type.WKSendMsgResult; import com.xinbida.wukongim.message.type.WKSendMsgResult;
import com.xinbida.wukongim.msgmodel.WKImageContent; import com.xinbida.wukongim.msgmodel.WKImageContent;
@ -307,6 +308,9 @@ public class MsgManager extends BaseManager {
// 显示最后一页数据 // 显示最后一页数据
// oldestOrderSeq = 0; // oldestOrderSeq = 0;
tempOldestOrderSeq = getMessageOrderSeq(maxMsgSeq, channelId, channelType); tempOldestOrderSeq = getMessageOrderSeq(maxMsgSeq, channelId, channelType);
if (tempOldestOrderSeq < aroundMsgOrderSeq){
tempOldestOrderSeq = aroundMsgOrderSeq;
}
tempContain = true; tempContain = true;
tempPullMode = 0; tempPullMode = 0;
} else { } else {
@ -904,6 +908,7 @@ public class MsgManager extends BaseManager {
if (list == null || list.size() == 0) return; if (list == null || list.size() == 0) return;
List<WKMsg> msgList = new ArrayList<>(); List<WKMsg> msgList = new ArrayList<>();
List<WKMsgExtra> msgExtraList = new ArrayList<>(); List<WKMsgExtra> msgExtraList = new ArrayList<>();
List<WKMsgReaction> reactionList = new ArrayList<>();
for (int j = 0, len = list.size(); j < len; j++) { for (int j = 0, len = list.size(); j < len; j++) {
WKMsg wkMsg = WKSyncRecent2WKMsg(list.get(j)); WKMsg wkMsg = WKSyncRecent2WKMsg(list.get(j));
msgList.add(wkMsg); msgList.add(wkMsg);
@ -911,6 +916,9 @@ public class MsgManager extends BaseManager {
WKMsgExtra extra = WKSyncExtraMsg2WKMsgExtra(wkMsg.channelID, wkMsg.channelType, list.get(j).message_extra); WKMsgExtra extra = WKSyncExtraMsg2WKMsgExtra(wkMsg.channelID, wkMsg.channelType, list.get(j).message_extra);
msgExtraList.add(extra); msgExtraList.add(extra);
} }
if (wkMsg.reactionList != null && wkMsg.reactionList.size() > 0) {
reactionList.addAll(wkMsg.reactionList);
}
} }
if (msgExtraList.size() > 0) { if (msgExtraList.size() > 0) {
MsgDbManager.getInstance().insertOrUpdateMsgExtras(msgExtraList); MsgDbManager.getInstance().insertOrUpdateMsgExtras(msgExtraList);
@ -918,7 +926,9 @@ public class MsgManager extends BaseManager {
if (msgList.size() > 0) { if (msgList.size() > 0) {
MsgDbManager.getInstance().insertMsgs(msgList); MsgDbManager.getInstance().insertMsgs(msgList);
} }
if (reactionList.size() > 0) {
MsgDbManager.getInstance().insertMsgReactions(reactionList);
}
} }
public void addOnSendMsgAckListener(String key, ISendACK iSendACKListener) { public void addOnSendMsgAckListener(String key, ISendACK iSendACKListener) {

View File

@ -44,22 +44,26 @@ class ConnectionClient implements IDataHandler, IConnectHandler,
if (WKConnection.getInstance().connection == null) { if (WKConnection.getInstance().connection == null) {
Log.e("连接信息为空", "--->"); Log.e("连接信息为空", "--->");
} }
if (WKConnection.getInstance().connection != null && iNonBlockingConnection != null) { try {
if (!WKConnection.getInstance().connection.getId().equals(iNonBlockingConnection.getId())) { if (WKConnection.getInstance().connection != null && iNonBlockingConnection != null) {
close(iNonBlockingConnection); if (!WKConnection.getInstance().connection.getId().equals(iNonBlockingConnection.getId())) {
WKConnection.getInstance().forcedReconnection(); close(iNonBlockingConnection);
WKConnection.getInstance().forcedReconnection();
} else {
//连接成功
isConnectSuccess = true;
WKLoggerUtils.getInstance().e("连接成功");
WKConnection.getInstance().sendConnectMsg();
}
} else { } else {
//连接成功 close(iNonBlockingConnection);
isConnectSuccess = true; WKLoggerUtils.getInstance().e("连接成功连接对象为空");
WKLoggerUtils.getInstance().e("连接成功"); WKConnection.getInstance().forcedReconnection();
WKConnection.getInstance().sendConnectMsg();
} }
} else { } catch (Exception ignored) {
close(iNonBlockingConnection);
WKLoggerUtils.getInstance().e("连接成功连接对象为空");
WKConnection.getInstance().forcedReconnection();
} }
return false; return false;
} }
@Override @Override
@ -75,7 +79,7 @@ class ConnectionClient implements IDataHandler, IConnectHandler,
public boolean onData(INonBlockingConnection iNonBlockingConnection) throws BufferUnderflowException { public boolean onData(INonBlockingConnection iNonBlockingConnection) throws BufferUnderflowException {
Object id = iNonBlockingConnection.getAttachment(); Object id = iNonBlockingConnection.getAttachment();
if (id instanceof String) { if (id instanceof String) {
if (id.toString().startsWith("close")){ if (id.toString().startsWith("close")) {
return true; return true;
} }
if (!TextUtils.isEmpty(WKConnection.getInstance().socketSingleID) && !WKConnection.getInstance().socketSingleID.equals(id)) { if (!TextUtils.isEmpty(WKConnection.getInstance().socketSingleID) && !WKConnection.getInstance().socketSingleID.equals(id)) {
@ -129,23 +133,28 @@ class ConnectionClient implements IDataHandler, IConnectHandler,
@Override @Override
public boolean onDisconnect(INonBlockingConnection iNonBlockingConnection) { public boolean onDisconnect(INonBlockingConnection iNonBlockingConnection) {
WKLoggerUtils.getInstance().e("连接断开"); WKLoggerUtils.getInstance().e("连接断开");
if (iNonBlockingConnection != null && !TextUtils.isEmpty(iNonBlockingConnection.getId()) && iNonBlockingConnection.getAttachment() != null) { try {
String id = iNonBlockingConnection.getId(); if (iNonBlockingConnection != null && !TextUtils.isEmpty(iNonBlockingConnection.getId()) && iNonBlockingConnection.getAttachment() != null) {
Object attachmentObject = iNonBlockingConnection.getAttachment(); String id = iNonBlockingConnection.getId();
if (attachmentObject instanceof String) { Object attachmentObject = iNonBlockingConnection.getAttachment();
String att = (String) attachmentObject; if (attachmentObject instanceof String) {
String attStr = "close" + id; String att = (String) attachmentObject;
if (att.equals(attStr)) { String attStr = "close" + id;
return true; if (att.equals(attStr)) {
return true;
}
} }
} }
if (WKIMApplication.getInstance().isCanConnect) {
WKConnection.getInstance().forcedReconnection();
} else {
WKLoggerUtils.getInstance().e("不能重连-->");
}
close(iNonBlockingConnection);
} catch (Exception ignored) {
} }
if (WKIMApplication.getInstance().isCanConnect) {
WKConnection.getInstance().forcedReconnection();
} else {
WKLoggerUtils.getInstance().e("不能重连-->");
}
close(iNonBlockingConnection);
return true; return true;
} }