Compare commits

...
29 Commits
Author SHA1 Message Date
imhao183 c4a764d81d update 2020-07-01 11:22:20 +08:00
imhao183 2c5ae2bd86 update version to 0.42 2020-07-01 11:04:42 +08:00
imhao183 b11d609ea0 update 2020-07-01 11:04:10 +08:00
imhao183 b8170c4757 修改好友欢迎提示方式,默认为关,需要在客户端上实现后打开 2020-06-30 17:15:53 +08:00
imhao183 e42d6f8e4f fix sql error 2020-06-25 16:07:49 +08:00
imhao183 e0c95bace9 数据库group表添加2个字段 2020-06-25 16:00:08 +08:00
imhao183 8623223991 添加群成员时,检查系统群最大成员数 2020-06-24 11:57:15 +08:00
heavyrain.lee efdcc24067 Update README.md 2020-06-24 09:26:46 +08:00
imhao183 ec18e40eb0 normal 类型的群组群成员可以修改群名称头像和extra,群主和群管理可以修改所有信息 2020-06-22 21:50:17 +08:00
heavyrain2012 f9d970c730 server api 发送接口添加extra字段 2020-06-18 17:22:45 +08:00
imhao183 590b02cc8e session修改成同步操作 2020-06-16 17:01:59 +08:00
imhao183 f2f75d3048 计数问题修正 2020-06-12 07:54:28 +08:00
imhao183 94466139f6 群成员增加加入时间字段 2020-06-11 20:58:24 +08:00
imhao183 70aeff9ac5 更新协议,在群成员数据结构中添加创建时间属性 2020-06-11 15:47:40 +08:00
imndx 7e56fe2ee0 参数校验 2020-06-09 17:11:48 +08:00
imndx 599547d627 修复黑名单问题. fix #213, fix #212 2020-06-09 16:53:24 +08:00
imhao183 28600ea7f9 修正文件名中带有&字符错误问题 2020-06-08 21:43:12 +08:00
heavyrain2012 a73507c673 解决群组通知line错误问题 2020-06-08 19:10:13 +08:00
imhao183 84b8d4cd09 fix build error 2020-06-04 07:47:11 +08:00
imhao183 b66aa3d634 消息转发时带上消息ID和时间戳 2020-06-04 07:44:11 +08:00
imhao183 508beaf62c SDK增加群内成员禁言功能 2020-05-24 19:02:39 +08:00
imhao183 e914afedf4 同步专业版数据库 2020-05-23 17:25:52 +08:00
heavyrain.lee 49c32d7fa1 Update README.md 2020-05-20 07:02:32 +08:00
imhao183 aac106d37e 更新注释 2020-05-15 09:51:31 +08:00
imhao183 8bd17a8093 更新注释 2020-05-13 19:16:15 +08:00
imhao183 b1f07f49ff api接口获取群成员信息时,过滤掉已删除成员 2020-05-11 12:12:51 +08:00
imhao183 86dddfd85f fix build error 2020-05-11 08:33:09 +08:00
imhao183 db733efc44 解决SDK中修改群信息的接口缺少自定义消息的问题 2020-05-06 21:00:41 +08:00
imhao183 69f28bd35b 当接受好友邀请时,如果已经是好友,返回“已经是好友”的错误码 2020-05-06 20:50:15 +08:00
35 changed files with 721 additions and 2023 deletions
+3 -9
View File
@@ -43,11 +43,6 @@
![野火IM](http://static.wildfirechat.cn/download_qrcode.png)
#### 加入野火官方体验交流群
使用野火IM移动客户端扫码下面二维码(不是使用微信扫码),和野火IM的爱好者一起畅谈野火IM的问题和经验:
![野火IM官方交流群](http://static.wildfirechat.cn/wildfirechat_official_group.jpeg)
#### 应用截图
![ios-demo](http://static.wildfirechat.cn/ios-demo.gif)
@@ -73,12 +68,11 @@
## 编译
在安装JDK1.8以上及maven的前提下,在命令行中执行```mvn clean compile package```,生成的目标文件在```./distribution/target/distribution-xxxx-bundle-tar.tar.gz```
> 由于使用了一个git的maven插件,如果本地没有git信息就会编译出错,请使用```git clone```的方法下载代码,或者下载压缩包解压后在根目录创建```.git```的空目录。建议用```git clone```的方式下载代码。
## 捐赠者名单
## 升级说明
1. 从0.42 版本增加了群成员数限制,默认为2000。如果您从之前的版本升级到这个版本或以后,需要注意到群成员数的限制。升级之后超出限制的群不受影响,但不能继续加人,如果您想修改默认值,可以在升级版本之后,修改t_setting表,把默认的大小改为您期望的人数。另外修改t_group表,把已经存在的群组max_member_count改成您期望的,然后重启。
| 捐赠者 | 商标 | 金额 | 简介 |
| ----- | ---- | -------- | --- |
| [SAMOS](http://samos.io) | ![SAMOS](http://static.wildfirechat.cn/SAMOS.png) | 保密 | 一站式区块链解决方案服务商(http://samos.io) |
## 特别感谢
1. [moquette](https://github.com/moquette-io/moquette) 本项目是基于此项目二次开发而来,处理MQTT相关业务。
+12 -2
View File
@@ -55,10 +55,12 @@ token.key testim
##token的过期时间,单位为毫秒,默认为无限期。如果需要设置无限期,客户端上一定需要加上token过期的处理。token过期的处理请参考文档的常见问题
##token.expire_time 2592000000
##首次登录,是否接收之前的历史消息。0 不接收;1接收。
##首次登录,是否接收之前的历史消息。
##0 不接收历史消息,只接收5分钟以内的消息,由于服务器没有保存已经收取记录,所以如果有超过5分钟之前未收取的消息也不会收取下拉;
##1接收,会接收 message.max_queue 配置的条数的历史消息
message.roaming 0
##是否开启拉取远程历史消息
##是否开启拉取远程历史消息。如果为1,客户端在会话内如果本地消息读取完了,可以下拉继续加载在服务器上的该会话的消息;如果为0则不能。
message.remote_history_message 0
##服务器为每个用户缓存的消息数量。这个值改得太大,拉取消息时间变长,另外会占用大量内存。
@@ -92,6 +94,12 @@ friend.reject_request_duration 2592000000
##好友请求过期时间,单位是毫秒,默认是7天,0为不限制
friend.request_expiration_duration 604800000
##添加好友后会发送欢迎消息,比如"你们已经是好友了,可以聊天了"。这个开关控制是用旧的方式还是用新的方式。
##旧的方式会发送notification消息(contenttype是80),内容会根据好友接收者的语言选择对应的语言,如果双方语言不一致会导致另外一方看到的不是本地语言。
##新的方式会发送添加好友消息(contenttype是93)和欢迎消息(contenttype是92),需要客户端实现这两种消息。
##如果客户端已经实现这两种消息可以打开这个开关
friend.new_welcome_message false
## 聊天室观众空闲退出时间,单位为毫秒,默认为15分钟,0为永远不退出
chatroom.participant_idle_time 900000
@@ -174,6 +182,8 @@ push.ios.server.address http://localhost:8085/ios/push
#mongodb.client_uri mongodb://host1:27017,host2:27017,host3:27017/wfchat?replicaSet=myReplicaSet
mongodb.client_uri mongodb://wfc:123456@localhost:27017/wfchat
mongodb.database wfchat
#仅在第一次启动时会设置消息数据的过期时间,如果之后再修改将不生效。
#如果需要修改过期时间,请修改t_messages_x和t_user_message_x的索引过期时间,修改方法请行百度
mongodb.data_expire_days 1096
#*********************************************************************
+42
View File
@@ -0,0 +1,42 @@
DROP TABLE IF EXISTS `t_read_report`;
CREATE TABLE `t_read_report` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`_uid` varchar(64) NULL,
`_type` tinyint NULL,
`_line` int(11) NULL,
`_target` varchar(64) NULL,
`_dt` bigint(20) NOT NULL DEFAULT 0,
INDEX `read_report_index` (`_uid`, `_type`, `_line`, `_target`)
);
DROP TABLE IF EXISTS `t_user_read_report`;
CREATE TABLE `t_user_read_report` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`_rid` int(11) NOT NULL,
`_uid` varchar(64) NOT NULL,
`_seq` bigint(20) NOT NULL,
`_dt` DATETIME NOT NULL DEFAULT NOW(),
INDEX `user_read_report_index` (`_uid` DESC, `_seq` DESC),
UNIQUE INDEX `user_read_report_index2` (`_uid` DESC, `_rid` DESC)
);
DROP TABLE IF EXISTS `t_delivery_report`;
CREATE TABLE `t_delivery_report` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`_uid` varchar(64) NOT NULL,
`_dt` bigint(20) NOT NULL,
UNIQUE INDEX `delivery_index` (`_uid`)
);
DROP TABLE IF EXISTS `t_user_delivery_report`;
CREATE TABLE `t_user_delivery_report` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`_rid` varchar(64) NOT NULL,
`_uid` varchar(64) NOT NULL,
`_seq` bigint(20) NOT NULL,
`_dt` DATETIME NOT NULL DEFAULT NOW(),
INDEX `user_delivery_index` (`_uid` DESC, `_seq` DESC),
UNIQUE INDEX `user_delivery_index2` (`_uid` DESC, `_rid` DESC)
);
+1
View File
@@ -0,0 +1 @@
alter table t_group_member add column `_create_dt` bigint(20) DEFAULT 0;
@@ -0,0 +1,2 @@
alter table `t_group` add column `_history_message` tinyint NOT NULL DEFAULT 0;
alter table `t_group` add column `_max_member_count` int(11) NOT NULL DEFAULT 2000;
+54
View File
@@ -0,0 +1,54 @@
DROP TABLE IF EXISTS `t_read_report`;
CREATE TABLE `t_read_report` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`_uid` varchar(64) NULL,
`_type` tinyint NULL,
`_line` int(11) NULL,
`_target` varchar(64) NULL,
`_dt` bigint(20) NOT NULL DEFAULT 0,
INDEX `read_report_index` (`_uid`, `_type`, `_line`, `_target`)
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `t_user_read_report`;
CREATE TABLE `t_user_read_report` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`_rid` int(11) NOT NULL,
`_uid` varchar(64) NOT NULL,
`_seq` bigint(20) NOT NULL,
`_dt` DATETIME NOT NULL DEFAULT NOW(),
INDEX `user_read_report_index` (`_uid` DESC, `_seq` DESC),
UNIQUE INDEX `user_read_report_index2` (`_uid` DESC, `_rid` DESC)
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `t_delivery_report`;
CREATE TABLE `t_delivery_report` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`_uid` varchar(64) NOT NULL,
`_dt` bigint(20) NOT NULL,
UNIQUE INDEX `delivery_index` (`_uid`)
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `t_user_delivery_report`;
CREATE TABLE `t_user_delivery_report` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`_rid` varchar(64) NOT NULL,
`_uid` varchar(64) NOT NULL,
`_seq` bigint(20) NOT NULL,
`_dt` DATETIME NOT NULL DEFAULT NOW(),
INDEX `user_delivery_index` (`_uid` DESC, `_seq` DESC),
UNIQUE INDEX `user_delivery_index2` (`_uid` DESC, `_rid` DESC)
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_unicode_ci;
+1
View File
@@ -0,0 +1 @@
alter table t_group_member add column `_create_dt` bigint(20) DEFAULT 0, COMMENT "group member create time";
@@ -0,0 +1,2 @@
alter table `t_group` add column `_history_message` tinyint NOT NULL DEFAULT 0, COMMENT "new group member can load group history messages";
alter table `t_group` add column `_max_member_count` int(11) NOT NULL DEFAULT 2000, COMMENT "max group member count";
+1 -1
View File
@@ -5,7 +5,7 @@
<relativePath>../</relativePath>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>0.41</version>
<version>0.42</version>
</parent>
<artifactId>moquette-broker</artifactId>
@@ -109,7 +109,8 @@ public class FileAction extends Action {
}
// 路径安全检查
if (httpPath.contains("/.") || httpPath.contains("./") || httpPath.charAt(0) == '.' || httpPath.charAt(httpPath.length() - 1) == '.' || ReUtil.isMatch(INSECURE_URI, httpPath)) {
String path = httpPath.substring(0, httpPath.lastIndexOf("/"));
if (path.contains("/.") || path.contains("./") || path.charAt(0) == '.' || path.charAt(path.length() - 1) == '.' || ReUtil.isMatch(INSECURE_URI, path)) {
return null;
}
@@ -14,6 +14,7 @@ import cn.wildfirechat.pojos.InputGetGroup;
import cn.wildfirechat.pojos.OutputGroupMemberList;
import cn.wildfirechat.pojos.PojoGroupInfo;
import cn.wildfirechat.pojos.PojoGroupMember;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import com.google.gson.Gson;
import com.xiaoleilu.loServer.RestResult;
@@ -56,6 +57,9 @@ public class GetGroupMembersAction extends AdminAction {
OutputGroupMemberList out = new OutputGroupMemberList();
out.setMembers(new ArrayList<>());
for (WFCMessage.GroupMember member : members) {
if (member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Removed) {
continue;
}
PojoGroupMember pm = new PojoGroupMember();
pm.setMember_id(member.getMemberId());
pm.setAlias(member.getAlias());
@@ -135,6 +135,7 @@ public final class BrokerConstants {
public static final String FRIEND_Repeat_Request_Duration = "friend.repeat_request_duration";
public static final String FRIEND_Reject_Request_Duration = "friend.reject_request_duration";
public static final String FRIEND_Request_Expiration_Duration = "friend.request_expiration_duration";
public static final String FRIEND_New_Welcome_Message = "friend.new_welcome_message";
public static final String CHATROOM_Participant_Idle_Time = "chatroom.participant_idle_time";
public static final String CHATROOM_Rejoin_When_Active = "chatroom.rejoin_when_active";
@@ -17,7 +17,7 @@ import java.util.List;
abstract public class GroupHandler<T> extends IMHandler<T> {
protected void sendGroupNotification(String fromUser, String targetId, List<Integer> lines, WFCMessage.MessageContent content) {
if (lines != null) {
if (lines == null) {
lines = new ArrayList<>();
}
@@ -43,7 +43,12 @@ public class HandleFriendRequestHandler extends IMHandler<WFCMessage.HandleFrien
if (session != null && !StringUtil.isNullOrEmpty(session.getLanguage())) {
language = session.getLanguage();
}
WFCMessage.MessageContent.Builder contentBuilder = WFCMessage.MessageContent.newBuilder().setType(90).setContent(I18n.getString(language, "Above_Greeting_Message"));
WFCMessage.MessageContent.Builder contentBuilder = WFCMessage.MessageContent.newBuilder();
if (m_messagesStore.isNewFriendWelcomeMessage()) {
contentBuilder.setType(92);
} else {
contentBuilder.setType(90).setContent(I18n.getString(language, "Above_Greeting_Message"));
}
builder = WFCMessage.Message.newBuilder();
builder.setFromUser(request.getTargetUid());
@@ -56,7 +61,12 @@ public class HandleFriendRequestHandler extends IMHandler<WFCMessage.HandleFrien
builder.setMessageId(messageId);
saveAndPublish(request.getTargetUid(), null, builder.build(), false);
contentBuilder.setContent(I18n.getString(language, "Friend_Can_Start_Chat"));
if (m_messagesStore.isNewFriendWelcomeMessage()) {
contentBuilder.setType(93);
} else {
contentBuilder.setContent(I18n.getString(language, "Friend_Can_Start_Chat"));
}
builder.setContent(contentBuilder);
messageId = MessageShardingUtil.generateId();
builder.setMessageId(messageId);
@@ -331,7 +331,7 @@ public class DatabaseStore {
String sql = "select `_mid`" +
", `_alias`" +
", `_type`" +
", `_dt` from t_group_member where _gid = ?";
", `_dt`, `_create_dt` from t_group_member where _gid = ?";
statement = connection.prepareStatement(sql);
statement.setString(1, groupId);
@@ -358,6 +358,9 @@ public class DatabaseStore {
long longValue = rs.getLong(index++);
builder.setUpdateDt(longValue);
longValue = rs.getLong(index++);
builder.setCreateDt(longValue);
WFCMessage.GroupMember member = builder.build();
groupMembers.put(groupId, member);
}
@@ -1338,7 +1341,6 @@ public class DatabaseStore {
}
void updateSessionDeleted(String uid, String cid, int deleted) {
mScheduler.execute(()->{
Connection connection = null;
PreparedStatement statement = null;
@@ -1363,11 +1365,9 @@ public class DatabaseStore {
} finally {
DBUtil.closeDB(connection, statement);
}
});
}
void updateSessionPlatform(String uid, String cid, int platform) {
mScheduler.execute(()->{
Connection connection = null;
PreparedStatement statement = null;
@@ -1392,7 +1392,6 @@ public class DatabaseStore {
} finally {
DBUtil.closeDB(connection, statement);
}
});
}
private boolean strEqual(String left, String right) {
@@ -1652,7 +1651,7 @@ public class DatabaseStore {
", `_mid`" +
", `_alias`" +
", `_type`" +
", `_dt`) values(?, ?, ?, ?, ?)" +
", `_dt`, `_create_dt`) values(?, ?, ?, ?, ?, ?)" +
" ON DUPLICATE KEY UPDATE " +
"`_alias` = ?," +
"`_type` = ?," +
@@ -1673,6 +1672,7 @@ public class DatabaseStore {
statement.setString(index++, member.getAlias());
statement.setInt(index++, member.getType());
statement.setLong(index++, dt);
statement.setLong(index++, member.getCreateDt());
statement.setString(index++, member.getAlias());
statement.setInt(index++, member.getType());
statement.setLong(index++, dt);
@@ -127,6 +127,7 @@ public class MemoryMessagesStore implements IMessagesStore {
private long mFriendRequestDuration = 7 * 24 * 60 * 60 * 1000;
private long mFriendRejectDuration = 30 * 24 * 60 * 60 * 1000;
private long mFriendRequestExpiration = 7 * 24 * 60 * 60 * 1000;
private boolean mFriendNewWelcomeMessage = false;
private boolean mMultiPlatformNotification = false;
private boolean mDisableStrangerChat = false;
@@ -204,6 +205,15 @@ public class MemoryMessagesStore implements IMessagesStore {
printMissConfigLog(FRIEND_Request_Expiration_Duration, mFriendRequestExpiration + "");
}
try {
mFriendNewWelcomeMessage = Boolean.parseBoolean(m_Server.getConfig().getProperty(FRIEND_New_Welcome_Message));
} catch (Exception e) {
e.printStackTrace();
Utility.printExecption(LOG, e);
printMissConfigLog(FRIEND_New_Welcome_Message, mFriendNewWelcomeMessage + "");
}
try {
mChatroomRejoinWhenActive = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.CHATROOM_Rejoin_When_Active));
} catch (Exception e) {
@@ -781,9 +791,9 @@ public class MemoryMessagesStore implements IMessagesStore {
List<WFCMessage.GroupMember> updatedMemberList = new ArrayList<>();
for (WFCMessage.GroupMember member : memberList) {
if (member.getMemberId().equals(groupInfo.getOwner())) {
member = member.toBuilder().setUpdateDt(dt).setType(ProtoConstants.GroupMemberType.GroupMemberType_Owner).build();
member = member.toBuilder().setUpdateDt(dt).setCreateDt(dt).setType(ProtoConstants.GroupMemberType.GroupMemberType_Owner).build();
} else {
member = member.toBuilder().setUpdateDt(dt).build();
member = member.toBuilder().setUpdateDt(dt).setCreateDt(dt).build();
}
groupMembers.put(groupId, member);
updatedMemberList.add(member);
@@ -806,6 +816,8 @@ public class MemoryMessagesStore implements IMessagesStore {
}
int maxCount = Integer.MAX_VALUE;
if (!isAdmin) {
boolean isMember = false;
boolean isManager = false;
@@ -835,6 +847,15 @@ public class MemoryMessagesStore implements IMessagesStore {
if (!isMember && !(memberList.size() == 1 && operator.equals(memberList.get(0).getMemberId()))) {
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
}
SystemSettingPojo maxMemberSetting = databaseStore.getSystemSetting(ProtoConstants.SystemSettingType.Group_Max_Member_Count);
if (maxMemberSetting != null) {
try {
maxCount = Integer.parseInt(maxMemberSetting.value);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
long updateDt = System.currentTimeMillis();
@@ -843,9 +864,9 @@ public class MemoryMessagesStore implements IMessagesStore {
ArrayList<String> newInviteUsers = new ArrayList<>();
for (WFCMessage.GroupMember member : memberList) {
if (member.getMemberId().equals(groupInfo.getOwner())) {
member = member.toBuilder().setType(GroupMemberType_Owner).setUpdateDt(updateDt).setAlias("").build();
member = member.toBuilder().setType(GroupMemberType_Owner).setUpdateDt(updateDt).setCreateDt(updateDt).setAlias("").build();
} else {
member = member.toBuilder().setType(GroupMemberType_Normal).setUpdateDt(updateDt).setAlias("").build();
member = member.toBuilder().setType(GroupMemberType_Normal).setUpdateDt(updateDt).setCreateDt(updateDt).setAlias("").build();
}
tmp.add(member);
newInviteUsers.add(member.getMemberId());
@@ -858,6 +879,18 @@ public class MemoryMessagesStore implements IMessagesStore {
members = loadGroupMemberFromDB(hzInstance, groupId);
}
if (maxCount != Integer.MAX_VALUE) {
int existCount = 0;
for (WFCMessage.GroupMember member : members) {
if (member.getType() != GroupMemberType_Removed) {
existCount++;
}
}
if (existCount + newInviteUsers.size() > maxCount) {
return ErrorCode.ERROR_CODE_GROUP_EXCEED_MAX_MEMBER_COUNT;
}
}
for (WFCMessage.GroupMember member : members) {
if (newInviteUsers.contains(member.getMemberId())) {
groupMembers.remove(groupId, member);
@@ -1063,15 +1096,23 @@ public class MemoryMessagesStore implements IMessagesStore {
}
if (oldInfo.getType() == ProtoConstants.GroupType.GroupType_Normal) {
if (oldInfo.getOwner() == null) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
if (!oldInfo.getOwner().equals(operator)) {
if (modifyType == Modify_Group_Extra) {
if (!operator.equals(oldInfo.getOwner())) {
WFCMessage.GroupMember gm = getGroupMember(groupId, operator);
boolean isManager = false;
if (gm != null && gm.getType() == GroupMemberType_Manager) {
isManager = true;
}
if (!isManager && modifyType != Modify_Group_Name && modifyType != Modify_Group_Portrait && modifyType != Modify_Group_Extra) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
}
if (oldInfo.getType() == ProtoConstants.GroupType.GroupType_Free) {
if (modifyType != Modify_Group_Name && modifyType != Modify_Group_Portrait && modifyType != Modify_Group_Extra) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
}
@@ -2147,6 +2188,25 @@ public class MemoryMessagesStore implements IMessagesStore {
public ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendRequest request, WFCMessage.Message.Builder msgBuilder, long[] heads, boolean isAdmin) {
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
if(request.getStatus() == ProtoConstants.FriendRequestStatus.RequestStatus_Accepted) {
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
Collection<FriendData> friends = friendsMap.get(userId);
if (friends == null || friends.size() == 0) {
friends = loadFriend(friendsMap, userId);
}
for (FriendData fd : friends) {
if (fd.getFriendUid().equals(request.getTargetUid())) {
if (fd.getState() == 0) {
return ErrorCode.ERROR_CODE_ALREADY_FRIENDS;
} else {
break;
}
}
}
}
if (isAdmin) {
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
@@ -2252,10 +2312,12 @@ public class MemoryMessagesStore implements IMessagesStore {
@Override
public ErrorCode blackUserRequest(String fromUser, String targetUserId, int state, long[] heads) {
if(state != 0 && state != 1 && state != 2){
return ErrorCode.INVALID_PARAMETER;
}
if (state == 2) {
state = 1;
} else {
state = 0;
}
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
@@ -2384,6 +2446,11 @@ public class MemoryMessagesStore implements IMessagesStore {
return true;
}
@Override
public boolean isNewFriendWelcomeMessage() {
return mFriendNewWelcomeMessage;
}
@Override
public ErrorCode deleteFriend(String userId, String friendUid, long[] head) {
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
@@ -167,6 +167,7 @@ public interface IMessagesStore {
ErrorCode saveAddFriendRequest(String userId, WFCMessage.AddFriendRequest request, long[] head);
ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendRequest request, WFCMessage.Message.Builder msgBuilder, long[] heads, boolean isAdmin);
boolean isNewFriendWelcomeMessage();
ErrorCode deleteFriend(String userId, String friendUid, long[] head);
ErrorCode blackUserRequest(String fromUser, String targetUserId, int status, long[] head);
FriendData getFriendData(String fromUser, String targetUserId);
@@ -16,6 +16,7 @@
package io.moquette.spi.impl;
import cn.wildfirechat.pojos.OutputMessageData;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import cn.wildfirechat.push.PushServer;
@@ -252,7 +253,7 @@ public class MessagesPublisher {
}
}
if (!StringUtil.isNullOrEmpty(pushContent) || messageContentType == 400 || messageContentType == 402) {
if (!StringUtil.isNullOrEmpty(pushContent) || messageContentType == 400) {
if (!isSlient) {
targetSession.setUnReceivedMsgs(targetSession.getUnReceivedMsgs() + 1);
}
@@ -549,7 +550,7 @@ public class MessagesPublisher {
}
public void forwardMessage(final WFCMessage.Message message, String forwardUrl) {
executorCallback.execute(() -> HttpUtils.httpJsonPost(forwardUrl, new Gson().toJson(SendMessageData.fromProtoMessage(message), SendMessageData.class)));
executorCallback.execute(() -> HttpUtils.httpJsonPost(forwardUrl, new Gson().toJson(OutputMessageData.fromProtoMessage(message), OutputMessageData.class)));
}
public void notifyChannelListenStatusChanged(WFCMessage.ChannelInfo channelInfo, String user, boolean listen) {
@@ -13,7 +13,7 @@ import java.util.Date;
public class MessageShardingUtil {
private static SpinLock mLock = new SpinLock();
private static int rotateId = 0;
private static volatile int rotateId = 0;
private static int nodeId = 0;
private static int rotateIdWidth = 15;
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>0.41</version>
<version>0.42</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -53,6 +53,7 @@ public interface APIPath {
String Group_Member_Kickoff = "/admin/group/member/del";
String Group_Member_Quit = "/admin/group/member/quit";
String Group_Set_Manager = "/admin/group/manager/set";
String Group_Mute_Member = "/admin/group/manager/mute";
String Get_User_Groups = "/admin/group/of_user";
@@ -42,6 +42,9 @@ public enum ErrorCode {
ERROR_CODE_NOT_IN_CHANNEL(21, "not in channel"),
ERROR_CODE_ALREADY_FRIENDS(23, "already friends"),
ERROR_CODE_GROUP_EXCEED_MAX_MEMBER_COUNT(240, "group exceed max member count"),
ERROR_CODE_GROUP_MUTED(241, "group is muted"),
ERROR_CODE_SENSITIVE_MATCHED(242, "sensitive matched"),
ERROR_CODE_SIGN_EXPIRED(243, "sign expired"),
@@ -145,6 +145,8 @@ public class GroupNotificationBinaryContent {
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_SET_MANAGER);
}
public WFCMessage.MessageContent getMuteGroupMemberNotifyContent() {
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_MUTE_MEMBER);
}
}
@@ -0,0 +1,72 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package cn.wildfirechat.pojos;
import cn.wildfirechat.proto.WFCMessage;
import io.netty.util.internal.StringUtil;
import java.util.List;
public class InputMuteGroupMember extends InputGroupBase {
private String group_id;
private List<String> members;
private boolean is_manager;
public String getGroup_id() {
return group_id;
}
public void setGroup_id(String group_id) {
this.group_id = group_id;
}
public List<String> getMembers() {
return members;
}
public void setMembers(List<String> members) {
this.members = members;
}
public boolean isIs_manager() {
return is_manager;
}
public void setIs_manager(boolean is_manager) {
this.is_manager = is_manager;
}
public boolean isValide() {
if (StringUtil.isNullOrEmpty(operator) || StringUtil.isNullOrEmpty(group_id) || members == null || members.isEmpty()) {
return false;
}
return true;
}
public WFCMessage.SetGroupManagerRequest toProtoGroupRequest() {
WFCMessage.SetGroupManagerRequest.Builder addGroupBuilder = WFCMessage.SetGroupManagerRequest.newBuilder();
addGroupBuilder.setGroupId(group_id);
addGroupBuilder.addAllUserId(members);
addGroupBuilder.setType(is_manager ? 1 : 0);
if (to_lines != null) {
for (Integer line : to_lines
) {
addGroupBuilder.addToLine(line);
}
}
if (notify_message != null) {
addGroupBuilder.setNotifyContent(notify_message.toProtoMessageContent());
}
return addGroupBuilder.build();
}
}
@@ -28,6 +28,8 @@ public class MessagePayload {
private int expireDuration;
private int mentionedType;
private List<String> mentionedTarget;
private String extra;
public int getType() {
return type;
@@ -117,6 +119,14 @@ public class MessagePayload {
this.mentionedTarget = mentionedTarget;
}
public String getExtra() {
return extra;
}
public void setExtra(String extra) {
this.extra = extra;
}
public WFCMessage.MessageContent toProtoMessageContent() {
WFCMessage.MessageContent.Builder builder = WFCMessage.MessageContent.newBuilder()
.setType(type)
@@ -137,6 +147,8 @@ public class MessagePayload {
builder.setRemoteMediaUrl(remoteMediaUrl);
if (mentionedTarget != null && mentionedTarget.size() > 0)
builder.addAllMentionedTarget(mentionedTarget);
if (!StringUtil.isNullOrEmpty(extra))
builder.setExtra(extra);
return builder.build();
}
@@ -159,6 +171,7 @@ public class MessagePayload {
payload.mentionedType = protoContent.getMentionedType();
payload.mentionedTarget = new ArrayList<>();
payload.mentionedTarget.addAll(protoContent.getMentionedTargetList());
payload.extra = protoContent.getExtra();
return payload;
}
}
@@ -0,0 +1,85 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package cn.wildfirechat.pojos;
import cn.wildfirechat.proto.WFCMessage;
import io.netty.util.internal.StringUtil;
import java.util.List;
public class OutputMessageData {
private long messageId;
private String sender;
private Conversation conv;
private MessagePayload payload;
private List<String> toUsers;
private long timestamp;
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public Conversation getConv() {
return conv;
}
public void setConv(Conversation conv) {
this.conv = conv;
}
public MessagePayload getPayload() {
return payload;
}
public void setPayload(MessagePayload payload) {
this.payload = payload;
}
public List<String> getToUsers() {
return toUsers;
}
public void setToUsers(List<String> toUsers) {
this.toUsers = toUsers;
}
public long getMessageId() {
return messageId;
}
public void setMessageId(long messageId) {
this.messageId = messageId;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public static OutputMessageData fromProtoMessage(WFCMessage.Message protoMessage) {
OutputMessageData data = new OutputMessageData();
data.messageId = protoMessage.getMessageId();
data.sender = protoMessage.getFromUser();
data.conv = new Conversation();
data.conv.setTarget(protoMessage.getConversation().getTarget());
data.conv.setType(protoMessage.getConversation().getType());
data.conv.setLine(protoMessage.getConversation().getLine());
data.payload = MessagePayload.fromProtoMessageContent(protoMessage.getContent());
data.timestamp = protoMessage.getServerTimestamp();
data.toUsers = protoMessage.getToList();
return data;
}
}
@@ -181,5 +181,6 @@ public class ProtoConstants {
public static final int MESSAGE_CONTENT_TYPE_CHANGE_SEARCHABLE = 116;
public static final int MESSAGE_CONTENT_TYPE_SET_MANAGER = 117;
public static final int MESSAGE_CONTENT_TYPE_MUTE_MEMBER = 118;
}
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -6,7 +6,7 @@
<!--<relativePath>../pom.xml</relativePath>-->
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>0.41</version>
<version>0.42</version>
</parent>
<artifactId>distribution</artifactId>
@@ -41,7 +41,7 @@
<!--关闭连接时,是否提交未提交的事务,默认为false,即关闭连接,回滚未提交的事务 -->
<property name="autoCommitOnClose">false</property>
<!--c3p0将建一张名为Test的空表,并使用其自带的查询语句进行测试。如果定义了这个参数那么属性preferredTestQuery将被忽略。你不能在这张Test表上进行任何操作,它将只供c3p0测试使用。默认值: null -->
<property name="automaticTestTable">Test</property>
<!-- <property name="automaticTestTable">Test</property>-->
<!--如果为false,则获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常,但是数据源仍有效保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。默认: false-->
<property name="breakAfterAcquireFailure">false</property>
<!--每60秒检查所有连接池中的空闲连接。默认值: 0,不检查 -->
@@ -46,10 +46,12 @@ token.key testim
##token的过期时间,单位为毫秒,默认为无限期。如果需要设置无限期,客户端上一定需要加上token过期的处理。token过期的处理请参考文档的常见问题
##token.expire_time 2592000000
##首次登录,是否接收之前的历史消息。0 不接收;1接收。
##首次登录,是否接收之前的历史消息。
##0 不接收历史消息,只接收5分钟以内的消息,由于服务器没有保存已经收取记录,所以如果有超过5分钟之前未收取的消息也不会收取下拉;
##1接收,会接收 message.max_queue 配置的条数的历史消息
message.roaming 0
##是否开启拉取远程历史消息
##是否开启拉取远程历史消息。如果为1,客户端在会话内如果本地消息读取完了,可以下拉继续加载在服务器上的该会话的消息;如果为0则不能。
message.remote_history_message 0
##服务器为每个用户缓存的消息数量。这个值改得太大,拉取消息时间变长,另外会占用大量内存。
@@ -83,6 +85,12 @@ friend.reject_request_duration 2592000000
##好友请求过期时间,单位是毫秒,默认是7天,0为不限制
friend.request_expiration_duration 604800000
##添加好友后会发送欢迎消息,比如"你们已经是好友了,可以聊天了"。这个开关控制是用旧的方式还是用新的方式。
##旧的方式会发送notification消息(contenttype是80),内容会根据好友接收者的语言选择对应的语言,如果双方语言不一致会导致另外一方看到的不是本地语言。
##新的方式会发送添加好友消息(contenttype是93)和欢迎消息(contenttype是92),需要客户端实现这两种消息。
##如果客户端已经实现这两种消息可以打开这个开关
friend.new_welcome_message false
## 聊天室观众空闲退出时间,单位为毫秒,默认为15分钟,0为永远不退出
chatroom.participant_idle_time 900000
+1 -1
View File
@@ -12,7 +12,7 @@
<artifactId>wildfirechat-parent</artifactId>
<packaging>pom</packaging>
<version>0.41</version>
<version>0.42</version>
<name>Wildfire Chat</name>
<description>Wildfire Chat Server</description>
<inceptionYear>2019</inceptionYear>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>0.41</version>
<version>0.42</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -52,7 +52,7 @@ public class GroupAdmin {
return AdminHttpUtils.httpJsonPost(path, transferGroup, Void.class);
}
public static IMResult<Void> modifyGroupInfo(String operator, String groupId, int type, String value, List<Integer> to_lines) throws Exception {
public static IMResult<Void> modifyGroupInfo(String operator, String groupId, /*ModifyGroupInfoType*/int type, String value, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Group_Modify_Info;
InputModifyGroupInfo modifyGroupInfo = new InputModifyGroupInfo();
modifyGroupInfo.setGroup_id(groupId);
@@ -60,6 +60,7 @@ public class GroupAdmin {
modifyGroupInfo.setTo_lines(to_lines);
modifyGroupInfo.setType(type);
modifyGroupInfo.setValue(value);
modifyGroupInfo.setNotify_message(notify_message);
return AdminHttpUtils.httpJsonPost(path, modifyGroupInfo, Void.class);
}
@@ -100,7 +101,17 @@ public class GroupAdmin {
return AdminHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
}
public static IMResult<Void> muteGroupMemeber(String operator, String groupId, List<String> groupMemberIds, boolean isManager, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Group_Mute_Member;
InputMuteGroupMember addGroupMember = new InputMuteGroupMember();
addGroupMember.setGroup_id(groupId);
addGroupMember.setMembers(groupMemberIds);
addGroupMember.setIs_manager(isManager);
addGroupMember.setOperator(operator);
addGroupMember.setTo_lines(to_lines);
addGroupMember.setNotify_message(notify_message);
return AdminHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
}
public static IMResult<Void> kickoffGroupMembers(String operator, String groupId, List<String> groupMemberIds, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Group_Member_Kickoff;
@@ -130,5 +141,4 @@ public class GroupAdmin {
return AdminHttpUtils.httpJsonPost(path, inputUserId, OutputGroupIds.class);
}
}
@@ -37,6 +37,7 @@ public class Main {
testChatroom();
testMessage();
testGeneralApi();
testDevice();
System.out.println("Congratulation, all admin test case passed!!!!!!!");
}
@@ -351,7 +352,7 @@ public class Main {
System.exit(-1);
}
voidIMResult = GroupAdmin.modifyGroupInfo(groupInfo.getOwner(), groupInfo.getTarget_id(), ProtoConstants.ModifyGroupInfoType.Modify_Group_Name,"HelloWorld", null);
voidIMResult = GroupAdmin.modifyGroupInfo(groupInfo.getOwner(), groupInfo.getTarget_id(), ProtoConstants.ModifyGroupInfoType.Modify_Group_Name,"HelloWorld", null, null);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("transfer success");
} else {
@@ -413,6 +414,23 @@ public class Main {
System.exit(-1);
}
voidIMResult = GroupAdmin.muteGroupMemeber("user1", groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), true, null, null);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("mute group member success");
} else {
System.out.println("mute group member failure");
System.exit(-1);
}
voidIMResult = GroupAdmin.muteGroupMemeber("user1", groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), false, null, null);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("unmute group member success");
} else {
System.out.println("unmute group member failure");
System.exit(-1);
}
voidIMResult = GroupAdmin.quitGroup("user4", groupInfo.getTarget_id(), null, null);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {