mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-07 10:01:02 +00:00
优化连接
This commit is contained in:
parent
8bf6ceb042
commit
1be9507dca
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@ -18,5 +18,6 @@
|
|||||||
</option>
|
</option>
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
|
<option name="offlineMode" value="true" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,com.wukong.im.db.WKDBHelper,rawQuery" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
2574a1a954394bc0e14512c8c9130d29
|
@ -0,0 +1 @@
|
|||||||
|
400b72d0de18580ae143d524e08c3b67010b44be
|
@ -0,0 +1 @@
|
|||||||
|
5ace1b9a36a5370e07e744f9431064021db7d362ef58620f5868d5932c823c21
|
@ -0,0 +1 @@
|
|||||||
|
84d94b8f261faf5aedf1a4e7be07c953fdc0e6c6d37639c1640a8fe62924d9cacba636c97767cf2355bb3736b1a40f8bbad33e6bfa0e46ca6cff23df437c355a
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.wukong.im</groupId>
|
||||||
|
<artifactId>WKIMLib_loca</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>aar</packaging>
|
||||||
|
</project>
|
@ -0,0 +1 @@
|
|||||||
|
3ba12068a79874b5d3c0630df3e9424a
|
@ -0,0 +1 @@
|
|||||||
|
661ca872e7597a96bae9bb32206029fda635c03a
|
@ -0,0 +1 @@
|
|||||||
|
dd3e739be498f556545ae3c39336dc876f5ad6dce006e3fdf83044087989592e
|
@ -0,0 +1 @@
|
|||||||
|
b2ae240f103954a7b5a2d3f2d75dd8cc248f57365ec7b570af7c2c886fe018989903d12cb45733b5ee1923e0e4262fff1ba2c0f7d84edc191ed252543daf4d6c
|
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
a834d1c870e1b58d4530b187a1c568a9
|
@ -0,0 +1 @@
|
|||||||
|
130d3588b00c2e6b7798da9c05cd6b7db58417f5
|
@ -0,0 +1 @@
|
|||||||
|
681dbddd2958c98592015fa8b037bd7766b09c77e786db6867018f98ea0d6a10
|
@ -0,0 +1 @@
|
|||||||
|
058dd5210889a9b24ae14826adcbc00f02aa86fb8eca7eec8bb4e6ec864cc56cca0859e73a8c6ded84363b6354f2d790634efaf702c9e2dc8019a6a1c161c2ec
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.wukong.im</groupId>
|
||||||
|
<artifactId>WKIMLib_loca</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
<packaging>aar</packaging>
|
||||||
|
</project>
|
@ -0,0 +1 @@
|
|||||||
|
ae5443a8ec63e4a3c4e4c75b011d8329
|
@ -0,0 +1 @@
|
|||||||
|
c54007b4b6d9c943e65452a032cf5f0f3fad7f1c
|
@ -0,0 +1 @@
|
|||||||
|
8284daf4ec8bbe6079a4c956ad7870c739e9724157dd3b7a82e4381b4941e68e
|
@ -0,0 +1 @@
|
|||||||
|
71f01502b151fe8b755106e2cc88d9b1a106b04c527515d977e3a15d2803421f6fa05c3fcfdc746fcd15d5867566a4294743532b8065951617afddcd5c2d3499
|
14
repository/com/wukong/im/WKIMLib_loca/maven-metadata.xml
Normal file
14
repository/com/wukong/im/WKIMLib_loca/maven-metadata.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<metadata>
|
||||||
|
<groupId>com.wukong.im</groupId>
|
||||||
|
<artifactId>WKIMLib_loca</artifactId>
|
||||||
|
<versioning>
|
||||||
|
<latest>1.0.1</latest>
|
||||||
|
<release>1.0.1</release>
|
||||||
|
<versions>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</versions>
|
||||||
|
<lastUpdated>20230609162512</lastUpdated>
|
||||||
|
</versioning>
|
||||||
|
</metadata>
|
@ -0,0 +1 @@
|
|||||||
|
d8d7749f8b5c0d9dfb58ce497eb00966
|
@ -0,0 +1 @@
|
|||||||
|
7b0a4a0d8ae72d7d20fa5917d47098bb72996ad4
|
@ -0,0 +1 @@
|
|||||||
|
9ce496a230bd923be4da34abd5f3501fe8dd686e8dd5e72b82515ab84e32a668
|
@ -0,0 +1 @@
|
|||||||
|
6279bd9f456efb566b4707ef2fe43d19f0ef8adc8f92cbba1fd497e5d55da8dc70b5c7096d76079a409d85e32ddc51938c751d69b24fd9a78a488087cbcac892
|
@ -11,7 +11,7 @@ afterEvaluate {
|
|||||||
afterEvaluate { artifact(tasks.getByName("bundleReleaseAar")) }
|
afterEvaluate { artifact(tasks.getByName("bundleReleaseAar")) }
|
||||||
groupId = 'com.wukong.im'
|
groupId = 'com.wukong.im'
|
||||||
artifactId = 'WKIMLib_loca'
|
artifactId = 'WKIMLib_loca'
|
||||||
version = '1.0.0'
|
version = '1.0.1'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.wukong.im.db;
|
package com.wukong.im.db;
|
||||||
|
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.channel;
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.channelMembers;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -21,8 +24,6 @@ import java.util.List;
|
|||||||
* channel DB manager
|
* channel DB manager
|
||||||
*/
|
*/
|
||||||
public class ChannelDBManager {
|
public class ChannelDBManager {
|
||||||
private final String channel = "channel";
|
|
||||||
private final String channelMembers = "channel_members";
|
|
||||||
|
|
||||||
private ChannelDBManager() {
|
private ChannelDBManager() {
|
||||||
}
|
}
|
||||||
@ -74,24 +75,24 @@ public class ChannelDBManager {
|
|||||||
selectionArgs[0] = channelId;
|
selectionArgs[0] = channelId;
|
||||||
selectionArgs[1] = String.valueOf(channelType);
|
selectionArgs[1] = String.valueOf(channelType);
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
WKChannel channel = null;
|
WKChannel wkChannel = null;
|
||||||
try {
|
try {
|
||||||
cursor = WKIMApplication
|
cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper()
|
.getDbHelper()
|
||||||
.select(this.channel, selection, selectionArgs,
|
.select(channel, selection, selectionArgs,
|
||||||
null);
|
null);
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
if (cursor.getCount() > 0) {
|
if (cursor.getCount() > 0) {
|
||||||
cursor.moveToNext();
|
cursor.moveToNext();
|
||||||
channel = serializableChannel(cursor);
|
wkChannel = serializableChannel(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null)
|
if (cursor != null)
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
return channel;
|
return wkChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isExist(String channelId, int channelType) {
|
private boolean isExist(String channelId, int channelType) {
|
||||||
@ -162,29 +163,29 @@ public class ChannelDBManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void insertChannel(WKChannel channel) {
|
private synchronized void insertChannel(WKChannel wkChannel) {
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
try {
|
try {
|
||||||
cv = WKSqlContentValues.getContentValuesWithChannel(channel);
|
cv = WKSqlContentValues.getContentValuesWithChannel(wkChannel);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
WKIMApplication.getInstance().getDbHelper()
|
WKIMApplication.getInstance().getDbHelper()
|
||||||
.insert(this.channel, cv);
|
.insert(channel, cv);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateChannel(WKChannel channel) {
|
public synchronized void updateChannel(WKChannel wkChannel) {
|
||||||
String[] update = new String[2];
|
String[] update = new String[2];
|
||||||
update[0] = channel.channelID;
|
update[0] = wkChannel.channelID;
|
||||||
update[1] = String.valueOf(channel.channelType);
|
update[1] = String.valueOf(wkChannel.channelType);
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
try {
|
try {
|
||||||
cv = WKSqlContentValues.getContentValuesWithChannel(channel);
|
cv = WKSqlContentValues.getContentValuesWithChannel(wkChannel);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
WKIMApplication.getInstance().getDbHelper()
|
WKIMApplication.getInstance().getDbHelper()
|
||||||
.update(this.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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.wukong.im.db;
|
package com.wukong.im.db;
|
||||||
|
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.channel;
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.channelMembers;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -21,9 +24,7 @@ import java.util.List;
|
|||||||
* 频道成员数据管理
|
* 频道成员数据管理
|
||||||
*/
|
*/
|
||||||
public class ChannelMembersDbManager {
|
public class ChannelMembersDbManager {
|
||||||
final String channelMembers = "channel_members";
|
final String channelCols = "" + channel + ".channel_remark," + channel + ".channel_name," + channel + ".avatar," + channel + ".avatar_cache_key";
|
||||||
final String channelTab = "channel";
|
|
||||||
final String channelCols = "" + channelTab + ".channel_remark," + channelTab + ".channel_name," + channelTab + ".avatar," + channelTab + ".avatar_cache_key";
|
|
||||||
|
|
||||||
private ChannelMembersDbManager() {
|
private ChannelMembersDbManager() {
|
||||||
}
|
}
|
||||||
@ -38,7 +39,7 @@ public class ChannelMembersDbManager {
|
|||||||
|
|
||||||
public synchronized List<WKChannelMember> search(String channelId, byte channelType, String keyword, int page, int size) {
|
public synchronized List<WKChannelMember> search(String channelId, byte channelType, String keyword, int page, int size) {
|
||||||
int queryPage = (page - 1) * size;
|
int queryPage = (page - 1) * size;
|
||||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channelTab + " on " + channelMembers + ".member_uid=" + channelTab + ".channel_id and " + channelTab + ".channel_type=1 where " + channelMembers + ".channel_id=" + "\"" + channelId + "\"" + " and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 and (member_name like '%" + keyword + "%' or member_remark like '%" + keyword + "%' or channel_name like '%" + keyword + "%' or channel_remark like '%" + keyword + "%') order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc limit " + queryPage + "," + size + "";
|
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id=" + "\"" + channelId + "\"" + " and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 and (member_name like '%" + keyword + "%' or member_remark like '%" + keyword + "%' or channel_name like '%" + keyword + "%' or channel_remark like '%" + keyword + "%') order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc limit " + queryPage + "," + size + "";
|
||||||
Cursor cursor = WKIMApplication
|
Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql);
|
.getDbHelper().rawQuery(sql);
|
||||||
@ -55,7 +56,7 @@ public class ChannelMembersDbManager {
|
|||||||
|
|
||||||
public synchronized List<WKChannelMember> queryWithPage(String channelId, byte channelType, int page, int size) {
|
public synchronized List<WKChannelMember> queryWithPage(String channelId, byte channelType, int page, int size) {
|
||||||
int queryPage = (page - 1) * size;
|
int queryPage = (page - 1) * size;
|
||||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channelTab + " on " + channelMembers + ".member_uid=" + channelTab + ".channel_id and " + channelTab + ".channel_type=1 where " + channelMembers + ".channel_id=" + "\"" + channelId + "\"" + " and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc limit " + queryPage + "," + size + "";
|
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id=" + "\"" + channelId + "\"" + " and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc limit " + queryPage + "," + size + "";
|
||||||
Cursor cursor = WKIMApplication
|
Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql);
|
.getDbHelper().rawQuery(sql);
|
||||||
@ -77,7 +78,7 @@ public class ChannelMembersDbManager {
|
|||||||
* @return List<WKChannelMember>
|
* @return List<WKChannelMember>
|
||||||
*/
|
*/
|
||||||
public synchronized List<WKChannelMember> query(String channelId, byte channelType) {
|
public synchronized List<WKChannelMember> query(String channelId, byte channelType) {
|
||||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channelTab + " on " + channelMembers + ".member_uid=" + channelTab + ".channel_id and " + channelTab + ".channel_type=1 where " + channelMembers + ".channel_id=" + "\"" + channelId + "\"" + " and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id=" + "\"" + channelId + "\"" + " and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
||||||
Cursor cursor = WKIMApplication
|
Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql);
|
.getDbHelper().rawQuery(sql);
|
||||||
@ -93,7 +94,7 @@ public class ChannelMembersDbManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized List<WKChannelMember> queryDeleted(String channelId, byte channelType) {
|
public synchronized List<WKChannelMember> queryDeleted(String channelId, byte channelType) {
|
||||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channelTab + " on " + channelMembers + ".member_uid=" + channelTab + ".channel_id and " + channelTab + ".channel_type=1 where " + channelMembers + ".channel_id=" + "\"" + channelId + "\"" + " and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=1 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id=" + "\"" + channelId + "\"" + " and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=1 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
||||||
Cursor cursor = WKIMApplication
|
Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql);
|
.getDbHelper().rawQuery(sql);
|
||||||
@ -110,7 +111,7 @@ public class ChannelMembersDbManager {
|
|||||||
|
|
||||||
public synchronized boolean isExist(String channelId, byte channelType, String uid) {
|
public synchronized boolean isExist(String channelId, byte channelType, String uid) {
|
||||||
boolean isExist = false;
|
boolean isExist = false;
|
||||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " left join " + channelTab + " on " + channelMembers + ".member_uid = " + channelTab + ".channel_id AND " + channelTab + ".channel_type=1 where (" + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_id + "=" + "\"" + channelId + "\"" + " and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_type + "=" + channelType + " and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.member_uid + "=" + "\"" + uid + "\")";
|
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " left join " + channel + " on " + channelMembers + ".member_uid = " + channel + ".channel_id AND " + channel + ".channel_type=1 where (" + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_id + "=" + "\"" + channelId + "\"" + " and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_type + "=" + channelType + " and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.member_uid + "=" + "\"" + uid + "\")";
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql)) {
|
.getDbHelper().rawQuery(sql)) {
|
||||||
@ -156,7 +157,7 @@ public class ChannelMembersDbManager {
|
|||||||
*/
|
*/
|
||||||
public synchronized WKChannelMember query(String channelId, byte channelType, String uid) {
|
public synchronized WKChannelMember query(String channelId, byte channelType, String uid) {
|
||||||
WKChannelMember wkChannelMember = null;
|
WKChannelMember wkChannelMember = null;
|
||||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " left join " + channelTab + " on " + channelMembers + ".member_uid = " + channelTab + ".channel_id AND " + channelTab + ".channel_type=1 where (" + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_id + "=" + "\"" + channelId + "\"" + " and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_type + "=" + channelType + " and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.member_uid + "=" + "\"" + uid + "\")";
|
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " left join " + channel + " on " + channelMembers + ".member_uid = " + channel + ".channel_id AND " + channel + ".channel_type=1 where (" + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_id + "=" + "\"" + channelId + "\"" + " and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_type + "=" + channelType + " and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.member_uid + "=" + "\"" + uid + "\")";
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql)) {
|
.getDbHelper().rawQuery(sql)) {
|
||||||
@ -435,7 +436,7 @@ public class ChannelMembersDbManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized List<WKChannelMember> queryChannelMembersByStatus(String channelId, byte channelType, int status) {
|
public synchronized List<WKChannelMember> queryChannelMembersByStatus(String channelId, byte channelType, int status) {
|
||||||
String sql = "select " + channelMembers + ".*," + channelTab + ".channel_name," + channelTab + ".channel_remark," + channelTab + ".avatar from " + channelMembers + " left Join " + channelTab + " where " + channelMembers + ".member_uid = " + channelTab + ".channel_id AND " + channelTab + ".channel_type=1 AND " + channelMembers + ".channel_id=" + "\"" + channelId + "\"" + " and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".status=" + status + " order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
String sql = "select " + channelMembers + ".*," + channel + ".channel_name," + channel + ".channel_remark," + channel + ".avatar from " + channelMembers + " left Join " + channel + " where " + channelMembers + ".member_uid = " + channel + ".channel_id AND " + channel + ".channel_type=1 AND " + channelMembers + ".channel_id=" + "\"" + channelId + "\"" + " and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".status=" + status + " order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
||||||
Cursor cursor = WKIMApplication
|
Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql);
|
.getDbHelper().rawQuery(sql);
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package com.wukong.im.db;
|
package com.wukong.im.db;
|
||||||
|
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.channel;
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.conversation;
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.conversationExtra;
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.message;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -13,7 +18,6 @@ import com.wukong.im.entity.WKConversationMsgExtra;
|
|||||||
import com.wukong.im.entity.WKMsg;
|
import com.wukong.im.entity.WKMsg;
|
||||||
import com.wukong.im.entity.WKUIConversationMsg;
|
import com.wukong.im.entity.WKUIConversationMsg;
|
||||||
import com.wukong.im.manager.ConversationManager;
|
import com.wukong.im.manager.ConversationManager;
|
||||||
import com.wukong.im.utils.WKLoggerUtils;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -28,10 +32,6 @@ import java.util.List;
|
|||||||
* 最近会话
|
* 最近会话
|
||||||
*/
|
*/
|
||||||
public class ConversationDbManager {
|
public class ConversationDbManager {
|
||||||
private final String message = "message";
|
|
||||||
private final String conversation = "conversation";
|
|
||||||
private final String conversationExtra = "conversation_extra";
|
|
||||||
private final String channel = "channel";
|
|
||||||
private final String extraCols = "IFNULL(" + conversationExtra + ".browse_to,0) AS browse_to,IFNULL(" + conversationExtra + ".keep_message_seq,0) AS keep_message_seq,IFNULL(" + conversationExtra + ".keep_offset_y,0) AS keep_offset_y,IFNULL(" + conversationExtra + ".draft,'') AS draft,IFNULL(" + conversationExtra + ".version,0) AS extra_version";
|
private final String extraCols = "IFNULL(" + conversationExtra + ".browse_to,0) AS browse_to,IFNULL(" + conversationExtra + ".keep_message_seq,0) AS keep_message_seq,IFNULL(" + conversationExtra + ".keep_offset_y,0) AS keep_offset_y,IFNULL(" + conversationExtra + ".draft,'') AS draft,IFNULL(" + conversationExtra + ".version,0) AS extra_version";
|
||||||
private final String channelCols = channel + ".channel_remark," +
|
private final String channelCols = channel + ".channel_remark," +
|
||||||
channel + ".channel_name," +
|
channel + ".channel_name," +
|
||||||
@ -75,7 +75,6 @@ public class ConversationDbManager {
|
|||||||
+ conversation + ".channel_id = " + channel + ".channel_id AND "
|
+ 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 + ".is_deleted=0 order by "
|
+ 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 + ".is_deleted=0 order by "
|
||||||
+ WKDBColumns.WKCoverMessageColumns.last_msg_timestamp + " desc";
|
+ WKDBColumns.WKCoverMessageColumns.last_msg_timestamp + " desc";
|
||||||
|
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper()
|
.getDbHelper()
|
||||||
@ -83,7 +82,6 @@ public class ConversationDbManager {
|
|||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
|
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
|
||||||
WKConversationMsg msg = serializeMsg(cursor);
|
WKConversationMsg msg = serializeMsg(cursor);
|
||||||
if (msg.isDeleted == 0) {
|
if (msg.isDeleted == 0) {
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package com.wukong.im.db;
|
package com.wukong.im.db;
|
||||||
|
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.channel;
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.channelMembers;
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.message;
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.messageExtra;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -35,9 +40,6 @@ import java.util.List;
|
|||||||
* 消息管理
|
* 消息管理
|
||||||
*/
|
*/
|
||||||
public class MsgDbManager {
|
public class MsgDbManager {
|
||||||
private final String message = "message";
|
|
||||||
private final String messageExtra = "message_extra";
|
|
||||||
private final String channel = "channel";
|
|
||||||
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";
|
||||||
|
|
||||||
@ -54,9 +56,9 @@ public class MsgDbManager {
|
|||||||
|
|
||||||
private int requestCount;
|
private int requestCount;
|
||||||
|
|
||||||
public void getOrSyncHistoryMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, boolean dropDown, int limit, final IGetOrSyncHistoryMsgBack iGetOrSyncHistoryMsgBack) {
|
public void getOrSyncHistoryMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, int pullMode, int limit, final IGetOrSyncHistoryMsgBack iGetOrSyncHistoryMsgBack) {
|
||||||
//获取原始数据
|
//获取原始数据
|
||||||
List<WKMsg> list = getMessages(channelId, channelType, oldestOrderSeq, contain, dropDown, limit);
|
List<WKMsg> list = getMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit);
|
||||||
|
|
||||||
//业务判断数据
|
//业务判断数据
|
||||||
List<WKMsg> tempList = new ArrayList<>();
|
List<WKMsg> tempList = new ArrayList<>();
|
||||||
@ -83,31 +85,38 @@ public class MsgDbManager {
|
|||||||
boolean isSyncMsg = false;
|
boolean isSyncMsg = false;
|
||||||
//reverse false:从区间大值开始拉取true:从区间小值开始拉取
|
//reverse false:从区间大值开始拉取true:从区间小值开始拉取
|
||||||
boolean reverse = false;
|
boolean reverse = false;
|
||||||
|
long startMsgSeq = 0;
|
||||||
|
long endMsgSeq = 0;
|
||||||
//同步消息的最大messageSeq
|
//同步消息的最大messageSeq
|
||||||
long syncMaxMsgSeq = 0;
|
// long syncMaxMsgSeq = 0;
|
||||||
//同步消息最小messageSeq,
|
//同步消息最小messageSeq,
|
||||||
long syncMinMsgSeq = 0;
|
// long syncMinMsgSeq = 0;
|
||||||
|
|
||||||
//判断页与页之间是否连续
|
//判断页与页之间是否连续
|
||||||
long oldestMsgSeq;
|
long oldestMsgSeq;
|
||||||
|
|
||||||
//如果获取到的messageSeq为0说明oldestOrderSeq这条消息是本地消息则获取他上一条或下一条消息的messageSeq做为判断
|
//如果获取到的messageSeq为0说明oldestOrderSeq这条消息是本地消息则获取他上一条或下一条消息的messageSeq做为判断
|
||||||
if (oldestOrderSeq % 1000 != 0)
|
if (oldestOrderSeq % 1000 != 0)
|
||||||
oldestMsgSeq = getMsgSeq(channelId, channelType, oldestOrderSeq, dropDown);
|
oldestMsgSeq = getMsgSeq(channelId, channelType, oldestOrderSeq, pullMode);
|
||||||
else oldestMsgSeq = oldestOrderSeq / 1000;
|
else oldestMsgSeq = oldestOrderSeq / 1000;
|
||||||
if (dropDown) {
|
if (pullMode == 0) {
|
||||||
//下拉获取消息
|
//下拉获取消息
|
||||||
if (maxMessageSeq != 0 && oldestMsgSeq != 0 && oldestMsgSeq - maxMessageSeq > 1) {
|
if (maxMessageSeq != 0 && oldestMsgSeq != 0 && oldestMsgSeq - maxMessageSeq > 1) {
|
||||||
isSyncMsg = true;
|
isSyncMsg = true;
|
||||||
syncMaxMsgSeq = oldestMsgSeq;
|
// syncMaxMsgSeq = oldestMsgSeq;
|
||||||
syncMinMsgSeq = maxMessageSeq;
|
// syncMinMsgSeq = maxMessageSeq;
|
||||||
|
startMsgSeq = maxMessageSeq;
|
||||||
|
endMsgSeq = oldestMsgSeq;
|
||||||
reverse = false;//区间大值开始获取
|
reverse = false;//区间大值开始获取
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//上拉获取消息
|
//上拉获取消息
|
||||||
if (minMessageSeq != 0 && oldestMsgSeq != 0 && minMessageSeq - oldestMsgSeq > 1) {
|
if (minMessageSeq != 0 && oldestMsgSeq != 0 && minMessageSeq - oldestMsgSeq > 1) {
|
||||||
isSyncMsg = true;
|
isSyncMsg = true;
|
||||||
syncMaxMsgSeq = minMessageSeq;
|
// syncMaxMsgSeq = minMessageSeq;
|
||||||
syncMinMsgSeq = oldestMsgSeq;
|
// syncMinMsgSeq = oldestMsgSeq;
|
||||||
|
startMsgSeq = minMessageSeq;
|
||||||
|
endMsgSeq = oldestMsgSeq;
|
||||||
reverse = true;//区间小值开始获取
|
reverse = true;//区间小值开始获取
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,10 +132,24 @@ public class MsgDbManager {
|
|||||||
int num = getDeletedCount(tempList.get(i).messageSeq, tempList.get(nextIndex).messageSeq, channelId, channelType);
|
int num = getDeletedCount(tempList.get(i).messageSeq, tempList.get(nextIndex).messageSeq, channelId, channelType);
|
||||||
if (num < (tempList.get(nextIndex).messageSeq - tempList.get(i).messageSeq) - 1) {
|
if (num < (tempList.get(nextIndex).messageSeq - tempList.get(i).messageSeq) - 1) {
|
||||||
isSyncMsg = true;
|
isSyncMsg = true;
|
||||||
syncMaxMsgSeq = tempList.get(nextIndex).messageSeq;
|
// syncMaxMsgSeq = tempList.get(nextIndex).messageSeq;
|
||||||
syncMinMsgSeq = tempList.get(i).messageSeq;
|
// syncMinMsgSeq = tempList.get(i).messageSeq;
|
||||||
if (dropDown) reverse = false;//区间大值开始获取
|
long max = tempList.get(nextIndex).messageSeq;
|
||||||
else reverse = true;//区间小值开始获取
|
long min = tempList.get(i).messageSeq;
|
||||||
|
if (tempList.get(nextIndex).messageSeq < tempList.get(i).messageSeq) {
|
||||||
|
max = tempList.get(i).messageSeq;
|
||||||
|
min = tempList.get(nextIndex).messageSeq;
|
||||||
|
}
|
||||||
|
if (pullMode == 0) {
|
||||||
|
// 下拉
|
||||||
|
startMsgSeq = max;
|
||||||
|
endMsgSeq = min;
|
||||||
|
} else {
|
||||||
|
startMsgSeq = min;
|
||||||
|
endMsgSeq = max;
|
||||||
|
}
|
||||||
|
// if (pullMode == 0) reverse = false;//区间大值开始获取
|
||||||
|
// else reverse = true;//区间小值开始获取
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,18 +166,22 @@ public class MsgDbManager {
|
|||||||
}
|
}
|
||||||
//计算最后一页后是否还存在消息
|
//计算最后一页后是否还存在消息
|
||||||
if (!isSyncMsg && tempList.size() < limit) {
|
if (!isSyncMsg && tempList.size() < limit) {
|
||||||
if (dropDown) {
|
if (pullMode == 0) {
|
||||||
//如果下拉获取数据
|
//如果下拉获取数据
|
||||||
isSyncMsg = true;
|
isSyncMsg = true;
|
||||||
reverse = false;//从区间大值开始获取数据
|
reverse = false;//从区间大值开始获取数据
|
||||||
syncMinMsgSeq = 0;
|
// syncMinMsgSeq = 0;
|
||||||
syncMaxMsgSeq = oldestMsgSeq;
|
// syncMaxMsgSeq = oldestMsgSeq;
|
||||||
|
startMsgSeq = oldestMsgSeq;
|
||||||
|
endMsgSeq = 0;
|
||||||
} else {
|
} else {
|
||||||
//如果上拉获取数据
|
//如果上拉获取数据
|
||||||
isSyncMsg = true;
|
isSyncMsg = true;
|
||||||
reverse = true;//从区间小值开始获取数据
|
reverse = true;//从区间小值开始获取数据
|
||||||
syncMaxMsgSeq = 0;
|
// syncMaxMsgSeq = 0;
|
||||||
syncMinMsgSeq = maxMessageSeq;
|
// syncMinMsgSeq = maxMessageSeq;
|
||||||
|
startMsgSeq = oldestMsgSeq;
|
||||||
|
endMsgSeq = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if (!isContain) {
|
// if (!isContain) {
|
||||||
@ -184,12 +211,12 @@ public class MsgDbManager {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (isSyncMsg && syncMaxMsgSeq != syncMinMsgSeq && syncMaxMsgSeq != 0 && requestCount < 5) {
|
if (isSyncMsg && startMsgSeq != endMsgSeq && requestCount < 5) {
|
||||||
//同步消息
|
//同步消息
|
||||||
requestCount++;
|
requestCount++;
|
||||||
MsgManager.getInstance().setSyncChannelMsgListener(channelId, channelType, syncMinMsgSeq, syncMaxMsgSeq, limit, reverse, 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) {
|
||||||
getOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, dropDown, limit, iGetOrSyncHistoryMsgBack);
|
getOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit, iGetOrSyncHistoryMsgBack);
|
||||||
} else {
|
} else {
|
||||||
requestCount = 0;
|
requestCount = 0;
|
||||||
iGetOrSyncHistoryMsgBack.onResult(list);
|
iGetOrSyncHistoryMsgBack.onResult(list);
|
||||||
@ -247,14 +274,14 @@ public class MsgDbManager {
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<WKMsg> getMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, boolean dropDown, int limit) {
|
private List<WKMsg> getMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, int pullMode, int limit) {
|
||||||
List<WKMsg> msgList = new ArrayList<>();
|
List<WKMsg> msgList = new ArrayList<>();
|
||||||
String sql;
|
String sql;
|
||||||
|
|
||||||
if (oldestOrderSeq <= 0) {
|
if (oldestOrderSeq <= 0) {
|
||||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelId + "' and " + message + ".channel_type=" + channelType + " and " + message + ".type<>0 and " + message + ".type<>99) where is_deleted=0 and is_mutual_deleted=0 order by order_seq desc limit 0," + limit;
|
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelId + "' and " + message + ".channel_type=" + channelType + " and " + message + ".type<>0 and " + message + ".type<>99) where is_deleted=0 and is_mutual_deleted=0 order by order_seq desc limit 0," + limit;
|
||||||
} else {
|
} else {
|
||||||
if (dropDown) {
|
if (pullMode == 0) {
|
||||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelId + "' and " + message + ".channel_type=" + channelType + " and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq<" + oldestOrderSeq + ") where is_deleted=0 and is_mutual_deleted=0 order by order_seq desc limit 0," + limit;
|
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelId + "' and " + message + ".channel_type=" + channelType + " and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq<" + oldestOrderSeq + ") where is_deleted=0 and is_mutual_deleted=0 order by order_seq desc limit 0," + limit;
|
||||||
} else {
|
} else {
|
||||||
if (contain) {
|
if (contain) {
|
||||||
@ -283,7 +310,7 @@ public class MsgDbManager {
|
|||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(wkMsg.fromUID))
|
if (!TextUtils.isEmpty(wkMsg.fromUID))
|
||||||
fromUIDs.add(wkMsg.fromUID);
|
fromUIDs.add(wkMsg.fromUID);
|
||||||
if (dropDown)
|
if (pullMode == 0)
|
||||||
msgList.add(0, wkMsg);
|
msgList.add(0, wkMsg);
|
||||||
else msgList.add(wkMsg);
|
else msgList.add(wkMsg);
|
||||||
}
|
}
|
||||||
@ -709,6 +736,7 @@ public class MsgDbManager {
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除消息
|
* 删除消息
|
||||||
*
|
*
|
||||||
@ -1192,10 +1220,10 @@ public class MsgDbManager {
|
|||||||
return messageSeq;
|
return messageSeq;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMsgSeq(String channelID, byte channelType, long oldestOrderSeq, boolean dropDown) {
|
private int getMsgSeq(String channelID, byte channelType, long oldestOrderSeq, int pullMode) {
|
||||||
String sql;
|
String sql;
|
||||||
int messageSeq = 0;
|
int messageSeq = 0;
|
||||||
if (!dropDown) {
|
if (pullMode == 1) {
|
||||||
sql = "select * from " + message + " where channel_id=" + "\"" + channelID + "\"" + " and channel_type=" + channelType + " and order_seq>" + oldestOrderSeq + " and message_seq<>0 order by message_seq desc limit 1";
|
sql = "select * from " + message + " where channel_id=" + "\"" + channelID + "\"" + " and channel_type=" + channelType + " and order_seq>" + oldestOrderSeq + " and message_seq<>0 order by message_seq desc limit 1";
|
||||||
} else
|
} else
|
||||||
sql = "select * from " + message + " where channel_id=" + "\"" + channelID + "\"" + " and channel_type=" + channelType + " and order_seq<" + oldestOrderSeq + " and message_seq<>0 order by message_seq asc limit 1";
|
sql = "select * from " + message + " where channel_id=" + "\"" + channelID + "\"" + " and channel_type=" + channelType + " and order_seq<" + oldestOrderSeq + " and message_seq<>0 order by message_seq asc limit 1";
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.wukong.im.db;
|
package com.wukong.im.db;
|
||||||
|
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.messageReaction;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -18,7 +20,6 @@ import java.util.List;
|
|||||||
* 消息回应
|
* 消息回应
|
||||||
*/
|
*/
|
||||||
class MsgReactionDBManager {
|
class MsgReactionDBManager {
|
||||||
final String messageReaction = "message_reaction";
|
|
||||||
private MsgReactionDBManager() {
|
private MsgReactionDBManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.wukong.im.db;
|
package com.wukong.im.db;
|
||||||
|
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.reminders;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -18,8 +20,6 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ReminderDBManager {
|
public class ReminderDBManager {
|
||||||
private final String tab = "reminders";
|
|
||||||
|
|
||||||
private ReminderDBManager() {
|
private ReminderDBManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ public class ReminderDBManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long getMaxVersion() {
|
public long getMaxVersion() {
|
||||||
String sql = "select * from " + tab + " order by version desc limit 1";
|
String sql = "select * from " + reminders + " order by version desc limit 1";
|
||||||
long version = 0;
|
long version = 0;
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
@ -48,7 +48,7 @@ public class ReminderDBManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<WKReminder> queryWithChannel(String channelID, byte channelType, int done) {
|
public List<WKReminder> queryWithChannel(String channelID, byte channelType, int done) {
|
||||||
String sql = "select * from " + tab + " where channel_id='" + channelID + "' and channel_type=" + channelType + " and done=" + done + " order by message_seq desc";
|
String sql = "select * from " + reminders + " where channel_id='" + channelID + "' and channel_type=" + channelType + " and done=" + done + " order by message_seq desc";
|
||||||
List<WKReminder> list = new ArrayList<>();
|
List<WKReminder> list = new ArrayList<>();
|
||||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
@ -63,7 +63,7 @@ public class ReminderDBManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<WKReminder> queryWithChannelAndType(String channelID, byte channelType, int done, int type) {
|
public List<WKReminder> queryWithChannelAndType(String channelID, byte channelType, int done, int type) {
|
||||||
String sql = "select * from " + tab + " where channel_id='" + channelID + "' and channel_type=" + channelType + " and done=" + done + " and type =" + type + " order by message_seq desc";
|
String sql = "select * from " + reminders + " where channel_id='" + channelID + "' and channel_type=" + channelType + " and done=" + done + " and type =" + type + " order by message_seq desc";
|
||||||
List<WKReminder> list = new ArrayList<>();
|
List<WKReminder> list = new ArrayList<>();
|
||||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
@ -85,7 +85,7 @@ public class ReminderDBManager {
|
|||||||
}
|
}
|
||||||
stringBuffer.append(ids.get(i));
|
stringBuffer.append(ids.get(i));
|
||||||
}
|
}
|
||||||
String sql = "select * from " + tab + " where reminder_id in (" + stringBuffer + ")";
|
String sql = "select * from " + reminders + " where reminder_id in (" + stringBuffer + ")";
|
||||||
List<WKReminder> list = new ArrayList<>();
|
List<WKReminder> list = new ArrayList<>();
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
@ -111,7 +111,7 @@ public class ReminderDBManager {
|
|||||||
}
|
}
|
||||||
stringBuffer.append(channelIds.get(i)).append("'");
|
stringBuffer.append(channelIds.get(i)).append("'");
|
||||||
}
|
}
|
||||||
String sql = "select * from " + tab + " where channel_id in ('" + stringBuffer + ")";
|
String sql = "select * from " + reminders + " where channel_id in ('" + stringBuffer + ")";
|
||||||
List<WKReminder> list = new ArrayList<>();
|
List<WKReminder> list = new ArrayList<>();
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
@ -165,7 +165,7 @@ public class ReminderDBManager {
|
|||||||
.beginTransaction();
|
.beginTransaction();
|
||||||
if (insertCVs.size() > 0) {
|
if (insertCVs.size() > 0) {
|
||||||
for (ContentValues cv : insertCVs) {
|
for (ContentValues cv : insertCVs) {
|
||||||
WKIMApplication.getInstance().getDbHelper().insert(tab, cv);
|
WKIMApplication.getInstance().getDbHelper().insert(reminders, cv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updateCVs.size() > 0) {
|
if (updateCVs.size() > 0) {
|
||||||
@ -173,7 +173,7 @@ public class ReminderDBManager {
|
|||||||
String[] update = new String[1];
|
String[] update = new String[1];
|
||||||
update[0] = cv.getAsString("reminder_id");
|
update[0] = cv.getAsString("reminder_id");
|
||||||
WKIMApplication.getInstance().getDbHelper()
|
WKIMApplication.getInstance().getDbHelper()
|
||||||
.update(tab, cv, "reminder_id=?", update);
|
.update(reminders, cv, "reminder_id=?", update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WKIMApplication.getInstance().getDbHelper().getDb()
|
WKIMApplication.getInstance().getDbHelper().getDb()
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.wukong.im.db;
|
package com.wukong.im.db;
|
||||||
|
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.robot;
|
||||||
|
import static com.wukong.im.db.WKDBColumns.TABLE.robotMenu;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
@ -11,8 +14,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RobotDBManager {
|
public class RobotDBManager {
|
||||||
private final String robot = "robot";
|
|
||||||
private final String robotMenu = "robot_menu";
|
|
||||||
|
|
||||||
private RobotDBManager() {
|
private RobotDBManager() {
|
||||||
}
|
}
|
||||||
@ -26,11 +27,11 @@ public class RobotDBManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void insertOrUpdateMenu(List<WKRobotMenu> list) {
|
public void insertOrUpdateMenu(List<WKRobotMenu> list) {
|
||||||
for (WKRobotMenu robotMenu : list) {
|
for (WKRobotMenu menu : list) {
|
||||||
if (isExitMenu(robotMenu.robotID, robotMenu.cmd)) {
|
if (isExitMenu(menu.robotID, menu.cmd)) {
|
||||||
update(robotMenu);
|
update(menu);
|
||||||
} else {
|
} else {
|
||||||
WKIMApplication.getInstance().getDbHelper().insert(this.robotMenu, getCV(robotMenu));
|
WKIMApplication.getInstance().getDbHelper().insert(robotMenu, getCV(menu));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,33 +89,33 @@ public class RobotDBManager {
|
|||||||
return isExist;
|
return isExist;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(WKRobot robot) {
|
private void update(WKRobot wkRobot) {
|
||||||
String[] updateKey = new String[6];
|
String[] updateKey = new String[6];
|
||||||
String[] updateValue = new String[6];
|
String[] updateValue = new String[6];
|
||||||
updateKey[0] = "status";
|
updateKey[0] = "status";
|
||||||
updateValue[0] = String.valueOf(robot.status);
|
updateValue[0] = String.valueOf(wkRobot.status);
|
||||||
updateKey[1] = "version";
|
updateKey[1] = "version";
|
||||||
updateValue[1] = String.valueOf(robot.version);
|
updateValue[1] = String.valueOf(wkRobot.version);
|
||||||
updateKey[2] = "updated_at";
|
updateKey[2] = "updated_at";
|
||||||
updateValue[2] = String.valueOf(robot.updatedAT);
|
updateValue[2] = String.valueOf(wkRobot.updatedAT);
|
||||||
updateKey[3] = "username";
|
updateKey[3] = "username";
|
||||||
updateValue[3] = robot.username;
|
updateValue[3] = wkRobot.username;
|
||||||
updateKey[4] = "placeholder";
|
updateKey[4] = "placeholder";
|
||||||
updateValue[4] = robot.placeholder;
|
updateValue[4] = wkRobot.placeholder;
|
||||||
updateKey[5] = "inline_on";
|
updateKey[5] = "inline_on";
|
||||||
updateValue[5] = String.valueOf(robot.inlineOn);
|
updateValue[5] = String.valueOf(wkRobot.inlineOn);
|
||||||
|
|
||||||
String where = "robot_id=?";
|
String where = "robot_id=?";
|
||||||
String[] whereValue = new String[1];
|
String[] whereValue = new String[1];
|
||||||
whereValue[0] = robot.robotID;
|
whereValue[0] = wkRobot.robotID;
|
||||||
WKIMApplication.getInstance().getDbHelper()
|
WKIMApplication.getInstance().getDbHelper()
|
||||||
.update(this.robot, updateKey, updateValue, where, whereValue);
|
.update(robot, updateKey, updateValue, where, whereValue);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insert(WKRobot robot) {
|
private void insert(WKRobot robot1) {
|
||||||
ContentValues cv = getCV(robot);
|
ContentValues cv = getCV(robot1);
|
||||||
WKIMApplication.getInstance().getDbHelper().insert(this.robot, cv);
|
WKIMApplication.getInstance().getDbHelper().insert(robot, cv);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertRobots(List<WKRobot> list) {
|
public void insertRobots(List<WKRobot> list) {
|
||||||
@ -136,8 +137,8 @@ public class RobotDBManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WKRobot query(String robotID) {
|
public WKRobot query(String robotID) {
|
||||||
WKRobot robot = null;
|
WKRobot wkRobot = null;
|
||||||
String sql = "select * from " + this.robot + " where robot_id = " + "\"" + robotID + "\"";
|
String sql = "select * from " + robot + " where robot_id = " + "\"" + robotID + "\"";
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql)) {
|
.getDbHelper().rawQuery(sql)) {
|
||||||
@ -145,15 +146,15 @@ public class RobotDBManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (cursor.moveToLast()) {
|
if (cursor.moveToLast()) {
|
||||||
robot = serializeRobot(cursor);
|
wkRobot = serializeRobot(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return robot;
|
return wkRobot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WKRobot queryWithUsername(String username) {
|
public WKRobot queryWithUsername(String username) {
|
||||||
WKRobot robot = null;
|
WKRobot wkRobot = null;
|
||||||
String sql = "select * from " + this.robot + " where username = " + "\"" + username + "\"";
|
String sql = "select * from " + robot + " where username = " + "\"" + username + "\"";
|
||||||
try (Cursor cursor = WKIMApplication
|
try (Cursor cursor = WKIMApplication
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.getDbHelper().rawQuery(sql)) {
|
.getDbHelper().rawQuery(sql)) {
|
||||||
@ -161,10 +162,10 @@ public class RobotDBManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (cursor.moveToLast()) {
|
if (cursor.moveToLast()) {
|
||||||
robot = serializeRobot(cursor);
|
wkRobot = serializeRobot(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return robot;
|
return wkRobot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<WKRobot> queryRobots(List<String> robotIds) {
|
public List<WKRobot> queryRobots(List<String> robotIds) {
|
||||||
|
@ -5,6 +5,18 @@ package com.wukong.im.db;
|
|||||||
* 数据库字段
|
* 数据库字段
|
||||||
*/
|
*/
|
||||||
public interface WKDBColumns {
|
public interface WKDBColumns {
|
||||||
|
class TABLE{
|
||||||
|
public static final String message = "message";
|
||||||
|
public static final String messageReaction = "message_reaction";
|
||||||
|
public static final String messageExtra = "message_extra";
|
||||||
|
public static final String conversation = "conversation";
|
||||||
|
public static final String conversationExtra = "conversation_extra";
|
||||||
|
public static final String channel = "channel";
|
||||||
|
public static final String channelMembers = "channel_members";
|
||||||
|
public static final String reminders = "reminders";
|
||||||
|
public static final String robot = "robot";
|
||||||
|
public static final String robotMenu = "robot_menu";
|
||||||
|
}
|
||||||
//频道db字段
|
//频道db字段
|
||||||
class WKChannelColumns {
|
class WKChannelColumns {
|
||||||
//自增ID
|
//自增ID
|
||||||
|
@ -5,5 +5,5 @@ package com.wukong.im.interfaces;
|
|||||||
* 同步频道消息
|
* 同步频道消息
|
||||||
*/
|
*/
|
||||||
public interface ISyncChannelMsgListener {
|
public interface ISyncChannelMsgListener {
|
||||||
void syncChannelMsgs(String channelID, byte channelType, long minMessageSeq, long maxMesageSeq, int limit, boolean reverse, ISyncChannelMsgBack iSyncChannelMsgBack);
|
void syncChannelMsgs(String channelID, byte channelType, long startMessageSeq, long endMessageSeq, int limit, int pullMode, ISyncChannelMsgBack iSyncChannelMsgBack);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import com.wukong.im.message.MessageHandler;
|
|||||||
import com.wukong.im.utils.WKLoggerUtils;
|
import com.wukong.im.utils.WKLoggerUtils;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,9 +81,16 @@ public class ConnectionManager extends BaseManager {
|
|||||||
WKIMApplication.getInstance().closeDbHelper();
|
WKIMApplication.getInstance().closeDbHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getIpAndPort(IGetSocketIpAndPortListener iGetIpAndPortListener) {
|
public interface IRequestIP {
|
||||||
|
void onResult(String requestId, String ip, int port);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getIpAndPort(String requestId, IRequestIP iRequestIP) {
|
||||||
if (iGetIpAndPort != null) {
|
if (iGetIpAndPort != null) {
|
||||||
runOnMainThread(() -> iGetIpAndPort.getIP(iGetIpAndPortListener));
|
WKLoggerUtils.getInstance().e("获取IP中...");
|
||||||
|
runOnMainThread(() -> iGetIpAndPort.getIP((ip, port) -> iRequestIP.onResult(requestId, ip, port)));
|
||||||
|
} else {
|
||||||
|
WKLoggerUtils.getInstance().e("未注册获取IP事件");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,19 +285,19 @@ public class MsgManager extends BaseManager {
|
|||||||
* @param channelType 频道类型
|
* @param channelType 频道类型
|
||||||
* @param oldestOrderSeq 最后一次消息大orderSeq 第一次进入聊天传入0
|
* @param oldestOrderSeq 最后一次消息大orderSeq 第一次进入聊天传入0
|
||||||
* @param contain 是否包含 oldestOrderSeq 这条消息
|
* @param contain 是否包含 oldestOrderSeq 这条消息
|
||||||
* @param dropDown 是否下拉
|
* @param pullMode 拉取模式 0:向下拉取 1:向上拉取
|
||||||
* @param aroundMsgOrderSeq 查询此消息附近消息
|
* @param aroundMsgOrderSeq 查询此消息附近消息
|
||||||
* @param limit 每次获取数量
|
* @param limit 每次获取数量
|
||||||
* @param iGetOrSyncHistoryMsgBack 请求返还
|
* @param iGetOrSyncHistoryMsgBack 请求返还
|
||||||
*/
|
*/
|
||||||
public void getOrSyncHistoryMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, boolean dropDown, 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) {
|
||||||
if (aroundMsgOrderSeq != 0) {
|
if (aroundMsgOrderSeq != 0) {
|
||||||
long maxMsgSeq = getMaxMessageSeq(channelId, channelType);
|
long maxMsgSeq = getMaxMessageSeq(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;
|
||||||
contain = false;
|
contain = false;
|
||||||
dropDown = true;
|
pullMode = 0;
|
||||||
} else {
|
} else {
|
||||||
long minOrderSeq = MsgDbManager.getInstance().getOrderSeq(channelId, channelType, aroundMsgOrderSeq, 3);
|
long minOrderSeq = MsgDbManager.getInstance().getOrderSeq(channelId, channelType, aroundMsgOrderSeq, 3);
|
||||||
if (minOrderSeq == 0) {
|
if (minOrderSeq == 0) {
|
||||||
@ -318,11 +318,11 @@ public class MsgManager extends BaseManager {
|
|||||||
oldestOrderSeq = startOrderSeq;
|
oldestOrderSeq = startOrderSeq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dropDown = false;
|
pullMode = 1;
|
||||||
contain = true;
|
contain = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MsgDbManager.getInstance().getOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, dropDown, limit, iGetOrSyncHistoryMsgBack);
|
MsgDbManager.getInstance().getOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq, contain, pullMode, limit, iGetOrSyncHistoryMsgBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<WKMsg> queryAll() {
|
public List<WKMsg> queryAll() {
|
||||||
@ -879,9 +879,9 @@ public class MsgManager extends BaseManager {
|
|||||||
this.iSyncChannelMsgListener = listener;
|
this.iSyncChannelMsgListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSyncChannelMsgListener(String channelID, byte channelType, long minMessageSeq, long maxMesageSeq, int limit, boolean reverse, ISyncChannelMsgBack iSyncChannelMsgBack) {
|
public void setSyncChannelMsgListener(String channelID, byte channelType, long startMessageSeq, long endMessageSeq, int limit, int pullMode, ISyncChannelMsgBack iSyncChannelMsgBack) {
|
||||||
if (this.iSyncChannelMsgListener != null) {
|
if (this.iSyncChannelMsgListener != null) {
|
||||||
runOnMainThread(() -> iSyncChannelMsgListener.syncChannelMsgs(channelID, channelType, minMessageSeq, maxMesageSeq, limit, reverse, syncChannelMsg -> {
|
runOnMainThread(() -> iSyncChannelMsgListener.syncChannelMsgs(channelID, channelType, startMessageSeq, endMessageSeq, limit, pullMode, syncChannelMsg -> {
|
||||||
if (syncChannelMsg != null && syncChannelMsg.messages != null && syncChannelMsg.messages.size() > 0) {
|
if (syncChannelMsg != null && syncChannelMsg.messages != null && syncChannelMsg.messages.size() > 0) {
|
||||||
saveSyncChannelMSGs(syncChannelMsg.messages);
|
saveSyncChannelMSGs(syncChannelMsg.messages);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class ClientHandler implements IDataHandler, IConnectHandler,
|
|||||||
@Override
|
@Override
|
||||||
public boolean onConnectException(INonBlockingConnection iNonBlockingConnection, IOException e) {
|
public boolean onConnectException(INonBlockingConnection iNonBlockingConnection, IOException e) {
|
||||||
WKLoggerUtils.getInstance().e("连接异常");
|
WKLoggerUtils.getInstance().e("连接异常");
|
||||||
ConnectionHandler.getInstance().reconnection();
|
ConnectionHandler.getInstance().forcedReconnection();
|
||||||
close(iNonBlockingConnection);
|
close(iNonBlockingConnection);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ class ClientHandler implements IDataHandler, IConnectHandler,
|
|||||||
if (ConnectionHandler.getInstance().connection != null && iNonBlockingConnection != null) {
|
if (ConnectionHandler.getInstance().connection != null && iNonBlockingConnection != null) {
|
||||||
if (!ConnectionHandler.getInstance().connection.getId().equals(iNonBlockingConnection.getId())) {
|
if (!ConnectionHandler.getInstance().connection.getId().equals(iNonBlockingConnection.getId())) {
|
||||||
close(iNonBlockingConnection);
|
close(iNonBlockingConnection);
|
||||||
ConnectionHandler.getInstance().reconnection();
|
ConnectionHandler.getInstance().forcedReconnection();
|
||||||
} else {
|
} else {
|
||||||
//连接成功
|
//连接成功
|
||||||
isConnectSuccess = true;
|
isConnectSuccess = true;
|
||||||
@ -57,7 +57,7 @@ class ClientHandler implements IDataHandler, IConnectHandler,
|
|||||||
} else {
|
} else {
|
||||||
close(iNonBlockingConnection);
|
close(iNonBlockingConnection);
|
||||||
WKLoggerUtils.getInstance().e("连接成功连接对象为空");
|
WKLoggerUtils.getInstance().e("连接成功连接对象为空");
|
||||||
ConnectionHandler.getInstance().reconnection();
|
ConnectionHandler.getInstance().forcedReconnection();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ class ClientHandler implements IDataHandler, IConnectHandler,
|
|||||||
public boolean onConnectionTimeout(INonBlockingConnection iNonBlockingConnection) {
|
public boolean onConnectionTimeout(INonBlockingConnection iNonBlockingConnection) {
|
||||||
if (!isConnectSuccess) {
|
if (!isConnectSuccess) {
|
||||||
WKLoggerUtils.getInstance().e("连接超时");
|
WKLoggerUtils.getInstance().e("连接超时");
|
||||||
ConnectionHandler.getInstance().reconnection();
|
ConnectionHandler.getInstance().forcedReconnection();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ class ClientHandler implements IDataHandler, IConnectHandler,
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionHandler.getInstance().reconnection();
|
ConnectionHandler.getInstance().forcedReconnection();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ class ClientHandler implements IDataHandler, IConnectHandler,
|
|||||||
public boolean onDisconnect(INonBlockingConnection iNonBlockingConnection) {
|
public boolean onDisconnect(INonBlockingConnection iNonBlockingConnection) {
|
||||||
WKLoggerUtils.getInstance().e("连接断开");
|
WKLoggerUtils.getInstance().e("连接断开");
|
||||||
if (WKIMApplication.getInstance().isCanConnect) {
|
if (WKIMApplication.getInstance().isCanConnect) {
|
||||||
ConnectionHandler.getInstance().reconnection();
|
ConnectionHandler.getInstance().forcedReconnection();
|
||||||
}else {
|
}else {
|
||||||
WKLoggerUtils.getInstance().e("不能重连-->");
|
WKLoggerUtils.getInstance().e("不能重连-->");
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ class ClientHandler implements IDataHandler, IConnectHandler,
|
|||||||
public boolean onIdleTimeout(INonBlockingConnection iNonBlockingConnection) {
|
public boolean onIdleTimeout(INonBlockingConnection iNonBlockingConnection) {
|
||||||
if (!isConnectSuccess) {
|
if (!isConnectSuccess) {
|
||||||
WKLoggerUtils.getInstance().e("Idle连接超时");
|
WKLoggerUtils.getInstance().e("Idle连接超时");
|
||||||
ConnectionHandler.getInstance().reconnection();
|
ConnectionHandler.getInstance().forcedReconnection();
|
||||||
close(iNonBlockingConnection);
|
close(iNonBlockingConnection);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -2,7 +2,6 @@ package com.wukong.im.message;
|
|||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.CountDownTimer;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -46,6 +45,8 @@ import java.io.IOException;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -74,15 +75,25 @@ public class ConnectionHandler {
|
|||||||
private long lastMsgTime = 0;
|
private long lastMsgTime = 0;
|
||||||
private String ip;
|
private String ip;
|
||||||
private int port;
|
private int port;
|
||||||
INonBlockingConnection connection;
|
volatile INonBlockingConnection connection;
|
||||||
ClientHandler clientHandler;
|
volatile ClientHandler clientHandler;
|
||||||
private long requestIPTime;
|
private long requestIPTime;
|
||||||
|
private final long requestIPTimeoutTime = 6;
|
||||||
public String socketSingleID;
|
public String socketSingleID;
|
||||||
|
private String lastRequestId;
|
||||||
|
|
||||||
|
public synchronized void forcedReconnection() {
|
||||||
|
isReConnecting = false;
|
||||||
|
requestIPTime = 0;
|
||||||
|
reconnection();
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void reconnection() {
|
public synchronized void reconnection() {
|
||||||
|
ip = "";
|
||||||
|
port = 0;
|
||||||
if (isReConnecting) {
|
if (isReConnecting) {
|
||||||
long nowTime = DateUtils.getInstance().getCurrentSeconds();
|
long nowTime = DateUtils.getInstance().getCurrentSeconds();
|
||||||
if (nowTime - requestIPTime > 5) {
|
if (nowTime - requestIPTime > requestIPTimeoutTime) {
|
||||||
isReConnecting = false;
|
isReConnecting = false;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -107,14 +118,14 @@ public class ConnectionHandler {
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
reconnection();
|
new Handler(Looper.getMainLooper()).post(() -> reconnection());
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getIPAndPort() {
|
private synchronized void getIPAndPort() {
|
||||||
if (!WKIMApplication.getInstance().isNetworkConnected()) {
|
if (!WKIMApplication.getInstance().isNetworkConnected()) {
|
||||||
isReConnecting = false;
|
isReConnecting = false;
|
||||||
reconnection();
|
reconnection();
|
||||||
@ -127,24 +138,29 @@ public class ConnectionHandler {
|
|||||||
}
|
}
|
||||||
WKIM.getInstance().getConnectionManager().setConnectionStatus(WKConnectStatus.connecting, WKConnectReason.Connecting);
|
WKIM.getInstance().getConnectionManager().setConnectionStatus(WKConnectStatus.connecting, WKConnectReason.Connecting);
|
||||||
// 计算获取IP时长 todo
|
// 计算获取IP时长 todo
|
||||||
ConnectionManager.getInstance().getIpAndPort((ip, port) -> {
|
startRequestIPTimer();
|
||||||
if (countDownTimer != null) {
|
lastRequestId = UUID.randomUUID().toString().replace("-", "");
|
||||||
countDownTimer.cancel();
|
ConnectionManager.getInstance().getIpAndPort(lastRequestId, (requestId, ip, port) -> {
|
||||||
countDownTimer = null;
|
|
||||||
WKLoggerUtils.getInstance().e("取消请求socket IP倒计时器--->");
|
|
||||||
}
|
|
||||||
if (TextUtils.isEmpty(ip) || port == 0) {
|
if (TextUtils.isEmpty(ip) || port == 0) {
|
||||||
WKLoggerUtils.getInstance().e("返回连接IP或port错误," + String.format("ip:%s & port:%s", ip, port));
|
WKLoggerUtils.getInstance().e("返回连接IP或port错误," + String.format("ip:%s & port:%s", ip, port));
|
||||||
isReConnecting = false;
|
isReConnecting = false;
|
||||||
reconnection();
|
reconnection();
|
||||||
} else {
|
} else {
|
||||||
this.ip = ip;
|
if (lastRequestId.equals(requestId)) {
|
||||||
this.port = port;
|
ConnectionHandler.this.ip = ip;
|
||||||
WKLoggerUtils.getInstance().e("连接的IP和Port" + ip + ":" + port);
|
ConnectionHandler.this.port = port;
|
||||||
new Thread(this::connSocket).start();
|
WKLoggerUtils.getInstance().e("连接的IP和Port" + ip + ":" + port);
|
||||||
|
if (connectionIsNull()) {
|
||||||
|
new Thread(ConnectionHandler.this::connSocket).start();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (connectionIsNull()) {
|
||||||
|
WKLoggerUtils.getInstance().e("请求IP的编号不一致,重连中");
|
||||||
|
reconnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
new Handler(Looper.getMainLooper()).post(this::startRequestIPTimer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void connSocket() {
|
private void connSocket() {
|
||||||
@ -509,7 +525,7 @@ public class ConnectionHandler {
|
|||||||
if (connection != null && connection.isOpen()) {
|
if (connection != null && connection.isOpen()) {
|
||||||
try {
|
try {
|
||||||
WKLoggerUtils.getInstance().e("stop connection" + connection.getId());
|
WKLoggerUtils.getInstance().e("stop connection" + connection.getId());
|
||||||
connection.flush();
|
// connection.flush();
|
||||||
connection.close();
|
connection.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -519,28 +535,39 @@ public class ConnectionHandler {
|
|||||||
connection = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CountDownTimer countDownTimer;
|
private Timer checkNetWorkTimer;
|
||||||
|
|
||||||
private synchronized void startRequestIPTimer() {
|
private synchronized void startRequestIPTimer() {
|
||||||
if (countDownTimer != null) {
|
if (checkNetWorkTimer != null) {
|
||||||
return;
|
checkNetWorkTimer.cancel();
|
||||||
|
checkNetWorkTimer = null;
|
||||||
}
|
}
|
||||||
countDownTimer = new CountDownTimer(5000, 1000) {
|
checkNetWorkTimer = new Timer();
|
||||||
|
WKLoggerUtils.getInstance().e("开始计算IP请求时间");
|
||||||
|
checkNetWorkTimer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void onTick(long l) {
|
public void run() {
|
||||||
WKLoggerUtils.getInstance().e("请求socket IP倒计时中--->");
|
long nowTime = DateUtils.getInstance().getCurrentSeconds();
|
||||||
}
|
if (nowTime - requestIPTime >= requestIPTimeoutTime) {
|
||||||
|
checkNetWorkTimer.cancel();
|
||||||
@Override
|
checkNetWorkTimer.purge();
|
||||||
public void onFinish() {
|
checkNetWorkTimer = null;
|
||||||
if (connectionIsNull()) {
|
if (TextUtils.isEmpty(ip) || port == 0) {
|
||||||
WKLoggerUtils.getInstance().e("请求socket IP已超时--->");
|
WKLoggerUtils.getInstance().e("请求IP已超时,开始重连--->");
|
||||||
isReConnecting = false;
|
isReConnecting = false;
|
||||||
countDownTimer = null;
|
reconnection();
|
||||||
reconnection();
|
}
|
||||||
|
} else {
|
||||||
|
if (!TextUtils.isEmpty(ip) && port != 0) {
|
||||||
|
checkNetWorkTimer.cancel();
|
||||||
|
checkNetWorkTimer.purge();
|
||||||
|
checkNetWorkTimer = null;
|
||||||
|
WKLoggerUtils.getInstance().e("请求IP倒计时已销毁--->");
|
||||||
|
} else {
|
||||||
|
WKLoggerUtils.getInstance().e("请求IP倒计时中--->" + (nowTime - requestIPTime));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}, 500, 1000L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user