|
|
@ -9,7 +9,7 @@ import com.kanglai.push.entity.LocalPushChatMsg; |
|
|
|
import com.kanglai.push.entity.User; |
|
|
|
import com.kanglai.push.entity.User; |
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Type; |
|
|
|
import java.lang.reflect.Type; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
|
|
import lombok.experimental.UtilityClass; |
|
|
|
import lombok.experimental.UtilityClass; |
|
|
@ -19,17 +19,17 @@ public class HistoryMsgUtil { |
|
|
|
|
|
|
|
|
|
|
|
private User user = CacheDiskUtils.getInstance().getParcelable(CacheConstant.USER_INFO, User.CREATOR, new User()); |
|
|
|
private User user = CacheDiskUtils.getInstance().getParcelable(CacheConstant.USER_INFO, User.CREATOR, new User()); |
|
|
|
|
|
|
|
|
|
|
|
public Map<String, LocalPushChatMsg> select() { |
|
|
|
public HashMap<String, LocalPushChatMsg> select() { |
|
|
|
String localHistoryMsgJson = CacheDiskUtils.getInstance().getString(user.getId().concat(user.getUserType()) ,""); |
|
|
|
String localHistoryMsgJson = CacheDiskUtils.getInstance().getString(user.getId().concat(user.getUserType()) ,""); |
|
|
|
Type type = new TypeToken<Map<String, LocalPushChatMsg>>(){}.getType(); |
|
|
|
Type type = new TypeToken<HashMap<String, LocalPushChatMsg>>(){}.getType(); |
|
|
|
return new Gson().fromJson(localHistoryMsgJson, type); |
|
|
|
return new Gson().fromJson(localHistoryMsgJson, type); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void put(String key,LocalPushChatMsg value) { |
|
|
|
public void put(String key,LocalPushChatMsg value) { |
|
|
|
Objects.requireNonNull(key); |
|
|
|
Objects.requireNonNull(key); |
|
|
|
String localHistoryMsgJson = CacheDiskUtils.getInstance().getString(user.getId().concat(user.getUserType()) ,""); |
|
|
|
String localHistoryMsgJson = CacheDiskUtils.getInstance().getString(user.getId().concat(user.getUserType()) ,""); |
|
|
|
Type type = new TypeToken<Map<String, LocalPushChatMsg>>(){}.getType(); |
|
|
|
Type type = new TypeToken<HashMap<String, LocalPushChatMsg>>(){}.getType(); |
|
|
|
Map<String, LocalPushChatMsg> localHistoryMsg = Objects.requireNonNullElse(new Gson().fromJson(localHistoryMsgJson, type), MapUtils.newHashMap()); |
|
|
|
HashMap<String, LocalPushChatMsg> localHistoryMsg = Objects.requireNonNullElse(new Gson().fromJson(localHistoryMsgJson, type), MapUtils.newHashMap()); |
|
|
|
localHistoryMsg.put(key, value); |
|
|
|
localHistoryMsg.put(key, value); |
|
|
|
String newLocalHistoryMsgJson = new Gson().toJson(localHistoryMsg); |
|
|
|
String newLocalHistoryMsgJson = new Gson().toJson(localHistoryMsg); |
|
|
|
CacheDiskUtils.getInstance().put(user.getId().concat(user.getUserType()), newLocalHistoryMsgJson); |
|
|
|
CacheDiskUtils.getInstance().put(user.getId().concat(user.getUserType()), newLocalHistoryMsgJson); |
|
|
@ -38,8 +38,8 @@ public class HistoryMsgUtil { |
|
|
|
public void del(String key){ |
|
|
|
public void del(String key){ |
|
|
|
Objects.requireNonNull(key); |
|
|
|
Objects.requireNonNull(key); |
|
|
|
String localHistoryMsgJson = CacheDiskUtils.getInstance().getString(user.getId().concat(user.getUserType()) ,""); |
|
|
|
String localHistoryMsgJson = CacheDiskUtils.getInstance().getString(user.getId().concat(user.getUserType()) ,""); |
|
|
|
Type type = new TypeToken<Map<String, LocalPushChatMsg>>(){}.getType(); |
|
|
|
Type type = new TypeToken<HashMap<String, LocalPushChatMsg>>(){}.getType(); |
|
|
|
Map<String, LocalPushChatMsg> localHistoryMsg = Objects.requireNonNullElse(new Gson().fromJson(localHistoryMsgJson, type), MapUtils.newHashMap()); |
|
|
|
HashMap<String, LocalPushChatMsg> localHistoryMsg = Objects.requireNonNullElse(new Gson().fromJson(localHistoryMsgJson, type), MapUtils.newHashMap()); |
|
|
|
localHistoryMsg.remove(key); |
|
|
|
localHistoryMsg.remove(key); |
|
|
|
String newLocalHistoryMsgJson = new Gson().toJson(localHistoryMsg); |
|
|
|
String newLocalHistoryMsgJson = new Gson().toJson(localHistoryMsg); |
|
|
|
CacheDiskUtils.getInstance().put(user.getId().concat(user.getUserType()), newLocalHistoryMsgJson); |
|
|
|
CacheDiskUtils.getInstance().put(user.getId().concat(user.getUserType()), newLocalHistoryMsgJson); |
|
|
|