Compare commits

...
7 Commits
Author SHA1 Message Date
heavyrian2012 c805bddca1 version and release note 2024-01-14 10:47:49 +08:00
heavyrian2012 cb5754fe07 群组信息变更回调中加上群组信息 2024-01-14 09:51:46 +08:00
heavyrian2012 c014b78d95 1,添加配置,可以禁止拉陌生人进群
2,拉人进群时检查是否被拉黑
2024-01-14 09:42:42 +08:00
heavyrian2012 8a13a32615 sdk支持流式文本 2023-12-30 19:09:30 +08:00
heavyrian2012 bc409042b0 解决搜索时特殊字符的转义问题 2023-12-27 20:07:48 +08:00
heavyrian2012 49ad4f5eb6 机器人sdk添加撤回和更新接口 2023-12-26 09:20:34 +08:00
heavyrian2012 8c93e2ee42 update readme 2023-12-11 10:55:30 +08:00
21 changed files with 308 additions and 34 deletions
+3
View File
@@ -140,6 +140,9 @@ mvn clean package
详细维护说明请参考 [野火维护说明](https://docs.wildfirechat.cn/base_knowledge/maintain.html)。
## 服务对象
因为野火的使用范围比较广,难免被一些不法分子利用,国内反诈反赌力度很大,所以国内多地警方都跟我们都有过联系。***为了预防我们的产品被用于非法目的,试用及购买只能支持境内法人单位,不接受个人或者境外团体。如果我们发现产品被用于非法目的,我们会立即停止技术支持服务并且报警和配合警方调查。请用于非法目的用户绕行!***
## 应用截图
登录界面
+3
View File
@@ -201,6 +201,9 @@ group.visible_quit_or_kickoff_notification 0
## Server API不受此限制。
#group.forbidden_client_operation 0xFFF
## 是否禁止陌生人拉人入群,默认为false
group.disable_stranger_invite false
## 隐藏用户信息属性类型,2是性别,3是电话号码,4是邮箱,5是地址,6是公司信息,7是社交账号,8是Extra信息。当需要隐藏多个时以英文逗号分开;
## 本配置是为了提高安全性,避免把对应信息同步到客户端,这样就能防止程序被破解从而拿到用户关键信息。仅对客户端有效,server api不受影响。
## 注意,修改本配置不会对已经同步的信息产生影响。
+2 -2
View File
@@ -5,7 +5,7 @@
<relativePath>../</relativePath>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>1.2.1</version>
<version>1.2.2</version>
</parent>
<artifactId>moquette-broker</artifactId>
@@ -169,7 +169,7 @@
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
<dependency>
@@ -57,6 +57,9 @@ public class GetGroupInfoAction extends AdminAction {
pojoGroupInfo.setJoin_type(groupInfo.getJoinType());
pojoGroupInfo.setPrivate_chat(groupInfo.getPrivateChat());
pojoGroupInfo.setSearchable(groupInfo.getSearchable());
pojoGroupInfo.setMax_member_count(groupInfo.getMemberCount());
pojoGroupInfo.setHistory_message(groupInfo.getHistoryMessage());
pojoGroupInfo.setSuper_group(groupInfo.getSuperGroup()>0);
result = RestResult.ok(pojoGroupInfo);
}
setResponseContent(result, response);
@@ -185,6 +185,8 @@ public final class BrokerConstants {
public static final String GROUP_Visible_Quit_Kickoff_Notification = "group.visible_quit_or_kickoff_notification";
public static final String GROUP_Forbidden_Client_Operation = "group.forbidden_client_operation";
public static final String GROUP_Disable_Stranger_Invite = "group.disable_stranger_invite";
public static final String USER_HIDE_PROPERTIES = "user.hide_properties";
public static final String USER_KEEP_DISPLAY_NAME_WHEN_DESTROY = "user.keep_display_name_when_destroy";
@@ -50,6 +50,14 @@ public class CreateGroupHandler extends GroupHandler<WFCMessage.CreateGroupReque
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
if(requestSourceType == ProtoConstants.RequestSourceType.Request_From_User) {
ErrorCode errorCode = m_messagesStore.canAddGroupMembers(fromUser, request.getGroup().getMembersList());
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
return errorCode;
}
}
WFCMessage.GroupInfo groupInfo = m_messagesStore.createGroup(fromUser, request.getGroup().getGroupInfo(), request.getGroup().getMembersList(), request.getMemberExtra(), isAdmin);
if (groupInfo != null) {
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
@@ -412,7 +412,7 @@ public class DatabaseStore {
connection = DBUtil.getConnection();
String sql = "select u._uid, u._name, u._display_name, u._portrait, u._mobile, u._gender, u._email, u._address, u._company, u._social, u._extra, u._dt, u._type " +
" from t_user u left join (select _uid, _value from t_user_setting where _scope = 27) s on u._uid = s._uid " +
" where u._display_name like ? and u._type <> 2 and u._deleted = 0 ";
" where u._display_name like ? ESCAPE '!' and u._type <> 2 and u._deleted = 0 ";
if(nameOrIdMatched.size() == 1) {
sql += " and u._uid <> ? and u._name <> ?";
} else if(nameOrIdMatched.size() == 2) {
@@ -430,6 +430,12 @@ public class DatabaseStore {
sql += " offset " + (page * 20 - nameOrIdMatched.size());
}
keyword = keyword
.replace("!", "!!")
.replace("%", "!%")
.replace("_", "!_")
.replace("[", "![");
statement = connection.prepareStatement(sql);
statement.setString(1, "%" + keyword + "%");
if(nameOrIdMatched.size() == 1) {
@@ -3631,7 +3637,7 @@ public class DatabaseStore {
", `_extra`" +
", `_dt` from t_channel";
if (buzzy) {
sql += " where `_name` like ?";
sql += " where `_name` like ? ESCAPE '!' ";
} else {
sql += " where `_name` = ?";
}
@@ -3645,6 +3651,12 @@ public class DatabaseStore {
sql += " offset " + page * 20;
}
keyword = keyword
.replace("!", "!!")
.replace("%", "!%")
.replace("_", "!_")
.replace("[", "![");
statement = connection.prepareStatement(sql);
int index = 1;
if (buzzy) {
@@ -23,6 +23,8 @@ import com.google.gson.Gson;
import com.google.protobuf.ByteString;
import com.hazelcast.core.*;
import com.hazelcast.util.StringUtil;
import com.xiaoleilu.hutool.system.UserInfo;
import com.xiaoleilu.loServer.RestResult;
import com.xiaoleilu.loServer.action.admin.AdminAction;
import com.xiaoleilu.loServer.model.FriendData;
import cn.wildfirechat.common.ErrorCode;
@@ -159,6 +161,7 @@ public class MemoryMessagesStore implements IMessagesStore {
private boolean mMobileDefaultSilentWhenPCOnline = true;
private boolean mDisableStrangerChat = false;
private Set<String> mAllowStrangerChatSet = new HashSet<>();
private boolean mDisableStrangerAddGroup = false;
private Set<String> mClientSignatureSet = new HashSet<>();
private boolean mRejectEmptySignature = true;
@@ -515,6 +518,11 @@ public class MemoryMessagesStore implements IMessagesStore {
}
try {
mDisableStrangerAddGroup = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.GROUP_Disable_Stranger_Invite, "false"));
} catch (Exception e) {
}
try {
String s = server.getConfig().getProperty(GROUP_Forbidden_Client_Operation, null);
if(!StringUtil.isNullOrEmptyAfterTrim(s)) {
@@ -1194,6 +1202,85 @@ public class MemoryMessagesStore implements IMessagesStore {
return messageSeq;
}
@Override
public ErrorCode canAddGroupMembers(String fromUser, List<WFCMessage.GroupMember> memberList) {
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
IMap<String, WFCMessage.User> mUserMap = hzInstance.getMap(USERS);
WFCMessage.User operator = mUserMap.get(fromUser);
if(operator != null && operator.getType() > 1) {
return ErrorCode.ERROR_CODE_SUCCESS;
}
if (mDisableStrangerAddGroup) {
for (WFCMessage.GroupMember groupMember : memberList) {
String targetUser = groupMember.getMemberId();
if(fromUser.equals(targetUser)) {
continue;
}
Collection<FriendData> friendDatas = friendsMap.get(targetUser);
if (friendDatas == null || friendDatas.size() == 0) {
friendDatas = loadFriend(friendsMap, targetUser);
}
boolean allow = false;
for (FriendData friendData : friendDatas) {
if (friendData.getFriendUid().equals(fromUser)) {
if (friendData.getBlacked() == 1) {
return ErrorCode.ERROR_CODE_IN_BLACK_LIST;
} else {
if (friendData.getState() == 0) {
allow = true;
}
break;
}
}
}
if(allow) {
continue;
}
//在禁止私聊时,是否是允许私聊的用户id
if(mAllowStrangerChatSet.contains(targetUser) || mAllowStrangerChatSet.contains(fromUser)) {
continue;
}
//在禁止私聊时,允许机器人,物联网设备及管理员进行私聊。
WFCMessage.User target = mUserMap.get(targetUser);
if (target != null && target.getType() != ProtoConstants.UserType.UserType_Normal) {
continue;
}
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
} else {
for (WFCMessage.GroupMember groupMember : memberList) {
String targetUser = groupMember.getMemberId();
if(fromUser.equals(targetUser)) {
continue;
}
Collection<FriendData> friendDatas = friendsMap.get(targetUser);
if (friendDatas == null || friendDatas.size() == 0) {
friendDatas = loadFriend(friendsMap, targetUser);
}
for (FriendData friendData : friendDatas) {
if (friendData.getFriendUid().equals(fromUser)) {
if (friendData.getBlacked() == 1) {
return ErrorCode.ERROR_CODE_IN_BLACK_LIST;
} else {
break;
}
}
}
}
}
return ErrorCode.ERROR_CODE_SUCCESS;
}
@Override
public WFCMessage.GroupInfo createGroup(String fromUser, WFCMessage.GroupInfo groupInfo, List<WFCMessage.GroupMember> memberList, String memberExtra, boolean isAdmin) {
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
@@ -1269,17 +1356,35 @@ public class MemoryMessagesStore implements IMessagesStore {
mIMap.set(groupId, groupInfo);
databaseStore.persistGroupMember(groupId, updatedMemberList, false);
callbackGroupEvent(fromUser, groupInfo.getTargetId(), ProtoConstants.GroupUpdateEventType.Group_Event_Create);
callbackGroupEvent(fromUser, groupInfo.getTargetId(), ProtoConstants.GroupUpdateEventType.Group_Event_Create, groupInfo);
return groupInfo;
}
private void callbackGroupEvent(String operatorId, String groupId, int type) {
private void callbackGroupEvent(String operatorId, String groupId, int type, WFCMessage.GroupInfo groupInfo) {
if (!StringUtil.isNullOrEmpty(mGroupInfoUpdateCallback)) {
GroupUpdateEvent event = new GroupUpdateEvent();
event.operatorId = operatorId;
event.groupId = groupId;
event.type = type;
PojoGroupInfo pojoGroupInfo = new PojoGroupInfo();
event.groupInfo = pojoGroupInfo;
if (groupInfo != null) {
pojoGroupInfo.setExtra(groupInfo.getExtra());
pojoGroupInfo.setName(groupInfo.getName());
pojoGroupInfo.setOwner(groupInfo.getOwner());
pojoGroupInfo.setPortrait(groupInfo.getPortrait());
pojoGroupInfo.setTarget_id(groupInfo.getTargetId());
pojoGroupInfo.setType(groupInfo.getType());
pojoGroupInfo.setMute(groupInfo.getMute());
pojoGroupInfo.setJoin_type(groupInfo.getJoinType());
pojoGroupInfo.setPrivate_chat(groupInfo.getPrivateChat());
pojoGroupInfo.setSearchable(groupInfo.getSearchable());
pojoGroupInfo.setMax_member_count(groupInfo.getMemberCount());
pojoGroupInfo.setHistory_message(groupInfo.getHistoryMessage());
pojoGroupInfo.setSuper_group(groupInfo.getSuperGroup()>0);
}
m_Server.getCallbackScheduler().execute(() -> {
try {
HttpUtils.httpJsonPost(mGroupInfoUpdateCallback, GsonUtil.gson.toJson(event), HttpUtils.HttpPostType.POST_TYPE_Grout_Event_Callback);
@@ -1693,7 +1798,7 @@ public class MemoryMessagesStore implements IMessagesStore {
removeFavGroup(groupId, ids);
removeGroupUserSettings(groupId, ids);
callbackGroupEvent(operator, groupId, ProtoConstants.GroupUpdateEventType.Group_Event_Destroy);
callbackGroupEvent(operator, groupId, ProtoConstants.GroupUpdateEventType.Group_Event_Destroy, groupInfo);
return ErrorCode.ERROR_CODE_SUCCESS;
}
@@ -1778,12 +1883,12 @@ public class MemoryMessagesStore implements IMessagesStore {
if (modifyType == Modify_Group_Mute) {
if (newInfoBuilder.getMute() > 0) {
callbackGroupEvent(operator, groupId, ProtoConstants.GroupUpdateEventType.Group_Event_Mute);
callbackGroupEvent(operator, groupId, ProtoConstants.GroupUpdateEventType.Group_Event_Mute, newInfoBuilder.build());
} else {
callbackGroupEvent(operator, groupId, ProtoConstants.GroupUpdateEventType.Group_Event_Unmute);
callbackGroupEvent(operator, groupId, ProtoConstants.GroupUpdateEventType.Group_Event_Unmute, newInfoBuilder.build());
}
} else {
callbackGroupEvent(operator, groupId, ProtoConstants.GroupUpdateEventType.Group_Event_Update);
callbackGroupEvent(operator, groupId, ProtoConstants.GroupUpdateEventType.Group_Event_Update, newInfoBuilder.build());
}
return ErrorCode.ERROR_CODE_SUCCESS;
}
@@ -2130,7 +2235,7 @@ public class MemoryMessagesStore implements IMessagesStore {
}
}
callbackGroupEvent(operator, groupId, ProtoConstants.GroupUpdateEventType.Group_Event_Transfer);
callbackGroupEvent(operator, groupId, ProtoConstants.GroupUpdateEventType.Group_Event_Transfer, groupInfo);
return ErrorCode.ERROR_CODE_SUCCESS;
}
@@ -102,6 +102,7 @@ public interface IMessagesStore {
WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType);
WFCMessage.PullMessageResult loadRemoteMessages(String user, WFCMessage.Conversation conversation, long beforeUid, int count, Collection<Integer> contentTypes);
long insertUserMessages(String sender, int conversationType, String target, int line, int messageContentType, String userId, long messageId, boolean directing);
ErrorCode canAddGroupMembers(String operator, List<WFCMessage.GroupMember> memberList);
WFCMessage.GroupInfo createGroup(String operator, WFCMessage.GroupInfo groupInfo, List<WFCMessage.GroupMember> memberList, String memberExtra, boolean isAdmin);
ErrorCode addGroupMembers(String operator, boolean isAdmin, String groupId, List<WFCMessage.GroupMember> memberList, String extra);
ErrorCode kickoffGroupMembers(String operator, boolean isAdmin, String groupId, List<String> memberList);
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>1.2.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -116,6 +116,8 @@ public interface APIPath {
String Robot_User_Info = "/robot/user_info";
String Robot_Get_Profile = "/robot/profile";
String Robot_Message_Send = "/robot/message/send";
String Robot_Message_Recall = "/robot/message/recall";
String Robot_Message_Update = "/robot/message/update";
String Robot_Set_Callback = "/robot/set_callback";
String Robot_Get_Callback = "/robot/get_callback";
String Robot_Delete_Callback = "/robot/delete_callback";
@@ -0,0 +1,48 @@
package cn.wildfirechat.messagecontentbuilder;
import cn.wildfirechat.pojos.MessagePayload;
import cn.wildfirechat.proto.ProtoConstants;
import com.google.gson.Gson;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
public class StreamingTextMessageContentBuilder extends MessageContentBuilder{
private String text;
private String streamId;
private boolean generating;
public static StreamingTextMessageContentBuilder newBuilder(String streamId) {
StreamingTextMessageContentBuilder builder = new StreamingTextMessageContentBuilder();
builder.generating = false;
builder.streamId = streamId;
return builder;
}
public StreamingTextMessageContentBuilder text(String text) {
this.text = text;
return this;
}
public StreamingTextMessageContentBuilder generating(boolean generating) {
this.generating = generating;
return this;
}
@Override
public MessagePayload build() {
MessagePayload payload = encodeBase();
payload.setSearchableContent(text);
payload.setContent(streamId);
if(generating) {
//正在生成消息的类型是14,存储标记位为透传为4。
payload.setType(14);
payload.setPersistFlag(4);
} else {
//已经生成消息的类型是15,存储标记位为透传为3。
payload.setType(15);
payload.setPersistFlag(3);
}
return payload;
}
}
@@ -4,4 +4,5 @@ public class GroupUpdateEvent {
public String operatorId;
public String groupId;
public int type;
public PojoGroupInfo groupInfo;
}
+1 -1
View File
@@ -6,7 +6,7 @@
<!--<relativePath>../pom.xml</relativePath>-->
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>1.2.1</version>
<version>1.2.2</version>
</parent>
<artifactId>distribution</artifactId>
@@ -200,6 +200,9 @@ group.visible_quit_or_kickoff_notification 0
## 如果有客户端有被破解的风险,可以禁止客户端群操作,然后通过Server API操作。Server API不受限制。
#group.forbidden_client_operation 0xFFF
## 是否禁止陌生人拉人入群,默认为false
group.disable_stranger_invite false
## 隐藏用户信息属性类型,2是性别,3是电话号码,4是邮箱,5是地址,6是公司信息,7是社交账号,8是Extra信息。当需要隐藏多个时以英文逗号分开;
## 本配置是为了提高安全性,避免把对应信息同步到客户端,这样就能防止程序被破解从而拿到用户关键信息。仅对客户端有效,server api不受影响。
## 注意,修改本配置不会对已经同步的信息产生影响。
+1 -1
View File
@@ -12,7 +12,7 @@
<artifactId>wildfirechat-parent</artifactId>
<packaging>pom</packaging>
<version>1.2.1</version>
<version>1.2.2</version>
<name>Wildfire Chat</name>
<description>Wildfire Chat Server</description>
<inceptionYear>2019</inceptionYear>
+9
View File
@@ -12,6 +12,15 @@
# 更新记录
--------------
Release note 1.2.2:
1. 解决搜索特殊字符时的转义问题。
2. SDK添加流式消息。
3. 添加配置,是否禁止拉陌生人入群。
4. 放被拉黑时禁止被拉入群
5. 群组信息变更回调时加上群组信息
6. 机器人sdk添加撤回和更新消息接口
--------------
Release note 1.2.1:
1. 添加获取在线用户功能。
+1 -1
View File
@@ -3,7 +3,7 @@
<parent>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>1.2.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+2 -2
View File
@@ -45,7 +45,7 @@
<dependency>
<groupId>cn.wildfirechat</groupId>
<artifactId>sdk</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/lib/sdk-1.1.9.jar</systemPath>
</dependency>
@@ -53,7 +53,7 @@
<dependency>
<groupId>cn.wildfirechat</groupId>
<artifactId>common</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/lib/common-1.1.9.jar</systemPath>
</dependency>
+70 -17
View File
@@ -2,6 +2,7 @@ package cn.wildfirechat.sdk;
import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.messagecontentbuilder.RichNotificationContentBuilder;
import cn.wildfirechat.messagecontentbuilder.StreamingTextMessageContentBuilder;
import cn.wildfirechat.messagecontentbuilder.TextMessageContentBuilder;
import cn.wildfirechat.pojos.*;
import cn.wildfirechat.proto.ProtoConstants;
@@ -377,21 +378,6 @@ public class Main {
System.exit(-1);
}
result = RelationAdmin.sendFriendRequest("ff1", "ff2", "hello2", false);
if (result != null && result.getErrorCode() != ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("success");
} else {
System.out.println("failure");
System.exit(-1);
}
result = RelationAdmin.sendFriendRequest("ff1", "ff2", "hello3", true);
if (result != null && (result.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS || result.getErrorCode() == ErrorCode.ERROR_CODE_ALREADY_FRIENDS)) {
System.out.println("success");
} else {
System.out.println("send friend request success");
}
IMResult<Void> updateFriendStatusResult = RelationAdmin.setUserFriend("ff1", "ff2", true, "{\"from\":1}");
if (updateFriendStatusResult != null && updateFriendStatusResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("update friend status success");
@@ -847,6 +833,42 @@ public class Main {
} else {
System.out.println("failure");
}
testStreamingText();
}
static void testStreamingText() throws Exception {
Conversation conversation = new Conversation();
conversation.setTarget("uygqmws2k");
conversation.setType(ProtoConstants.ConversationType.ConversationType_Private);
String fullText = "北京野火无限网络科技有限公司是成立于2019年底的一家科技创新企业,公司的主要目标是为广大企业和单位提供优质可控、私有部署的即时通讯和实时音视频能力,为社会信息化水平提高作出自己的贡献。\n" +
"\n" +
"野火IM是公司研发一套自主可控的即时通讯组件,具有全部私有化、功能齐全、协议稳定可靠、全平台支持、安全性高和支持国产化等技术特点。客户端分层设计,既可开箱即用,也可与现有系统深度融合。具有完善的服务端API和自定义消息功能,可以任意扩展功能。代码开源率高,方便二次开发和使用。支持多人实时音视频和会议功能,线上沟通更通畅。\n" +
"\n" +
"公司致力于开源项目,在Github上开源项目广受好评,其中Server项目有超过7.1K个Star,组织合计Star超过1万个。有大量的技术公司受益于我们的开源,为自己的产品添加了即时通讯能力,这也算是我们公司为社会信息化建设做出的一点点贡献吧。\n" +
"\n" +
"公司以即时通讯技术为核心,持续努力优化和完善即时通讯和实时音视频产品,努力为客户提供最优质的即时通讯和实时音视频能力。";
int i = 0;
String streamId = UUID.randomUUID().toString();
while (i < fullText.length()) {
i+= 15;
boolean finish = i >= fullText.length();
String partText = finish?fullText:fullText.substring(0, i);
MessagePayload payload = StreamingTextMessageContentBuilder.newBuilder(streamId).text(partText).generating(!finish).build();
IMResult<SendMessageResult> resultSendMessage = MessageAdmin.sendMessage("admin", conversation, payload, null);
if (resultSendMessage != null && resultSendMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("send message success");
} else {
System.out.println("send message failure");
System.exit(-1);
}
Thread.sleep(500);
}
}
//***********************************************
@@ -982,7 +1004,7 @@ public class Main {
System.exit(-1);
}
IMResult<OutputUserChatroom> userChatroomIMResult = ChatroomAdmin.getUserChatroom("hygqmws2k");
IMResult<OutputUserChatroom> userChatroomIMResult = ChatroomAdmin.getUserChatroom("uygqmws2k");
if(userChatroomIMResult != null && (userChatroomIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS || userChatroomIMResult.getErrorCode() == ErrorCode.ERROR_CODE_NOT_EXIST)) {
System.out.println("get user chatroom success");
} else {
@@ -1181,7 +1203,7 @@ public class Main {
payload.setType(1);
payload.setSearchableContent("hello world");
IMResult<SendMessageResult> resultRobotSendMessage = robotService.sendMessage("robot1", conversation, payload);
IMResult<SendMessageResult> resultRobotSendMessage = robotService.sendMessage(robotService.getRobotId(), conversation, payload);
if (resultRobotSendMessage != null && resultRobotSendMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("robot send message success");
} else {
@@ -1189,6 +1211,37 @@ public class Main {
System.exit(-1);
}
if(commercialServer) {
Thread.sleep(1000);
IMResult<String> recallMessageResult = robotService.recallMessage(resultRobotSendMessage.result.getMessageUid());
if (recallMessageResult != null && recallMessageResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("robot recall message success");
} else {
System.out.println("robot recall message failure");
System.exit(-1);
}
payload.setSearchableContent("hello world, hello world");
resultRobotSendMessage = robotService.sendMessage(robotService.getRobotId(), conversation, payload);
if (resultRobotSendMessage != null && resultRobotSendMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("robot send message success");
} else {
System.out.println("robot send message failure");
System.exit(-1);
}
Thread.sleep(1000);
payload.setSearchableContent("hello world, updated message content");
IMResult<Void> updateMessageResult = robotService.updateMessage(resultRobotSendMessage.result.getMessageUid(), payload);
if (updateMessageResult != null && updateMessageResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("robot update message success");
} else {
System.out.println("robot update message failure");
System.exit(-1);
}
}
IMResult<InputOutputUserInfo> resultRobotGetUserInfo = robotService.getUserInfo("userId1");
if (resultRobotGetUserInfo != null && resultRobotGetUserInfo.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("robot get user info success");
@@ -17,6 +17,10 @@ public class RobotService {
robotHttpUtils = new RobotHttpUtils(url, robotId, robotSecret);
}
public String getRobotId() {
return robotHttpUtils.getRobotId();
}
public IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload) throws Exception {
String path = APIPath.Robot_Message_Send;
SendMessageData messageData = new SendMessageData();
@@ -26,6 +30,23 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
}
public IMResult<String> recallMessage(long messageUid) throws Exception {
String path = APIPath.Robot_Message_Recall;
RecallMessageData messageData = new RecallMessageData();
messageData.setMessageUid(messageUid);
return robotHttpUtils.httpJsonPost(path, messageData, String.class);
}
public IMResult<Void> updateMessage(long messageUid, MessagePayload payload) throws Exception {
String path = APIPath.Robot_Message_Update;
UpdateMessageContentData updateMessageContentData = new UpdateMessageContentData();
updateMessageContentData.setMessageUid(messageUid);
updateMessageContentData.setPayload(payload);
updateMessageContentData.setUpdateTimestamp(0);
updateMessageContentData.setDistribute(1);
return robotHttpUtils.httpJsonPost(path, updateMessageContentData, Void.class);
}
public IMResult<InputOutputUserInfo> getUserInfo(String userId) throws Exception {
String path = APIPath.Robot_User_Info;
InputGetUserInfo getUserInfo = new InputGetUserInfo(userId, null, null);