mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-08 18:53:05 +00:00
add message expire time
This commit is contained in:
parent
1ac36f570a
commit
ac7e11f070
2
wkim/src/main/assets/wk_sql/202309211049.sql
Normal file
2
wkim/src/main/assets/wk_sql/202309211049.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE 'message' add column 'expire_time' BIGINT DEFAULT 0;
|
||||||
|
ALTER TABLE 'message' add column 'expire_timestamp' BIGINT DEFAULT 0;
|
@ -19,7 +19,7 @@ import com.xinbida.wukongim.utils.WKLoggerUtils;
|
|||||||
* 5/20/21 5:25 PM
|
* 5/20/21 5:25 PM
|
||||||
*/
|
*/
|
||||||
public class WKIM {
|
public class WKIM {
|
||||||
private final String Version = "V1.0.7";
|
private final String Version = "V1.0.9";
|
||||||
|
|
||||||
private WKIM() {
|
private WKIM() {
|
||||||
|
|
||||||
@ -33,12 +33,21 @@ public class WKIM {
|
|||||||
return WKIMBinder.im;
|
return WKIMBinder.im;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDebug;
|
private boolean isDebug = false;
|
||||||
|
private boolean isWriteLog = false;
|
||||||
|
|
||||||
public boolean isDebug() {
|
public boolean isDebug() {
|
||||||
return isDebug;
|
return isDebug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isWriteLog() {
|
||||||
|
return isWriteLog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWriteLog(boolean isWriteLog) {
|
||||||
|
this.isWriteLog = isWriteLog;
|
||||||
|
}
|
||||||
|
|
||||||
// debug模式会输出一些连接信息,发送消息情况等
|
// debug模式会输出一些连接信息,发送消息情况等
|
||||||
public void setDebug(boolean isDebug) {
|
public void setDebug(boolean isDebug) {
|
||||||
this.isDebug = isDebug;
|
this.isDebug = isDebug;
|
||||||
|
@ -20,6 +20,9 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class WKIMApplication {
|
public class WKIMApplication {
|
||||||
private final String sharedName = "wk_account_config";
|
private final String sharedName = "wk_account_config";
|
||||||
|
//协议版本
|
||||||
|
public final byte defaultProtocolVersion = 4;
|
||||||
|
public byte protocolVersion = 4;
|
||||||
|
|
||||||
private WKIMApplication() {
|
private WKIMApplication() {
|
||||||
}
|
}
|
||||||
@ -35,6 +38,9 @@ public class WKIMApplication {
|
|||||||
private WeakReference<Context> mContext;
|
private WeakReference<Context> mContext;
|
||||||
|
|
||||||
public Context getContext() {
|
public Context getContext() {
|
||||||
|
if (mContext == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return mContext.get();
|
return mContext.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,11 @@ public class ChannelDBManager {
|
|||||||
}
|
}
|
||||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_id + " in (" + stringBuffer + ") and " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType;
|
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_id + " in (" + stringBuffer + ") and " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType;
|
||||||
List<WKChannel> list = new ArrayList<>();
|
List<WKChannel> list = new ArrayList<>();
|
||||||
|
if (WKIMApplication
|
||||||
|
.getInstance()
|
||||||
|
.getDbHelper() == null) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper()
|
.getDbHelper()
|
||||||
@ -71,6 +76,11 @@ public class ChannelDBManager {
|
|||||||
selectionArgs[1] = String.valueOf(channelType);
|
selectionArgs[1] = String.valueOf(channelType);
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
WKChannel wkChannel = null;
|
WKChannel wkChannel = null;
|
||||||
|
if (WKIMApplication
|
||||||
|
.getInstance()
|
||||||
|
.getDbHelper() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
cursor = WKIMApplication
|
cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
@ -98,6 +108,11 @@ public class ChannelDBManager {
|
|||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
boolean isExist = false;
|
boolean isExist = false;
|
||||||
try {
|
try {
|
||||||
|
if (WKIMApplication
|
||||||
|
.getInstance()
|
||||||
|
.getDbHelper() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
cursor = WKIMApplication
|
cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper()
|
.getDbHelper()
|
||||||
@ -123,6 +138,9 @@ public class ChannelDBManager {
|
|||||||
else newCVList.add(cv);
|
else newCVList.add(cv);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if (WKIMApplication.getInstance().getDbHelper() == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
WKIMApplication.getInstance().getDbHelper().getDb()
|
WKIMApplication.getInstance().getDbHelper().getDb()
|
||||||
.beginTransaction();
|
.beginTransaction();
|
||||||
if (updateCVList.size() > 0) {
|
if (updateCVList.size() > 0) {
|
||||||
@ -165,6 +183,9 @@ public class ChannelDBManager {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
if (WKIMApplication.getInstance().getDbHelper() == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
WKIMApplication.getInstance().getDbHelper()
|
WKIMApplication.getInstance().getDbHelper()
|
||||||
.insert(channel, cv);
|
.insert(channel, cv);
|
||||||
}
|
}
|
||||||
@ -179,6 +200,9 @@ public class ChannelDBManager {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
if (WKIMApplication.getInstance().getDbHelper() == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
WKIMApplication.getInstance().getDbHelper()
|
WKIMApplication.getInstance().getDbHelper()
|
||||||
.update(channel, cv, WKDBColumns.WKChannelColumns.channel_id + "=? and " + WKDBColumns.WKChannelColumns.channel_type + "=?", update);
|
.update(channel, cv, WKDBColumns.WKChannelColumns.channel_id + "=? and " + WKDBColumns.WKChannelColumns.channel_type + "=?", update);
|
||||||
|
|
||||||
@ -195,6 +219,9 @@ public class ChannelDBManager {
|
|||||||
public synchronized List<WKChannel> queryWithFollowAndStatus(byte channelType, int follow, int status) {
|
public synchronized List<WKChannel> queryWithFollowAndStatus(byte channelType, int follow, int status) {
|
||||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKChannelColumns.follow + "=" + follow + " and " + WKDBColumns.WKChannelColumns.status + "=" + status + " and is_deleted=0";
|
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKChannelColumns.follow + "=" + follow + " and " + WKDBColumns.WKChannelColumns.status + "=" + status + " and is_deleted=0";
|
||||||
List<WKChannel> channels = new ArrayList<>();
|
List<WKChannel> channels = new ArrayList<>();
|
||||||
|
if (WKIMApplication
|
||||||
|
.getInstance()
|
||||||
|
.getDbHelper() != null) {
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql)) {
|
.getDbHelper().rawQuery(sql)) {
|
||||||
@ -205,6 +232,8 @@ public class ChannelDBManager {
|
|||||||
channels.add(serializableChannel(cursor));
|
channels.add(serializableChannel(cursor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return channels;
|
return channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +247,9 @@ public class ChannelDBManager {
|
|||||||
public synchronized List<WKChannel> queryWithStatus(byte channelType, int status) {
|
public synchronized List<WKChannel> queryWithStatus(byte channelType, int status) {
|
||||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKChannelColumns.status + "=" + status;
|
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKChannelColumns.status + "=" + status;
|
||||||
List<WKChannel> channels = new ArrayList<>();
|
List<WKChannel> channels = new ArrayList<>();
|
||||||
|
if (WKIMApplication.getInstance().getDbHelper() == null){
|
||||||
|
return channels;
|
||||||
|
}
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql)) {
|
.getDbHelper().rawQuery(sql)) {
|
||||||
|
@ -223,7 +223,7 @@ public class ConversationDbManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WKConversationMsg queryWithChannel(String channelID, byte channelType) {
|
public WKConversationMsg queryWithChannel(String channelID, byte channelType) {
|
||||||
String sql = "select " + conversation + ".*," + channelCols + "," + extraCols + " from " + conversation + " left join " + channel + " on " + conversation + ".channel_id=" + channel + ".channel_id and " + conversation + ".channel_type=" + channel + ".channel_type left join " + conversationExtra + " on " + conversation + ".channel_id=" + conversationExtra + ".channel_id and " + conversation + ".channel_type=" + conversationExtra + ".channel_type where " + conversation + ".channel_id='" + channelID + "' and " + conversation + ".channel_type=" + channelType;
|
String sql = "select " + conversation + ".*," + channelCols + "," + extraCols + " from " + conversation + " left join " + channel + " on " + conversation + ".channel_id=" + channel + ".channel_id and " + conversation + ".channel_type=" + channel + ".channel_type left join " + conversationExtra + " on " + conversation + ".channel_id=" + conversationExtra + ".channel_id and " + conversation + ".channel_type=" + conversationExtra + ".channel_type where " + conversation + ".channel_id='" + channelID + "' and " + conversation + ".channel_type=" + channelType + " and " + conversation + ".is_deleted=0";
|
||||||
Cursor cursor = WKIMApplication
|
Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper()
|
.getDbHelper()
|
||||||
|
@ -42,7 +42,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class MsgDbManager {
|
public class MsgDbManager {
|
||||||
private final String extraCols = "IFNULL(" + messageExtra + ".readed,0) as readed,IFNULL(" + messageExtra + ".readed_count,0) as readed_count,IFNULL(" + messageExtra + ".unread_count,0) as unread_count,IFNULL(" + messageExtra + ".revoke,0) as revoke,IFNULL(" + messageExtra + ".revoker,'') as revoker,IFNULL(" + messageExtra + ".extra_version,0) as extra_version,IFNULL(" + messageExtra + ".is_mutual_deleted,0) as is_mutual_deleted,IFNULL(" + messageExtra + ".content_edit,'') as content_edit,IFNULL(" + messageExtra + ".edited_at,0) as edited_at";
|
private final String extraCols = "IFNULL(" + messageExtra + ".readed,0) as readed,IFNULL(" + messageExtra + ".readed_count,0) as readed_count,IFNULL(" + messageExtra + ".unread_count,0) as unread_count,IFNULL(" + messageExtra + ".revoke,0) as revoke,IFNULL(" + messageExtra + ".revoker,'') as revoker,IFNULL(" + messageExtra + ".extra_version,0) as extra_version,IFNULL(" + messageExtra + ".is_mutual_deleted,0) as is_mutual_deleted,IFNULL(" + messageExtra + ".content_edit,'') as content_edit,IFNULL(" + messageExtra + ".edited_at,0) as edited_at";
|
||||||
private final String messageCols = message + ".client_seq," + message + ".message_id," + message + ".message_seq," + message + ".channel_id," + message + ".channel_type," + message + ".timestamp," + message + ".from_uid," + message + ".type," + message + ".content," + message + ".status," + message + ".voice_status," + message + ".created_at," + message + ".updated_at," + message + ".searchable_word," + message + ".client_msg_no," + message + ".setting," + message + ".order_seq," + message + ".extra," + message + ".is_deleted," + message + ".flame," + message + ".flame_second," + message + ".viewed," + message + ".viewed_at";
|
private final String messageCols = message + ".client_seq," + message + ".message_id," + message + ".message_seq," + message + ".channel_id," + message + ".channel_type," + message + ".timestamp," + message + ".from_uid," + message + ".type," + message + ".content," + message + ".status," + message + ".voice_status," + message + ".created_at," + message + ".updated_at," + message + ".searchable_word," + message + ".client_msg_no," + message + ".setting," + message + ".order_seq," + message + ".extra," + message + ".is_deleted," + message + ".flame," + message + ".flame_second," + message + ".viewed," + message + ".viewed_at," + message + ".expire_time," + message + ".expire_timestamp";
|
||||||
|
|
||||||
private MsgDbManager() {
|
private MsgDbManager() {
|
||||||
}
|
}
|
||||||
@ -87,7 +87,6 @@ public class MsgDbManager {
|
|||||||
long endMsgSeq = 0;
|
long endMsgSeq = 0;
|
||||||
//判断页与页之间是否连续
|
//判断页与页之间是否连续
|
||||||
long oldestMsgSeq;
|
long oldestMsgSeq;
|
||||||
|
|
||||||
//如果获取到的messageSeq为0说明oldestOrderSeq这条消息是本地消息则获取他上一条或下一条消息的messageSeq做为判断
|
//如果获取到的messageSeq为0说明oldestOrderSeq这条消息是本地消息则获取他上一条或下一条消息的messageSeq做为判断
|
||||||
if (oldestOrderSeq % 1000 != 0)
|
if (oldestOrderSeq % 1000 != 0)
|
||||||
oldestMsgSeq = queryMsgSeq(channelId, channelType, oldestOrderSeq, pullMode);
|
oldestMsgSeq = queryMsgSeq(channelId, channelType, oldestOrderSeq, pullMode);
|
||||||
@ -156,7 +155,11 @@ public class MsgDbManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (oldestOrderSeq == 0) {
|
||||||
|
isSyncMsg = true;
|
||||||
|
startMsgSeq = 0;
|
||||||
|
endMsgSeq = 0;
|
||||||
|
}
|
||||||
if (!isSyncMsg) {
|
if (!isSyncMsg) {
|
||||||
if (minMessageSeq == 1) {
|
if (minMessageSeq == 1) {
|
||||||
requestCount = 0;
|
requestCount = 0;
|
||||||
@ -170,16 +173,23 @@ public class MsgDbManager {
|
|||||||
startMsgSeq = oldestMsgSeq;
|
startMsgSeq = oldestMsgSeq;
|
||||||
endMsgSeq = 0;
|
endMsgSeq = 0;
|
||||||
}
|
}
|
||||||
|
if (startMsgSeq == 0 && endMsgSeq == 0 && tempList.size() < limit) {
|
||||||
|
isSyncMsg = true;
|
||||||
|
endMsgSeq = oldestMsgSeq;
|
||||||
|
startMsgSeq = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSyncMsg && requestCount < 5) {
|
||||||
if (isSyncMsg && startMsgSeq != endMsgSeq && requestCount < 5) {
|
|
||||||
if (requestCount == 0) {
|
if (requestCount == 0) {
|
||||||
new Handler(Looper.getMainLooper()).post(() -> iGetOrSyncHistoryMsgBack.onSyncing());
|
new Handler(Looper.getMainLooper()).post(iGetOrSyncHistoryMsgBack::onSyncing);
|
||||||
}
|
}
|
||||||
//同步消息
|
//同步消息
|
||||||
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 && syncChannelMsg.messages != null && syncChannelMsg.messages.size() > 0) {
|
||||||
|
if (oldestMsgSeq == 0) {
|
||||||
|
requestCount = 5;
|
||||||
|
}
|
||||||
queryOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit, iGetOrSyncHistoryMsgBack);
|
queryOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit, iGetOrSyncHistoryMsgBack);
|
||||||
} else {
|
} else {
|
||||||
requestCount = 0;
|
requestCount = 0;
|
||||||
@ -367,6 +377,21 @@ public class MsgDbManager {
|
|||||||
return wkMsgs;
|
return wkMsgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<WKMsg> queryExpireMessages(long timestamp, int limit) {
|
||||||
|
String sql = "SELECT * from " + message + " where is_deleted=0 and " + WKDBColumns.WKMessageColumns.expire_time + ">0 and " + WKDBColumns.WKMessageColumns.expire_timestamp + "<=" + timestamp + " order by order_seq desc limit 0," + limit;
|
||||||
|
List<WKMsg> list = new ArrayList<>();
|
||||||
|
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||||
|
if (cursor == null) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
|
||||||
|
WKMsg wkMsg = serializeMsg(cursor);
|
||||||
|
list.add(wkMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public List<WKMsg> queryWithFromUID(String channelID, byte channelType, String fromUID, long oldestOrderSeq, int limit) {
|
public List<WKMsg> queryWithFromUID(String channelID, byte channelType, String fromUID, long oldestOrderSeq, int limit) {
|
||||||
String sql;
|
String sql;
|
||||||
if (oldestOrderSeq == 0) {
|
if (oldestOrderSeq == 0) {
|
||||||
@ -1158,6 +1183,22 @@ public class MsgDbManager {
|
|||||||
return orderSeq;
|
return orderSeq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int queryMaxMessageSeqNotDeletedWithChannel(String channelID,byte channelType){
|
||||||
|
String sql = "SELECT max(message_seq) message_seq FROM " + message + " WHERE channel_id='" + channelID + "' AND channel_type=" + channelType +" AND is_deleted=0";
|
||||||
|
int messageSeq = 0;
|
||||||
|
try (Cursor cursor = WKIMApplication
|
||||||
|
.getInstance()
|
||||||
|
.getDbHelper().rawQuery(sql)) {
|
||||||
|
if (cursor == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (cursor.moveToLast()) {
|
||||||
|
messageSeq = WKCursor.readInt(cursor, WKDBColumns.WKMessageColumns.message_seq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messageSeq;
|
||||||
|
}
|
||||||
|
|
||||||
public int queryMaxMessageSeqWithChannel(String channelID, byte channelType) {
|
public int queryMaxMessageSeqWithChannel(String channelID, byte channelType) {
|
||||||
String sql = "SELECT max(message_seq) message_seq FROM " + message + " WHERE channel_id='" + channelID + "' AND channel_type=" + channelType;
|
String sql = "SELECT max(message_seq) message_seq FROM " + message + " WHERE channel_id='" + channelID + "' AND channel_type=" + channelType;
|
||||||
int messageSeq = 0;
|
int messageSeq = 0;
|
||||||
@ -1494,6 +1535,8 @@ public class MsgDbManager {
|
|||||||
msg.viewed = WKCursor.readInt(cursor, WKDBColumns.WKMessageColumns.viewed);
|
msg.viewed = WKCursor.readInt(cursor, WKDBColumns.WKMessageColumns.viewed);
|
||||||
msg.viewedAt = WKCursor.readLong(cursor, WKDBColumns.WKMessageColumns.viewed_at);
|
msg.viewedAt = WKCursor.readLong(cursor, WKDBColumns.WKMessageColumns.viewed_at);
|
||||||
msg.topicID = WKCursor.readString(cursor, WKDBColumns.WKMessageColumns.topic_id);
|
msg.topicID = WKCursor.readString(cursor, WKDBColumns.WKMessageColumns.topic_id);
|
||||||
|
msg.expireTime = WKCursor.readInt(cursor, WKDBColumns.WKMessageColumns.expire_time);
|
||||||
|
msg.expireTimestamp = WKCursor.readInt(cursor, WKDBColumns.WKMessageColumns.expire_timestamp);
|
||||||
// 扩展表数据
|
// 扩展表数据
|
||||||
msg.remoteExtra = serializeMsgExtra(cursor);
|
msg.remoteExtra = serializeMsgExtra(cursor);
|
||||||
|
|
||||||
|
@ -166,6 +166,8 @@ public interface WKDBColumns {
|
|||||||
public static final String viewed_at = "viewed_at";
|
public static final String viewed_at = "viewed_at";
|
||||||
// 话题ID
|
// 话题ID
|
||||||
public static final String topic_id = "topic_id";
|
public static final String topic_id = "topic_id";
|
||||||
|
public static final String expire_time = "expire_time";
|
||||||
|
public static final String expire_timestamp = "expire_timestamp";
|
||||||
}
|
}
|
||||||
|
|
||||||
//最近会话db字段
|
//最近会话db字段
|
||||||
|
@ -103,10 +103,16 @@ public class WKDBHelper {
|
|||||||
|
|
||||||
|
|
||||||
void insertSql(String tab, ContentValues cv) {
|
void insertSql(String tab, ContentValues cv) {
|
||||||
|
if (mDb == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mDb.insertWithOnConflict(tab, "", cv, SQLiteDatabase.CONFLICT_REPLACE);
|
mDb.insertWithOnConflict(tab, "", cv, SQLiteDatabase.CONFLICT_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor rawQuery(String sql) {
|
public Cursor rawQuery(String sql) {
|
||||||
|
if (mDb == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return mDb.rawQuery(sql, null);
|
return mDb.rawQuery(sql, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,8 @@ class WKSqlContentValues {
|
|||||||
contentValues.put(WKDBColumns.WKMessageColumns.viewed, msg.viewed);
|
contentValues.put(WKDBColumns.WKMessageColumns.viewed, msg.viewed);
|
||||||
contentValues.put(WKDBColumns.WKMessageColumns.viewed_at, msg.viewedAt);
|
contentValues.put(WKDBColumns.WKMessageColumns.viewed_at, msg.viewedAt);
|
||||||
contentValues.put(WKDBColumns.WKMessageColumns.topic_id, msg.topicID);
|
contentValues.put(WKDBColumns.WKMessageColumns.topic_id, msg.topicID);
|
||||||
|
contentValues.put(WKDBColumns.WKMessageColumns.expire_time, msg.expireTime);
|
||||||
|
contentValues.put(WKDBColumns.WKMessageColumns.expire_timestamp, msg.expireTimestamp);
|
||||||
byte setting = WKTypeUtils.getInstance().getMsgSetting(msg.setting);
|
byte setting = WKTypeUtils.getInstance().getMsgSetting(msg.setting);
|
||||||
contentValues.put(WKDBColumns.WKMessageColumns.setting, setting);
|
contentValues.put(WKDBColumns.WKMessageColumns.setting, setting);
|
||||||
if (msg.baseContentMsgModel != null) {
|
if (msg.baseContentMsgModel != null) {
|
||||||
|
@ -29,6 +29,8 @@ public class WKMsg implements Parcelable {
|
|||||||
public long clientSeq;
|
public long clientSeq;
|
||||||
//消息时间10位时间戳
|
//消息时间10位时间戳
|
||||||
public long timestamp;
|
public long timestamp;
|
||||||
|
public int expireTime;
|
||||||
|
public long expireTimestamp;
|
||||||
//消息来源发送者
|
//消息来源发送者
|
||||||
public String fromUID;
|
public String fromUID;
|
||||||
//频道id
|
//频道id
|
||||||
@ -90,6 +92,8 @@ public class WKMsg implements Parcelable {
|
|||||||
this.createdAt = DateUtils.getInstance().time2DateStr(timestamp);
|
this.createdAt = DateUtils.getInstance().time2DateStr(timestamp);
|
||||||
this.updatedAt = DateUtils.getInstance().time2DateStr(timestamp);
|
this.updatedAt = DateUtils.getInstance().time2DateStr(timestamp);
|
||||||
this.messageSeq = 0;
|
this.messageSeq = 0;
|
||||||
|
this.expireTime = 0;
|
||||||
|
this.expireTimestamp = 0;
|
||||||
status = WKSendMsgResult.send_loading;
|
status = WKSendMsgResult.send_loading;
|
||||||
clientMsgNO = WKIM.getInstance().getMsgManager().createClientMsgNO();
|
clientMsgNO = WKIM.getInstance().getMsgManager().createClientMsgNO();
|
||||||
header = new WKMsgHeader();
|
header = new WKMsgHeader();
|
||||||
@ -121,22 +125,17 @@ public class WKMsg implements Parcelable {
|
|||||||
from = in.readParcelable(WKChannel.class.getClassLoader());
|
from = in.readParcelable(WKChannel.class.getClassLoader());
|
||||||
memberOfFrom = in.readParcelable(WKChannelMember.class.getClassLoader());
|
memberOfFrom = in.readParcelable(WKChannelMember.class.getClassLoader());
|
||||||
channelInfo = in.readParcelable(WKChannelMember.class.getClassLoader());
|
channelInfo = in.readParcelable(WKChannelMember.class.getClassLoader());
|
||||||
// revoker = in.readString();
|
|
||||||
// extraVersion = in.readLong();
|
|
||||||
// readedCount = in.readInt();
|
|
||||||
// unreadCount = in.readInt();
|
|
||||||
// readed = in.readInt();
|
|
||||||
setting = in.readParcelable(WKMsgSetting.class.getClassLoader());
|
setting = in.readParcelable(WKMsgSetting.class.getClassLoader());
|
||||||
header = in.readParcelable(WKMsgHeader.class.getClassLoader());
|
header = in.readParcelable(WKMsgHeader.class.getClassLoader());
|
||||||
reactionList = in.createTypedArrayList(WKMsgReaction.CREATOR);
|
reactionList = in.createTypedArrayList(WKMsgReaction.CREATOR);
|
||||||
// editAt = in.readLong();
|
|
||||||
// contentEdit = in.readString();
|
|
||||||
// needUploadExtra = in.readInt();
|
|
||||||
flame = in.readInt();
|
flame = in.readInt();
|
||||||
flameSecond = in.readInt();
|
flameSecond = in.readInt();
|
||||||
viewed = in.readInt();
|
viewed = in.readInt();
|
||||||
viewedAt = in.readLong();
|
viewedAt = in.readLong();
|
||||||
topicID = in.readString();
|
topicID = in.readString();
|
||||||
|
expireTime = in.readInt();
|
||||||
|
expireTimestamp = in.readLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<WKMsg> CREATOR = new Creator<WKMsg>() {
|
public static final Creator<WKMsg> CREATOR = new Creator<WKMsg>() {
|
||||||
@ -181,23 +180,16 @@ public class WKMsg implements Parcelable {
|
|||||||
dest.writeParcelable(from, flags);
|
dest.writeParcelable(from, flags);
|
||||||
dest.writeParcelable(memberOfFrom, flags);
|
dest.writeParcelable(memberOfFrom, flags);
|
||||||
dest.writeParcelable(channelInfo, flags);
|
dest.writeParcelable(channelInfo, flags);
|
||||||
// dest.writeString(revoker);
|
|
||||||
// dest.writeLong(extraVersion);
|
|
||||||
// dest.writeInt(readedCount);
|
|
||||||
// dest.writeInt(unreadCount);
|
|
||||||
// dest.writeInt(readed);
|
|
||||||
dest.writeParcelable(setting, flags);
|
dest.writeParcelable(setting, flags);
|
||||||
dest.writeParcelable(header, flags);
|
dest.writeParcelable(header, flags);
|
||||||
dest.writeTypedList(reactionList);
|
dest.writeTypedList(reactionList);
|
||||||
// dest.writeLong(editAt);
|
|
||||||
// dest.writeString(contentEdit);
|
|
||||||
// dest.writeParcelable(contentEditMsgModel, flags);
|
|
||||||
// dest.writeInt(needUploadExtra);
|
|
||||||
dest.writeInt(flame);
|
dest.writeInt(flame);
|
||||||
dest.writeInt(flameSecond);
|
dest.writeInt(flameSecond);
|
||||||
dest.writeInt(viewed);
|
dest.writeInt(viewed);
|
||||||
dest.writeLong(viewedAt);
|
dest.writeLong(viewedAt);
|
||||||
dest.writeString(topicID);
|
dest.writeString(topicID);
|
||||||
|
dest.writeInt(expireTime);
|
||||||
|
dest.writeLong(expireTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocalMapExtraString() {
|
public String getLocalMapExtraString() {
|
||||||
|
@ -25,6 +25,7 @@ public class WKSyncRecent {
|
|||||||
public int readed;
|
public int readed;
|
||||||
public int receipt;
|
public int receipt;
|
||||||
public int setting;
|
public int setting;
|
||||||
|
public int expire;
|
||||||
public Map payload;
|
public Map payload;
|
||||||
public String signal_payload;
|
public String signal_payload;
|
||||||
public List<WKSyncMsgReaction> reactions;
|
public List<WKSyncMsgReaction> reactions;
|
||||||
|
@ -298,7 +298,9 @@ public class MsgManager extends BaseManager {
|
|||||||
long tempOldestOrderSeq = oldestOrderSeq;
|
long tempOldestOrderSeq = oldestOrderSeq;
|
||||||
boolean tempContain = contain;
|
boolean tempContain = contain;
|
||||||
if (aroundMsgOrderSeq != 0) {
|
if (aroundMsgOrderSeq != 0) {
|
||||||
long maxMsgSeq = getMaxMessageSeqWithChannel(channelId, channelType);
|
// long maxMsgSeq = getMaxMessageSeqWithChannel(channelId, channelType);
|
||||||
|
long maxMsgSeq =
|
||||||
|
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) {
|
||||||
@ -397,6 +399,11 @@ public class MsgManager extends BaseManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<WKMsg> getExpireMessages(int limit) {
|
||||||
|
long time = DateUtils.getInstance().getCurrentSeconds();
|
||||||
|
return MsgDbManager.getInstance().queryExpireMessages(time, limit);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除某条消息
|
* 删除某条消息
|
||||||
*
|
*
|
||||||
@ -1047,6 +1054,8 @@ public class MsgManager extends BaseManager {
|
|||||||
msg.remoteExtra.unreadCount = wkSyncRecent.unread_count;
|
msg.remoteExtra.unreadCount = wkSyncRecent.unread_count;
|
||||||
msg.remoteExtra.readedCount = wkSyncRecent.readed_count;
|
msg.remoteExtra.readedCount = wkSyncRecent.readed_count;
|
||||||
msg.remoteExtra.readed = wkSyncRecent.readed;
|
msg.remoteExtra.readed = wkSyncRecent.readed;
|
||||||
|
msg.expireTime = wkSyncRecent.expire;
|
||||||
|
msg.expireTimestamp = msg.expireTime + msg.timestamp;
|
||||||
// msg.reactionList = wkSyncRecent.reactions;
|
// msg.reactionList = wkSyncRecent.reactions;
|
||||||
// msg.receipt = wkSyncRecent.receipt;
|
// msg.receipt = wkSyncRecent.receipt;
|
||||||
msg.remoteExtra.extraVersion = wkSyncRecent.extra_version;
|
msg.remoteExtra.extraVersion = wkSyncRecent.extra_version;
|
||||||
|
@ -191,24 +191,25 @@ public class MessageHandler {
|
|||||||
if (g_msg.packetType == WKMsgType.CONNACK) {
|
if (g_msg.packetType == WKMsgType.CONNACK) {
|
||||||
WKConnectAckMsg loginStatusMsg = (WKConnectAckMsg) g_msg;
|
WKConnectAckMsg loginStatusMsg = (WKConnectAckMsg) g_msg;
|
||||||
mIReceivedMsgListener.loginStatusMsg(loginStatusMsg.reasonCode);
|
mIReceivedMsgListener.loginStatusMsg(loginStatusMsg.reasonCode);
|
||||||
|
WKLoggerUtils.getInstance().e("头信息-->" + no_persist);
|
||||||
} else if (g_msg.packetType == WKMsgType.SENDACK) {
|
} else if (g_msg.packetType == WKMsgType.SENDACK) {
|
||||||
//发送ack
|
//发送ack
|
||||||
WKSendAckMsg talkSendStatus = (WKSendAckMsg) g_msg;
|
WKSendAckMsg sendAckMsg = (WKSendAckMsg) g_msg;
|
||||||
WKMsg wkMsg = null;
|
WKMsg wkMsg = null;
|
||||||
if (no_persist == 0) {
|
if (no_persist == 0) {
|
||||||
wkMsg = MsgDbManager.getInstance().updateMsgSendStatus(talkSendStatus.clientSeq, talkSendStatus.messageSeq, talkSendStatus.messageID, talkSendStatus.reasonCode);
|
wkMsg = MsgDbManager.getInstance().updateMsgSendStatus(sendAckMsg.clientSeq, sendAckMsg.messageSeq, sendAckMsg.messageID, sendAckMsg.reasonCode);
|
||||||
}
|
}
|
||||||
if (wkMsg == null) {
|
if (wkMsg == null) {
|
||||||
wkMsg = new WKMsg();
|
wkMsg = new WKMsg();
|
||||||
wkMsg.clientSeq = talkSendStatus.clientSeq;
|
wkMsg.clientSeq = sendAckMsg.clientSeq;
|
||||||
wkMsg.messageID = talkSendStatus.messageID;
|
wkMsg.messageID = sendAckMsg.messageID;
|
||||||
wkMsg.status = talkSendStatus.reasonCode;
|
wkMsg.status = sendAckMsg.reasonCode;
|
||||||
wkMsg.messageSeq = (int) talkSendStatus.messageSeq;
|
wkMsg.messageSeq = (int) sendAckMsg.messageSeq;
|
||||||
}
|
}
|
||||||
WKIM.getInstance().getMsgManager().setSendMsgAck(wkMsg);
|
WKIM.getInstance().getMsgManager().setSendMsgAck(wkMsg);
|
||||||
|
|
||||||
mIReceivedMsgListener
|
mIReceivedMsgListener
|
||||||
.sendAckMsg(talkSendStatus);
|
.sendAckMsg(sendAckMsg);
|
||||||
} else if (g_msg.packetType == WKMsgType.RECVEIVED) {
|
} else if (g_msg.packetType == WKMsgType.RECVEIVED) {
|
||||||
//收到消息
|
//收到消息
|
||||||
WKMsg message = WKProto.getInstance().baseMsg2WKMsg(g_msg);
|
WKMsg message = WKProto.getInstance().baseMsg2WKMsg(g_msg);
|
||||||
|
@ -374,10 +374,6 @@ public class WKConnection {
|
|||||||
|
|
||||||
public void sendMessage(WKMessageContent baseContentModel, WKMsgSetting wkMsgSetting, String channelID, byte channelType) {
|
public void sendMessage(WKMessageContent baseContentModel, WKMsgSetting wkMsgSetting, String channelID, byte channelType) {
|
||||||
final WKMsg wkMsg = new WKMsg();
|
final WKMsg wkMsg = new WKMsg();
|
||||||
if (!TextUtils.isEmpty(WKIMApplication.getInstance().getUid())) {
|
|
||||||
wkMsg.fromUID = WKIMApplication.getInstance().getUid();
|
|
||||||
}
|
|
||||||
// wkMsg.content = baseContentModel.content;
|
|
||||||
wkMsg.type = baseContentModel.type;
|
wkMsg.type = baseContentModel.type;
|
||||||
wkMsg.setting = wkMsgSetting;
|
wkMsg.setting = wkMsgSetting;
|
||||||
//设置会话信息
|
//设置会话信息
|
||||||
@ -405,6 +401,12 @@ public class WKConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(WKMsg msg) {
|
public void sendMessage(WKMsg msg) {
|
||||||
|
if (TextUtils.isEmpty(msg.fromUID)) {
|
||||||
|
msg.fromUID = WKIMApplication.getInstance().getUid();
|
||||||
|
}
|
||||||
|
if (msg.expireTime > 0) {
|
||||||
|
msg.expireTimestamp = DateUtils.getInstance().getCurrentSeconds() + msg.expireTime;
|
||||||
|
}
|
||||||
boolean hasAttached = false;
|
boolean hasAttached = false;
|
||||||
//如果是图片消息
|
//如果是图片消息
|
||||||
if (msg.baseContentMsgModel instanceof WKImageContent) {
|
if (msg.baseContentMsgModel instanceof WKImageContent) {
|
||||||
|
@ -70,13 +70,14 @@ class WKProto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
byte[] enConnectMsg(WKConnectMsg connectMsg) {
|
byte[] enConnectMsg(WKConnectMsg connectMsg) {
|
||||||
|
WKIMApplication.getInstance().protocolVersion = WKIMApplication.getInstance().defaultProtocolVersion;
|
||||||
byte[] remainingBytes = WKTypeUtils.getInstance().getRemainingLengthByte(connectMsg.getRemainingLength());
|
byte[] remainingBytes = WKTypeUtils.getInstance().getRemainingLengthByte(connectMsg.getRemainingLength());
|
||||||
int totalLen = connectMsg.getTotalLen();
|
int totalLen = connectMsg.getTotalLen();
|
||||||
WKWrite wkWrite = new WKWrite(totalLen);
|
WKWrite wkWrite = new WKWrite(totalLen);
|
||||||
try {
|
try {
|
||||||
wkWrite.writeByte(WKTypeUtils.getInstance().getHeader(connectMsg.packetType, connectMsg.flag, 0, 0));
|
wkWrite.writeByte(WKTypeUtils.getInstance().getHeader(connectMsg.packetType, connectMsg.flag, 0, 0));
|
||||||
wkWrite.writeBytes(remainingBytes);
|
wkWrite.writeBytes(remainingBytes);
|
||||||
wkWrite.writeByte(connectMsg.protocolVersion);
|
wkWrite.writeByte(WKIMApplication.getInstance().protocolVersion);
|
||||||
wkWrite.writeByte(connectMsg.deviceFlag);
|
wkWrite.writeByte(connectMsg.deviceFlag);
|
||||||
wkWrite.writeString(connectMsg.deviceID);
|
wkWrite.writeString(connectMsg.deviceID);
|
||||||
wkWrite.writeString(WKIMApplication.getInstance().getUid());
|
wkWrite.writeString(WKIMApplication.getInstance().getUid());
|
||||||
@ -124,6 +125,9 @@ class WKProto {
|
|||||||
wkWrite.writeString(sendMsg.clientMsgNo);
|
wkWrite.writeString(sendMsg.clientMsgNo);
|
||||||
wkWrite.writeString(sendMsg.channelId);
|
wkWrite.writeString(sendMsg.channelId);
|
||||||
wkWrite.writeByte(sendMsg.channelType);
|
wkWrite.writeByte(sendMsg.channelType);
|
||||||
|
if (WKIMApplication.getInstance().protocolVersion >= 3) {
|
||||||
|
wkWrite.writeInt(sendMsg.expire);
|
||||||
|
}
|
||||||
wkWrite.writeString(msgKeyContent);
|
wkWrite.writeString(msgKeyContent);
|
||||||
if (sendMsg.setting.topic == 1) {
|
if (sendMsg.setting.topic == 1) {
|
||||||
wkWrite.writeString(sendMsg.topicID);
|
wkWrite.writeString(sendMsg.topicID);
|
||||||
@ -136,9 +140,15 @@ class WKProto {
|
|||||||
return wkWrite.getWriteBytes();
|
return wkWrite.getWriteBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private WKConnectAckMsg deConnectAckMsg(WKRead wkRead) {
|
private WKConnectAckMsg deConnectAckMsg(WKRead wkRead, int hasServerVersion) {
|
||||||
WKConnectAckMsg connectAckMsg = new WKConnectAckMsg();
|
WKConnectAckMsg connectAckMsg = new WKConnectAckMsg();
|
||||||
try {
|
try {
|
||||||
|
if (hasServerVersion == 1) {
|
||||||
|
byte serverVersion = wkRead.readByte();
|
||||||
|
if (serverVersion != 0) {
|
||||||
|
WKIMApplication.getInstance().protocolVersion = (byte) Math.min(serverVersion, WKIMApplication.getInstance().protocolVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
long time = wkRead.readLong();
|
long time = wkRead.readLong();
|
||||||
short reasonCode = wkRead.readByte();
|
short reasonCode = wkRead.readByte();
|
||||||
String serverKey = wkRead.readString();
|
String serverKey = wkRead.readString();
|
||||||
@ -193,6 +203,9 @@ class WKProto {
|
|||||||
receivedMsg.fromUID = wkRead.readString();
|
receivedMsg.fromUID = wkRead.readString();
|
||||||
receivedMsg.channelID = wkRead.readString();
|
receivedMsg.channelID = wkRead.readString();
|
||||||
receivedMsg.channelType = wkRead.readByte();
|
receivedMsg.channelType = wkRead.readByte();
|
||||||
|
if (WKIMApplication.getInstance().protocolVersion >= 3) {
|
||||||
|
receivedMsg.expire = wkRead.readInt();
|
||||||
|
}
|
||||||
receivedMsg.clientMsgNo = wkRead.readString();
|
receivedMsg.clientMsgNo = wkRead.readString();
|
||||||
if (receivedMsg.setting.stream == 1) {
|
if (receivedMsg.setting.stream == 1) {
|
||||||
receivedMsg.streamNO = wkRead.readString();
|
receivedMsg.streamNO = wkRead.readString();
|
||||||
@ -234,7 +247,8 @@ class WKProto {
|
|||||||
int packetType = wkRead.readPacketType();
|
int packetType = wkRead.readPacketType();
|
||||||
wkRead.readRemainingLength();
|
wkRead.readRemainingLength();
|
||||||
if (packetType == WKMsgType.CONNACK) {
|
if (packetType == WKMsgType.CONNACK) {
|
||||||
return deConnectAckMsg(wkRead);
|
int hasServerVersion = WKTypeUtils.getInstance().getBit(bytes[0], 0);
|
||||||
|
return deConnectAckMsg(wkRead, hasServerVersion);
|
||||||
} else if (packetType == WKMsgType.SENDACK) {
|
} else if (packetType == WKMsgType.SENDACK) {
|
||||||
return deSendAckMsg(wkRead);
|
return deSendAckMsg(wkRead);
|
||||||
} else if (packetType == WKMsgType.DISCONNECT) {
|
} else if (packetType == WKMsgType.DISCONNECT) {
|
||||||
@ -336,7 +350,7 @@ class WKProto {
|
|||||||
sendMsg.channelType = msg.channelType;
|
sendMsg.channelType = msg.channelType;
|
||||||
sendMsg.topicID = msg.topicID;
|
sendMsg.topicID = msg.topicID;
|
||||||
sendMsg.setting = msg.setting;
|
sendMsg.setting = msg.setting;
|
||||||
|
sendMsg.expire = msg.expireTime;
|
||||||
if (WKMediaMessageContent.class.isAssignableFrom(msg.baseContentMsgModel.getClass())) {
|
if (WKMediaMessageContent.class.isAssignableFrom(msg.baseContentMsgModel.getClass())) {
|
||||||
//多媒体数据
|
//多媒体数据
|
||||||
if (jsonObject.has("localPath")) {
|
if (jsonObject.has("localPath")) {
|
||||||
@ -366,7 +380,10 @@ class WKProto {
|
|||||||
msg.clientMsgNO = receivedMsg.clientMsgNo;
|
msg.clientMsgNO = receivedMsg.clientMsgNo;
|
||||||
msg.status = WKSendMsgResult.send_success;
|
msg.status = WKSendMsgResult.send_success;
|
||||||
msg.topicID = receivedMsg.topicID;
|
msg.topicID = receivedMsg.topicID;
|
||||||
|
msg.expireTime = receivedMsg.expire;
|
||||||
|
if (msg.expireTime > 0) {
|
||||||
|
msg.expireTimestamp = msg.expireTime + msg.timestamp;
|
||||||
|
}
|
||||||
msg.orderSeq = WKIM.getInstance().getMsgManager().getMessageOrderSeq(msg.messageSeq, msg.channelID, msg.channelType);
|
msg.orderSeq = WKIM.getInstance().getMsgManager().getMessageOrderSeq(msg.messageSeq, msg.channelID, msg.channelType);
|
||||||
msg.isDeleted = isDelete(msg.content);
|
msg.isDeleted = isDelete(msg.content);
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -14,7 +14,6 @@ import java.util.List;
|
|||||||
* 基础内容消息实体
|
* 基础内容消息实体
|
||||||
*/
|
*/
|
||||||
public class WKMessageContent implements Parcelable {
|
public class WKMessageContent implements Parcelable {
|
||||||
public boolean isCheckForceSendMsg = true;
|
|
||||||
//内容
|
//内容
|
||||||
public String content;
|
public String content;
|
||||||
//发送者id
|
//发送者id
|
||||||
@ -33,10 +32,11 @@ public class WKMessageContent implements Parcelable {
|
|||||||
public String searchableWord;
|
public String searchableWord;
|
||||||
//最近会话提示文字
|
//最近会话提示文字
|
||||||
public String displayContent;
|
public String displayContent;
|
||||||
public int isDelete;
|
// public int isDelete;
|
||||||
public String robotID;
|
public String robotID;
|
||||||
public int flame;
|
public int flame;
|
||||||
public int flameSecond;
|
public int flameSecond;
|
||||||
|
@Deprecated
|
||||||
public String topicID;
|
public String topicID;
|
||||||
public List<WKMsgEntity> entities;
|
public List<WKMsgEntity> entities;
|
||||||
|
|
||||||
@ -44,7 +44,6 @@ public class WKMessageContent implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected WKMessageContent(Parcel in) {
|
protected WKMessageContent(Parcel in) {
|
||||||
isCheckForceSendMsg = in.readByte() != 0;
|
|
||||||
content = in.readString();
|
content = in.readString();
|
||||||
fromUID = in.readString();
|
fromUID = in.readString();
|
||||||
fromName = in.readString();
|
fromName = in.readString();
|
||||||
@ -55,7 +54,7 @@ public class WKMessageContent implements Parcelable {
|
|||||||
searchableWord = in.readString();
|
searchableWord = in.readString();
|
||||||
displayContent = in.readString();
|
displayContent = in.readString();
|
||||||
reply = in.readParcelable(WKReply.class.getClassLoader());
|
reply = in.readParcelable(WKReply.class.getClassLoader());
|
||||||
isDelete = in.readInt();
|
// isDelete = in.readInt();
|
||||||
robotID = in.readString();
|
robotID = in.readString();
|
||||||
entities = in.createTypedArrayList(WKMsgEntity.CREATOR);
|
entities = in.createTypedArrayList(WKMsgEntity.CREATOR);
|
||||||
flame = in.readInt();
|
flame = in.readInt();
|
||||||
@ -65,7 +64,6 @@ public class WKMessageContent implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeByte((byte) (isCheckForceSendMsg ? 1 : 0));
|
|
||||||
dest.writeString(content);
|
dest.writeString(content);
|
||||||
dest.writeString(fromUID);
|
dest.writeString(fromUID);
|
||||||
dest.writeString(fromName);
|
dest.writeString(fromName);
|
||||||
@ -75,7 +73,7 @@ public class WKMessageContent implements Parcelable {
|
|||||||
dest.writeString(searchableWord);
|
dest.writeString(searchableWord);
|
||||||
dest.writeString(displayContent);
|
dest.writeString(displayContent);
|
||||||
dest.writeParcelable(reply, flags);
|
dest.writeParcelable(reply, flags);
|
||||||
dest.writeInt(isDelete);
|
// dest.writeInt(isDelete);
|
||||||
dest.writeString(robotID);
|
dest.writeString(robotID);
|
||||||
dest.writeTypedList(entities);
|
dest.writeTypedList(entities);
|
||||||
dest.writeInt(flame);
|
dest.writeInt(flame);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.xinbida.wukongim.protocol;
|
package com.xinbida.wukongim.protocol;
|
||||||
|
|
||||||
|
import com.xinbida.wukongim.WKIMApplication;
|
||||||
import com.xinbida.wukongim.message.type.WKMsgType;
|
import com.xinbida.wukongim.message.type.WKMsgType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -9,8 +10,6 @@ import com.xinbida.wukongim.message.type.WKMsgType;
|
|||||||
* @see WKMsgType 对应packetType类型
|
* @see WKMsgType 对应packetType类型
|
||||||
*/
|
*/
|
||||||
public class WKBaseMsg {
|
public class WKBaseMsg {
|
||||||
//协议版本
|
|
||||||
public byte protocolVersion = 1;
|
|
||||||
//报文类型
|
//报文类型
|
||||||
public short packetType;
|
public short packetType;
|
||||||
//标示位(目前为固定值)
|
//标示位(目前为固定值)
|
||||||
|
@ -33,7 +33,7 @@ public class WKReceivedMsg extends WKBaseMsg {
|
|||||||
public String streamNO;
|
public String streamNO;
|
||||||
public int streamSeq;
|
public int streamSeq;
|
||||||
public int streamFlag;
|
public int streamFlag;
|
||||||
|
public int expire;
|
||||||
private final int settingLength = 1;
|
private final int settingLength = 1;
|
||||||
private final int msgKeyLength = 2;
|
private final int msgKeyLength = 2;
|
||||||
public int msgKeyContentLength = 0;
|
public int msgKeyContentLength = 0;
|
||||||
|
@ -3,6 +3,7 @@ package com.xinbida.wukongim.protocol;
|
|||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.xinbida.wukongim.WKIMApplication;
|
||||||
import com.xinbida.wukongim.entity.WKMsgSetting;
|
import com.xinbida.wukongim.entity.WKMsgSetting;
|
||||||
import com.xinbida.wukongim.message.type.WKMsgType;
|
import com.xinbida.wukongim.message.type.WKMsgType;
|
||||||
import com.xinbida.wukongim.utils.CryptoUtils;
|
import com.xinbida.wukongim.utils.CryptoUtils;
|
||||||
@ -41,12 +42,15 @@ public class WKSendMsg extends WKBaseMsg {
|
|||||||
public short settingLength = 1;
|
public short settingLength = 1;
|
||||||
private String cryptoPayload;
|
private String cryptoPayload;
|
||||||
private String msgKey;
|
private String msgKey;
|
||||||
|
public int expire;
|
||||||
|
public int expireLength = 4;
|
||||||
|
|
||||||
public WKSendMsg() {
|
public WKSendMsg() {
|
||||||
packetType = WKMsgType.SEND;
|
packetType = WKMsgType.SEND;
|
||||||
remainingLength = 8 + 1;
|
remainingLength = 8 + 1;
|
||||||
cryptoPayload = "";
|
cryptoPayload = "";
|
||||||
msgKey = "";
|
msgKey = "";
|
||||||
|
expire = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSendContent() {
|
public String getSendContent() {
|
||||||
@ -75,8 +79,16 @@ public class WKSendMsg extends WKBaseMsg {
|
|||||||
return topicLen;
|
return topicLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getExpireLength() {
|
||||||
|
if (WKIMApplication.getInstance().protocolVersion >= 3) {
|
||||||
|
return expireLength;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public int getTotalLength() {
|
public int getTotalLength() {
|
||||||
int topicLen = getTopicLength();
|
int topicLen = getTopicLength();
|
||||||
|
int expireLen = getExpireLength();
|
||||||
String msgKeyContent = getMsgKey();
|
String msgKeyContent = getMsgKey();
|
||||||
String sendContent = getSendContent();
|
String sendContent = getSendContent();
|
||||||
byte[] remainingBytes = WKTypeUtils.getInstance().getRemainingLengthByte(getRemainingLength());
|
byte[] remainingBytes = WKTypeUtils.getInstance().getRemainingLengthByte(getRemainingLength());
|
||||||
@ -88,6 +100,7 @@ public class WKSendMsg extends WKBaseMsg {
|
|||||||
+ channelIdLength
|
+ channelIdLength
|
||||||
+ channelId.length()
|
+ channelId.length()
|
||||||
+ channelTypeLength
|
+ channelTypeLength
|
||||||
|
+ expireLen
|
||||||
+ msgKeyLength
|
+ msgKeyLength
|
||||||
+ msgKeyContent.length()
|
+ msgKeyContent.length()
|
||||||
+ topicLen
|
+ topicLen
|
||||||
@ -99,11 +112,13 @@ public class WKSendMsg extends WKBaseMsg {
|
|||||||
String sendContent = getSendContent();
|
String sendContent = getSendContent();
|
||||||
String msgKeyContent = getMsgKey();
|
String msgKeyContent = getMsgKey();
|
||||||
int topicLen = getTopicLength();
|
int topicLen = getTopicLength();
|
||||||
|
int expireLen = getExpireLength();
|
||||||
remainingLength = settingLength
|
remainingLength = settingLength
|
||||||
+ clientSeqLength
|
+ clientSeqLength
|
||||||
+ clientMsgNoLength + clientMsgNo.length()
|
+ clientMsgNoLength + clientMsgNo.length()
|
||||||
+ channelIdLength + channelId.length()
|
+ channelIdLength + channelId.length()
|
||||||
+ channelTypeLength
|
+ channelTypeLength
|
||||||
|
+ expireLen
|
||||||
+ msgKeyLength + msgKeyContent.length()
|
+ msgKeyLength + msgKeyContent.length()
|
||||||
+ topicLen
|
+ topicLen
|
||||||
+ sendContent.getBytes().length;
|
+ sendContent.getBytes().length;
|
||||||
|
@ -24,11 +24,14 @@ public class WKLoggerUtils {
|
|||||||
* log TAG
|
* log TAG
|
||||||
*/
|
*/
|
||||||
private final String TAG = "WKLogger" + WKIM.getInstance().getVersion();
|
private final String TAG = "WKLogger" + WKIM.getInstance().getVersion();
|
||||||
private final String ROOT = Objects.requireNonNull(WKIMApplication.getInstance().getContext().getExternalFilesDir(null)).getAbsolutePath() + "/";
|
|
||||||
//Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
|
//Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
|
||||||
private final String FILE_NAME = "wkLogger_" + WKIM.getInstance().getVersion() + ".log";
|
private final String FILE_NAME = "wkLogger_" + WKIM.getInstance().getVersion() + ".log";
|
||||||
|
|
||||||
//
|
//
|
||||||
private final String logFile = ROOT + FILE_NAME;
|
private String getLogFilePath() {
|
||||||
|
final String ROOT = Objects.requireNonNull(WKIMApplication.getInstance().getContext().getExternalFilesDir(null)).getAbsolutePath() + "/";
|
||||||
|
return ROOT + FILE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
private WKLoggerUtils() {
|
private WKLoggerUtils() {
|
||||||
|
|
||||||
@ -236,7 +239,10 @@ public class WKLoggerUtils {
|
|||||||
@SuppressLint("SimpleDateFormat")
|
@SuppressLint("SimpleDateFormat")
|
||||||
private void writeLog(String content) {
|
private void writeLog(String content) {
|
||||||
try {
|
try {
|
||||||
File file = new File(logFile);
|
if (WKIMApplication.getInstance().getContext() == null || !WKIM.getInstance().isWriteLog()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File file = new File(getLogFilePath());
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user