mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-06 01:03:55 +00:00
update sync channel message api
This commit is contained in:
parent
99d0a8bffd
commit
c8483c4a62
@ -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
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,12 +52,13 @@ 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) {
|
||||||
|
@ -292,53 +292,51 @@ 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
|
int tempPullMode = pullMode;
|
||||||
public void run() {
|
long tempOldestOrderSeq = oldestOrderSeq;
|
||||||
int tempPullMode = pullMode;
|
boolean tempContain = contain;
|
||||||
long tempOldestOrderSeq = oldestOrderSeq;
|
if (aroundMsgOrderSeq != 0) {
|
||||||
boolean tempContain = contain;
|
|
||||||
if (aroundMsgOrderSeq != 0) {
|
|
||||||
// long maxMsgSeq = getMaxMessageSeqWithChannel(channelId, channelType);
|
// long maxMsgSeq = getMaxMessageSeqWithChannel(channelId, channelType);
|
||||||
long maxMsgSeq =
|
long maxMsgSeq =
|
||||||
MsgDbManager.getInstance().queryMaxMessageSeqNotDeletedWithChannel(channelId, channelType);
|
MsgDbManager.getInstance().queryMaxMessageSeqNotDeletedWithChannel(channelId, channelType);
|
||||||
long aroundMsgSeq = getOrNearbyMsgSeq(aroundMsgOrderSeq);
|
long aroundMsgSeq = getOrNearbyMsgSeq(aroundMsgOrderSeq);
|
||||||
|
|
||||||
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);
|
||||||
if (tempOldestOrderSeq < aroundMsgOrderSeq) {
|
// tempOldestOrderSeq = getMessageOrderSeq(maxMsgSeq, channelId, channelType);
|
||||||
tempOldestOrderSeq = aroundMsgOrderSeq;
|
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;
|
|
||||||
}
|
}
|
||||||
|
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();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user