update sync channel message api

This commit is contained in:
SL 2024-03-02 10:09:00 +08:00
parent 99d0a8bffd
commit c8483c4a62
4 changed files with 58 additions and 50 deletions

View File

@ -24,8 +24,6 @@ afterEvaluate {
android { android {
compileSdk 33 compileSdk 33
buildToolsVersion '33.0.2'
defaultConfig { defaultConfig {
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 33 targetSdkVersion 33

View File

@ -9,6 +9,7 @@ import android.database.Cursor;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.xinbida.wukongim.WKIM; import com.xinbida.wukongim.WKIM;
import com.xinbida.wukongim.WKIMApplication; import com.xinbida.wukongim.WKIMApplication;
@ -57,10 +58,16 @@ public class MsgDbManager {
} }
private int requestCount; private int requestCount;
private int more = 1;
public void queryOrSyncHistoryMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, int pullMode, int limit, final IGetOrSyncHistoryMsgBack iGetOrSyncHistoryMsgBack) { public void queryOrSyncHistoryMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, int pullMode, int limit, final IGetOrSyncHistoryMsgBack iGetOrSyncHistoryMsgBack) {
//获取原始数据 //获取原始数据
List<WKMsg> list = queryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit); List<WKMsg> list = queryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit);
if (more == 0) {
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list));
more = 1;
return;
}
//业务判断数据 //业务判断数据
List<WKMsg> tempList = new ArrayList<>(); List<WKMsg> tempList = new ArrayList<>();
for (int i = 0, size = list.size(); i < size; i++) { for (int i = 0, size = list.size(); i < size; i++) {
@ -164,6 +171,7 @@ public class MsgDbManager {
if (!isSyncMsg) { if (!isSyncMsg) {
if (minMessageSeq == 1) { if (minMessageSeq == 1) {
requestCount = 0; requestCount = 0;
more = 1;
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list)); new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list));
return; return;
} }
@ -187,18 +195,21 @@ public class MsgDbManager {
//同步消息 //同步消息
requestCount++; requestCount++;
MsgManager.getInstance().setSyncChannelMsgListener(channelId, channelType, startMsgSeq, endMsgSeq, limit, pullMode, syncChannelMsg -> { MsgManager.getInstance().setSyncChannelMsgListener(channelId, channelType, startMsgSeq, endMsgSeq, limit, pullMode, syncChannelMsg -> {
if (syncChannelMsg != null && syncChannelMsg.messages != null && syncChannelMsg.messages.size() > 0) { if (syncChannelMsg != null) {
if (oldestMsgSeq == 0) { if (oldestMsgSeq == 0) {
requestCount = 5; requestCount = 5;
} }
more = syncChannelMsg.more;
queryOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit, iGetOrSyncHistoryMsgBack); queryOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit, iGetOrSyncHistoryMsgBack);
} else { } else {
requestCount = 0; requestCount = 0;
more = 1;
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list)); new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list));
} }
}); });
} else { } else {
requestCount = 0; requestCount = 0;
more = 1;
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list)); new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list));
} }

View File

@ -52,13 +52,14 @@ class MsgReactionDBManager {
} }
public synchronized void insertOrUpdate(WKMsgReaction reaction) { public synchronized void insertOrUpdate(WKMsgReaction reaction) {
boolean isExist = isExist(reaction.uid, reaction.messageID); // boolean isExist = isExist(reaction.uid, reaction.messageID);
if (isExist) { // if (isExist) {
update(reaction); // update(reaction);
} else { // } else {
// insert(reaction);
// }
insert(reaction); insert(reaction);
} }
}
public void insert(WKMsgReaction reaction) { public void insert(WKMsgReaction reaction) {
WKIMApplication.getInstance().getDbHelper() WKIMApplication.getInstance().getDbHelper()

View File

@ -292,9 +292,7 @@ public class MsgManager extends BaseManager {
* @param iGetOrSyncHistoryMsgBack 请求返还 * @param iGetOrSyncHistoryMsgBack 请求返还
*/ */
public void getOrSyncHistoryMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, int pullMode, int limit, long aroundMsgOrderSeq, final IGetOrSyncHistoryMsgBack iGetOrSyncHistoryMsgBack) { public void getOrSyncHistoryMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, int pullMode, int limit, long aroundMsgOrderSeq, final IGetOrSyncHistoryMsgBack iGetOrSyncHistoryMsgBack) {
new Thread(new Runnable() { new Thread(() -> {
@Override
public void run() {
int tempPullMode = pullMode; int tempPullMode = pullMode;
long tempOldestOrderSeq = oldestOrderSeq; long tempOldestOrderSeq = oldestOrderSeq;
boolean tempContain = contain; boolean tempContain = contain;
@ -307,7 +305,8 @@ public class MsgManager extends BaseManager {
if (maxMsgSeq >= aroundMsgSeq && maxMsgSeq - aroundMsgSeq <= limit) { if (maxMsgSeq >= aroundMsgSeq && maxMsgSeq - aroundMsgSeq <= limit) {
// 显示最后一页数据 // 显示最后一页数据
// oldestOrderSeq = 0; // oldestOrderSeq = 0;
tempOldestOrderSeq = getMessageOrderSeq(maxMsgSeq, channelId, channelType); tempOldestOrderSeq = getMaxOrderSeqWithChannel(channelId, channelType);
// tempOldestOrderSeq = getMessageOrderSeq(maxMsgSeq, channelId, channelType);
if (tempOldestOrderSeq < aroundMsgOrderSeq) { if (tempOldestOrderSeq < aroundMsgOrderSeq) {
tempOldestOrderSeq = aroundMsgOrderSeq; tempOldestOrderSeq = aroundMsgOrderSeq;
} }
@ -338,7 +337,6 @@ public class MsgManager extends BaseManager {
} }
} }
MsgDbManager.getInstance().queryOrSyncHistoryMessages(channelId, channelType, tempOldestOrderSeq, tempContain, tempPullMode, limit, iGetOrSyncHistoryMsgBack); MsgDbManager.getInstance().queryOrSyncHistoryMessages(channelId, channelType, tempOldestOrderSeq, tempContain, tempPullMode, limit, iGetOrSyncHistoryMsgBack);
}
}).start(); }).start();
} }