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 {
compileSdk 33
buildToolsVersion '33.0.2'
defaultConfig {
minSdkVersion 19
targetSdkVersion 33

View File

@ -9,6 +9,7 @@ import android.database.Cursor;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import com.xinbida.wukongim.WKIM;
import com.xinbida.wukongim.WKIMApplication;
@ -57,10 +58,16 @@ public class MsgDbManager {
}
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) {
//获取原始数据
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<>();
for (int i = 0, size = list.size(); i < size; i++) {
@ -164,6 +171,7 @@ public class MsgDbManager {
if (!isSyncMsg) {
if (minMessageSeq == 1) {
requestCount = 0;
more = 1;
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list));
return;
}
@ -187,18 +195,21 @@ public class MsgDbManager {
//同步消息
requestCount++;
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) {
requestCount = 5;
}
more = syncChannelMsg.more;
queryOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit, iGetOrSyncHistoryMsgBack);
} else {
requestCount = 0;
more = 1;
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list));
}
});
} else {
requestCount = 0;
more = 1;
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onResult(list));
}

View File

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

View File

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