Compare commits

..
8 Commits
30 changed files with 270 additions and 21 deletions
+4
View File
@@ -448,6 +448,10 @@ push.harmony.server.address http://localhost:8085/harmony/push
## 如果开启 message.sensitive.forward.url 配置,命中敏感词的消息还会被回调到这个地址
sensitive.filter.type 2
## 敏感词是否只处理消息。如果为true,只过滤消息;如果为false,会同时过滤用户昵称、群组名和群昵称。
## 除了消息之外的信息只支持内部敏感词处理,不支持外置审核。
sensitive.only_message false
## 敏感词添加或者删除有2种方式,一种是通过Server API进行,这种方式会立即生效。另外一种方法是修改数据库,直接中数据库的t_sensitive_word表中处理
## 修改数据库的方法不会立即生效,IM服务会2个小时重新加载一次敏感词。所以如果直接修改敏感词表,需要等2个小时,或者重启才能生效。
@@ -1 +1 @@
CREATE INDEX `user_gid_mid_dt_index` ON `t_group_member` (`_gid`, `_mid`, `_dt`);
CREATE INDEX `user_gid_dt_index` ON `t_group_member` (`_gid`, `_dt`);
+1
View File
@@ -0,0 +1 @@
insert into t_settings(`id`, `_value`,`_desc`) values (2, '文件传输助手,客服,官方', '禁止使用名称,如果有多个,以英文逗号隔开。直接修改数据库,不用重启IM服务');
@@ -0,0 +1,2 @@
DROP INDEX `user_gid_mid_dt_index` ON `t_group_member`;
CREATE INDEX `user_gid_dt_index` ON `t_group_member` (`_gid`, `_dt`);
+1
View File
@@ -0,0 +1 @@
insert into t_settings(`id`, `_value`,`_desc`) values (2, '文件传输助手,客服,官方', '禁止使用名称,如果有多个,以英文逗号隔开。直接修改数据库,不用重启IM服务');
+1 -1
View File
@@ -5,7 +5,7 @@
<relativePath>../</relativePath>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>1.3.7</version>
<version>1.3.8</version>
</parent>
<artifactId>moquette-broker</artifactId>
@@ -51,7 +51,7 @@ public class SendMessageAction extends AdminAction {
} else {
return new Result(errorCode);
}
});
}, sendMessageData.isUserMessage());
return false;
} else {
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
@@ -124,7 +124,7 @@ public final class BrokerConstants {
public static final String SENSITIVE_Filter_Type = "sensitive.filter.type";
public static final String SENSITIVE_Only_Message = "sensitive.only_message";
public static final String SENSITIVE_Remote_Server_URL = "sensitive.remote_server_url";
public static final String SENSITIVE_Remote_Message_Type = "sensitive.remote_sensitive_message_type";
public static final String SENSITIVE_Remote_Fail_When_Matched = "sensitive.remote_fail_when_matched";
@@ -19,6 +19,7 @@ import win.liyufan.im.IMTopic;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@Handler(value = IMTopic.CreateGroupTopic)
public class CreateGroupHandler extends GroupHandler<WFCMessage.CreateGroupRequest> {
@@ -68,6 +69,19 @@ public class CreateGroupHandler extends GroupHandler<WFCMessage.CreateGroupReque
return ErrorCode.INVALID_PARAMETER;
}
if(!isAdmin && !StringUtil.isNullOrEmpty(request.getGroup().getGroupInfo().getName())) {
if(!m_messagesStore.isSensitiveOnlyMessage()) {
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getGroup().getGroupInfo().getName());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
}
}
if(!m_messagesStore.isAllowName(request.getGroup().getGroupInfo().getName())) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
WFCMessage.GroupInfo groupInfo = m_messagesStore.createGroup(fromUser, request.getGroup().getGroupInfo(), request.getGroup().getMembersList(), request.getMemberExtra(), isAdmin, failedMembers);
if (groupInfo != null && groupInfo.getDeleted() == 0) {
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
@@ -11,11 +11,14 @@ package io.moquette.imhandler;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import cn.wildfirechat.pojos.GroupNotificationBinaryContent;
import com.hazelcast.util.StringUtil;
import io.moquette.spi.impl.Qos1PublishHandler;
import io.netty.buffer.ByteBuf;
import cn.wildfirechat.common.ErrorCode;
import win.liyufan.im.IMTopic;
import java.util.Set;
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
@Handler(IMTopic.ModifyGroupAliasTopic)
@@ -26,10 +29,24 @@ public class ModifyGroupAliasHandler extends GroupHandler<WFCMessage.ModifyGroup
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0 && requestSourceType == ProtoConstants.RequestSourceType.Request_From_User && !m_messagesStore.isAllowClientCustomGroupNotification()) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0 && requestSourceType == ProtoConstants.RequestSourceType.Request_From_Robot && !m_messagesStore.isAllowRobotCustomGroupNotification()) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
if (!isAdmin && !StringUtil.isNullOrEmpty(request.getAlias())) {
if(!m_messagesStore.isSensitiveOnlyMessage()) {
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getAlias());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
}
}
if(!m_messagesStore.isAllowName(request.getAlias())) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
ErrorCode errorCode = m_messagesStore.modifyGroupMemberAlias(fromUser, request.getGroupId(), request.getAlias(), null, isAdmin);
if (errorCode == ERROR_CODE_SUCCESS) {
if (request.hasNotifyContent()&& request.getNotifyContent().getType() > 0) {
@@ -12,10 +12,13 @@ import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.pojos.GroupNotificationBinaryContent;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import com.hazelcast.util.StringUtil;
import io.moquette.spi.impl.Qos1PublishHandler;
import io.netty.buffer.ByteBuf;
import win.liyufan.im.IMTopic;
import java.util.Set;
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
@Handler(IMTopic.ModifyGroupMemberAliasTopic)
@@ -29,6 +32,18 @@ public class ModifyGroupMemberAliasHandler extends GroupHandler<WFCMessage.Modif
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0 && requestSourceType == ProtoConstants.RequestSourceType.Request_From_Robot && !m_messagesStore.isAllowRobotCustomGroupNotification()) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
if (!isAdmin && !StringUtil.isNullOrEmpty(request.getAlias())) {
if(!m_messagesStore.isSensitiveOnlyMessage()) {
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getAlias());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
}
}
if(!m_messagesStore.isAllowName(request.getAlias())) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
ErrorCode errorCode = m_messagesStore.modifyGroupMemberAlias(fromUser, request.getGroupId(), request.getAlias(), request.getMemberId(), isAdmin);
if (errorCode == ERROR_CODE_SUCCESS) {
@@ -136,6 +136,15 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
boolean isAdmin = requestSourceType == ProtoConstants.RequestSourceType.Request_From_Admin;
if (message != null) {
if(message.getContent().getContent().length() +
message.getContent().getSearchableContent().length() +
message.getContent().getData().size() +
message.getContent().getExtra().length() +
message.getContent().getPushContent().length() +
message.getContent().getPushData().length() > 64 * 1024) {
return ErrorCode.ERROR_CODE_MESSAGE_TOO_LARGE;
}
boolean ignoreMsg = false;
if (!isAdmin) { //admin do not check the right
// 不能在端上直接发送撤回和群通知
@@ -171,7 +171,7 @@ public class MemoryMessagesStore implements IMessagesStore {
private boolean mGroupAllowPartSuccess = false;
private boolean mIDUseUUID = true;
private boolean mSensitiveOnlyMessage = true;
private Set<String> mClientSignatureSet = new HashSet<>();
private boolean mRejectEmptySignature = true;
@@ -671,6 +671,11 @@ public class MemoryMessagesStore implements IMessagesStore {
mIDUseUUID = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ID_USE_UUID, "false"));
} catch (Exception e) {
}
try {
mSensitiveOnlyMessage = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.SENSITIVE_Only_Message, "true"));
} catch (Exception e) {
}
}
private void printMissConfigLog(String config, String defaultValue) {
@@ -1974,6 +1979,19 @@ public class MemoryMessagesStore implements IMessagesStore {
if (!isAllow) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
if (modifyType == Modify_Group_Name && !StringUtil.isNullOrEmpty(value)) {
if(!mSensitiveOnlyMessage) {
Set<String> matched = handleSensitiveWord(value);
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
}
}
if(!isAllowName(value)) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
}
if (oldInfo.getType() == ProtoConstants.GroupType.GroupType_Normal) {
@@ -2810,6 +2828,19 @@ public class MemoryMessagesStore implements IMessagesStore {
) {
switch (entry.getType()) {
case Modify_DisplayName:
if(!StringUtil.isNullOrEmpty(entry.getValue())) {
if (!mSensitiveOnlyMessage) {
Set<String> matched = handleSensitiveWord(entry.getValue());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
}
}
if(!isAllowName(entry.getValue())) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
builder.setDisplayName(entry.getValue());
modified = true;
break;
@@ -3901,6 +3932,25 @@ public class MemoryMessagesStore implements IMessagesStore {
return ErrorCode.ERROR_CODE_SUCCESS;
}
@Override
public boolean isAllowName(String name) {
if(StringUtil.isNullOrEmpty(name)) {
return true;
}
name = name.trim();
SystemSettingPojo notAllowNameSetting = getSystemSetting(ProtoConstants.SystemSettingType.NOT_ALLOW_USER_NAMES);
if (notAllowNameSetting != null && !StringUtil.isNullOrEmpty(notAllowNameSetting.value)) {
String[] ss = notAllowNameSetting.value.split(",");
for (String s : ss) {
if(name.contains(s.trim())) {
return false;
}
}
}
return true;
}
@Override
public ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId) {
IMap<String, WFCMessage.ChatroomInfo> chatroomInfoMap = m_Server.getHazelcastInstance().getMap(CHATROOMS);
@@ -4770,6 +4820,11 @@ public class MemoryMessagesStore implements IMessagesStore {
return new ArrayList<>(databaseStore.getSensitiveWord());
}
@Override
public boolean isSensitiveOnlyMessage() {
return mSensitiveOnlyMessage;
}
@Override
public WFCMessage.Message getMessage(long messageId) {
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
@@ -190,6 +190,8 @@ public interface IMessagesStore {
ErrorCode setFriendAliasRequest(String fromUser, String targetUserId, String alias, long[] head);
ErrorCode setFriendExtraRequest(String fromUser, String targetUserId, String extra, long[] head);
boolean isAllowName(String name);
ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId);
ErrorCode handleQuitChatroom(String userId, String clientId, String chatroomId);
@@ -232,6 +234,7 @@ public interface IMessagesStore {
boolean addSensitiveWords(List<String> words);
boolean removeSensitiveWords(List<String> words);
List<String> getAllSensitiveWords();
boolean isSensitiveOnlyMessage();
WFCMessage.Message getMessage(long messageId);
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>1.3.7</version>
<version>1.3.8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -128,6 +128,8 @@ public interface APIPath {
String Channel_Update_Profile = "/channel/update_profile";
String Channel_Get_Profile = "/channel/get_profile";
String Channel_Message_Send = "/channel/message/send";
String Channel_Msg_Recall = "/channel/message/recall";
String Channel_Msg_Republish = "/channel/message/republish";
String Channel_Subscribe = "/channel/subscribe";
String Channel_Subscriber_List = "/channel/subscriber_list";
String Channel_Is_Subscriber = "/channel/is_subscriber";
@@ -49,6 +49,7 @@ public enum ErrorCode {
ERROR_CODE_ROBOT_NO_TOKEN(27, "robot no token"),
ERROR_CODE_WS_NOT_CONFIGURED_CORRECTLY(28, "ws not configured correctly"),
ERROR_CODE_TIME_INCONSISTENT(30, "time inconsistent"),
ERROR_CODE_MESSAGE_TOO_LARGE(35, "message too large"),
ERROR_CODE_CONFERENCE_ROOM_NOT_EXIST(60, "conference room not exist"),
ERROR_CODE_CONFERENCE_SERVICE_NOT_AVAILABLE(61, "conference service not available"),
@@ -0,0 +1,32 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package cn.wildfirechat.pojos;
import java.util.List;
public class RepublishChannelMessageData {
private List<String> targets;
private long messageId;
public List<String> getTargets() {
return targets;
}
public void setTargets(List<String> targets) {
this.targets = targets;
}
public long getMessageId() {
return messageId;
}
public void setMessageId(long messageId) {
this.messageId = messageId;
}
}
@@ -20,6 +20,7 @@ public class SendMessageData {
private MessagePayload payload;
private List<String> toUsers;
private boolean isMeshMessage;
private boolean isUserMessage;
public String getSender() {
return sender;
@@ -61,6 +62,14 @@ public class SendMessageData {
isMeshMessage = meshMessage;
}
public boolean isUserMessage() {
return isUserMessage;
}
public void setUserMessage(boolean userMessage) {
isUserMessage = userMessage;
}
public static boolean isValide(SendMessageData sendMessageData) {
if(sendMessageData == null ||
sendMessageData.getConv() == null ||
@@ -226,6 +226,7 @@ public class ProtoConstants {
public interface SystemSettingType {
int Group_Max_Member_Count = 1;
int NOT_ALLOW_USER_NAMES = 2;
}
public interface SearchUserType {
+1 -1
View File
@@ -6,7 +6,7 @@
<!--<relativePath>../pom.xml</relativePath>-->
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>1.3.7</version>
<version>1.3.8</version>
</parent>
<artifactId>distribution</artifactId>
@@ -455,6 +455,10 @@ push.harmony.server.address http://localhost:8085/harmony/push
## 如果开启 message.sensitive.forward.url 配置,命中敏感词的消息还会被回调到这个地址
sensitive.filter.type 2
## 敏感词是否只处理消息。如果为true,只过滤消息;如果为false,会同时过滤用户昵称、群组名和群昵称。
## 除了消息之外的信息只支持内部敏感词处理,不支持外置审核。
sensitive.only_message false
## 敏感词添加或者删除有2种方式,一种是通过Server API进行,这种方式会立即生效。另外一种方法是修改数据库,直接中数据库的t_sensitive_word表中处理
## 修改数据库的方法不会立即生效,IM服务会2个小时重新加载一次敏感词。所以如果直接修改敏感词表,需要等2个小时,或者重启才能生效。
+1 -1
View File
@@ -12,7 +12,7 @@
<artifactId>wildfirechat-parent</artifactId>
<packaging>pom</packaging>
<version>1.3.7</version>
<version>1.3.8</version>
<name>Wildfire Chat</name>
<description>Wildfire Chat Server</description>
<inceptionYear>2019</inceptionYear>
+9
View File
@@ -9,8 +9,17 @@
8. *** 从0.78 版本起把MySQL数据库中关键字都改为大小写敏感,另外生成id的方法也做了改变,只生成小写的id,避免出现id重复的问题,建议所有客户都升级 ***
9. *** 从0.79 版本起把log4j升级到log4j2,因为log4j已经不再维护而且还有已知的漏洞,建议所有客户都升级,升级时注意更新log4j2的配置文件 ***
10. *** 0.97版本更改了启动脚本```wildfirechat.sh```,如果是升级服务,请注意更新启动脚本。***
11. *** 1.3.8版本添加了server api发送消息的限制,限制消息体最大内容不能超过64KB,如果升级请注意业务系统发送消息大小。***
# 更新记录
--------------
Release note 1.3.8:
1. 添加限制,server api发送消息,限制消息体不能大于64KB。
2. 添加配置敏感词是否过滤用户信息群组信息昵称等。
3. 配置文件可以设置不允许使用的用户名字群组名称群名片等。
4. server api发送消息添加参数,可以以用户权限发送消息。
5. server api添加群备注和收藏群组接口。
--------------
Release note 1.3.7:
1. 搜索用户可以指定搜索机器人、普通用户或者所有。
+1 -1
View File
@@ -3,7 +3,7 @@
<parent>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>1.3.7</version>
<version>1.3.8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -4,6 +4,7 @@ import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.pojos.*;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.sdk.model.IMResult;
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
import cn.wildfirechat.sdk.utilities.ChannelHttpUtils;
import com.google.gson.Gson;
import org.apache.commons.codec.digest.DigestUtils;
@@ -65,6 +66,23 @@ public class ChannelServiceApi {
return channelHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
}
//仅专业版支持
public IMResult<String> recallMessage(long messageUid) throws Exception {
String path = APIPath.Channel_Msg_Recall;
RecallMessageData messageData = new RecallMessageData();
messageData.setMessageUid(messageUid);
return channelHttpUtils.httpJsonPost(path, messageData, String.class);
}
//仅专业版支持
public IMResult<Void> republishMessage(long messageUid, List<String> targets) throws Exception {
String path = APIPath.Channel_Msg_Republish;
RepublishChannelMessageData messageData = new RepublishChannelMessageData();
messageData.setMessageId(messageUid);
messageData.setTargets(targets);
return channelHttpUtils.httpJsonPost(path, messageData, Void.class);
}
public IMResult<Void> subscribe(String userId) throws Exception {
String path = APIPath.Channel_Subscribe;
InputChannelSubscribe input = new InputChannelSubscribe();
@@ -1,6 +1,7 @@
package cn.wildfirechat.sdk;
import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.pojos.*;
import cn.wildfirechat.sdk.model.IMResult;
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
@@ -178,6 +179,36 @@ public class GroupAdmin {
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
public static IMResult<Void> setGroupRemark(String userId, String groupId, String remark) throws Exception {
return GeneralAdmin.setUserSetting(userId, 26, groupId, remark);
}
public static IMResult<String> getGroupRemark(String userId, String groupId) throws Exception {
IMResult<UserSettingPojo> imResult = GeneralAdmin.getUserSetting(userId, 26, groupId);
IMResult<String> result = new IMResult<>();
result.code = imResult.code;;
result.msg = imResult.msg;;
if(imResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
result.result = imResult.result.getValue();
}
return result;
}
public static IMResult<Void> setFavGroup(String userId, String groupId, boolean fav) throws Exception {
return GeneralAdmin.setUserSetting(userId, 6, groupId, fav?"1":"0");
}
public static IMResult<Boolean> isFavGroup(String userId, String groupId) throws Exception {
IMResult<UserSettingPojo> imResult = GeneralAdmin.getUserSetting(userId, 6, groupId);
IMResult<Boolean> result = new IMResult<>();
result.code = imResult.code;;
result.msg = imResult.msg;;
if(imResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
result.result = "1".equals(imResult.getResult().getValue());
}
return result;
}
public static IMResult<OutputGroupIds> getUserGroups(String user) throws Exception {
String path = APIPath.Get_User_Groups;
InputUserId inputUserId = new InputUserId();
@@ -58,6 +58,9 @@ public class Main {
//测试解析数据库中消息内容
testReadMessageContentFromDB();
//计算消息分表
testMessageSharding();
//Robot和Channel都是使用的80端口,第三方可以创建或者为第三方创建,第三方可以使用robot或者channel与IM系统进行对接。
testRobot();
testChannel();
@@ -616,7 +619,7 @@ public class Main {
System.exit(-1);
}
voidIMResult = GroupAdmin.setGroupMemberAlias("user1", groupInfo.getTarget_id(), "user3", "test user3", null, null);
voidIMResult = GroupAdmin.setGroupMemberAlias("user1", groupInfo.getTarget_id(), "user2", "test user2", null, null);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("set group member alias success");
} else {
@@ -1003,13 +1006,24 @@ public class Main {
testStreamingText(sender, conversation);
}
static void testReadMessageContentFromDB() throws Exception {
//需要注意几点:
// 1 WFCMessage类不能混淆,如果混淆 WFCMessage.MessageContent.parseFrom(data) 就会失败。
// 2 MessageContentFactory方法会自动查找所有的消息类,包括文本/图片/语音等。也有可能在某些环境下找不到这些类。可以检查MessageContentFactory
// 类的源码,修改registerAllMessageContent方法,确保能找到所有的内容类。也可以显式调用注册的方法把所有已知消息都注册一遍,比如:
// MessageContentFactory.registerCustomMessageContent(TextMessageContent.class); //这里示例只写了文本的,其他所有已知消息都需要注册一遍。
//消息相关表分为2类,分表是:t_messages_x和t_user_messages_y,并且是分表存储的。表内存储数据和分表规则请参考 https://docs.wildfirechat.cn/faq/server.html 问题2
static void testMessageSharding() {
String userId = "user1";
int hashId = Math.abs(userId.hashCode())%128;
String userMessageTable = "t_user_messages_" + hashId;
System.out.println("user:" + userId + " user messages table is " + userMessageTable);
Calendar calendar = Calendar.getInstance();
Date date = new Date();
calendar.setTime(date);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
year %= 3;
String messageTable = "t_messages_" + (year * 12 + month);
System.out.println("This month save message to table " + messageTable);
}
static void testReadMessageContentFromDB() throws Exception {
//从数据库t_messages_x表中读取到消息内容字段_data的二进制数据为
byte[] data = {8,1,18,5,72,101,108,108,111,64,3};
//1. 先把二进制数据转化为协议栈消息内容。
@@ -1605,7 +1619,7 @@ public class Main {
System.exit(-1);
}
voidIMResult = robotService.setGroupMemberAlias(groupInfo.getTarget_id(), "user3", "test user3", null, null);
voidIMResult = robotService.setGroupMemberAlias(groupInfo.getTarget_id(), "user2", "test user2", null, null);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("set group member alias success");
} else {
@@ -11,14 +11,21 @@ public class MessageAdmin {
public static IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload) throws Exception {
return sendMessage(sender, conversation, payload, null);
}
//toUsers为发送给会话中部分用户用的,正常为null,仅当需要指定群/频道/聊天室中部分接收用户时使用
public static IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload, List<String> toUsers) throws Exception {
return sendMessage(sender, conversation, payload, toUsers, false);
}
//toUsers为发送给会话中部分用户用的,正常为null,仅当需要指定群/频道/聊天室中部分接收用户时使用
public static IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload, List<String> toUsers, boolean isUserMessage) throws Exception {
String path = APIPath.Msg_Send;
SendMessageData messageData = new SendMessageData();
messageData.setSender(sender);
messageData.setConv(conversation);
messageData.setPayload(payload);
messageData.setToUsers(toUsers);
messageData.setUserMessage(isUserMessage);
if (payload.getType() == 1 && (payload.getSearchableContent() == null || payload.getSearchableContent().isEmpty())) {
System.out.println("Payload错误,Payload格式应该跟客户端消息encode出来的Payload对齐,这样客户端才能正确识别。比如文本消息,文本需要放到searchableContent属性。请与客户端同事确认Payload的格式,或则去 https://gitee.com/wfchat/android-chat/tree/master/client/src/main/java/cn/wildfirechat/message 找到消息encode的实现方法!");
}
@@ -67,8 +67,8 @@ public class AdminHttpUtils extends JsonUtils {
public static <T> IMResult<T> httpGet(String path, Class<T> clazz) throws Exception {
if (isNullOrEmpty(adminUrl) || isNullOrEmpty(adminSecret)) {
LOG.error("野火IM Server SDK必须先初始化才能使用,是不是忘记初始化了!!!!");
throw new Exception("SDK没有初始化");
LOG.error("野火IM Server SDK必须先初始化才能使用,是不是忘记初始化了!请调用AdminConfig.initAdmin(AdminUrl, AdminSecret);进行初始化");
throw new Exception("SDK没有初始化,请调用AdminConfig.initAdmin(AdminUrl, AdminSecret);进行初始化");
}
if (isNullOrEmpty(path)) {
@@ -114,8 +114,8 @@ public class AdminHttpUtils extends JsonUtils {
public static <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception {
if (isNullOrEmpty(adminUrl) || isNullOrEmpty(adminSecret)) {
LOG.error("野火IM Server SDK必须先初始化才能使用,是不是忘记初始化了!!!!");
throw new Exception("SDK没有初始化");
LOG.error("野火IM Server SDK必须先初始化才能使用,是不是忘记初始化了!请调用AdminConfig.initAdmin(AdminUrl, AdminSecret);进行初始化");
throw new Exception("SDK没有初始化,请调用AdminConfig.initAdmin(AdminUrl, AdminSecret);进行初始化");
}
if (isNullOrEmpty(path)) {