mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-02 23:39:05 +00:00
update sync channel message api
This commit is contained in:
parent
99d0a8bffd
commit
c8483c4a62
@ -24,8 +24,6 @@ afterEvaluate {
|
||||
|
||||
android {
|
||||
compileSdk 33
|
||||
buildToolsVersion '33.0.2'
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 33
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -52,12 +52,13 @@ class MsgReactionDBManager {
|
||||
}
|
||||
|
||||
public synchronized void insertOrUpdate(WKMsgReaction reaction) {
|
||||
boolean isExist = isExist(reaction.uid, reaction.messageID);
|
||||
if (isExist) {
|
||||
update(reaction);
|
||||
} else {
|
||||
insert(reaction);
|
||||
}
|
||||
// boolean isExist = isExist(reaction.uid, reaction.messageID);
|
||||
// if (isExist) {
|
||||
// update(reaction);
|
||||
// } else {
|
||||
// insert(reaction);
|
||||
// }
|
||||
insert(reaction);
|
||||
}
|
||||
|
||||
public void insert(WKMsgReaction reaction) {
|
||||
|
@ -292,53 +292,51 @@ 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() {
|
||||
int tempPullMode = pullMode;
|
||||
long tempOldestOrderSeq = oldestOrderSeq;
|
||||
boolean tempContain = contain;
|
||||
if (aroundMsgOrderSeq != 0) {
|
||||
new Thread(() -> {
|
||||
int tempPullMode = pullMode;
|
||||
long tempOldestOrderSeq = oldestOrderSeq;
|
||||
boolean tempContain = contain;
|
||||
if (aroundMsgOrderSeq != 0) {
|
||||
// long maxMsgSeq = getMaxMessageSeqWithChannel(channelId, channelType);
|
||||
long maxMsgSeq =
|
||||
MsgDbManager.getInstance().queryMaxMessageSeqNotDeletedWithChannel(channelId, channelType);
|
||||
long aroundMsgSeq = getOrNearbyMsgSeq(aroundMsgOrderSeq);
|
||||
long maxMsgSeq =
|
||||
MsgDbManager.getInstance().queryMaxMessageSeqNotDeletedWithChannel(channelId, channelType);
|
||||
long aroundMsgSeq = getOrNearbyMsgSeq(aroundMsgOrderSeq);
|
||||
|
||||
if (maxMsgSeq >= aroundMsgSeq && maxMsgSeq - aroundMsgSeq <= limit) {
|
||||
// 显示最后一页数据
|
||||
if (maxMsgSeq >= aroundMsgSeq && maxMsgSeq - aroundMsgSeq <= limit) {
|
||||
// 显示最后一页数据
|
||||
// oldestOrderSeq = 0;
|
||||
tempOldestOrderSeq = getMessageOrderSeq(maxMsgSeq, channelId, channelType);
|
||||
if (tempOldestOrderSeq < aroundMsgOrderSeq) {
|
||||
tempOldestOrderSeq = aroundMsgOrderSeq;
|
||||
}
|
||||
tempContain = true;
|
||||
tempPullMode = 0;
|
||||
} else {
|
||||
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;
|
||||
tempOldestOrderSeq = getMaxOrderSeqWithChannel(channelId, channelType);
|
||||
// tempOldestOrderSeq = getMessageOrderSeq(maxMsgSeq, channelId, channelType);
|
||||
if (tempOldestOrderSeq < aroundMsgOrderSeq) {
|
||||
tempOldestOrderSeq = aroundMsgOrderSeq;
|
||||
}
|
||||
tempContain = true;
|
||||
tempPullMode = 0;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
MsgDbManager.getInstance().queryOrSyncHistoryMessages(channelId, channelType, tempOldestOrderSeq, tempContain, tempPullMode, limit, iGetOrSyncHistoryMsgBack);
|
||||
}
|
||||
MsgDbManager.getInstance().queryOrSyncHistoryMessages(channelId, channelType, tempOldestOrderSeq, tempContain, tempPullMode, limit, iGetOrSyncHistoryMsgBack);
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user