Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Commit

Permalink
登录信息获取调整为异步请求
Browse files Browse the repository at this point in the history
  • Loading branch information
Acexy committed Oct 10, 2018
1 parent 8a54ea1 commit 96c9e4a
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 8 deletions.
86 changes: 81 additions & 5 deletions src/main/java/com/thankjava/wqq/core/action/GetInfoAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class GetInfoAction {
* @date 2016年12月22日 下午1:34:35
* @version 1.0
*/
@Deprecated
public FriendsList getFriendsList() {

AsyncResponse response = null;
Expand Down Expand Up @@ -111,7 +110,6 @@ public void onListener(ActionListener actionListener) {
* @date 2017年6月14日 下午2:46:17
* @version 1.0
*/
@Deprecated
public FriendsList getOnlineStatus() {

FriendsList friendsList = session.getFriendsList();
Expand All @@ -136,6 +134,7 @@ public FriendsList getOnlineStatus() {
return null;
}


public void getOnlineStatus(final CallBackListener callBackListener, final Integer... tryTimes) {

final int tryTime = tryTimes == null || tryTimes.length == 0 ? 1 : tryTimes[0] + 1;
Expand Down Expand Up @@ -198,6 +197,40 @@ public DiscusList getDiscusList() {
return null;
}

/**
* 异步获取讨论组信息
* @param callBackListener
* @param tryTimes
*/
public void getDiscusList(final CallBackListener callBackListener, final Integer... tryTimes) {
final int tryTime = tryTimes == null || tryTimes.length == 0 ? 1 : tryTimes[0] + 1;

if (tryTime >= ConfigParams.EXCEPTION_RETRY_MAX_TIME) {
logger.error("getGroupNameListMask2 失败 (已尝试重试)");
callBackListener.onListener(new ActionListener(null));
return;
}

getDiscusList.doRequest(new CallBackListener() {
@Override
public void onListener(ActionListener actionListener) {
if (actionListener.getData() != null) {
AsyncResponse asyncResponse = (AsyncResponse) actionListener.getData();
DiscusList discusList = JSON2Entity.getDiscusList(asyncResponse.getDataString());
if (discusList != null) {
session.setDiscusList(discusList);
callBackListener.onListener(new ActionListener(discusList));
} else {
getDiscusList(callBackListener, tryTime);
}
} else {
getDiscusList(callBackListener, tryTime);
}
}

});
}

/**
* 获取群列表
* <p>Function: getGroupsList</p>
Expand Down Expand Up @@ -226,6 +259,11 @@ public GroupsList getGroupsList() {
return null;
}

/**
* 异步获取群组列表
* @param callBackListener
* @param tryTimes
*/
public void getGroupsList(final CallBackListener callBackListener, final Integer... tryTimes) {

final int tryTime = tryTimes == null || tryTimes.length == 0 ? 1 : tryTimes[0] + 1;
Expand All @@ -246,10 +284,10 @@ public void onListener(ActionListener actionListener) {
session.setGroupsList(groupList);
callBackListener.onListener(new ActionListener(groupList));
} else {
getOnlineStatus(callBackListener, tryTime);
getGroupsList(callBackListener, tryTime);
}
} else {
getOnlineStatus(callBackListener, tryTime);
getGroupsList(callBackListener, tryTime);
}
}

Expand Down Expand Up @@ -284,10 +322,48 @@ public DetailedInfo getSelfInfo() {
return null;
}


/**
* 异步获取个人信息
* @param callBackListener
* @param tryTimes
*/
public void getSelfInfo(final CallBackListener callBackListener, final Integer... tryTimes) {

final int tryTime = tryTimes == null || tryTimes.length == 0 ? 1 : tryTimes[0] + 1;

if (tryTime >= ConfigParams.EXCEPTION_RETRY_MAX_TIME) {
logger.error("getSelfInfo2 失败 (已尝试重试)");
callBackListener.onListener(new ActionListener(null));
return;
}

getSelfInfo2.doRequest(new CallBackListener() {

@Override
public void onListener(ActionListener actionListener) {
if (actionListener.getData() != null) {
AsyncResponse asyncResponse = (AsyncResponse) actionListener.getData();
DetailedInfo detailedInfo = JSON2Entity.getSelfInfo(asyncResponse.getDataString());
if (detailedInfo != null) {
session.setSelfInfo(detailedInfo);
callBackListener.onListener(new ActionListener(detailedInfo));
} else {
getSelfInfo(callBackListener, tryTime);
}
} else {
getSelfInfo(callBackListener, tryTime);
}
}

});
}

/**
* 获取最近联系的好友,没有实际意义未实现
*/
@Deprecated
void getRecentList() {
getRecentList2.doRequest(null).isEmptyDataString();
}
}
}
31 changes: 28 additions & 3 deletions src/main/java/com/thankjava/wqq/core/action/LoginAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void onListener(ActionListener actionListener) {
if (actionListener.getData() == null) {
logger.error("查询好友状态失败");
} else {
logger.error("查询好友状态失败");
logger.debug("查询好友状态成功");
}
}
});
Expand All @@ -215,6 +215,31 @@ public void onListener(ActionListener actionListener) {
public void onListener(ActionListener actionListener) {
if (actionListener.getData() != null) {
logger.debug("获取群列表成功");
}else {
logger.error("获取群列表失败");
}
}
});

getInfo.getSelfInfo(new CallBackListener() {
@Override
public void onListener(ActionListener actionListener) {
if (actionListener.getData() != null) {
logger.debug("获取个人信息成功");
}else {
logger.error("获取个人信息失败");
}
}
});

getInfo.getDiscusList(new CallBackListener() {
@Override
public void onListener(ActionListener actionListener) {
if (actionListener.getData() != null) {
logger.debug("获取讨论组列表成功");
} else {
logger.error("获取讨论组列表失败");

}
}
});
Expand All @@ -230,8 +255,8 @@ public void onListener(ActionListener actionListener) {
// }
// getInfo.getGroupsList();
// getInfo.getDiscusList();
getInfo.getSelfInfo();
getInfo.getRecentList();
// getInfo.getSelfInfo();
// getInfo.getRecentList();



Expand Down

0 comments on commit 96c9e4a

Please sign in to comment.