mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-05 16:53:57 +00:00
fix:update Modify entity class serialization
This commit is contained in:
parent
05a454bf60
commit
deaf7fbbc8
@ -7,7 +7,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.4.0'
|
||||
classpath 'com.android.tools.build:gradle:8.4.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
@ -10,14 +10,10 @@ import android.text.TextUtils;
|
||||
import com.xinbida.wukongim.WKIMApplication;
|
||||
import com.xinbida.wukongim.entity.WKChannel;
|
||||
import com.xinbida.wukongim.entity.WKChannelSearchResult;
|
||||
import com.xinbida.wukongim.utils.WKCommonUtils;
|
||||
import com.xinbida.wukongim.utils.WKLoggerUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -394,26 +390,8 @@ public class ChannelDBManager {
|
||||
channel.parentChannelType = WKCursor.readByte(cursor, WKDBColumns.WKChannelColumns.parent_channel_type);
|
||||
String extra = WKCursor.readString(cursor, WKDBColumns.WKChannelColumns.localExtra);
|
||||
String remoteExtra = WKCursor.readString(cursor, WKDBColumns.WKChannelColumns.remote_extra);
|
||||
channel.localExtra = getChannelExtra(extra);
|
||||
channel.remoteExtraMap = getChannelExtra(remoteExtra);
|
||||
channel.localExtra = WKCommonUtils.str2HashMap(extra);
|
||||
channel.remoteExtraMap = WKCommonUtils.str2HashMap(remoteExtra);
|
||||
return channel;
|
||||
}
|
||||
|
||||
public HashMap<String, Object> getChannelExtra(String extra) {
|
||||
HashMap<String, Object> hashMap = new HashMap<>();
|
||||
if (!TextUtils.isEmpty(extra)) {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(extra);
|
||||
Iterator<String> keys = jsonObject.keys();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
hashMap.put(key, jsonObject.opt(key));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
WKLoggerUtils.getInstance().e(TAG , "get channel getChannelExtra error");
|
||||
}
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ public class ChannelMembersDbManager {
|
||||
try {
|
||||
cv = WKSqlContentValues.getContentValuesWithChannelMember(channelMember);
|
||||
} catch (Exception e) {
|
||||
WKLoggerUtils.getInstance().e(TAG , "insert error");
|
||||
WKLoggerUtils.getInstance().e(TAG, "insert error");
|
||||
}
|
||||
WKIMApplication.getInstance().getDbHelper()
|
||||
.insert(channelMembers, cv);
|
||||
@ -237,19 +237,19 @@ public class ChannelMembersDbManager {
|
||||
|
||||
public void insertMembers(List<WKChannelMember> allMemberList, List<WKChannelMember> existList) {
|
||||
List<ContentValues> insertCVList = new ArrayList<>();
|
||||
List<ContentValues> updateCVList = new ArrayList<>();
|
||||
// List<ContentValues> updateCVList = new ArrayList<>();
|
||||
for (WKChannelMember channelMember : allMemberList) {
|
||||
boolean isAdd = true;
|
||||
for (WKChannelMember cm : existList) {
|
||||
if (channelMember.memberUID.equals(cm.memberUID)) {
|
||||
isAdd = false;
|
||||
updateCVList.add(WKSqlContentValues.getContentValuesWithChannelMember(channelMember));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isAdd) {
|
||||
insertCVList.add(WKSqlContentValues.getContentValuesWithChannelMember(channelMember));
|
||||
}
|
||||
// boolean isAdd = true;
|
||||
// for (WKChannelMember cm : existList) {
|
||||
// if (channelMember.memberUID.equals(cm.memberUID)) {
|
||||
// isAdd = false;
|
||||
// updateCVList.add(WKSqlContentValues.getContentValuesWithChannelMember(channelMember));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (isAdd) {
|
||||
insertCVList.add(WKSqlContentValues.getContentValuesWithChannelMember(channelMember));
|
||||
// }
|
||||
}
|
||||
WKIMApplication.getInstance().getDbHelper().getDb()
|
||||
.beginTransaction();
|
||||
@ -259,16 +259,16 @@ public class ChannelMembersDbManager {
|
||||
WKIMApplication.getInstance().getDbHelper().insert(channelMembers, cv);
|
||||
}
|
||||
}
|
||||
if (WKCommonUtils.isNotEmpty(updateCVList)) {
|
||||
for (ContentValues cv : updateCVList) {
|
||||
String[] update = new String[3];
|
||||
update[0] = cv.getAsString(WKDBColumns.WKChannelMembersColumns.channel_id);
|
||||
update[1] = String.valueOf(cv.getAsByte(WKDBColumns.WKChannelMembersColumns.channel_type));
|
||||
update[2] = cv.getAsString(WKDBColumns.WKChannelMembersColumns.member_uid);
|
||||
WKIMApplication.getInstance().getDbHelper()
|
||||
.update(channelMembers, cv, WKDBColumns.WKChannelMembersColumns.channel_id + "=? and " + WKDBColumns.WKChannelMembersColumns.channel_type + "=? and " + WKDBColumns.WKChannelMembersColumns.member_uid + "=?", update);
|
||||
}
|
||||
}
|
||||
// if (WKCommonUtils.isNotEmpty(updateCVList)) {
|
||||
// for (ContentValues cv : updateCVList) {
|
||||
// String[] update = new String[3];
|
||||
// update[0] = cv.getAsString(WKDBColumns.WKChannelMembersColumns.channel_id);
|
||||
// update[1] = String.valueOf(cv.getAsByte(WKDBColumns.WKChannelMembersColumns.channel_type));
|
||||
// update[2] = cv.getAsString(WKDBColumns.WKChannelMembersColumns.member_uid);
|
||||
// WKIMApplication.getInstance().getDbHelper()
|
||||
// .update(channelMembers, cv, WKDBColumns.WKChannelMembersColumns.channel_id + "=? and " + WKDBColumns.WKChannelMembersColumns.channel_type + "=? and " + WKDBColumns.WKChannelMembersColumns.member_uid + "=?", update);
|
||||
// }
|
||||
// }
|
||||
WKIMApplication.getInstance().getDbHelper().getDb().setTransactionSuccessful();
|
||||
} finally {
|
||||
if (WKIMApplication.getInstance().getDbHelper().getDb().inTransaction()) {
|
||||
@ -301,7 +301,7 @@ public class ChannelMembersDbManager {
|
||||
try {
|
||||
cv = WKSqlContentValues.getContentValuesWithChannelMember(channelMember);
|
||||
} catch (Exception e) {
|
||||
WKLoggerUtils.getInstance().e(TAG , "update error");
|
||||
WKLoggerUtils.getInstance().e(TAG, "update error");
|
||||
}
|
||||
WKIMApplication.getInstance().getDbHelper()
|
||||
.update(channelMembers, cv, WKDBColumns.WKChannelMembersColumns.channel_id + "=? and " + WKDBColumns.WKChannelMembersColumns.channel_type + "=? and " + WKDBColumns.WKChannelMembersColumns.member_uid + "=?", update);
|
||||
@ -524,7 +524,7 @@ public class ChannelMembersDbManager {
|
||||
hashMap.put(key, jsonObject.opt(key));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
WKLoggerUtils.getInstance().e(TAG , "serializableChannelMember extra error");
|
||||
WKLoggerUtils.getInstance().e(TAG, "serializableChannelMember extra error");
|
||||
}
|
||||
channelMember.extraMap = hashMap;
|
||||
}
|
||||
|
@ -142,9 +142,9 @@ public class ConversationDbManager {
|
||||
WKChannel channel = ChannelDBManager.getInstance().serializableChannel(cursor);
|
||||
if (channel != null) {
|
||||
String extra = WKCursor.readString(cursor, "channel_extra");
|
||||
channel.localExtra = ChannelDBManager.getInstance().getChannelExtra(extra);
|
||||
channel.localExtra = WKCommonUtils.str2HashMap(extra);
|
||||
String remoteExtra = WKCursor.readString(cursor, "channel_remote_extra");
|
||||
channel.remoteExtraMap = ChannelDBManager.getInstance().getChannelExtra(remoteExtra);
|
||||
channel.remoteExtraMap = WKCommonUtils.str2HashMap(remoteExtra);
|
||||
channel.status = WKCursor.readInt(cursor, "channel_status");
|
||||
channel.version = WKCursor.readLong(cursor, "channel_version");
|
||||
channel.parentChannelID = WKCursor.readString(cursor, "c_parent_channel_id");
|
||||
|
@ -4,6 +4,9 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.xinbida.wukongim.utils.DateUtils;
|
||||
import com.xinbida.wukongim.utils.WKCommonUtils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -101,7 +104,6 @@ public class WKChannel implements Parcelable {
|
||||
updatedAt = in.readString();
|
||||
avatar = in.readString();
|
||||
version = in.readLong();
|
||||
localExtra = in.readHashMap(HashMap.class.getClassLoader());
|
||||
online = in.readInt();
|
||||
lastOffline = in.readLong();
|
||||
category = in.readString();
|
||||
@ -109,13 +111,15 @@ public class WKChannel implements Parcelable {
|
||||
robot = in.readInt();
|
||||
username = in.readString();
|
||||
avatarCacheKey = in.readString();
|
||||
remoteExtraMap = in.readHashMap(HashMap.class.getClassLoader());
|
||||
flame = in.readInt();
|
||||
flameSecond = in.readInt();
|
||||
deviceFlag = in.readInt();
|
||||
parentChannelID = in.readString();
|
||||
parentChannelType = in.readByte();
|
||||
// mainDeviceFlag = in.readInt();
|
||||
String localStr = in.readString();
|
||||
localExtra = WKCommonUtils.str2HashMap(localStr);
|
||||
String remoteStr = in.readString();
|
||||
remoteExtraMap = WKCommonUtils.str2HashMap(remoteStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,7 +142,6 @@ public class WKChannel implements Parcelable {
|
||||
dest.writeString(updatedAt);
|
||||
dest.writeString(avatar);
|
||||
dest.writeLong(version);
|
||||
dest.writeMap(localExtra);
|
||||
dest.writeInt(online);
|
||||
dest.writeLong(lastOffline);
|
||||
dest.writeString(category);
|
||||
@ -146,13 +149,23 @@ public class WKChannel implements Parcelable {
|
||||
dest.writeInt(robot);
|
||||
dest.writeString(username);
|
||||
dest.writeString(avatarCacheKey);
|
||||
dest.writeMap(remoteExtraMap);
|
||||
dest.writeInt(flame);
|
||||
dest.writeInt(flameSecond);
|
||||
dest.writeInt(deviceFlag);
|
||||
dest.writeString(parentChannelID);
|
||||
dest.writeByte(parentChannelType);
|
||||
// dest.writeInt(mainDeviceFlag);
|
||||
String localExtraStr = "";
|
||||
String remoteExtraStr = "";
|
||||
if (localExtra != null && !localExtra.isEmpty()) {
|
||||
JSONObject jsonObject = new JSONObject(localExtra);
|
||||
localExtraStr = jsonObject.toString();
|
||||
}
|
||||
dest.writeString(localExtraStr);
|
||||
if (remoteExtraMap != null && !remoteExtraMap.isEmpty()) {
|
||||
JSONObject jsonObject = new JSONObject(remoteExtraMap);
|
||||
remoteExtraStr = jsonObject.toString();
|
||||
}
|
||||
dest.writeString(remoteExtraStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,9 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.xinbida.wukongim.utils.DateUtils;
|
||||
import com.xinbida.wukongim.utils.WKCommonUtils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -69,12 +72,13 @@ public class WKChannelMember implements Parcelable {
|
||||
createdAt = in.readString();
|
||||
updatedAt = in.readString();
|
||||
version = in.readLong();
|
||||
extraMap = in.readHashMap(HashMap.class.getClassLoader());
|
||||
remark = in.readString();
|
||||
memberInviteUID = in.readString();
|
||||
robot = in.readInt();
|
||||
forbiddenExpirationTime = in.readLong();
|
||||
memberAvatarCacheKey = in.readString();
|
||||
String extraStr = in.readString();
|
||||
extraMap = WKCommonUtils.str2HashMap(extraStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -92,12 +96,17 @@ public class WKChannelMember implements Parcelable {
|
||||
dest.writeString(createdAt);
|
||||
dest.writeString(updatedAt);
|
||||
dest.writeLong(version);
|
||||
dest.writeMap(extraMap);
|
||||
dest.writeString(remark);
|
||||
dest.writeString(memberInviteUID);
|
||||
dest.writeInt(robot);
|
||||
dest.writeLong(forbiddenExpirationTime);
|
||||
dest.writeString(memberAvatarCacheKey);
|
||||
String extraStr = "";
|
||||
if (extraMap != null && !extraMap.isEmpty()) {
|
||||
JSONObject jsonObject = new JSONObject(extraMap);
|
||||
extraStr = jsonObject.toString();
|
||||
}
|
||||
dest.writeString(extraStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,6 +9,7 @@ import com.xinbida.wukongim.manager.ChannelMembersManager;
|
||||
import com.xinbida.wukongim.message.type.WKSendMsgResult;
|
||||
import com.xinbida.wukongim.msgmodel.WKMessageContent;
|
||||
import com.xinbida.wukongim.utils.DateUtils;
|
||||
import com.xinbida.wukongim.utils.WKCommonUtils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -119,7 +120,8 @@ public class WKMsg implements Parcelable {
|
||||
createdAt = in.readString();
|
||||
updatedAt = in.readString();
|
||||
searchableWord = in.readString();
|
||||
localExtraMap = in.readHashMap(HashMap.class.getClassLoader());
|
||||
String localExtraStr = in.readString();
|
||||
localExtraMap = WKCommonUtils.str2HashMap(localExtraStr);
|
||||
baseContentMsgModel = in.readParcelable(WKMsg.class
|
||||
.getClassLoader());
|
||||
from = in.readParcelable(WKChannel.class.getClassLoader());
|
||||
@ -175,7 +177,7 @@ public class WKMsg implements Parcelable {
|
||||
dest.writeString(createdAt);
|
||||
dest.writeString(updatedAt);
|
||||
dest.writeString(searchableWord);
|
||||
dest.writeMap(localExtraMap);
|
||||
dest.writeString(getLocalMapExtraString());
|
||||
dest.writeParcelable(baseContentMsgModel, flags);
|
||||
dest.writeParcelable(from, flags);
|
||||
dest.writeParcelable(memberOfFrom, flags);
|
||||
@ -194,7 +196,7 @@ public class WKMsg implements Parcelable {
|
||||
|
||||
public String getLocalMapExtraString() {
|
||||
String extras = "";
|
||||
if (localExtraMap != null && localExtraMap.size() > 0) {
|
||||
if (localExtraMap != null && !localExtraMap.isEmpty()) {
|
||||
JSONObject jsonObject = new JSONObject(localExtraMap);
|
||||
extras = jsonObject.toString();
|
||||
}
|
||||
|
@ -812,6 +812,28 @@ public class MsgManager extends BaseManager {
|
||||
if (!isSuccess) {
|
||||
WKLoggerUtils.getInstance().e(TAG, "saveRemoteExtraMsg delete message error");
|
||||
}
|
||||
String deletedMsgId = "";
|
||||
WKConversationMsg conversationMsg = ConversationDbManager.getInstance().queryWithChannel(channel.channelID, channel.channelType);
|
||||
if (conversationMsg != null && !TextUtils.isEmpty(conversationMsg.lastClientMsgNO)) {
|
||||
WKMsg msg = getWithClientMsgNO(conversationMsg.lastClientMsgNO);
|
||||
if (msg != null && !TextUtils.isEmpty(msg.messageID) && msg.messageSeq != 0) {
|
||||
for (String msgId : deleteMsgIds) {
|
||||
if (msg.messageID.equals(msgId)) {
|
||||
deletedMsgId = msgId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!TextUtils.isEmpty(deletedMsgId) && conversationMsg != null) {
|
||||
int rowNo = WKIM.getInstance().getMsgManager().getRowNoWithMessageID(channel.channelID, channel.channelType, deletedMsgId);
|
||||
if (rowNo < conversationMsg.unreadCount) {
|
||||
conversationMsg.unreadCount--;
|
||||
}
|
||||
WKIM.getInstance().getConversationManager().updateWithMsg(conversationMsg);
|
||||
WKUIConversationMsg wkuiConversationMsg = WKIM.getInstance().getConversationManager().getUIConversationMsg(channel.channelID, channel.channelType);
|
||||
WKIM.getInstance().getConversationManager().setOnRefreshMsg(wkuiConversationMsg, true, TAG + " saveRemoteExtraMsg");
|
||||
}
|
||||
}
|
||||
getMsgReactionsAndRefreshMsg(messageIds, updatedMsgList);
|
||||
}
|
||||
|
@ -538,7 +538,6 @@ public class WKConnection {
|
||||
connection.setAttachment("close" + connection.getId());
|
||||
connection.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
WKLoggerUtils.getInstance().e("stop connection IOException" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,17 @@
|
||||
package com.xinbida.wukongim.utils;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class WKCommonUtils {
|
||||
private static final String TAG = "WKCommonUtils";
|
||||
|
||||
public static String stringValue(JSONObject jsonObject, String key) {
|
||||
if (jsonObject == null || !jsonObject.has(key))
|
||||
return "";
|
||||
@ -18,4 +25,21 @@ public class WKCommonUtils {
|
||||
public static <T> boolean isEmpty(List<T> list) {
|
||||
return list == null || list.isEmpty();
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> str2HashMap(String extra) {
|
||||
HashMap<String, Object> hashMap = new HashMap<>();
|
||||
if (!TextUtils.isEmpty(extra)) {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(extra);
|
||||
Iterator<String> keys = jsonObject.keys();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
hashMap.put(key, jsonObject.opt(key));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
WKLoggerUtils.getInstance().e(TAG, "str2HashMap error");
|
||||
}
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user