mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-03 23:58:19 +00:00
update attachment message upload failed refresh msg listener
This commit is contained in:
parent
d4d1dc8b3d
commit
2e1f27c781
@ -6,6 +6,8 @@ import static com.xinbida.wukongim.db.WKDBColumns.TABLE.messageExtra;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.xinbida.wukongim.WKIM;
|
||||
@ -158,7 +160,7 @@ public class MsgDbManager {
|
||||
if (!isSyncMsg) {
|
||||
if (minMessageSeq == 1) {
|
||||
requestCount = 0;
|
||||
iGetOrSyncHistoryMsgBack.onResult(list);
|
||||
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -172,7 +174,7 @@ public class MsgDbManager {
|
||||
|
||||
if (isSyncMsg && startMsgSeq != endMsgSeq && requestCount < 5) {
|
||||
if (requestCount == 0) {
|
||||
iGetOrSyncHistoryMsgBack.onSyncing();
|
||||
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onSyncing());
|
||||
}
|
||||
//同步消息
|
||||
requestCount++;
|
||||
@ -181,12 +183,12 @@ public class MsgDbManager {
|
||||
queryOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit, iGetOrSyncHistoryMsgBack);
|
||||
} else {
|
||||
requestCount = 0;
|
||||
iGetOrSyncHistoryMsgBack.onResult(list);
|
||||
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
requestCount = 0;
|
||||
iGetOrSyncHistoryMsgBack.onResult(list);
|
||||
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1384,8 +1386,10 @@ public class MsgDbManager {
|
||||
.update(message, updateKey, updateValue, where, whereValue);
|
||||
if (row > 0) {
|
||||
WKMsg msg = queryWithClientSeq(client_seq);
|
||||
if (msg != null)
|
||||
if (msg != null) {
|
||||
msg.status = status;
|
||||
WKIM.getInstance().getMsgManager().setRefreshMsg(msg, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,6 @@ public class MsgManager extends BaseManager {
|
||||
* @param channelId 频道ID
|
||||
* @param channelType 频道类型
|
||||
* @param oldestOrderSeq 最后一次消息大orderSeq 第一次进入聊天传入0
|
||||
* @param channelMaxMsgSeq 当前channel最大消息的seq,可传0
|
||||
* @param contain 是否包含 oldestOrderSeq 这条消息
|
||||
* @param pullMode 拉取模式 0:向下拉取 1:向上拉取
|
||||
* @param aroundMsgOrderSeq 查询此消息附近消息
|
||||
@ -292,41 +291,49 @@ public class MsgManager extends BaseManager {
|
||||
* @param iGetOrSyncHistoryMsgBack 请求返还
|
||||
*/
|
||||
public void getOrSyncHistoryMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, int pullMode, int limit, long aroundMsgOrderSeq, final IGetOrSyncHistoryMsgBack iGetOrSyncHistoryMsgBack) {
|
||||
if (aroundMsgOrderSeq != 0) {
|
||||
long maxMsgSeq = getMaxMessageSeqWithChannel(channelId, channelType);
|
||||
long aroundMsgSeq = getOrNearbyMsgSeq(aroundMsgOrderSeq);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int tempPullMode = pullMode;
|
||||
long tempOldestOrderSeq = oldestOrderSeq;
|
||||
boolean tempContain = contain;
|
||||
if (aroundMsgOrderSeq != 0) {
|
||||
long maxMsgSeq = getMaxMessageSeqWithChannel(channelId, channelType);
|
||||
long aroundMsgSeq = getOrNearbyMsgSeq(aroundMsgOrderSeq);
|
||||
|
||||
if (maxMsgSeq >= aroundMsgSeq && maxMsgSeq - aroundMsgSeq <= limit) {
|
||||
// 显示最后一页数据
|
||||
if (maxMsgSeq >= aroundMsgSeq && maxMsgSeq - aroundMsgSeq <= limit) {
|
||||
// 显示最后一页数据
|
||||
// oldestOrderSeq = 0;
|
||||
oldestOrderSeq = getMessageOrderSeq(maxMsgSeq, channelId, channelType);
|
||||
contain = true;
|
||||
pullMode = 0;
|
||||
} else {
|
||||
long minOrderSeq = MsgDbManager.getInstance().queryOrderSeq(channelId, channelType, aroundMsgOrderSeq, 3);
|
||||
if (minOrderSeq == 0) {
|
||||
oldestOrderSeq = aroundMsgOrderSeq;
|
||||
} else {
|
||||
if (minOrderSeq + limit < aroundMsgOrderSeq) {
|
||||
if (aroundMsgOrderSeq % wkOrderSeqFactor == 0) {
|
||||
oldestOrderSeq = (aroundMsgOrderSeq / wkOrderSeqFactor - 3) * wkOrderSeqFactor;
|
||||
} else
|
||||
oldestOrderSeq = aroundMsgOrderSeq - 3;
|
||||
// oldestOrderSeq = aroundMsgOrderSeq;
|
||||
tempOldestOrderSeq = getMessageOrderSeq(maxMsgSeq, channelId, channelType);
|
||||
tempContain = true;
|
||||
tempPullMode = 0;
|
||||
} else {
|
||||
// todo 这里只会查询3条数据 oldestOrderSeq = minOrderSeq
|
||||
long startOrderSeq = MsgDbManager.getInstance().queryOrderSeq(channelId, channelType, aroundMsgOrderSeq, limit);
|
||||
if (startOrderSeq == 0) {
|
||||
oldestOrderSeq = aroundMsgOrderSeq;
|
||||
} else
|
||||
oldestOrderSeq = startOrderSeq;
|
||||
long minOrderSeq = MsgDbManager.getInstance().queryOrderSeq(channelId, channelType, aroundMsgOrderSeq, 3);
|
||||
if (minOrderSeq == 0) {
|
||||
tempOldestOrderSeq = aroundMsgOrderSeq;
|
||||
} else {
|
||||
if (minOrderSeq + limit < aroundMsgOrderSeq) {
|
||||
if (aroundMsgOrderSeq % wkOrderSeqFactor == 0) {
|
||||
tempOldestOrderSeq = (aroundMsgOrderSeq / wkOrderSeqFactor - 3) * wkOrderSeqFactor;
|
||||
} else
|
||||
tempOldestOrderSeq = aroundMsgOrderSeq - 3;
|
||||
// oldestOrderSeq = aroundMsgOrderSeq;
|
||||
} else {
|
||||
// todo 这里只会查询3条数据 oldestOrderSeq = minOrderSeq
|
||||
long startOrderSeq = MsgDbManager.getInstance().queryOrderSeq(channelId, channelType, aroundMsgOrderSeq, limit);
|
||||
if (startOrderSeq == 0) {
|
||||
tempOldestOrderSeq = aroundMsgOrderSeq;
|
||||
} else
|
||||
tempOldestOrderSeq = startOrderSeq;
|
||||
}
|
||||
}
|
||||
tempPullMode = 1;
|
||||
tempContain = true;
|
||||
}
|
||||
}
|
||||
pullMode = 1;
|
||||
contain = true;
|
||||
MsgDbManager.getInstance().queryOrSyncHistoryMessages(channelId, channelType, tempOldestOrderSeq, tempContain, tempPullMode, limit, iGetOrSyncHistoryMsgBack);
|
||||
}
|
||||
}
|
||||
MsgDbManager.getInstance().queryOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit, iGetOrSyncHistoryMsgBack);
|
||||
}).start();
|
||||
}
|
||||
|
||||
public List<WKMsg> getAll() {
|
||||
|
@ -11,9 +11,11 @@ import com.xinbida.wukongim.WKIMApplication;
|
||||
import com.xinbida.wukongim.db.MsgDbManager;
|
||||
import com.xinbida.wukongim.entity.WKChannel;
|
||||
import com.xinbida.wukongim.entity.WKChannelType;
|
||||
import com.xinbida.wukongim.entity.WKConversationMsgExtra;
|
||||
import com.xinbida.wukongim.entity.WKMsg;
|
||||
import com.xinbida.wukongim.entity.WKMsgSetting;
|
||||
import com.xinbida.wukongim.entity.WKSyncMsgMode;
|
||||
import com.xinbida.wukongim.entity.WKUIConversationMsg;
|
||||
import com.xinbida.wukongim.interfaces.IReceivedMsgListener;
|
||||
import com.xinbida.wukongim.manager.ConnectionManager;
|
||||
import com.xinbida.wukongim.message.type.WKConnectReason;
|
||||
@ -23,11 +25,11 @@ import com.xinbida.wukongim.message.type.WKSendMsgResult;
|
||||
import com.xinbida.wukongim.message.type.WKSendingMsg;
|
||||
import com.xinbida.wukongim.msgmodel.WKImageContent;
|
||||
import com.xinbida.wukongim.msgmodel.WKMediaMessageContent;
|
||||
import com.xinbida.wukongim.msgmodel.WKMessageContent;
|
||||
import com.xinbida.wukongim.msgmodel.WKVideoContent;
|
||||
import com.xinbida.wukongim.protocol.WKBaseMsg;
|
||||
import com.xinbida.wukongim.protocol.WKConnectMsg;
|
||||
import com.xinbida.wukongim.protocol.WKDisconnectMsg;
|
||||
import com.xinbida.wukongim.msgmodel.WKMessageContent;
|
||||
import com.xinbida.wukongim.protocol.WKPingMsg;
|
||||
import com.xinbida.wukongim.protocol.WKPongMsg;
|
||||
import com.xinbida.wukongim.protocol.WKSendAckMsg;
|
||||
@ -35,6 +37,7 @@ import com.xinbida.wukongim.protocol.WKSendMsg;
|
||||
import com.xinbida.wukongim.utils.DateUtils;
|
||||
import com.xinbida.wukongim.utils.WKLoggerUtils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.xsocket.connection.IConnection;
|
||||
import org.xsocket.connection.INonBlockingConnection;
|
||||
import org.xsocket.connection.NonBlockingConnection;
|
||||
@ -420,9 +423,7 @@ public class WKConnection {
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//视频消息
|
||||
if (msg.baseContentMsgModel instanceof WKVideoContent) {
|
||||
@ -445,10 +446,11 @@ public class WKConnection {
|
||||
}
|
||||
|
||||
}
|
||||
WKBaseMsg base = WKProto.getInstance().getSendBaseMsg(msg);
|
||||
if (base != null && msg.clientSeq != 0) {
|
||||
msg.clientSeq = ((WKSendMsg) base).clientSeq;
|
||||
}
|
||||
saveSendMsg(msg);
|
||||
WKSendMsg sendMsg = WKProto.getInstance().getSendBaseMsg(msg);
|
||||
// if (base != null && msg.clientSeq == 0) {
|
||||
// msg.clientSeq = base.clientSeq;
|
||||
// }
|
||||
|
||||
if (WKMediaMessageContent.class.isAssignableFrom(msg.baseContentMsgModel.getClass())) {
|
||||
//如果是多媒体消息类型说明存在附件
|
||||
@ -467,10 +469,10 @@ public class WKConnection {
|
||||
hasAttached = true;
|
||||
}
|
||||
}
|
||||
if (hasAttached) {
|
||||
msg.content = msg.baseContentMsgModel.encodeMsg().toString();
|
||||
MsgDbManager.getInstance().insert(msg);
|
||||
}
|
||||
// if (hasAttached) {
|
||||
// msg.content = msg.baseContentMsgModel.encodeMsg().toString();
|
||||
// MsgDbManager.getInstance().insert(msg);
|
||||
// }
|
||||
}
|
||||
//获取发送者信息
|
||||
WKChannel from = WKIM.getInstance().getChannelManager().getChannel(WKIMApplication.getInstance().getUid(), WKChannelType.PERSONAL);
|
||||
@ -487,21 +489,20 @@ public class WKConnection {
|
||||
if (isSuccess) {
|
||||
if (!sendingMsgHashMap.containsKey((int) msg.clientSeq)) {
|
||||
msg.baseContentMsgModel = messageContent;
|
||||
WKBaseMsg base1 = WKProto.getInstance().getSendBaseMsg(msg);
|
||||
addSendingMsg((WKSendMsg) base1);
|
||||
WKSendMsg base1 = WKProto.getInstance().getSendBaseMsg(msg);
|
||||
addSendingMsg(base1);
|
||||
sendMessage(base1);
|
||||
}
|
||||
} else {
|
||||
msg.status = WKSendMsgResult.send_fail;
|
||||
MsgDbManager.getInstance().updateMsgStatus(msg.clientSeq, msg.status);
|
||||
MsgDbManager.getInstance().updateMsgStatus(msg.clientSeq, WKSendMsgResult.send_fail);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (base != null) {
|
||||
if (sendMsg != null) {
|
||||
if (msg.header != null && !msg.header.noPersist) {
|
||||
addSendingMsg((WKSendMsg) base);
|
||||
addSendingMsg(sendMsg);
|
||||
}
|
||||
sendMessage(base);
|
||||
sendMessage(sendMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -569,4 +570,28 @@ public class WKConnection {
|
||||
}
|
||||
}, 500, 1000L);
|
||||
}
|
||||
|
||||
private WKMsg saveSendMsg(WKMsg msg) {
|
||||
if (msg.setting == null) msg.setting = new WKMsgSetting();
|
||||
JSONObject jsonObject = WKProto.getInstance().getSendPayload(msg);
|
||||
msg.content = jsonObject.toString();
|
||||
long tempOrderSeq = MsgDbManager.getInstance().queryMaxOrderSeqWithChannel(msg.channelID, msg.channelType);
|
||||
msg.orderSeq = tempOrderSeq + 1;
|
||||
// 需要存储的消息入库后更改消息的clientSeq
|
||||
if (!msg.header.noPersist) {
|
||||
msg.clientSeq = (int) MsgDbManager.getInstance().insert(msg);
|
||||
if (msg.clientSeq > 0) {
|
||||
WKUIConversationMsg uiMsg = WKIM.getInstance().getConversationManager().updateWithWKMsg(msg);
|
||||
if (uiMsg != null) {
|
||||
long browseTo = WKIM.getInstance().getMsgManager().getMaxMessageSeqWithChannel(uiMsg.channelID, uiMsg.channelType);
|
||||
if (uiMsg.getRemoteMsgExtra() == null) {
|
||||
uiMsg.setRemoteMsgExtra(new WKConversationMsgExtra());
|
||||
}
|
||||
uiMsg.getRemoteMsgExtra().browseTo = browseTo;
|
||||
WKIM.getInstance().getConversationManager().setOnRefreshMsg(uiMsg, true, "getSendBaseMsg");
|
||||
}
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,8 @@ import android.text.TextUtils;
|
||||
|
||||
import com.xinbida.wukongim.WKIM;
|
||||
import com.xinbida.wukongim.WKIMApplication;
|
||||
import com.xinbida.wukongim.db.MsgDbManager;
|
||||
import com.xinbida.wukongim.db.WKDBColumns;
|
||||
import com.xinbida.wukongim.entity.WKConversationMsgExtra;
|
||||
import com.xinbida.wukongim.entity.WKMsg;
|
||||
import com.xinbida.wukongim.entity.WKMsgSetting;
|
||||
import com.xinbida.wukongim.entity.WKUIConversationMsg;
|
||||
import com.xinbida.wukongim.message.type.WKMsgType;
|
||||
import com.xinbida.wukongim.message.type.WKSendMsgResult;
|
||||
import com.xinbida.wukongim.msgmodel.WKMediaMessageContent;
|
||||
@ -258,14 +254,7 @@ class WKProto {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取发送的消息
|
||||
*
|
||||
* @param msg 本地消息
|
||||
* @return 网络消息
|
||||
*/
|
||||
WKBaseMsg getSendBaseMsg(WKMsg msg) {
|
||||
//发送消息
|
||||
JSONObject getSendPayload(WKMsg msg) {
|
||||
JSONObject jsonObject = null;
|
||||
if (msg.baseContentMsgModel != null) {
|
||||
jsonObject = msg.baseContentMsgModel.encodeMsg();
|
||||
@ -274,9 +263,6 @@ class WKProto {
|
||||
}
|
||||
try {
|
||||
if (jsonObject == null) jsonObject = new JSONObject();
|
||||
if (!jsonObject.has(WKDBColumns.WKMessageColumns.from_uid)) {
|
||||
jsonObject.put(WKDBColumns.WKMessageColumns.from_uid, WKIMApplication.getInstance().getUid());
|
||||
}
|
||||
jsonObject.put(WKDBColumns.WKMessageColumns.type, msg.type);
|
||||
//判断@情况
|
||||
if (msg.baseContentMsgModel.mentionInfo != null
|
||||
@ -327,6 +313,18 @@ class WKProto {
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取发送的消息
|
||||
*
|
||||
* @param msg 本地消息
|
||||
* @return 网络消息
|
||||
*/
|
||||
WKSendMsg getSendBaseMsg(WKMsg msg) {
|
||||
//发送消息
|
||||
JSONObject jsonObject = getSendPayload(msg);
|
||||
WKSendMsg sendMsg = new WKSendMsg();
|
||||
// 默认先设置clientSeq,因为有可能本条消息并不需要入库,UI上自己设置了clientSeq
|
||||
sendMsg.clientSeq = (int) msg.clientSeq;
|
||||
@ -337,27 +335,8 @@ class WKProto {
|
||||
sendMsg.channelId = msg.channelID;
|
||||
sendMsg.channelType = msg.channelType;
|
||||
sendMsg.topicID = msg.topicID;
|
||||
if (msg.setting == null) msg.setting = new WKMsgSetting();
|
||||
sendMsg.setting = msg.setting;
|
||||
msg.content = jsonObject.toString();
|
||||
long tempOrderSeq = MsgDbManager.getInstance().queryMaxOrderSeqWithChannel(msg.channelID, msg.channelType);
|
||||
msg.orderSeq = tempOrderSeq + 1;
|
||||
// 需要存储的消息入库后更改消息的clientSeq
|
||||
if (!sendMsg.no_persist) {
|
||||
sendMsg.clientSeq = (int) (msg.clientSeq = (int) MsgDbManager.getInstance().insert(msg));
|
||||
if (msg.clientSeq > 0) {
|
||||
// 2022/4/27
|
||||
WKUIConversationMsg uiMsg = WKIM.getInstance().getConversationManager().updateWithWKMsg(msg);
|
||||
if (uiMsg != null) {
|
||||
long browseTo = WKIM.getInstance().getMsgManager().getMaxMessageSeqWithChannel(uiMsg.channelID, uiMsg.channelType);
|
||||
if (uiMsg.getRemoteMsgExtra() == null) {
|
||||
uiMsg.setRemoteMsgExtra(new WKConversationMsgExtra());
|
||||
}
|
||||
uiMsg.getRemoteMsgExtra().browseTo = browseTo;
|
||||
WKIM.getInstance().getConversationManager().setOnRefreshMsg(uiMsg, true, "getSendBaseMsg");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (WKMediaMessageContent.class.isAssignableFrom(msg.baseContentMsgModel.getClass())) {
|
||||
//多媒体数据
|
||||
if (jsonObject.has("localPath")) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user