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.message.type.WKSendMsgResult;
import com.xinbida.wukongim.msgmodel.WKMessageContent;
import com.xinbida.wukongim.utils.WKLoggerUtils;
import com.xinbida.wukongim.utils.WKTypeUtils;
import org.json.JSONException;
@ -516,7 +517,9 @@ public class MsgDbManager {
saveList.add(list.get(i));
}
List<String> clientMsgNos = new ArrayList<>();
List<String> msgIds = new ArrayList<>();
List<WKMsg> existMsgList = new ArrayList<>();
List<WKMsg> msgIdExistMsgList = new ArrayList<>();
for (int i = 0, size = saveList.size(); i < size; i++) {
boolean isSave = WKIM.getInstance().getMsgManager().setMessageStoreBeforeIntercept(saveList.get(i));
if (!isSave) {
@ -525,36 +528,78 @@ public class MsgDbManager {
if (saveList.get(i).setting == null) {
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) {
List<WKMsg> tempList = queryWithClientMsgNos(clientMsgNos);
if (tempList != null && tempList.size() > 0)
existMsgList.addAll(tempList);
clientMsgNos.clear();
}
if (!TextUtils.isEmpty(saveList.get(i).messageID)) {
msgIds.add(saveList.get(i).messageID);
}
if (!TextUtils.isEmpty(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) {
List<WKMsg> tempList = queryWithClientMsgNos(clientMsgNos);
if (tempList != null && tempList.size() > 0)
if (tempList != null && tempList.size() > 0) {
existMsgList.addAll(tempList);
}
clientMsgNos.clear();
}
List<WKMsg> insertMsgList = new ArrayList<>();
for (WKMsg msg : saveList) {
if (TextUtils.isEmpty(msg.clientMsgNO) || TextUtils.isEmpty(msg.messageID)) {
continue;
}
boolean isAdd = true;
for (WKMsg tempMsg : existMsgList) {
if (tempMsg != null && !TextUtils.isEmpty(tempMsg.clientMsgNO)
&& !TextUtils.isEmpty(msg.clientMsgNO) && tempMsg.clientMsgNO.equals(msg.clientMsgNO)) {
if (tempMsg == null || TextUtils.isEmpty(tempMsg.clientMsgNO)) {
continue;
}
if (tempMsg.clientMsgNO.equals(msg.clientMsgNO)) {
if (msg.isDeleted == tempMsg.isDeleted && tempMsg.isDeleted == 1) {
isAdd = false;
}
msg.isDeleted = 1;
msg.clientMsgNO = WKIM.getInstance().getMsgManager().createClientMsgNO();
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<>();
for (WKMsg wkMsg : saveList) {
for (WKMsg wkMsg : insertMsgList) {
WKLoggerUtils.getInstance().e("插入数据" + wkMsg.messageID);
ContentValues cv = WKSqlContentValues.getContentValuesWithMsg(wkMsg);
cvList.add(cv);
}
@ -1183,8 +1228,8 @@ public class MsgDbManager {
return orderSeq;
}
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";
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";
int messageSeq = 0;
try (Cursor cursor = WKIMApplication
.getInstance()
@ -1253,14 +1298,15 @@ public class MsgDbManager {
}
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++) {
if (!TextUtils.isEmpty(stringBuffer)) {
stringBuffer.append(",");
if (!TextUtils.isEmpty(sb)) {
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<String> gChannelIds = new ArrayList<>();
List<String> pChannelIds = new ArrayList<>();

View File

@ -199,7 +199,6 @@ class MsgReactionDBManager {
WKMsgReaction reaction = new WKMsgReaction();
reaction.channelID = WKCursor.readString(cursor, "channel_id");
reaction.channelType = (byte) WKCursor.readInt(cursor, "channel_type");
reaction.isDeleted = WKCursor.readInt(cursor, "is_deleted");
reaction.uid = WKCursor.readString(cursor, "uid");
reaction.name = WKCursor.readString(cursor, "name");
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.message.WKConnection;
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.WKSendMsgResult;
import com.xinbida.wukongim.msgmodel.WKImageContent;
@ -307,6 +308,9 @@ public class MsgManager extends BaseManager {
// 显示最后一页数据
// oldestOrderSeq = 0;
tempOldestOrderSeq = getMessageOrderSeq(maxMsgSeq, channelId, channelType);
if (tempOldestOrderSeq < aroundMsgOrderSeq){
tempOldestOrderSeq = aroundMsgOrderSeq;
}
tempContain = true;
tempPullMode = 0;
} else {
@ -904,6 +908,7 @@ public class MsgManager extends BaseManager {
if (list == null || list.size() == 0) return;
List<WKMsg> msgList = new ArrayList<>();
List<WKMsgExtra> msgExtraList = new ArrayList<>();
List<WKMsgReaction> reactionList = new ArrayList<>();
for (int j = 0, len = list.size(); j < len; j++) {
WKMsg wkMsg = WKSyncRecent2WKMsg(list.get(j));
msgList.add(wkMsg);
@ -911,6 +916,9 @@ public class MsgManager extends BaseManager {
WKMsgExtra extra = WKSyncExtraMsg2WKMsgExtra(wkMsg.channelID, wkMsg.channelType, list.get(j).message_extra);
msgExtraList.add(extra);
}
if (wkMsg.reactionList != null && wkMsg.reactionList.size() > 0) {
reactionList.addAll(wkMsg.reactionList);
}
}
if (msgExtraList.size() > 0) {
MsgDbManager.getInstance().insertOrUpdateMsgExtras(msgExtraList);
@ -918,7 +926,9 @@ public class MsgManager extends BaseManager {
if (msgList.size() > 0) {
MsgDbManager.getInstance().insertMsgs(msgList);
}
if (reactionList.size() > 0) {
MsgDbManager.getInstance().insertMsgReactions(reactionList);
}
}
public void addOnSendMsgAckListener(String key, ISendACK iSendACKListener) {

View File

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