Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfb9638a38 | ||
|
|
8452b0675b | ||
|
|
930643706a | ||
|
|
a2eac1f721 | ||
|
|
6e994cd694 | ||
|
|
c82869c631 | ||
|
|
f5a94868c4 | ||
|
|
c5628d613b | ||
|
|
9509b1ffa8 | ||
|
|
c1dac8a21e | ||
|
|
950846df45 | ||
|
|
31d96e2dc6 | ||
|
|
031e96075e | ||
|
|
bf2caeac6c | ||
|
|
12e523b37e | ||
|
|
576c985d8f | ||
|
|
9365807f47 | ||
|
|
25ce10fa61 | ||
|
|
09c333501f | ||
|
|
c51b09ee3a | ||
|
|
4d82eace86 | ||
|
|
385b03a163 | ||
|
|
4b438afa69 | ||
|
|
66961b94da | ||
|
|
39b62e5942 | ||
|
|
5bb8ab3d95 | ||
|
|
8dfc23b61d | ||
|
|
c8769808b5 | ||
|
|
2fc106aa26 | ||
|
|
da0b725ff8 | ||
|
|
15703d66fb | ||
|
|
c68beeaa51 | ||
|
|
5ef8868916 | ||
|
|
24488cc985 | ||
|
|
1c9faaa1e6 | ||
|
|
ac32875b14 | ||
|
|
07c1dd29e0 | ||
|
|
bd93233c34 | ||
|
|
20aec2fbcf | ||
|
|
a149139143 | ||
|
|
c857d1abb7 | ||
|
|
dde9da7006 | ||
|
|
d18a1970e5 | ||
|
|
66b9aeec17 | ||
|
|
ea301a3923 | ||
|
|
ced272a783 | ||
|
|
c9f320da31 | ||
|
|
025873e66b | ||
|
|
ecddc40aa5 | ||
|
|
cb13a02b75 | ||
|
|
5714a9a1d3 | ||
|
|
d0671c1682 | ||
|
|
88b3ac42bb | ||
|
|
4ecf3dec76 | ||
|
|
b4b70ca7e5 | ||
|
|
d3aa68df05 | ||
|
|
36aa0518ed | ||
|
|
b1c5692322 | ||
|
|
db24edf7d5 | ||
|
|
798a576d0b | ||
|
|
b49225fbf7 | ||
|
|
439cf82fcc | ||
|
|
7527bf4761 |
@@ -51,3 +51,6 @@ broker/config/git.properties
|
||||
distribution/src/main/resources/git.properties
|
||||
broker/h2db
|
||||
broker/media
|
||||
common/target
|
||||
server/target
|
||||
sdk/target
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
|
||||
<img src="http://static.wildfirechat.cn/wx_wfc_qrcode.jpg" width = 50% height = 50% />
|
||||
|
||||
> 强烈建议关注我们的公众号。我们有新版本发布或者有重大更新会通过公众号通知大家,另外我们也会不定期的发布一些关于野火IM的技术介绍。
|
||||
|
||||
#### 体验Demo
|
||||
我们提供了体验demo,请使用微信扫码下载安装体验
|
||||
|
||||
@@ -59,6 +61,12 @@
|
||||
## 编译
|
||||
在安装JDK1.8以上及maven的前提下,在命令行中执行```mvn clean compile package```,生成的目标文件在```./distribution/target/distribution-xxxx-bundle-tar.tar.gz```
|
||||
|
||||
## 捐赠者名单
|
||||
|
||||
| 捐赠者 | 商标 | 金额 | 简介 |
|
||||
| ----- | ---- | -------- | --- |
|
||||
| [SAMOS](http://samos.io) |  | 保密 | 一站式区块链解决方案服务商(http://samos.io) |
|
||||
|
||||
## 特别感谢
|
||||
1. [moquette](https://github.com/moquette-io/moquette) 本项目是基于此项目二次开发而来,处理MQTT相关业务。
|
||||
2. [loServer](https://github.com/looly/loServer) 本项目使用loServer处理HTTP相关业务。
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#*********************************************************************
|
||||
#服务器的接入IP。给客户端提供是${server.ip}和${http_port}。
|
||||
#客户端会从${http_port}端口获取到长链接端口。
|
||||
server.ip 0.0.0.0
|
||||
server.ip 192.168.1.100
|
||||
|
||||
##原生客户端长链接端口
|
||||
port 1883
|
||||
@@ -27,7 +27,7 @@ host 0.0.0.0
|
||||
local_port 80
|
||||
|
||||
##是否使用内置DB。0使用mysql;1使用h2db
|
||||
embed.db 1
|
||||
embed.db 0
|
||||
|
||||
##服务器管理接口密钥
|
||||
http.admin.secret_key 123456
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
insert into t_user (`_uid`,`_name`,`_display_name`,`_type`,`_dt`) values ('admin','admin','系统管理员',3,1);
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
ALTER TABLE t_user_session MODIFY _token VARCHAR(240) DEFAULT NULL;
|
||||
@@ -0,0 +1,4 @@
|
||||
alter table `t_group` add column `_mute` tinyint NOT NULL DEFAULT 0;
|
||||
alter table `t_group` add column `_join_type` tinyint NOT NULL DEFAULT 0;
|
||||
alter table `t_group` add column `_private_chat` tinyint NOT NULL DEFAULT 0;
|
||||
alter table `t_group` add column `_searchable` tinyint NOT NULL DEFAULT 0;
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table t_user add column `_createTime` TIMESTAMP default CURRENT_TIMESTAMP;
|
||||
alter table t_group add column `_createTime` TIMESTAMP default CURRENT_TIMESTAMP;
|
||||
@@ -0,0 +1 @@
|
||||
alter table `t_messages` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_sensitive_messages`;
|
||||
CREATE TABLE `t_sensitive_messages` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`_mid` bigint(20) NOT NULL,
|
||||
`_from` varchar(64) NOT NULL,
|
||||
`_type` tinyint NOT NULL DEFAULT 0,
|
||||
`_target` varchar(64) NOT NULL,
|
||||
`_line` int(11) NOT NULL DEFAULT 0,
|
||||
`_data` BLOB NOT NULL,
|
||||
`_searchable_key` TEXT DEFAULT NULL,
|
||||
`_dt` DATETIME NOT NULL DEFAULT NOW(),
|
||||
`_content_type` int(11) NOT NULL DEFAULT 0,
|
||||
UNIQUE INDEX `sensitive_message_uid_index` (`_mid` ASC)
|
||||
);
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
insert into t_user (`_uid`,`_name`,`_display_name`,`_type`,`_dt`) values ('admin','admin','系统管理员',3,1);
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
ALTER TABLE t_user_session MODIFY _token VARCHAR(240) DEFAULT NULL;
|
||||
@@ -0,0 +1,4 @@
|
||||
alter table `t_group` add column `_mute` tinyint NOT NULL DEFAULT 0;
|
||||
alter table `t_group` add column `_join_type` tinyint NOT NULL DEFAULT 0;
|
||||
alter table `t_group` add column `_private_chat` tinyint NOT NULL DEFAULT 0;
|
||||
alter table `t_group` add column `_searchable` tinyint NOT NULL DEFAULT 0;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_session`;
|
||||
CREATE TABLE `t_session` (
|
||||
`row_id` varchar(50) not null primary key,
|
||||
`del_flag` tinyint(1) default 0 null,
|
||||
`create_time` timestamp null,
|
||||
`update_time` timestamp null,
|
||||
`expire_time` timestamp null,
|
||||
`user_id` int null,
|
||||
constraint `t_session_pk_2` unique (`user_id`, `expire_time`)
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_unicode_ci;
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table t_user MODIFY column `_createTime` DATETIME NOT NULL DEFAULT NOW();
|
||||
alter table t_group MODIFY column `_createTime` DATETIME NOT NULL DEFAULT NOW();
|
||||
@@ -0,0 +1,4 @@
|
||||
alter table t_session MODIFY column `create_time` DATETIME NOT NULL DEFAULT NOW();
|
||||
alter table t_session MODIFY column `update_time` DATETIME NOT NULL DEFAULT NOW();
|
||||
alter table t_session MODIFY column `expire_time` DATETIME NOT NULL DEFAULT NOW();
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
update t_messages_0 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_1 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_2 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_3 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_4 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_5 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_6 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_7 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_8 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_9 set _dt = date_add(_dt, interval 8 hour);
|
||||
|
||||
update t_messages_10 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_11 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_12 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_13 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_14 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_15 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_16 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_17 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_18 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_19 set _dt = date_add(_dt, interval 8 hour);
|
||||
|
||||
update t_messages_20 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_21 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_22 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_23 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_24 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_25 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_26 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_27 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_28 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_29 set _dt = date_add(_dt, interval 8 hour);
|
||||
|
||||
|
||||
update t_messages_30 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_31 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_32 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_33 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_34 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_35 set _dt = date_add(_dt, interval 8 hour);
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table t_user add column `_createTime` TIMESTAMP default CURRENT_TIMESTAMP;
|
||||
alter table t_group add column `_createTime` TIMESTAMP default CURRENT_TIMESTAMP;
|
||||
@@ -0,0 +1,36 @@
|
||||
alter table `t_messages_0` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_1` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_2` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_3` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_4` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_5` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_6` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_7` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_8` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_9` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_10` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_11` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_12` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_13` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_14` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_15` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_16` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_17` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_18` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_19` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_20` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_21` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_22` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_23` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_24` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_25` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_26` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_27` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_28` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_29` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_30` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_31` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_32` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_33` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_34` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
alter table `t_messages_35` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_sensitive_messages`;
|
||||
CREATE TABLE `t_sensitive_messages` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`_mid` bigint(20) NOT NULL,
|
||||
`_from` varchar(64) NOT NULL,
|
||||
`_type` tinyint NOT NULL DEFAULT 0,
|
||||
`_target` varchar(64) NOT NULL,
|
||||
`_line` int(11) NOT NULL DEFAULT 0,
|
||||
`_data` BLOB NOT NULL,
|
||||
`_searchable_key` TEXT DEFAULT NULL,
|
||||
`_dt` DATETIME NOT NULL,
|
||||
`_content_type` int(11) NOT NULL DEFAULT '0',
|
||||
INDEX `message_uid_index` (`_mid` DESC)
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_unicode_ci;
|
||||
+1
-7
@@ -5,7 +5,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.21</version>
|
||||
<version>0.24</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>moquette-broker</artifactId>
|
||||
@@ -132,12 +132,6 @@
|
||||
<version>5.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.bugsnag</groupId>
|
||||
<artifactId>bugsnag</artifactId>
|
||||
<version>[3.0,4.0)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
|
||||
@@ -35,12 +35,15 @@ import java.util.concurrent.Executor;
|
||||
@HttpMethod("POST")
|
||||
public class RouteAction extends Action {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RouteAction.class);
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
|
||||
response.setContentType("application/octet-stream");
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest)request.getNettyRequest();
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest) request.getNettyRequest();
|
||||
boolean b = false;
|
||||
if ("web".equalsIgnoreCase(fullHttpRequest.headers().get("p"))) {
|
||||
b = true;
|
||||
@@ -144,10 +147,14 @@ public class RouteAction extends Action {
|
||||
|
||||
private void sendResponse(Response response, ErrorCode errorCode, byte[] contents, boolean base64Response) {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
if(contents == null) {
|
||||
if (contents == null) {
|
||||
ByteBuf ackPayload = Unpooled.buffer();
|
||||
ackPayload.ensureWritable(1).writeByte(errorCode.getCode());
|
||||
response.setContent(ackPayload);
|
||||
contents = ackPayload.array();
|
||||
}
|
||||
if (base64Response) {
|
||||
byte[] base64Data = Base64.getEncoder().encode(contents);
|
||||
response.setContent(base64Data);
|
||||
} else {
|
||||
response.setContent(contents);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import cn.wildfirechat.pojos.OutputLoginData;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import win.liyufan.im.GitRepositoryState;
|
||||
import win.liyufan.im.Utility;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -32,7 +33,8 @@ public class VersionAction extends Action {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
|
||||
try {
|
||||
response.setContent(new Gson().toJson(GitRepositoryState.getGitRepositoryState()));
|
||||
|
||||
response.setContent(Utility.formatJson(new Gson().toJson(GitRepositoryState.getGitRepositoryState())));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
response.setContent("{\"version\":\"unknown\"}");
|
||||
|
||||
@@ -45,7 +45,7 @@ public class BlockUserAction extends AdminAction {
|
||||
result = RestResult.resultOf(errorCode);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
|
||||
if (inputUserBlock.getStatus() != 0) {
|
||||
if (inputUserBlock.getStatus() == 2) {
|
||||
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), inputUserBlock.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null, true);
|
||||
}
|
||||
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.BroadMessageData;
|
||||
import cn.wildfirechat.pojos.BroadMessageResult;
|
||||
import cn.wildfirechat.pojos.SendMessageData;
|
||||
import cn.wildfirechat.pojos.SendMessageResult;
|
||||
import com.google.gson.Gson;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.moquette.persistence.RPCCenter;
|
||||
import io.moquette.persistence.TargetEntry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Route(APIPath.Msg_Broadcast)
|
||||
@HttpMethod("POST")
|
||||
public class BroadcastMessageAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
BroadMessageData sendMessageData = getRequestBody(request.getNettyRequest(), BroadMessageData.class);
|
||||
if (BroadMessageData.isValide(sendMessageData) && !StringUtil.isNullOrEmpty(sendMessageData.getSender())) {
|
||||
RPCCenter.getInstance().sendRequest(sendMessageData.getSender(), null, IMTopic.BroadcastMessageTopic, sendMessageData.toProtoMessage().toByteArray(), sendMessageData.getSender(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
@Override
|
||||
public void onSuccess(byte[] result) {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
byteBuf.writeBytes(result);
|
||||
ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte());
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
long messageId = byteBuf.readLong();
|
||||
long count = byteBuf.readLong();
|
||||
sendResponse(response, null, new BroadMessageResult(messageId, count));
|
||||
} else {
|
||||
sendResponse(response, errorCode, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorCode errorCode) {
|
||||
sendResponse(response, errorCode, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeout() {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_TIMEOUT, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getResponseExecutor() {
|
||||
return command -> {
|
||||
ctx.executor().execute(command);
|
||||
};
|
||||
}
|
||||
}, true);
|
||||
return false;
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -48,10 +48,6 @@ public class CreateUserAction extends AdminAction {
|
||||
inputCreateUser.setUserId(messagesStore.getShortUUID());
|
||||
}
|
||||
|
||||
if (inputCreateUser.getPortrait() == null || inputCreateUser.getPortrait().length() == 0) {
|
||||
inputCreateUser.setPortrait("https://avatars.io/gravatar/" + inputCreateUser.getUserId());
|
||||
}
|
||||
|
||||
WFCMessage.User.Builder newUserBuilder = WFCMessage.User.newBuilder()
|
||||
.setUid(StringUtil.isNullOrEmpty(inputCreateUser.getUserId()) ? "" : inputCreateUser.getUserId());
|
||||
if (inputCreateUser.getName() != null)
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class KickoffGroupMemberAction extends AdminAction {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputKickoffGroupMember inputKickoffGroupMember = getRequestBody(request.getNettyRequest(), InputKickoffGroupMember.class);
|
||||
if (inputKickoffGroupMember.isValide()) {
|
||||
RPCCenter.getInstance().sendRequest(inputKickoffGroupMember.getOperator(), null, IMTopic.AddGroupMemberTopic, inputKickoffGroupMember.toProtoGroupRequest().toByteArray(), inputKickoffGroupMember.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
RPCCenter.getInstance().sendRequest(inputKickoffGroupMember.getOperator(), null, IMTopic.KickoffGroupMemberTopic, inputKickoffGroupMember.toProtoGroupRequest().toByteArray(), inputKickoffGroupMember.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
@Override
|
||||
public void onSuccess(byte[] result) {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Action处理单元
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
|
||||
@@ -45,7 +45,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
try {
|
||||
//do filter
|
||||
boolean isPass = this.doFilter(request, response);
|
||||
|
||||
|
||||
if(isPass){
|
||||
//do action
|
||||
this.doAction(ctx, request, response);
|
||||
@@ -64,10 +64,10 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
ctx.fireExceptionCaught(e);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
@@ -75,7 +75,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
Channel channel = ctx.channel();
|
||||
if(channel.isActive())ctx.close();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------- Private method start
|
||||
/**
|
||||
* 执行过滤
|
||||
@@ -91,7 +91,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//自定义Path过滤器
|
||||
filter = ServerSetting.getFilter(request.getPath());
|
||||
if(null != filter){
|
||||
@@ -99,7 +99,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -110,6 +110,10 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
* @param response 响应对象
|
||||
*/
|
||||
private void doAction(ChannelHandlerContext ctx, Request request, Response response){
|
||||
if( "/route".equalsIgnoreCase(request.getPath()) && "OPTIONS".equalsIgnoreCase(request.getMethod())){
|
||||
handleOptions(ctx, request, response);
|
||||
return;
|
||||
}
|
||||
Action action;
|
||||
if (isValidePath(request.getPath())) {
|
||||
action = ServerSetting.getAction(request.getPath(), request.getMethod().toUpperCase());
|
||||
@@ -141,4 +145,11 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------- Private method start
|
||||
|
||||
|
||||
private void handleOptions(ChannelHandlerContext ctx, Request request, Response response){
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setHeader("Access-Control-Allow-Headers", "*");
|
||||
response.send();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,9 +65,6 @@ public final class BrokerConstants {
|
||||
public static final String METRICS_LIBRATO_TOKEN_PROPERTY_NAME = "metrics.librato.token";
|
||||
public static final String METRICS_LIBRATO_SOURCE_PROPERTY_NAME = "metrics.librato.source";
|
||||
|
||||
public static final String BUGSNAG_ENABLE_PROPERTY_NAME = "use_bugsnag";
|
||||
public static final String BUGSNAG_TOKEN_PROPERTY_NAME = "bugsnag.token";
|
||||
|
||||
public static final String STORAGE_CLASS_NAME = "storage_class";
|
||||
|
||||
public static final String QINIU_SERVER_URL= "qiniu.server_url";
|
||||
|
||||
@@ -22,7 +22,7 @@ public class AddGroupMember extends GroupHandler<WFCMessage.AddGroupMemberReques
|
||||
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.AddGroupMemberRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = m_messagesStore.addGroupMembers(fromUser, request.getGroupId(), request.getAddedMemberList());
|
||||
ErrorCode errorCode = m_messagesStore.addGroupMembers(fromUser, isAdmin, request.getGroupId(), request.getAddedMemberList());
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import io.moquette.BrokerConstants;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import win.liyufan.im.IMTopic;
|
||||
import win.liyufan.im.MessageShardingUtil;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ContentType.Text;
|
||||
|
||||
@Handler(value = IMTopic.BroadcastMessageTopic)
|
||||
public class BroadcastMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.Message message, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
if (message != null) {
|
||||
if (!isAdmin) { //only admin can broadcast message
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
long messageId = MessageShardingUtil.generateId();
|
||||
message = message.toBuilder().setFromUser(fromUser).setMessageId(messageId).setServerTimestamp(timestamp).setConversation(WFCMessage.Conversation.newBuilder().setTarget(fromUser).setLine(message.getConversation().getLine()).setType(ProtoConstants.ConversationType.ConversationType_Private).build()).build();
|
||||
|
||||
long count = saveAndBroadcast(fromUser, clientID, message);
|
||||
ackPayload = ackPayload.capacity(20);
|
||||
ackPayload.writeLong(messageId);
|
||||
ackPayload.writeLong(count);
|
||||
} else {
|
||||
errorCode = ErrorCode.ERROR_CODE_INVALID_MESSAGE;
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,10 +14,18 @@ import io.netty.buffer.ByteBuf;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@Handler(IMTopic.DeleteFriendTopic)
|
||||
public class DeleteFriendHandler extends IMHandler<WFCMessage.IDBuf> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
return m_messagesStore.deleteFriend(fromUser, request.getId());
|
||||
long[] head = new long[2];
|
||||
ErrorCode errorCode = m_messagesStore.deleteFriend(fromUser, request.getId(), head);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
publisher.publishNotification(IMTopic.NotifyFriendTopic, fromUser, head[0]);
|
||||
publisher.publishNotification(IMTopic.NotifyFriendTopic, request.getId(), head[1]);
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import com.xiaoleilu.loServer.model.FriendData;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -25,7 +26,11 @@ public class FriendPullHandler extends IMHandler<WFCMessage.Version> {
|
||||
WFCMessage.GetFriendsResult.Builder builder = WFCMessage.GetFriendsResult.newBuilder();
|
||||
for (FriendData data : friendDatas
|
||||
) {
|
||||
builder.addEntry(WFCMessage.Friend.newBuilder().setState(data.getState()).setUid(data.getFriendUid()).setUpdateDt(data.getTimestamp()).setAlias(data.getAlias()).build());
|
||||
WFCMessage.Friend.Builder builder1 = WFCMessage.Friend.newBuilder().setState(data.getState()).setUid(data.getFriendUid()).setUpdateDt(data.getTimestamp());
|
||||
if (!StringUtil.isNullOrEmpty(data.getAlias())) {
|
||||
builder1.setAlias(data.getAlias());
|
||||
}
|
||||
builder.addEntry(builder1.build());
|
||||
}
|
||||
byte[] data = builder.build().toByteArray();
|
||||
ackPayload.ensureWritable(data.length).writeBytes(data);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
package io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
||||
import com.google.gson.Gson;
|
||||
@@ -205,9 +206,7 @@ abstract public class IMHandler<T> {
|
||||
}
|
||||
}
|
||||
|
||||
if(errorCode != ErrorCode.ERROR_CODE_ASYNC_HANDLER) {
|
||||
response(ackPayload, errorCode, callback);
|
||||
}
|
||||
response(ackPayload, errorCode, callback);
|
||||
} else {
|
||||
LOG.error("Handler {} preAction failure", this.getClass().getName());
|
||||
ByteBuf ackPayload = Unpooled.buffer(1);
|
||||
@@ -239,8 +238,16 @@ abstract public class IMHandler<T> {
|
||||
Set<String> notifyReceivers = new LinkedHashSet<>();
|
||||
|
||||
message = m_messagesStore.storeMessage(username, clientID, message);
|
||||
int pullType = m_messagesStore.getNotifyReceivers(username, message, notifyReceivers);
|
||||
this.publisher.publish2Receivers(message, notifyReceivers, clientID, pullType);
|
||||
return message.getMessageId();
|
||||
WFCMessage.Message.Builder messageBuilder = message.toBuilder();
|
||||
int pullType = m_messagesStore.getNotifyReceivers(username, messageBuilder, notifyReceivers);
|
||||
this.publisher.publish2Receivers(messageBuilder.build(), notifyReceivers, clientID, pullType);
|
||||
return notifyReceivers.size();
|
||||
}
|
||||
|
||||
protected long saveAndBroadcast(String username, String clientID, WFCMessage.Message message) {
|
||||
Set<String> notifyReceivers = m_messagesStore.getAllEnds();
|
||||
WFCMessage.Message updatedMessage = m_messagesStore.storeMessage(username, clientID, message);
|
||||
mServer.getImBusinessScheduler().execute(() -> publisher.publish2Receivers(updatedMessage, notifyReceivers, clientID, ProtoConstants.PullType.Pull_Normal));
|
||||
return notifyReceivers.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,20 +24,32 @@ public class KickoffGroupMember extends GroupHandler<WFCMessage.RemoveGroupMembe
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.getGroupInfo(request.getGroupId());
|
||||
if (groupInfo == null) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
|
||||
} else if ((groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted)
|
||||
&& groupInfo.getOwner() != null && groupInfo.getOwner().equals(fromUser)) {
|
||||
|
||||
//send notify message first, then kickoff the member
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, request.getRemovedMemberList()).getKickokfMemberGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
errorCode = m_messagesStore.kickoffGroupMembers(fromUser, request.getGroupId(), request.getRemovedMemberList());
|
||||
} else {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
boolean isAllow = isAdmin;
|
||||
if (!isAllow) {
|
||||
if (groupInfo.getOwner() != null && groupInfo.getOwner().equals(fromUser)) {
|
||||
isAllow = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAllow) {
|
||||
WFCMessage.GroupMember gm = m_messagesStore.getGroupMember(request.getGroupId(), fromUser);
|
||||
if (gm != null && gm.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Manager) {
|
||||
isAllow = true;
|
||||
}
|
||||
}
|
||||
if (!isAllow && (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted)) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
} else {
|
||||
//send notify message first, then kickoff the member
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, request.getRemovedMemberList()).getKickokfMemberGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
errorCode = m_messagesStore.kickoffGroupMembers(fromUser, isAdmin, request.getGroupId(), request.getRemovedMemberList());
|
||||
}
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@@ -14,16 +14,15 @@ import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.Modify_Group_Name;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.Modify_Group_Portrait;
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.*;
|
||||
import static win.liyufan.im.IMTopic.ModifyGroupInfoTopic;
|
||||
|
||||
@Handler(value = ModifyGroupInfoTopic)
|
||||
public class ModifyGroupInfoHandler extends GroupHandler<WFCMessage.ModifyGroupInfoRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.ModifyGroupInfoRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode= m_messagesStore.modifyGroupInfo(fromUser, request.getGroupId(), request.getType(), request.getValue());
|
||||
ErrorCode errorCode= m_messagesStore.modifyGroupInfo(fromUser, request.getGroupId(), request.getType(), request.getValue(), isAdmin);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||
@@ -33,6 +32,14 @@ public class ModifyGroupInfoHandler extends GroupHandler<WFCMessage.ModifyGroupI
|
||||
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupNameNotifyContent();
|
||||
} else if(request.getType() == Modify_Group_Portrait) {
|
||||
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, "").getChangeGroupPortraitNotifyContent();
|
||||
} else if(request.getType() == Modify_Group_Mute) {
|
||||
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupMuteNotifyContent();
|
||||
} else if(request.getType() == Modify_Group_JoinType) {
|
||||
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupJointypeNotifyContent();
|
||||
} else if(request.getType() == Modify_Group_PrivateChat) {
|
||||
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupPrivatechatNotifyContent();
|
||||
} else if(request.getType() == Modify_Group_Searchable) {
|
||||
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupSearchableNotifyContent();
|
||||
}
|
||||
|
||||
if (content != null) {
|
||||
|
||||
@@ -20,19 +20,14 @@ import static win.liyufan.im.IMTopic.QuitGroupTopic;
|
||||
public class QuitGroupHandler extends GroupHandler<WFCMessage.QuitGroupRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.QuitGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.getGroupInfo(request.getGroupId());
|
||||
if (groupInfo == null) {
|
||||
errorCode = m_messagesStore.quitGroup(fromUser, request.getGroupId());
|
||||
} else {
|
||||
//send notify message first, then quit group
|
||||
ErrorCode errorCode = m_messagesStore.quitGroup(fromUser, request.getGroupId());
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), request.getNotifyContent());
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, "").getQuitGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
errorCode = m_messagesStore.quitGroup(fromUser, request.getGroupId());
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class RecallMessageHandler extends IMHandler<WFCMessage.INT64Buf> {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
m_messagesStore.getNotifyReceivers(fromUser, message, notifyReceivers);
|
||||
m_messagesStore.getNotifyReceivers(fromUser, message.toBuilder(), notifyReceivers);
|
||||
this.publisher.publishRecall2Receivers(int64Buf.getId(), fromUser, notifyReceivers, clientID);
|
||||
|
||||
return errorCode;
|
||||
|
||||
@@ -46,6 +46,10 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
if (message != null) {
|
||||
if (!isAdmin) { //admin do not check the right
|
||||
// 不能在端上直接发送撤回和群通知
|
||||
if (message.getContent().getType() == 80 || (message.getContent().getType() >= 100 && message.getContent().getType() < 200)) {
|
||||
return ErrorCode.INVALID_PARAMETER;
|
||||
}
|
||||
int userStatus = m_messagesStore.getUserStatus(fromUser);
|
||||
if (userStatus == 1 || userStatus == 2) {
|
||||
return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG;
|
||||
@@ -58,14 +62,19 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
}
|
||||
|
||||
|
||||
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group && !m_messagesStore.isMemberInGroup(fromUser, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group && m_messagesStore.isForbiddenInGroup(fromUser, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_ChatRoom && !m_messagesStore.checkUserClientInChatroom(fromUser, clientID, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_CHATROOM;
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel && !m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL;
|
||||
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group ) {
|
||||
errorCode = m_messagesStore.canSendMessageInGroup(fromUser, message.getConversation().getTarget());
|
||||
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
return errorCode;
|
||||
}
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_ChatRoom) {
|
||||
if(!m_messagesStore.checkUserClientInChatroom(fromUser, clientID, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_CHATROOM;
|
||||
}
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) {
|
||||
if(!m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +90,7 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
if (!isAdmin && message.getContent().getType() == Text) {
|
||||
Set<String> matched = m_messagesStore.handleSensitiveWord(message.getContent().getSearchableContent());
|
||||
if (matched != null && !matched.isEmpty()) {
|
||||
m_messagesStore.storeSensitiveMessage(message);
|
||||
if (mSensitiveType == 0) {
|
||||
errorCode = ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
} else if(mSensitiveType == 1) {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.GroupNotificationBinaryContent;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@Handler(IMTopic.SetGroupManagerTopic)
|
||||
public class SetGroupManagerHandler extends GroupHandler<WFCMessage.SetGroupManagerRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.SetGroupManagerRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = m_messagesStore.setGroupManager(fromUser, request.getGroupId(), request.getType(), request.getUserIdList(), isAdmin);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getType() + "", request.getUserIdList()).getSetGroupManagerNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class UploadDeviceTokenHandler extends IMHandler<WFCMessage.UploadDeviceT
|
||||
session.setAppName(request.getAppName());
|
||||
if (request.getPlatform() == ProtoConstants.Platform.Platform_iOS && request.getPushType() == 2) {
|
||||
session.setVoipDeviceToken(request.getDeviceToken());
|
||||
session.setPushType(0);//如果有voip token,肯定是生产环境的推送
|
||||
// session.setPushType(0);//如果有voip token,肯定是生产环境的推送
|
||||
m_sessionsStore.updateSessionToken(session, true);
|
||||
} else {
|
||||
session.setDeviceToken(request.getDeviceToken());
|
||||
|
||||
@@ -97,9 +97,9 @@ public class DatabaseStore {
|
||||
", `_extra`" +
|
||||
", `_dt` from t_user";
|
||||
if (buzzy) {
|
||||
sql += " where `_display_name` like ?";
|
||||
sql += " where (`_display_name` like ? or `_name` = ? or `_mobile` = ?) ";
|
||||
} else {
|
||||
sql += " where `_display_name` = ?";
|
||||
sql += " where (`_display_name` = ? or `_name` = ? or `_mobile` = ?) ";
|
||||
}
|
||||
|
||||
sql += " and _type <> 2"; //can search normal user(0) and robot(1), can not search things
|
||||
@@ -118,6 +118,8 @@ public class DatabaseStore {
|
||||
} else {
|
||||
statement.setString(index++, keyword);
|
||||
}
|
||||
statement.setString(index++, keyword);
|
||||
statement.setString(index++, keyword);
|
||||
|
||||
rs = statement.executeQuery();
|
||||
while (rs.next()) {
|
||||
@@ -382,11 +384,12 @@ public class DatabaseStore {
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "insert into " + MessageShardingUtil.getMessageTable(message.getMessageId()) +
|
||||
" (`_mid`, `_from`, `_type`, `_target`, `_line`, `_data`, `_searchable_key`, `_dt`) values(?, ?, ?, ?, ?, ?, ?, ?)" +
|
||||
" (`_mid`, `_from`, `_type`, `_target`, `_line`, `_data`, `_searchable_key`, `_dt`, `_content_type`) values(?, ?, ?, ?, ?, ?, ?, ?, ?)" +
|
||||
" ON DUPLICATE KEY UPDATE " +
|
||||
"`_data` = ?," +
|
||||
"`_searchable_key` = ?," +
|
||||
"`_dt` = ?";
|
||||
"`_dt` = ?," +
|
||||
"`_content_type` = ?";
|
||||
|
||||
String searchableContent = message.getContent().getSearchableContent() == null ? "" : message.getContent().getSearchableContent();
|
||||
|
||||
@@ -402,10 +405,63 @@ public class DatabaseStore {
|
||||
statement.setBlob(index++, blob);
|
||||
statement.setString(index++, searchableContent);
|
||||
statement.setTimestamp(index++, new Timestamp(message.getServerTimestamp()));
|
||||
statement.setInt(index++, message.getContent().getType());
|
||||
|
||||
statement.setBlob(index++, blob);
|
||||
statement.setString(index++, searchableContent);
|
||||
statement.setTimestamp(index++, new Timestamp(message.getServerTimestamp()));
|
||||
statement.setInt(index++, message.getContent().getType());
|
||||
|
||||
int count = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", count);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void persistSensitiveMessage(final WFCMessage.Message message) {
|
||||
if(message.getContent().getPersistFlag() == Transparent) {
|
||||
return;
|
||||
}
|
||||
|
||||
mScheduler.execute(()-> {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "insert into " + "t_sensitive_messages" +
|
||||
" (`_mid`, `_from`, `_type`, `_target`, `_line`, `_data`, `_searchable_key`, `_dt`, `_content_type`) values(?, ?, ?, ?, ?, ?, ?, ?, ?)" +
|
||||
" ON DUPLICATE KEY UPDATE " +
|
||||
"`_data` = ?," +
|
||||
"`_searchable_key` = ?," +
|
||||
"`_dt` = ?," +
|
||||
"`_content_type` = ?";
|
||||
|
||||
String searchableContent = message.getContent().getSearchableContent() == null ? "" : message.getContent().getSearchableContent();
|
||||
|
||||
statement = connection.prepareStatement(sql);
|
||||
int index = 1;
|
||||
statement.setLong(index++, message.getMessageId());
|
||||
statement.setString(index++, message.getFromUser());
|
||||
statement.setInt(index++, message.getConversation().getType());
|
||||
statement.setString(index++, message.getConversation().getTarget());
|
||||
statement.setInt(index++, message.getConversation().getLine());
|
||||
Blob blob = connection.createBlob();
|
||||
blob.setBytes(1, message.getContent().toByteArray());
|
||||
statement.setBlob(index++, blob);
|
||||
statement.setString(index++, searchableContent);
|
||||
statement.setTimestamp(index++, new Timestamp(message.getServerTimestamp()));
|
||||
statement.setInt(index++, message.getContent().getType());
|
||||
|
||||
statement.setBlob(index++, blob);
|
||||
statement.setString(index++, searchableContent);
|
||||
statement.setTimestamp(index++, new Timestamp(message.getServerTimestamp()));
|
||||
statement.setInt(index++, message.getContent().getType());
|
||||
|
||||
int count = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", count);
|
||||
@@ -737,7 +793,11 @@ public class DatabaseStore {
|
||||
", `_extra`" +
|
||||
", `_dt`" +
|
||||
", `_member_count`" +
|
||||
", `_member_dt`) values(?, ?, ?, ?, ?, ?, ?, ?, ?)" +
|
||||
", `_mute`" +
|
||||
", `_join_type`" +
|
||||
", `_private_chat`" +
|
||||
", `_searchable`" +
|
||||
", `_member_dt`) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" +
|
||||
" ON DUPLICATE KEY UPDATE " +
|
||||
"`_name` = ?," +
|
||||
"`_portrait` = ?," +
|
||||
@@ -746,6 +806,10 @@ public class DatabaseStore {
|
||||
"`_extra` = ?," +
|
||||
"`_dt` = ?," +
|
||||
"`_member_count` = ?," +
|
||||
"`_mute` = ?" +
|
||||
", `_join_type` = ?" +
|
||||
", `_private_chat` = ?" +
|
||||
", `_searchable` = ?, " +
|
||||
"`_member_dt` = ?";
|
||||
|
||||
|
||||
@@ -760,6 +824,10 @@ public class DatabaseStore {
|
||||
statement.setString(index++, groupInfo.getExtra());
|
||||
statement.setLong(index++, groupInfo.getUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
||||
statement.setInt(index++, groupInfo.getMemberCount());
|
||||
statement.setInt(index++, groupInfo.getMute());
|
||||
statement.setInt(index++, groupInfo.getJoinType());
|
||||
statement.setInt(index++, groupInfo.getPrivateChat());
|
||||
statement.setInt(index++, groupInfo.getSearchable());
|
||||
statement.setLong(index++, groupInfo.getMemberUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
||||
|
||||
statement.setString(index++, groupInfo.getName());
|
||||
@@ -769,6 +837,10 @@ public class DatabaseStore {
|
||||
statement.setString(index++, groupInfo.getExtra());
|
||||
statement.setLong(index++, groupInfo.getUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
||||
statement.setInt(index++, groupInfo.getMemberCount());
|
||||
statement.setInt(index++, groupInfo.getMute());
|
||||
statement.setInt(index++, groupInfo.getJoinType());
|
||||
statement.setInt(index++, groupInfo.getPrivateChat());
|
||||
statement.setInt(index++, groupInfo.getSearchable());
|
||||
statement.setLong(index++, groupInfo.getMemberUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
||||
int count = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", count);
|
||||
@@ -1099,6 +1171,10 @@ public class DatabaseStore {
|
||||
", `_dt`" +
|
||||
", `_member_count`" +
|
||||
", `_member_dt`" +
|
||||
", `_mute`" +
|
||||
", `_join_type`" +
|
||||
", `_private_chat`" +
|
||||
", `_searchable`" +
|
||||
" from t_group where `_gid` = ?";
|
||||
|
||||
statement = connection.prepareStatement(sql);
|
||||
@@ -1134,18 +1210,27 @@ public class DatabaseStore {
|
||||
strValue = (strValue == null ? "" : strValue);
|
||||
builder.setExtra(strValue);
|
||||
|
||||
|
||||
|
||||
long longValue = rs.getLong(index++);
|
||||
builder.setUpdateDt(longValue);
|
||||
|
||||
|
||||
intValue = rs.getInt(index++);
|
||||
builder.setMemberCount(intValue);
|
||||
|
||||
longValue = rs.getLong(index++);
|
||||
builder.setMemberUpdateDt(longValue);
|
||||
|
||||
intValue = rs.getInt(index++);
|
||||
builder.setMute(intValue);
|
||||
|
||||
intValue = rs.getInt(index++);
|
||||
builder.setJoinType(intValue);
|
||||
|
||||
intValue = rs.getInt(index++);
|
||||
builder.setPrivateChat(intValue);
|
||||
|
||||
intValue = rs.getInt(index++);
|
||||
builder.setSearchable(intValue);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@@ -1567,6 +1652,27 @@ public class DatabaseStore {
|
||||
});
|
||||
}
|
||||
|
||||
void deleteUserStatus(String userId) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "delete from t_user_status where _uid = ?";
|
||||
statement = connection.prepareStatement(sql);
|
||||
statement.setString(1, userId);
|
||||
int count = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", count);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void updateUserStatus(String userId, int status) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
@@ -1774,6 +1880,33 @@ public class DatabaseStore {
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<String> getAllEnds() {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select distinct(`_uid`) from t_user_session";
|
||||
statement = connection.prepareStatement(sql);
|
||||
|
||||
|
||||
|
||||
rs = statement.executeQuery();
|
||||
Set<String> out = new HashSet<>();
|
||||
while (rs.next()) {
|
||||
String uid = rs.getString(1);
|
||||
out.add(uid);
|
||||
}
|
||||
return out;
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement, rs);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
List<FriendData> getPersistFriends(String userId) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
@@ -1874,7 +2007,6 @@ public class DatabaseStore {
|
||||
}
|
||||
|
||||
void persistFriendRequestUnreadStatus(String userId, long readDt, long updateDt) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
@@ -1901,11 +2033,9 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
//
|
||||
void persistOrUpdateFriendRequest(final WFCMessage.FriendRequest request) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
@@ -1942,11 +2072,9 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void persistOrUpdateFriendData(final FriendData request) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
@@ -1977,7 +2105,6 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean removeGroupInfoFromDB(String groupId) {
|
||||
|
||||
@@ -49,10 +49,9 @@ import java.util.function.Consumer;
|
||||
|
||||
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ChannelStatus.Channel_Status_Destoryed;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.GroupMemberType.*;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyChannelInfoType.*;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.Modify_Group_Extra;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.Modify_Group_Name;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.Modify_Group_Portrait;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.*;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.PersistFlag.Transparent;
|
||||
import static io.moquette.BrokerConstants.*;
|
||||
import static io.moquette.server.Constants.MAX_CHATROOM_MESSAGE_QUEUE;
|
||||
@@ -170,7 +169,14 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNotifyReceivers(String fromUser, WFCMessage.Message message, Set<String> notifyReceivers) {
|
||||
public void storeSensitiveMessage(WFCMessage.Message message) {
|
||||
databaseStore.persistSensitiveMessage(message);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getNotifyReceivers(String fromUser, WFCMessage.Message.Builder messageBuilder, Set<String> notifyReceivers) {
|
||||
WFCMessage.Message message = messageBuilder.build();
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
int type = message.getConversation().getType();
|
||||
|
||||
@@ -190,7 +196,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(message.getConversation().getTarget());
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
if (member.getType() != ProtoConstants.GroupMemberType.GroupMemberType_Removed) {
|
||||
if (member.getType() != GroupMemberType_Removed) {
|
||||
notifyReceivers.add(member.getMemberId());
|
||||
}
|
||||
}
|
||||
@@ -245,6 +251,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return pullType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAllEnds() {
|
||||
return databaseStore.getAllEnds();
|
||||
}
|
||||
@Override
|
||||
public WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType) {
|
||||
WFCMessage.PullMessageResult.Builder builder = WFCMessage.PullMessageResult.newBuilder();
|
||||
@@ -315,9 +325,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
long targetMessageId = entry.getValue();
|
||||
|
||||
MessageBundle bundle = mIMap.get(targetMessageId);
|
||||
if (bundle == null) {
|
||||
bundle = databaseStore.getMessage(targetMessageId);
|
||||
}
|
||||
|
||||
if (bundle != null) {
|
||||
if (exceptClientId == null || !exceptClientId.equals(bundle.getFromClientId()) || !user.equals(bundle.getFromUser())) {
|
||||
@@ -407,10 +414,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
long targetMessageId = entry.getValue();
|
||||
|
||||
MessageBundle bundle = mIMap.get(targetMessageId);
|
||||
if (bundle == null) {
|
||||
bundle = databaseStore.getMessage(targetMessageId);
|
||||
}
|
||||
|
||||
if (bundle != null) {
|
||||
if (exceptClientId == null || !exceptClientId.equals(bundle.getFromClientId()) || !fromUser.equals(bundle.getFromUser())) {
|
||||
size += bundle.getMessage().getSerializedSize();
|
||||
@@ -599,19 +602,25 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
mIMap.put(groupId, groupInfo);
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
|
||||
List<WFCMessage.GroupMember> updatedMemberList = new ArrayList<>();
|
||||
for (WFCMessage.GroupMember member : memberList) {
|
||||
member = member.toBuilder().setUpdateDt(dt).build();
|
||||
if (member.getMemberId().equals(groupInfo.getOwner())) {
|
||||
member = member.toBuilder().setUpdateDt(dt).setType(ProtoConstants.GroupMemberType.GroupMemberType_Owner).build();
|
||||
} else {
|
||||
member = member.toBuilder().setUpdateDt(dt).build();
|
||||
}
|
||||
groupMembers.put(groupId, member);
|
||||
updatedMemberList.add(member);
|
||||
}
|
||||
|
||||
databaseStore.persistGroupMember(groupId, memberList);
|
||||
databaseStore.persistGroupMember(groupId, updatedMemberList);
|
||||
|
||||
return groupInfo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ErrorCode addGroupMembers(String operator, String groupId, List<WFCMessage.GroupMember> memberList) {
|
||||
public ErrorCode addGroupMembers(String operator, boolean isAdmin, String groupId, List<WFCMessage.GroupMember> memberList) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||
|
||||
@@ -619,12 +628,38 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (groupInfo == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
if (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted && (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
|
||||
if (!isAdmin) {
|
||||
boolean isMember = false;
|
||||
boolean isManager = false;
|
||||
WFCMessage.GroupMember gm = getGroupMember(groupId, operator);
|
||||
if (gm != null) {
|
||||
if (gm.getType() == GroupMemberType_Removed) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||
} else if (gm.getType() == GroupMemberType_Silent) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
isManager = (gm.getType() == GroupMemberType_Manager || gm.getType() == GroupMemberType_Owner);
|
||||
isMember = true;
|
||||
}
|
||||
|
||||
if (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted && ((groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator)) && !isManager)) {
|
||||
if (groupInfo.getJoinType() == 2) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
} else if (groupInfo.getJoinType() == 1) {
|
||||
if (memberList.size() == 1 && operator.equals(memberList.get(0).getMemberId()))
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isMember) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||
}
|
||||
}
|
||||
|
||||
long updateDt = System.currentTimeMillis();
|
||||
|
||||
List<WFCMessage.GroupMember> tmp = new ArrayList<>();
|
||||
@@ -648,7 +683,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
int count = 0;
|
||||
for (WFCMessage.GroupMember member : groupMembers.get(groupId)) {
|
||||
if (member.getType() != ProtoConstants.GroupMemberType.GroupMemberType_Removed) {
|
||||
if (member.getType() != GroupMemberType_Removed) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -660,7 +695,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode kickoffGroupMembers(String operator, String groupId, List<String> memberList) {
|
||||
public ErrorCode kickoffGroupMembers(String operator, boolean isAdmin, String groupId, List<String> memberList) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||
|
||||
@@ -668,8 +703,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (groupInfo == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
if ((groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal)
|
||||
&& (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) {
|
||||
if (!isAdmin && ((groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal)
|
||||
&& (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator)))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
@@ -684,7 +719,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
boolean removed = groupMembers.remove(groupId, member);
|
||||
if (removed) {
|
||||
removeCount++;
|
||||
member = member.toBuilder().setType(ProtoConstants.GroupMemberType.GroupMemberType_Removed).setUpdateDt(updateDt).build();
|
||||
member = member.toBuilder().setType(GroupMemberType_Removed).setUpdateDt(updateDt).build();
|
||||
groupMembers.put(groupId, member);
|
||||
list.add(member);
|
||||
}
|
||||
@@ -735,7 +770,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
databaseStore.persistGroupMember(groupId, list);
|
||||
|
||||
databaseStore.updateGroupMemberCountDt(groupId, groupInfo.getMemberCount()-1, updateDt);
|
||||
member = member.toBuilder().setType(ProtoConstants.GroupMemberType.GroupMemberType_Removed).setUpdateDt(updateDt).build();
|
||||
member = member.toBuilder().setType(GroupMemberType_Removed).setUpdateDt(updateDt).build();
|
||||
groupMembers.put(groupId, member);
|
||||
}
|
||||
break;
|
||||
@@ -779,7 +814,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode modifyGroupInfo(String operator, String groupId, int modifyType, String value) {
|
||||
public ErrorCode modifyGroupInfo(String operator, String groupId, int modifyType, String value, boolean isAdmin) {
|
||||
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||
@@ -790,22 +825,36 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
if ((oldInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted)
|
||||
&& (oldInfo.getOwner() == null || !oldInfo.getOwner().equals(operator))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
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 (!isAdmin) {
|
||||
if (oldInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted) {
|
||||
boolean isAllow = false;
|
||||
if ((oldInfo.getOwner() != null && oldInfo.getOwner().equals(operator))) {
|
||||
isAllow = true;
|
||||
} else {
|
||||
WFCMessage.GroupMember gm = getGroupMember(groupId, operator);
|
||||
if (gm != null && gm.getType() == GroupMemberType_Manager) {
|
||||
isAllow = true;
|
||||
}
|
||||
}
|
||||
if (!isAllow) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
WFCMessage.GroupInfo.Builder newInfoBuilder = oldInfo.toBuilder();
|
||||
|
||||
if (modifyType == Modify_Group_Name)
|
||||
@@ -814,6 +863,16 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
newInfoBuilder.setPortrait(value);
|
||||
else if(modifyType == Modify_Group_Extra)
|
||||
newInfoBuilder.setExtra(value);
|
||||
else if(modifyType == Modify_Group_Mute)
|
||||
newInfoBuilder.setMute(Integer.parseInt(value));
|
||||
else if(modifyType == Modify_Group_JoinType)
|
||||
newInfoBuilder.setJoinType(Integer.parseInt(value));
|
||||
else if(modifyType == Modify_Group_PrivateChat)
|
||||
newInfoBuilder.setPrivateChat(Integer.parseInt(value));
|
||||
else if(modifyType == Modify_Group_Searchable)
|
||||
newInfoBuilder.setSearchable(Integer.parseInt(value));
|
||||
else
|
||||
return ErrorCode.INVALID_PARAMETER;
|
||||
|
||||
|
||||
newInfoBuilder.setUpdateDt(System.currentTimeMillis());
|
||||
@@ -911,6 +970,24 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WFCMessage.GroupMember getGroupMember(String groupId, String memberId) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
if (members != null) {
|
||||
for (WFCMessage.GroupMember gm : members) {
|
||||
if (gm.getMemberId().equals(memberId)) {
|
||||
return gm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin) {
|
||||
@@ -938,6 +1015,40 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode setGroupManager(String operator, String groupId, int type, List<String> userList, boolean isAdmin) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||
|
||||
|
||||
WFCMessage.GroupInfo groupInfo = mIMap.get(groupId);
|
||||
|
||||
if (groupInfo == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (!isAdmin && (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal)
|
||||
&& (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
long updateDt = System.currentTimeMillis();
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
if (userList.contains(member.getMemberId())) {
|
||||
groupMembers.remove(groupId, member);
|
||||
member = member.toBuilder().setType(ProtoConstants.GroupMemberType.GroupMemberType_Manager).setUpdateDt(updateDt).build();
|
||||
databaseStore.persistGroupMember(groupId, Arrays.asList(member));
|
||||
groupMembers.put(groupId, member);
|
||||
// userList.remove(member.getMemberId());
|
||||
}
|
||||
}
|
||||
|
||||
mIMap.put(groupId, groupInfo.toBuilder().setUpdateDt(updateDt).setMemberUpdateDt(updateDt).build());
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMemberInGroup(String memberId, String groupId) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
@@ -947,7 +1058,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
for (WFCMessage.GroupMember member : members
|
||||
) {
|
||||
if (member.getMemberId().equals(memberId) && member.getType() != ProtoConstants.GroupMemberType.GroupMemberType_Removed)
|
||||
if (member.getMemberId().equals(memberId) && member.getType() != GroupMemberType_Removed)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -955,19 +1066,41 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForbiddenInGroup(String memberId, String groupId) {
|
||||
public ErrorCode canSendMessageInGroup(String memberId, String groupId) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
IMap<String, WFCMessage.GroupInfo> groups = hzInstance.getMap(GROUPS_MAP);
|
||||
WFCMessage.GroupInfo groupInfo = groups.get(groupId);
|
||||
boolean isMute = false;
|
||||
if (groupInfo != null) {
|
||||
if (groupInfo.getOwner().equals(memberId)) {
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
isMute = groupInfo.getMute()>0;
|
||||
}
|
||||
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
|
||||
for (WFCMessage.GroupMember member : members
|
||||
) {
|
||||
if (member.getMemberId().equals(memberId) && member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Silent)
|
||||
return true;
|
||||
if (member.getMemberId().equals(memberId)) {
|
||||
if (member.getType() == GroupMemberType_Silent) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
if (isMute && member.getType() != GroupMemberType_Manager && member.getType() != GroupMemberType_Owner) {
|
||||
return ErrorCode.ERROR_CODE_GROUP_MUTED;
|
||||
}
|
||||
|
||||
if (member.getMemberId().equals(memberId) && member.getType() == GroupMemberType_Removed) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -998,7 +1131,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(message.getConversation().getTarget());
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
if (member.getMemberId().equals(operatorId)) {
|
||||
if (member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Manager || member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Owner) {
|
||||
if (member.getType() == GroupMemberType_Manager || member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Owner) {
|
||||
canRecall = true;
|
||||
}
|
||||
break;
|
||||
@@ -1161,7 +1294,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
} else {
|
||||
mUserMap.put(userId, status);
|
||||
}
|
||||
databaseStore.updateUserStatus(userId, status);
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1343,8 +1475,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
Collection<FriendData> friendDatas = friendsMap.get(fromUser);
|
||||
|
||||
if (friendDatas == null) {
|
||||
return false;
|
||||
if (friendDatas == null || friendDatas.size() == 0) {
|
||||
friendDatas = loadFriend(friendsMap, fromUser);
|
||||
}
|
||||
|
||||
for (FriendData friendData : friendDatas) {
|
||||
@@ -1415,6 +1547,31 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
}
|
||||
|
||||
synchronized Collection<FriendData> loadFriend(MultiMap<String, FriendData> friendsMap, String userId) {
|
||||
Collection<FriendData> friends = databaseStore.getPersistFriends(userId);
|
||||
if (friends != null) {
|
||||
for (FriendData friend : friends) {
|
||||
friendsMap.put(userId, friend);
|
||||
}
|
||||
} else {
|
||||
friends = new ArrayList<>();
|
||||
}
|
||||
return friends;
|
||||
}
|
||||
|
||||
synchronized Collection<WFCMessage.FriendRequest> loadFriendRequest(MultiMap<String, WFCMessage.FriendRequest> requestMap, String userId) {
|
||||
Collection<WFCMessage.FriendRequest> requests = databaseStore.getPersistFriendRequests(userId);
|
||||
if (requests != null) {
|
||||
for (WFCMessage.FriendRequest r : requests
|
||||
) {
|
||||
requestMap.put(userId, r);
|
||||
}
|
||||
} else {
|
||||
requests = new ArrayList<>();
|
||||
}
|
||||
return requests;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FriendData> getFriendList(String userId, long version) {
|
||||
List<FriendData> out = new ArrayList<FriendData>();
|
||||
@@ -1423,14 +1580,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
Collection<FriendData> friends = friendsMap.get(userId);
|
||||
if (friends == null || friends.size() == 0) {
|
||||
friends = databaseStore.getPersistFriends(userId);
|
||||
if (friends != null) {
|
||||
for (FriendData friend : friends) {
|
||||
friendsMap.put(userId, friend);
|
||||
}
|
||||
} else {
|
||||
friends = new ArrayList<>();
|
||||
}
|
||||
friends = loadFriend(friendsMap, userId);
|
||||
}
|
||||
|
||||
for (FriendData friend : friends) {
|
||||
@@ -1450,15 +1600,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
MultiMap<String, WFCMessage.FriendRequest> requestMap = hzInstance.getMultiMap(USER_FRIENDS_REQUEST);
|
||||
Collection<WFCMessage.FriendRequest> requests = requestMap.get(userId);
|
||||
if (requests == null || requests.size() == 0) {
|
||||
requests = databaseStore.getPersistFriendRequests(userId);
|
||||
if (requests != null) {
|
||||
for (WFCMessage.FriendRequest request : requests) {
|
||||
if (request.getUpdateDt() > version)
|
||||
requestMap.put(userId, request);
|
||||
}
|
||||
} else {
|
||||
requests = new ArrayList<>();
|
||||
}
|
||||
requests = loadFriendRequest(requestMap, userId);
|
||||
}
|
||||
|
||||
for (WFCMessage.FriendRequest request : requests) {
|
||||
@@ -1476,15 +1618,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
MultiMap<String, WFCMessage.FriendRequest> requestMap = hzInstance.getMultiMap(USER_FRIENDS_REQUEST);
|
||||
Collection<WFCMessage.FriendRequest> requests = requestMap.get(userId);
|
||||
if (requests == null || requests.size() == 0) {
|
||||
requests = databaseStore.getPersistFriendRequests(userId);
|
||||
if (requests != null) {
|
||||
for (WFCMessage.FriendRequest r : requests
|
||||
) {
|
||||
requestMap.put(userId, r);
|
||||
}
|
||||
} else {
|
||||
requests = new ArrayList<>();
|
||||
}
|
||||
requests = loadFriendRequest(requestMap, userId);
|
||||
}
|
||||
|
||||
WFCMessage.FriendRequest existRequest = null;
|
||||
@@ -1502,7 +1636,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
&& System.currentTimeMillis() - existRequest.getUpdateDt() < 30 * 24 * 60 * 60 * 1000) {
|
||||
return ErrorCode.ERROR_CODE_FRIEND_REQUEST_BLOCKED;
|
||||
}
|
||||
requestMap.remove(userId, existRequest);
|
||||
} else {
|
||||
return ErrorCode.ERROR_CODE_FRIEND_ALREADY_REQUEST;
|
||||
}
|
||||
@@ -1517,9 +1650,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
.setUpdateDt(System.currentTimeMillis())
|
||||
.build();
|
||||
|
||||
requestMap.put(userId, newRequest);
|
||||
requestMap.put(request.getTargetUid(), newRequest);
|
||||
databaseStore.persistOrUpdateFriendRequest(newRequest);
|
||||
requestMap.remove(userId);
|
||||
requestMap.remove(request.getTargetUid());
|
||||
|
||||
head[0] = newRequest.getUpdateDt();
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
@@ -1547,6 +1681,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
FriendData friendData1 = null;
|
||||
Collection<FriendData> friendDatas = friendsMap.get(userId);
|
||||
if (friendDatas == null || friendDatas.size() == 0) {
|
||||
friendDatas = loadFriend(friendsMap, userId);
|
||||
}
|
||||
for (FriendData fd : friendDatas) {
|
||||
if (fd.getFriendUid().equals(request.getTargetUid())) {
|
||||
friendData1 = fd;
|
||||
@@ -1556,18 +1693,19 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (friendData1 == null) {
|
||||
friendData1 = new FriendData(userId, request.getTargetUid(), "", request.getStatus(), System.currentTimeMillis());
|
||||
} else {
|
||||
friendsMap.remove(userId, friendData1);
|
||||
friendData1.setState(request.getStatus());
|
||||
friendData1.setTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
friendsMap.put(userId, friendData1);
|
||||
databaseStore.persistOrUpdateFriendData(friendData1);
|
||||
|
||||
if (request.getStatus() != 2) {
|
||||
FriendData friendData2 = null;
|
||||
|
||||
friendDatas = friendsMap.get(request.getTargetUid());
|
||||
if (friendDatas == null || friendDatas.size() == 0) {
|
||||
friendDatas = loadFriend(friendsMap, request.getTargetUid());
|
||||
}
|
||||
for (FriendData fd : friendDatas) {
|
||||
if (fd.getFriendUid().equals(userId)) {
|
||||
friendData2 = fd;
|
||||
@@ -1582,8 +1720,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
friendData2.setTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
friendsMap.put(request.getTargetUid(), friendData2);
|
||||
databaseStore.persistOrUpdateFriendData(friendData2);
|
||||
|
||||
heads[0] = friendData2.getTimestamp();
|
||||
@@ -1591,19 +1727,15 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
heads[0] = 0;
|
||||
}
|
||||
heads[1] = friendData1.getTimestamp();
|
||||
friendsMap.remove(userId);
|
||||
friendsMap.remove(request.getTargetUid());
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
MultiMap<String, WFCMessage.FriendRequest> requestMap = hzInstance.getMultiMap(USER_FRIENDS_REQUEST);
|
||||
Collection<WFCMessage.FriendRequest> requests = requestMap.get(userId);
|
||||
if (requests == null || requests.size() == 0) {
|
||||
requests = databaseStore.getPersistFriendRequests(userId);
|
||||
if (requests != null) {
|
||||
for (WFCMessage.FriendRequest r : requests
|
||||
) {
|
||||
requestMap.put(userId, r);
|
||||
}
|
||||
}
|
||||
requests = loadFriendRequest(requestMap, userId);
|
||||
}
|
||||
|
||||
WFCMessage.FriendRequest existRequest = null;
|
||||
@@ -1618,22 +1750,21 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (System.currentTimeMillis() - existRequest.getUpdateDt() > 7 * 24 * 60 * 60 * 1000) {
|
||||
return ErrorCode.ERROR_CODE_FRIEND_REQUEST_OVERTIME;
|
||||
} else {
|
||||
requestMap.remove(userId, existRequest);
|
||||
existRequest = existRequest.toBuilder().setStatus(ProtoConstants.FriendRequestStatus.RequestStatus_Accepted).setUpdateDt(System.currentTimeMillis()).build();
|
||||
databaseStore.persistOrUpdateFriendRequest(existRequest);
|
||||
requestMap.put(userId, existRequest);
|
||||
|
||||
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
|
||||
FriendData friendData1 = new FriendData(userId, request.getTargetUid(), "", 0, System.currentTimeMillis());
|
||||
friendsMap.put(userId, friendData1);
|
||||
databaseStore.persistOrUpdateFriendData(friendData1);
|
||||
|
||||
FriendData friendData2 = new FriendData(request.getTargetUid(), userId, "", 0, friendData1.getTimestamp());
|
||||
friendsMap.put(request.getTargetUid(), friendData2);
|
||||
databaseStore.persistOrUpdateFriendData(friendData2);
|
||||
|
||||
requestMap.remove(userId);
|
||||
requestMap.remove(request.getTargetUid());
|
||||
friendsMap.remove(userId);
|
||||
friendsMap.remove(request.getTargetUid());
|
||||
|
||||
heads[0] = friendData2.getTimestamp();
|
||||
heads[1] = friendData1.getTimestamp();
|
||||
|
||||
@@ -1653,6 +1784,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
FriendData friendData = null;
|
||||
Collection<FriendData> friends = friendsMap.get(fromUser);
|
||||
if (friends == null || friends.size() == 0) {
|
||||
friends = loadFriend(friendsMap, fromUser);
|
||||
}
|
||||
|
||||
for (FriendData fd:friends) {
|
||||
if (fd.getFriendUid().equals(targetUserId)) {
|
||||
friendData = fd;
|
||||
@@ -1666,8 +1801,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
friendData.setState(state);
|
||||
friendData.setTimestamp(System.currentTimeMillis());
|
||||
|
||||
friendsMap.put(fromUser, friendData);
|
||||
|
||||
databaseStore.persistOrUpdateFriendData(friendData);
|
||||
friendsMap.remove(fromUser);
|
||||
|
||||
heads[0] = friendData.getTimestamp();
|
||||
|
||||
@@ -1681,6 +1817,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
FriendData friendData = null;
|
||||
Collection<FriendData> friends = friendsMap.get(fromUser);
|
||||
if (friends == null || friends.size() == 0) {
|
||||
friends = loadFriend(friendsMap, fromUser);
|
||||
}
|
||||
|
||||
for (FriendData fd:friends) {
|
||||
if (fd.getFriendUid().equals(targetUserId)) {
|
||||
friendData = fd;
|
||||
@@ -1695,11 +1835,12 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
friendData.setAlias(alias);
|
||||
friendData.setTimestamp(System.currentTimeMillis());
|
||||
|
||||
friendsMap.put(fromUser, friendData);
|
||||
databaseStore.persistOrUpdateFriendData(friendData);
|
||||
|
||||
heads[0] = friendData.getTimestamp();
|
||||
|
||||
friendsMap.remove(fromUser);
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1734,35 +1875,43 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode deleteFriend(String userId, String friendUid) {
|
||||
public ErrorCode deleteFriend(String userId, String friendUid, long[] head) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
Collection<FriendData> user1Friends = friendsMap.get(userId);
|
||||
if (user1Friends == null || user1Friends.size() == 0) {
|
||||
user1Friends = loadFriend(friendsMap, userId);
|
||||
}
|
||||
for (FriendData data :
|
||||
user1Friends) {
|
||||
if (data.getFriendUid().equals(friendUid)) {
|
||||
friendsMap.remove(userId, data);
|
||||
long ts = System.currentTimeMillis();
|
||||
head[0] = ts;
|
||||
data.setState(1);
|
||||
data.setTimestamp(System.currentTimeMillis());
|
||||
friendsMap.put(userId, data);
|
||||
data.setTimestamp(ts);
|
||||
databaseStore.persistOrUpdateFriendData(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Collection<FriendData> user2Friends = friendsMap.get(friendUid);
|
||||
if (user2Friends == null || user2Friends.size() == 0) {
|
||||
user2Friends = loadFriend(friendsMap, friendUid);
|
||||
}
|
||||
for (FriendData data :
|
||||
user2Friends) {
|
||||
if (data.getFriendUid().equals(userId)) {
|
||||
friendsMap.remove(friendUid, data);
|
||||
data.setState(1);
|
||||
data.setTimestamp(System.currentTimeMillis());
|
||||
friendsMap.put(friendUid, data);
|
||||
long ts = System.currentTimeMillis();
|
||||
head[1] = ts;
|
||||
data.setTimestamp(ts);
|
||||
databaseStore.persistOrUpdateFriendData(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
friendsMap.remove(userId);
|
||||
friendsMap.remove(friendUid);
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1867,7 +2016,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (entry.getScope() == request.getScope() && entry.getKey().equals(request.getKey())) {
|
||||
userSettingMap.remove(userId, entry);
|
||||
userSettingMap.put(userId, settingEntry);
|
||||
return updateDt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2084,7 +2233,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
public boolean addSensitiveWords(List<String> words) {
|
||||
for (String word :
|
||||
words) {
|
||||
databaseStore.persistSensitiveWord(word);
|
||||
databaseStore.persistSensitiveWord(word.toLowerCase());
|
||||
}
|
||||
lastUpdateSensitiveTime = 0;
|
||||
return true;
|
||||
@@ -2111,10 +2260,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
MessageBundle bundle = mIMap.get(messageId);
|
||||
if (bundle != null) {
|
||||
return bundle.getMessage();
|
||||
} else {
|
||||
bundle = databaseStore.getMessage(messageId);
|
||||
if (bundle != null)
|
||||
return bundle.getMessage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -2157,15 +2302,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
Collection<FriendData> friends = friendsMap.get(userId);
|
||||
long max = 0;
|
||||
if (friends == null || friends.size() == 0) {
|
||||
friends = databaseStore.getPersistFriends(userId);
|
||||
for (FriendData friend :
|
||||
friends) {
|
||||
friendsMap.put(userId, friend);
|
||||
}
|
||||
friends = loadFriend(friendsMap, userId);
|
||||
}
|
||||
|
||||
long max = 0;
|
||||
if (friends != null && friends.size() > 0) {
|
||||
for (FriendData friend :
|
||||
friends) {
|
||||
@@ -2184,11 +2324,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
Collection<WFCMessage.FriendRequest> friendsReq = friendsReqMap.get(userId);
|
||||
long max = 0;
|
||||
if (friendsReq == null || friendsReq.size() == 0) {
|
||||
friendsReq = databaseStore.getPersistFriendRequests(userId);
|
||||
for (WFCMessage.FriendRequest req : friendsReq
|
||||
) {
|
||||
friendsReqMap.put(userId, req);
|
||||
}
|
||||
friendsReq = loadFriendRequest(friendsReqMap, userId);
|
||||
}
|
||||
|
||||
if (friendsReq != null && friendsReq.size() > 0) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.moquette.spi.ClientSession;
|
||||
import io.moquette.spi.IMessagesStore.StoredMessage;
|
||||
import io.moquette.spi.ISessionsStore;
|
||||
|
||||
import io.netty.handler.codec.mqtt.MqttVersion;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
@@ -49,6 +50,8 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
|
||||
private volatile int unReceivedMsgs;
|
||||
|
||||
private MqttVersion mqttVersion = MqttVersion.MQTT_3_1_1;
|
||||
|
||||
public long getLastActiveTime() {
|
||||
return lastActiveTime;
|
||||
}
|
||||
@@ -230,7 +233,13 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MqttVersion getMqttVersion() {
|
||||
return mqttVersion;
|
||||
}
|
||||
|
||||
public void setMqttVersion(MqttVersion mqttVersion) {
|
||||
this.mqttVersion = mqttVersion;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<String, Session> sessions = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -73,7 +73,7 @@ public class RPCCenter {
|
||||
info.future.cancel(true);
|
||||
if (info.callback != null) {
|
||||
info.callback.getResponseExecutor().execute(() -> {
|
||||
if (errorCode == 0) {
|
||||
if (errorCode == 0 || errorCode == ErrorCode.ERROR_CODE_SUCCESS_GZIPED.getCode()) {
|
||||
info.callback.onSuccess(message);
|
||||
} else {
|
||||
info.callback.onError(ErrorCode.fromCode(errorCode));
|
||||
|
||||
@@ -27,7 +27,7 @@ public class UserStatusLoader implements MapStore<String, Integer> {
|
||||
|
||||
@Override
|
||||
public void delete(String s) {
|
||||
getDatabaseStore().deleteUser(s);
|
||||
getDatabaseStore().deleteUserStatus(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2017 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.server.netty;
|
||||
|
||||
import com.bugsnag.Bugsnag;
|
||||
import io.moquette.server.config.IConfig;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
|
||||
import static io.moquette.BrokerConstants.BUGSNAG_TOKEN_PROPERTY_NAME;
|
||||
|
||||
@Sharable
|
||||
public class BugSnagErrorsHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
private Bugsnag bugsnag;
|
||||
|
||||
public void init(IConfig props) {
|
||||
final String token = props.getProperty(BUGSNAG_TOKEN_PROPERTY_NAME);
|
||||
this.bugsnag = new Bugsnag(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
bugsnag.notify(cause);
|
||||
ctx.fireExceptionCaught(cause);
|
||||
}
|
||||
}
|
||||
@@ -148,14 +148,8 @@ public class NettyAcceptor implements ServerAcceptor {
|
||||
this.metrics = Optional.empty();
|
||||
}
|
||||
|
||||
final boolean useBugSnag = Boolean.parseBoolean(props.getProperty(BUGSNAG_ENABLE_PROPERTY_NAME, "false"));
|
||||
if (useBugSnag) {
|
||||
BugSnagErrorsHandler bugSnagHandler = new BugSnagErrorsHandler();
|
||||
bugSnagHandler.init(props);
|
||||
this.errorsCather = Optional.of(bugSnagHandler);
|
||||
} else {
|
||||
this.errorsCather = Optional.empty();
|
||||
}
|
||||
this.errorsCather = Optional.empty();
|
||||
|
||||
initializePlainTCPTransport(mqttHandler, props);
|
||||
initializeWebSocketTransport(mqttHandler, props);
|
||||
String sslTcpPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME);
|
||||
@@ -260,7 +254,7 @@ public class NettyAcceptor implements ServerAcceptor {
|
||||
pipeline.addLast(new HttpServerCodec());
|
||||
pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
|
||||
pipeline.addLast("webSocketHandler",
|
||||
new WebSocketServerProtocolHandler("/org/fusesource/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
|
||||
new WebSocketServerProtocolHandler("/", MQTT_SUBPROTOCOL_CSV_LIST));
|
||||
pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
|
||||
pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
|
||||
pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0));
|
||||
|
||||
@@ -96,23 +96,27 @@ public interface IMessagesStore {
|
||||
|
||||
DatabaseStore getDatabaseStore();
|
||||
WFCMessage.Message storeMessage(String fromUser, String fromClientId, WFCMessage.Message message);
|
||||
int getNotifyReceivers(String fromUser, WFCMessage.Message message, Set<String> notifyReceivers);
|
||||
void storeSensitiveMessage(WFCMessage.Message message);
|
||||
int getNotifyReceivers(String fromUser, WFCMessage.Message.Builder message, Set<String> notifyReceivers);
|
||||
Set<String> getAllEnds();
|
||||
WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType);
|
||||
WFCMessage.PullMessageResult loadRemoteMessages(String user, WFCMessage.Conversation conversation, long beforeUid, int count);
|
||||
long insertUserMessages(String sender, int conversationType, String target, int line, int messageContentType, String userId, long messageId);
|
||||
WFCMessage.GroupInfo createGroup(String operator, WFCMessage.GroupInfo groupInfo, List<WFCMessage.GroupMember> memberList);
|
||||
ErrorCode addGroupMembers(String operator, String groupId, List<WFCMessage.GroupMember> memberList);
|
||||
ErrorCode kickoffGroupMembers(String operator, String groupId, List<String> memberList);
|
||||
ErrorCode addGroupMembers(String operator, boolean isAdmin, String groupId, List<WFCMessage.GroupMember> memberList);
|
||||
ErrorCode kickoffGroupMembers(String operator, boolean isAdmin, String groupId, List<String> memberList);
|
||||
ErrorCode quitGroup(String operator, String groupId);
|
||||
ErrorCode dismissGroup(String operator, String groupId, boolean isAdmin);
|
||||
ErrorCode modifyGroupInfo(String operator, String groupId, int modifyType, String value);
|
||||
ErrorCode modifyGroupInfo(String operator, String groupId, int modifyType, String value, boolean isAdmin);
|
||||
ErrorCode modifyGroupAlias(String operator, String groupId, String alias);
|
||||
List<WFCMessage.GroupInfo> getGroupInfos(List<WFCMessage.UserRequest> requests);
|
||||
WFCMessage.GroupInfo getGroupInfo(String groupId);
|
||||
ErrorCode getGroupMembers(String groupId, long maxDt, List<WFCMessage.GroupMember> members);
|
||||
WFCMessage.GroupMember getGroupMember(String groupId, String memberId);
|
||||
ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin);
|
||||
ErrorCode setGroupManager(String operator, String groupId, int type, List<String> userList, boolean isAdmin);
|
||||
boolean isMemberInGroup(String member, String groupId);
|
||||
boolean isForbiddenInGroup(String member, String groupId);
|
||||
ErrorCode canSendMessageInGroup(String member, String groupId);
|
||||
|
||||
ErrorCode recallMessage(long messageUid, String operatorId);
|
||||
|
||||
@@ -151,7 +155,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);
|
||||
ErrorCode deleteFriend(String userId, String friendUid);
|
||||
ErrorCode deleteFriend(String userId, String friendUid, long[] head);
|
||||
ErrorCode blackUserRequest(String fromUser, String targetUserId, int status, long[] head);
|
||||
ErrorCode SyncFriendRequestUnread(String userId, long unreadDt, long[] head);
|
||||
boolean isBlacked(String fromUser, String userId);
|
||||
|
||||
@@ -308,7 +308,7 @@ public class MessagesPublisher {
|
||||
}
|
||||
|
||||
if (isSlient) {
|
||||
LOG.info("The conversation is slient");
|
||||
LOG.info("Slient of user or conversation");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,8 @@ public class ProtocolProcessor {
|
||||
LOG.info("Processing CONNECT message. CId={}, username={}", clientId, payload.userName());
|
||||
|
||||
if (msg.variableHeader().version() != MqttVersion.MQTT_3_1.protocolLevel()
|
||||
&& msg.variableHeader().version() != MqttVersion.MQTT_3_1_1.protocolLevel()) {
|
||||
&& msg.variableHeader().version() != MqttVersion.MQTT_3_1_1.protocolLevel()
|
||||
&& msg.variableHeader().version() != MqttVersion.Wildfire_1.protocolLevel()) {
|
||||
MqttConnAckMessage badProto = connAck(CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION);
|
||||
|
||||
LOG.error("MQTT protocol version is not valid. CId={}", clientId);
|
||||
@@ -162,7 +163,8 @@ public class ProtocolProcessor {
|
||||
}
|
||||
|
||||
|
||||
if (!login(channel, msg, clientId)) {
|
||||
MqttVersion mqttVersion = MqttVersion.fromProtocolLevel(msg.variableHeader().version());
|
||||
if (!login(channel, msg, clientId, mqttVersion)) {
|
||||
channel.close();
|
||||
return;
|
||||
}
|
||||
@@ -238,7 +240,7 @@ public class ProtocolProcessor {
|
||||
MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(returnCode, sessionPresent);
|
||||
return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader, new MqttConnectAckPayload(data));
|
||||
}
|
||||
private boolean login(Channel channel, MqttConnectMessage msg, final String clientId) {
|
||||
private boolean login(Channel channel, MqttConnectMessage msg, final String clientId, MqttVersion mqttVersion) {
|
||||
// handle user authentication
|
||||
if (msg.variableHeader().hasUserName()) {
|
||||
int status = m_messagesStore.getUserStatus(msg.payload().userName());
|
||||
@@ -269,6 +271,7 @@ public class ProtocolProcessor {
|
||||
failedCredentials(channel);
|
||||
return false;
|
||||
}
|
||||
session.setMqttVersion(mqttVersion);
|
||||
} else if (!this.allowAnonymous) {
|
||||
LOG.error("Client didn't supply any password and MQTT anonymous mode is disabled CId={}", clientId);
|
||||
failedCredentials(channel);
|
||||
|
||||
@@ -23,8 +23,10 @@ import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_OVER_FREQUENCY;
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
||||
import com.google.gson.Gson;
|
||||
@@ -39,6 +41,7 @@ import io.moquette.server.ConnectionDescriptor;
|
||||
import io.moquette.server.Server;
|
||||
import io.moquette.spi.ClientSession;
|
||||
import io.moquette.spi.impl.security.AES;
|
||||
import io.netty.handler.codec.mqtt.MqttVersion;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
@@ -114,7 +117,7 @@ public class Qos1PublishHandler extends QosPublishHandler {
|
||||
byte[] response = new byte[ackPayload.readableBytes()];
|
||||
ackPayload.readBytes(response);
|
||||
ReferenceCountUtil.release(ackPayload);
|
||||
RPCCenter.getInstance().sendResponse(ERROR_CODE_SUCCESS.getCode(), response, from, requestId);
|
||||
RPCCenter.getInstance().sendResponse(errorCode.getCode(), response, from, requestId);
|
||||
}
|
||||
}, isAdmin);
|
||||
}
|
||||
@@ -174,8 +177,23 @@ public class Qos1PublishHandler extends QosPublishHandler {
|
||||
data = AES.AESEncrypt(data, "");
|
||||
} else {
|
||||
MemorySessionStore.Session session = m_sessionStore.getSession(clientID);
|
||||
if (session != null && session.getUsername().equals(fromUser))
|
||||
data = AES.AESEncrypt(data, session.getSecret());
|
||||
if (session != null && session.getUsername().equals(fromUser)) {
|
||||
if (data.length > 7*1024 && session.getMqttVersion() == MqttVersion.Wildfire_1) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip;
|
||||
try {
|
||||
gzip = new GZIPOutputStream(out);
|
||||
gzip.write(data);
|
||||
gzip.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
data = out.toByteArray();
|
||||
code = (byte)ErrorCode.ERROR_CODE_SUCCESS_GZIPED.code;
|
||||
}
|
||||
|
||||
data = AES.AESEncrypt(data, session.getSecret());
|
||||
}
|
||||
}
|
||||
}
|
||||
ackPayload.clear();
|
||||
|
||||
@@ -43,7 +43,7 @@ final class MqttCodecUtil {
|
||||
return clientId != null && clientId.length() >= MIN_CLIENT_ID_LENGTH &&
|
||||
clientId.length() <= MAX_CLIENT_ID_LENGTH;
|
||||
}
|
||||
if (mqttVersion == MqttVersion.MQTT_3_1_1) {
|
||||
if (mqttVersion == MqttVersion.MQTT_3_1_1 || mqttVersion == MqttVersion.Wildfire_1) {
|
||||
// In 3.1.3.1 Client Identifier of MQTT 3.1.1 specification, The Server MAY allow ClientId’s
|
||||
// that contain more than 23 encoded bytes. And, The Server MAY allow zero-length ClientId.
|
||||
return clientId != null;
|
||||
|
||||
@@ -223,7 +223,7 @@ public final class MqttDecoder extends ReplayingDecoder<DecoderState> {
|
||||
final int willQos = (b1 & 0x18) >> 3;
|
||||
final boolean willFlag = (b1 & 0x04) == 0x04;
|
||||
final boolean cleanSession = (b1 & 0x02) == 0x02;
|
||||
if (mqttVersion == MqttVersion.MQTT_3_1_1) {
|
||||
if (mqttVersion == MqttVersion.MQTT_3_1_1 || mqttVersion == MqttVersion.Wildfire_1) {
|
||||
final boolean zeroReservedFlag = (b1 & 0x01) == 0x0;
|
||||
if (!zeroReservedFlag) {
|
||||
// MQTT v3.1.1: The Server MUST validate that the reserved flag in the CONNECT Control Packet is
|
||||
|
||||
@@ -24,7 +24,8 @@ import io.netty.util.internal.ObjectUtil;
|
||||
*/
|
||||
public enum MqttVersion {
|
||||
MQTT_3_1("MQIsdp", (byte) 3),
|
||||
MQTT_3_1_1("MQTT", (byte) 4);
|
||||
MQTT_3_1_1("MQTT", (byte) 4),
|
||||
Wildfire_1("MQTT", (byte) 5);
|
||||
|
||||
private final String name;
|
||||
private final byte level;
|
||||
@@ -52,11 +53,19 @@ public enum MqttVersion {
|
||||
if (mv.level == protocolLevel) {
|
||||
return mv;
|
||||
} else {
|
||||
throw new MqttUnacceptableProtocolVersionException(protocolName + " and " +
|
||||
protocolLevel + " are not match");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new MqttUnacceptableProtocolVersionException(protocolName + "is unknown protocol name");
|
||||
}
|
||||
|
||||
public static MqttVersion fromProtocolLevel(int protocolLevel) {
|
||||
for (MqttVersion mv : values()) {
|
||||
if (mv.level == (byte )protocolLevel) {
|
||||
return mv;
|
||||
}
|
||||
}
|
||||
throw new MqttUnacceptableProtocolVersionException(protocolLevel + "is unknown protocol level");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
|
||||
package win.liyufan.im;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class GitRepositoryState {
|
||||
@@ -64,7 +63,9 @@ public class GitRepositoryState {
|
||||
public static GitRepositoryState getGitRepositoryState() throws IOException {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(new FileInputStream("config/git.properties"));
|
||||
InputStream inputStream = new FileInputStream("config/git.properties");
|
||||
BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream));
|
||||
properties.load(bf);
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public interface IMTopic {
|
||||
String PullMessageTopic = "MP";
|
||||
String NotifyMessageTopic = "MN";
|
||||
String NotifyRecallMessageTopic = "RMN";
|
||||
String BroadcastMessageTopic = "MBC";
|
||||
|
||||
String GetUserSettingTopic = "UG";
|
||||
String PutUserSettingTopic = "UP";
|
||||
@@ -29,7 +30,7 @@ public interface IMTopic {
|
||||
String GetGroupInfoTopic = "GPGI";
|
||||
String GetGroupMemberTopic = "GPGM";
|
||||
String TransferGroupTopic = "GTG";
|
||||
|
||||
String SetGroupManagerTopic = "GSM";
|
||||
|
||||
String GetUserInfoTopic = "UPUI";
|
||||
String ModifyMyInfoTopic = "MMI";
|
||||
|
||||
@@ -65,6 +65,11 @@ public class MessageBundle implements Serializable {
|
||||
}
|
||||
|
||||
public void setMessage(WFCMessage.Message message) {
|
||||
this.fromUser = message.getFromUser();
|
||||
this.type = message.getConversation().getType();
|
||||
this.targetId = message.getConversation().getTarget();
|
||||
this.line = message.getConversation().getLine();
|
||||
this.message = message;
|
||||
this.messageId = message.getMessageId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,10 +54,15 @@ public class MessageShardingUtil {
|
||||
return "t_messages";
|
||||
}
|
||||
|
||||
mid >>= (nodeIdWidth + rotateIdWidth);
|
||||
Date date = new Date(mid + T201801010000);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
if (mid != Long.MAX_VALUE) {
|
||||
mid >>= (nodeIdWidth + rotateIdWidth);
|
||||
Date date = new Date(mid + T201801010000);
|
||||
calendar.setTime(date);
|
||||
} else {
|
||||
Date date = new Date(System.currentTimeMillis());
|
||||
calendar.setTime(date);
|
||||
}
|
||||
int month = calendar.get(Calendar.MONTH);
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
year %= 3;
|
||||
|
||||
@@ -58,6 +58,7 @@ public class SensitiveFilter {
|
||||
return sensitiveWords;
|
||||
}
|
||||
|
||||
text = text.toLowerCase();
|
||||
for(int i=0;i<text.length();i++){
|
||||
int sensitiveWordLength = getSensitiveWordLength(text, i, matchType);
|
||||
if(sensitiveWordLength>0){
|
||||
|
||||
@@ -59,4 +59,78 @@ public class Utility {
|
||||
|
||||
return macAddressBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化
|
||||
*
|
||||
* @param jsonStr
|
||||
* @return
|
||||
* @author lizhgb
|
||||
* @Date 2015-10-14 下午1:17:35
|
||||
* @Modified 2017-04-28 下午8:55:35
|
||||
*/
|
||||
public static String formatJson(String jsonStr) {
|
||||
if (null == jsonStr || "".equals(jsonStr))
|
||||
return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
char last = '\0';
|
||||
char current = '\0';
|
||||
int indent = 0;
|
||||
boolean isInQuotationMarks = false;
|
||||
for (int i = 0; i < jsonStr.length(); i++) {
|
||||
last = current;
|
||||
current = jsonStr.charAt(i);
|
||||
switch (current) {
|
||||
case '"':
|
||||
if (last != '\\'){
|
||||
isInQuotationMarks = !isInQuotationMarks;
|
||||
}
|
||||
sb.append(current);
|
||||
break;
|
||||
case '{':
|
||||
case '[':
|
||||
sb.append(current);
|
||||
if (!isInQuotationMarks) {
|
||||
sb.append('\n');
|
||||
indent++;
|
||||
addIndentBlank(sb, indent);
|
||||
}
|
||||
break;
|
||||
case '}':
|
||||
case ']':
|
||||
if (!isInQuotationMarks) {
|
||||
sb.append('\n');
|
||||
indent--;
|
||||
addIndentBlank(sb, indent);
|
||||
}
|
||||
sb.append(current);
|
||||
break;
|
||||
case ',':
|
||||
sb.append(current);
|
||||
if (last != '\\' && !isInQuotationMarks) {
|
||||
sb.append('\n');
|
||||
addIndentBlank(sb, indent);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sb.append(current);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加space
|
||||
*
|
||||
* @param sb
|
||||
* @param indent
|
||||
* @author lizhgb
|
||||
* @Date 2015-10-14 上午10:38:04
|
||||
*/
|
||||
private static void addIndentBlank(StringBuilder sb, int indent) {
|
||||
for (int i = 0; i < indent; i++) {
|
||||
sb.append('\t');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<!--MySQL数据库驱动程序-->
|
||||
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
|
||||
<!--MySQL数据库地址-->
|
||||
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true</property>
|
||||
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf8</property>
|
||||
<!--MySQL数据库用户名-->
|
||||
<property name="user">root</property>
|
||||
<!--MySQL数据库密码-->
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.21</version>
|
||||
<version>0.24</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package cn.wildfirechat.client;
|
||||
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import cn.wildfirechat.pojos.InputRoute;
|
||||
import com.xiaoleilu.loServer.pojos.InputRoute;
|
||||
import io.moquette.spi.impl.security.AES;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
@@ -18,6 +19,7 @@ import org.fusesource.mqtt.client.*;
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
@@ -280,15 +282,38 @@ public class IMClient implements Listener {
|
||||
try {
|
||||
WFCMessage.NotifyMessage notifyMessage = WFCMessage.NotifyMessage.parseFrom(body.toByteArray());
|
||||
WFCMessage.PullMessageRequest request = WFCMessage.PullMessageRequest.newBuilder().setId(messageHead).setType(notifyMessage.getType()).build();
|
||||
connection.publish("MP", request.toByteArray(), QoS.AT_LEAST_ONCE, false, new Callback<byte[]>(){
|
||||
byte[] data = request.toByteArray();
|
||||
data = AES.AESEncrypt(data, privateSecret);
|
||||
connection.publish("MP", data, QoS.AT_LEAST_ONCE, false, new Callback<byte[]>(){
|
||||
@Override
|
||||
public void onSuccess(byte[] value) {
|
||||
if (value == null || value.length == 0) {
|
||||
System.out.println("Invalide data");
|
||||
}
|
||||
|
||||
if (value[0] != 0) {
|
||||
System.out.println("Pull message error with errorCode:" + value[0]);
|
||||
}
|
||||
|
||||
byte[] data = new byte[value.length - 1];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = value[i+1];
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] data = AES.AESDecrypt(value, privateSecret, true);
|
||||
data = AES.AESDecrypt(data, privateSecret, true);
|
||||
try {
|
||||
WFCMessage.PullMessageResult result = WFCMessage.PullMessageResult.parseFrom(data);
|
||||
if (receiveMessageCallback != null) {
|
||||
receiveMessageCallback.onReceiveMessages(result.getMessageList(), false);
|
||||
if (receiveMessageCallback != null && result.getMessageList().size() > 0) {
|
||||
List<WFCMessage.Message> messages = result.getMessageList();
|
||||
List<WFCMessage.Message> out = new ArrayList<>();
|
||||
for (WFCMessage.Message msg : messages) {
|
||||
if (msg.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Private && msg.getConversation().getTarget().equals(userId)) {
|
||||
msg = msg.toBuilder().setConversation(msg.getConversation().toBuilder().setTarget(msg.getFromUser())).build();
|
||||
}
|
||||
out.add(msg);
|
||||
}
|
||||
receiveMessageCallback.onReceiveMessages(out, false);
|
||||
}
|
||||
messageHead = result.getHead();
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
@@ -355,23 +380,24 @@ public class IMClient implements Listener {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//token与userid和clientid是绑定的,使用时一定要传入正确的userid和clientid,不然会认为token非法
|
||||
IMClient client = new IMClient("yzyOyOKK", "7SJk13q+YdHHe6EwDzry9BKogxTNf3UgtYj50cBTZgWNkNuxEkiqg2koKg0lXViONIX1LmwCR1jN0Mw8hvk6KGpiSKFi+IRaRkIb3mNzgIfrq4afhyIHaQfa2HOfsi6Ws+9YobkdDgdq7W70bEdVfiCSU9+JOIY449nxZzfg2Zw=", "DD72C212-26C7-4B38-A5FC-88550896B170", "192.168.1.101", 80);
|
||||
//clientId唯一代表一个设备,只能有一个登录。如果使用同一个clientId登录多次,会出现不可预料问题。
|
||||
IMClient client = new IMClient("KNK_K_00", "6I7UTfKSQT7VhsUJfU6UCvDeCyblLfcXPfajAFxgFGOcqvfFVQCvYy8A5vfAGUj2LSYgoM5W02MHh6jtG/otQs6ft8zLT4Efz315UlDLfrz+OSQYfwAuGFw9m0/x4ckrgiooprsKFxPMaNcCDact0qvp1dBhbeGUipdWVhI33b4=", "5B6DEB72-8A3D-45E2-A88A-47DC4E692B00", "192.168.0.193", 80);
|
||||
|
||||
client.setReceiveMessageCallback(new ReceiveMessageCallback() {
|
||||
@Override
|
||||
public void onReceiveMessages(List<WFCMessage.Message> messageList, boolean hasMore) {
|
||||
|
||||
System.out.println("recieved messages");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecallMessage(long messageUid) {
|
||||
|
||||
System.out.println("recalled messages");
|
||||
}
|
||||
});
|
||||
|
||||
client.setConnectionStatusCallback((ConnectionStatus newStatus) -> {
|
||||
if (newStatus == ConnectionStatus_Connected) {
|
||||
WFCMessage.Conversation conversation = WFCMessage.Conversation.newBuilder().setType(0).setTarget("yzyOyOKK").setLine(0).build();
|
||||
WFCMessage.Conversation conversation = WFCMessage.Conversation.newBuilder().setType(0).setTarget("IMININnn").setLine(0).build();
|
||||
WFCMessage.MessageContent messageContent = WFCMessage.MessageContent.newBuilder().setSearchableContent("helloworld").setType(1).build();
|
||||
client.sendMessage(conversation, messageContent, new SendMessageCallback() {
|
||||
@Override
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.wildfirechat.pojos;
|
||||
package com.xiaoleilu.loServer.pojos;
|
||||
|
||||
|
||||
public class InputRoute {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.21</version>
|
||||
<version>0.24</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
public class BroadMessageData {
|
||||
private String sender;
|
||||
private int line;
|
||||
private MessagePayload payload;
|
||||
|
||||
public String getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public void setSender(String sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
public void setLine(int line) {
|
||||
this.line = line;
|
||||
}
|
||||
|
||||
public MessagePayload getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(MessagePayload payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public static boolean isValide(BroadMessageData sendMessageData) {
|
||||
if(sendMessageData == null ||
|
||||
StringUtil.isNullOrEmpty(sendMessageData.getSender()) ||
|
||||
sendMessageData.getPayload() == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public WFCMessage.Message toProtoMessage() {
|
||||
return WFCMessage.Message.newBuilder().setFromUser(sender)
|
||||
.setConversation(WFCMessage.Conversation.newBuilder().setType(ProtoConstants.ConversationType.ConversationType_Private).setTarget(sender).setLine(line))
|
||||
.setContent(payload.toProtoMessageContent())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class BroadMessageResult {
|
||||
private long messageUid;
|
||||
private long count;
|
||||
|
||||
public BroadMessageResult() {
|
||||
}
|
||||
|
||||
public BroadMessageResult(long messageUid, long count) {
|
||||
this.messageUid = messageUid;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public long getMessageUid() {
|
||||
return messageUid;
|
||||
}
|
||||
|
||||
public void setMessageUid(long messageUid) {
|
||||
this.messageUid = messageUid;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(long count) {
|
||||
this.count = count;
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,13 @@ public class GroupNotificationBinaryContent {
|
||||
//operator
|
||||
private String o;
|
||||
|
||||
//name
|
||||
//value1(name or something)
|
||||
private String n;
|
||||
|
||||
//members
|
||||
private List<String> ms;
|
||||
|
||||
//members
|
||||
//value2(member or something)
|
||||
private String m;
|
||||
|
||||
public GroupNotificationBinaryContent(String g, String o, String n, String m) {
|
||||
@@ -124,4 +124,27 @@ public class GroupNotificationBinaryContent {
|
||||
public WFCMessage.MessageContent getModifyGroupMemberAliasNotifyContent() {
|
||||
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_MODIFY_GROUP_ALIAS);
|
||||
}
|
||||
|
||||
public WFCMessage.MessageContent getChangeGroupMuteNotifyContent() {
|
||||
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_CHANGE_MUTE);
|
||||
}
|
||||
|
||||
public WFCMessage.MessageContent getChangeGroupJointypeNotifyContent() {
|
||||
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_CHANGE_JOINTYPE);
|
||||
}
|
||||
|
||||
public WFCMessage.MessageContent getChangeGroupPrivatechatNotifyContent() {
|
||||
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_CHANGE_PRIVATECHAT);
|
||||
}
|
||||
|
||||
public WFCMessage.MessageContent getChangeGroupSearchableNotifyContent() {
|
||||
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_CHANGE_SEARCHABLE);
|
||||
}
|
||||
|
||||
public WFCMessage.MessageContent getSetGroupManagerNotifyContent() {
|
||||
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_SET_MANAGER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public interface APIPath {
|
||||
|
||||
String Msg_Send = "/admin/message/send";
|
||||
String Msg_Recall = "/admin/message/recall";
|
||||
String Msg_Broadcast = "/admin/message/broadcast";
|
||||
|
||||
String Create_Group = "/admin/group/create";
|
||||
String Group_Dismiss = "/admin/group/del";
|
||||
|
||||
@@ -42,6 +42,7 @@ public enum ErrorCode {
|
||||
|
||||
ERROR_CODE_NOT_IN_CHANNEL(21, "not in channel"),
|
||||
|
||||
ERROR_CODE_GROUP_MUTED(241, "group is muted"),
|
||||
ERROR_CODE_SENSITIVE_MATCHED(242, "sensitive matched"),
|
||||
ERROR_CODE_SIGN_EXPIRED(243, "sign expired"),
|
||||
ERROR_CODE_AUTH_FAILURE(244, "auth failure"),
|
||||
@@ -56,7 +57,7 @@ public enum ErrorCode {
|
||||
ERROR_CODE_NOT_IMPLEMENT(254, "not implement"),
|
||||
|
||||
|
||||
ERROR_CODE_ASYNC_HANDLER(255, "异步执行,服务器内部逻辑需要此代码,为正常情况,不能返回客户端"),;
|
||||
ERROR_CODE_SUCCESS_GZIPED(255, "success withe gzip response"),;
|
||||
|
||||
public int code;
|
||||
public String msg;
|
||||
|
||||
@@ -87,6 +87,10 @@ public class ProtoConstants {
|
||||
int Modify_Group_Name = 0;
|
||||
int Modify_Group_Portrait = 1;
|
||||
int Modify_Group_Extra = 2;
|
||||
int Modify_Group_Mute = 3;
|
||||
int Modify_Group_JoinType = 4;
|
||||
int Modify_Group_PrivateChat = 5;
|
||||
int Modify_Group_Searchable = 6;
|
||||
}
|
||||
|
||||
//ModifyGroupInfoRequest -> type
|
||||
@@ -137,5 +141,12 @@ public class ProtoConstants {
|
||||
public static final int MESSAGE_CONTENT_TYPE_CHANGE_GROUP_NAME = 110;
|
||||
public static final int MESSAGE_CONTENT_TYPE_MODIFY_GROUP_ALIAS = 111;
|
||||
public static final int MESSAGE_CONTENT_TYPE_CHANGE_GROUP_PORTRAIT = 112;
|
||||
|
||||
public static final int MESSAGE_CONTENT_TYPE_CHANGE_MUTE = 113;
|
||||
public static final int MESSAGE_CONTENT_TYPE_CHANGE_JOINTYPE = 114;
|
||||
public static final int MESSAGE_CONTENT_TYPE_CHANGE_PRIVATECHAT = 115;
|
||||
public static final int MESSAGE_CONTENT_TYPE_CHANGE_SEARCHABLE = 116;
|
||||
|
||||
public static final int MESSAGE_CONTENT_TYPE_SET_MANAGER = 117;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@
|
||||
<!--<relativePath>../pom.xml</relativePath>-->
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.21</version>
|
||||
<version>0.24</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>distribution</artifactId>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<!--MySQL数据库驱动程序-->
|
||||
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
|
||||
<!--MySQL数据库地址-->
|
||||
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true</property>
|
||||
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf8</property>
|
||||
<!--MySQL数据库用户名-->
|
||||
<property name="user">root</property>
|
||||
<!--MySQL数据库密码-->
|
||||
|
||||
@@ -30,6 +30,8 @@ set JAVA_OPTS=
|
||||
set JAVA_OPTS_SCRIPT=-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true
|
||||
set WILDFIRECHAT_PATH=%WILDFIRECHAT_HOME%
|
||||
set LOG_FILE=%WILDFIRECHAT_HOME%\config\log4j.properties
|
||||
set HZ_CONF_FILE=%WILDFIRECHAT_HOME%\config\hazelcast.xml
|
||||
set C3P0_CONF_FILE=%WILDFIRECHAT_HOME%\config\c3p0-config.xml
|
||||
|
||||
rem Use the Hotspot garbage-first collector.
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:+UseG1GC
|
||||
@@ -71,4 +73,4 @@ rem set JAVA_OPTS=%JAVA_OPTS% -XX:+UseGCLogFileRotation
|
||||
rem set JAVA_OPTS=%JAVA_OPTS% -XX:NumberOfGCLogFiles=10
|
||||
rem set JAVA_OPTS=%JAVA_OPTS% -XX:GCLogFileSize=10M"
|
||||
|
||||
%JAVA% -server %JAVA_OPTS% %JAVA_OPTS_SCRIPT% -Dlog4j.configuration=file:%LOG_FILE% -Dwildfirechat.path=%WILDFIRECHAT_PATH% -cp %WILDFIRECHAT_HOME%\lib\* cn.wildfirechat.server.Server
|
||||
%JAVA% -server %JAVA_OPTS% %JAVA_OPTS_SCRIPT% -Dlog4j.configuration=file:%LOG_FILE% -Dcom.mchange.v2.c3p0.cfg.xml=%C3P0_CONF_FILE% -Dhazelcast.configuration=file:%HZ_CONF_FILE% -Dwildfirechat.path=%WILDFIRECHAT_PATH% -cp %WILDFIRECHAT_HOME%\lib\* cn.wildfirechat.server.Server
|
||||
|
||||
@@ -70,7 +70,7 @@ JAVA_OPTS="$JAVA_OPTS -XX:MaxGCPauseMillis=500"
|
||||
### GC logging options -- uncomment to enable
|
||||
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails"
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDateStamps"
|
||||
#JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDateStamps"
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC"
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintTenuringDistribution"
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCApplicationStoppedTime"
|
||||
@@ -80,8 +80,8 @@ JAVA_OPTS="$JAVA_OPTS -XX:+UseGCLogFileRotation"
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:NumberOfGCLogFiles=10"
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M"
|
||||
|
||||
#JAVA_OPTS="$JAVA_OPTS -Xmx128M"
|
||||
#JAVA_OPTS="$JAVA_OPTS -Xms128M"
|
||||
|
||||
JAVA_OPTS="$JAVA_OPTS -Xmx128M"
|
||||
JAVA_OPTS="$JAVA_OPTS -Xms128M"
|
||||
|
||||
$JAVA -server $JAVA_OPTS $JAVA_OPTS_SCRIPT -Dlog4j.configuration="file:$LOG_FILE" -Dcom.mchange.v2.c3p0.cfg.xml="$C3P0_CONF_FILE" -Dhazelcast.configuration="file:$HZ_CONF_FILE" -Dwildfirechat.path="$WILDFIRECHAT_PATH" -cp "$WILDFIRECHAT_HOME/lib/*" cn.wildfirechat.server.Server
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
<version>0.21</version>
|
||||
<version>0.24</version>
|
||||
<name>Wildfire Chat</name>
|
||||
<description>Wildfire Chat Server</description>
|
||||
<inceptionYear>2019</inceptionYear>
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.21</version>
|
||||
<version>0.24</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -143,6 +143,26 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultVoid =UserAdmin.updateUserBlockStatus(userInfo.getUserId(), 0);
|
||||
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("block user done");
|
||||
} else {
|
||||
System.out.println("block user failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultCheckUserStatus = UserAdmin.checkUserBlockStatus(userInfo.getUserId());
|
||||
if (resultCheckUserStatus != null && resultCheckUserStatus.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (resultCheckUserStatus.getResult().getStatus() == 0) {
|
||||
System.out.println("check user status success");
|
||||
} else {
|
||||
System.out.println("user status not correct");
|
||||
System.exit(-1);
|
||||
}
|
||||
} else {
|
||||
System.out.println("block user failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
//***********************************************
|
||||
//**** 群组相关功能
|
||||
@@ -264,6 +284,14 @@ public class Main {
|
||||
}
|
||||
|
||||
|
||||
IMResult<BroadMessageResult> resultBroadcastMessage = MessageAdmin.broadcastMessage("user1", 0, payload);
|
||||
if (resultBroadcastMessage != null && resultBroadcastMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("broad message success, send message to " + resultBroadcastMessage.getResult().getCount() + " users");
|
||||
} else {
|
||||
System.out.println("broad message failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
//初始化机器人API
|
||||
RobotHttpUtils.init("http://localhost:18080", "robot1", "123456");
|
||||
|
||||
@@ -22,4 +22,13 @@ public class MessageAdmin {
|
||||
messageData.setMessageUid(messageUid);
|
||||
return AdminHttpUtils.httpJsonPost(path, messageData, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<BroadMessageResult> broadcastMessage(String sender, int line, MessagePayload payload) throws Exception {
|
||||
String path = APIPath.Msg_Broadcast;
|
||||
BroadMessageData messageData = new BroadMessageData();
|
||||
messageData.setSender(sender);
|
||||
messageData.setLine(line);
|
||||
messageData.setPayload(payload);
|
||||
return AdminHttpUtils.httpJsonPost(path, messageData, BroadMessageResult.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.21</version>
|
||||
<version>0.24</version>
|
||||
</parent>
|
||||
|
||||
<groupId>net.xmeter</groupId>
|
||||
|
||||
@@ -29,7 +29,7 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
||||
*/
|
||||
private static final long serialVersionUID = 2479085966683186422L;
|
||||
|
||||
private JLabeledChoice conversationTypeChoice;
|
||||
private JLabeledChoice conversationTypeChoice = new JLabeledChoice("ConversationType:", new String[] { CONV_TYPE_SINGLE, CONV_TYPE_GROUP }, true, false);
|
||||
private final JLabeledTextField target = new JLabeledTextField("Target:");
|
||||
// private JCheckBox timestamp = new JCheckBox("Add timestamp in payload");
|
||||
|
||||
@@ -62,13 +62,11 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
||||
JPanel optsPanelCon = new VerticalPanel();
|
||||
optsPanelCon.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Send message options"));
|
||||
|
||||
conversationTypeChoice = new JLabeledChoice("ConversationType:", new String[] { CONV_TYPE_SINGLE, CONV_TYPE_GROUP }, true, false);
|
||||
conversationTypeChoice.addChangeListener(this);
|
||||
|
||||
JPanel optsPanel = new HorizontalPanel();
|
||||
optsPanel.add(conversationTypeChoice);
|
||||
optsPanel.add(target);
|
||||
// optsPanel.add(timestamp);
|
||||
optsPanelCon.add(optsPanel);
|
||||
|
||||
return optsPanelCon;
|
||||
@@ -77,17 +75,11 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
||||
private JPanel createPayload() {
|
||||
JPanel optsPanelCon = new VerticalPanel();
|
||||
optsPanelCon.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Message Content"));
|
||||
|
||||
// JPanel horizon1 = new HorizontalPanel();
|
||||
//
|
||||
// stringLength.setVisible(true);
|
||||
// horizon1.add(stringLength);
|
||||
|
||||
|
||||
JPanel horizon2 = new VerticalPanel();
|
||||
messagePanel.setVisible(true);
|
||||
horizon2.add(messagePanel);
|
||||
|
||||
// optsPanelCon.add(horizon1);
|
||||
|
||||
optsPanelCon.add(horizon2);
|
||||
return optsPanelCon;
|
||||
}
|
||||
@@ -135,12 +127,16 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
||||
|
||||
connUI.configure(sampler);
|
||||
// if(sampler.getQOS().trim().indexOf(JMETER_VARIABLE_PREFIX) == -1){
|
||||
this.conversationTypeChoice.setSelectedIndex(0);
|
||||
if ("1".equals(sampler.getConvType())) {
|
||||
this.conversationTypeChoice.setSelectedIndex(1);
|
||||
} else {
|
||||
this.conversationTypeChoice.setSelectedIndex(0);
|
||||
}
|
||||
// } else {
|
||||
// this.conversationTypeChoice.setText(sampler.getQOS());
|
||||
// }
|
||||
|
||||
this.target.setText(sampler.getTopic());
|
||||
this.target.setText(sampler.getTarget());
|
||||
// this.timestamp.setSelected(sampler.isAddTimestamp());
|
||||
// if(MESSAGE_TYPE_STRING.equalsIgnoreCase(sampler.getMessageType())) {
|
||||
// this.messageTypes.setSelectedIndex(0);
|
||||
@@ -168,27 +164,7 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
||||
connUI.setupSamplerProperties(sampler);
|
||||
|
||||
sampler.setTarget(this.target.getText());
|
||||
|
||||
// if(this.conversationTypeChoice.getText().indexOf(JMETER_VARIABLE_PREFIX) == -1) {
|
||||
// int qos = QOS_0;
|
||||
// try {
|
||||
// qos = Integer.parseInt(this.conversationTypeChoice.getText());
|
||||
// if (qos < QOS_0 || qos > QOS_2) {
|
||||
// qos = QOS_0;
|
||||
// logger.info("Invalid QoS value, set to default QoS value 0.");
|
||||
// }
|
||||
// } catch (Exception ex) {
|
||||
// logger.info("Invalid QoS value, set to default QoS value 0.");
|
||||
// qos = QOS_0;
|
||||
// }
|
||||
// sampler.setQOS(String.valueOf(qos));
|
||||
// } else {
|
||||
// sampler.setQOS(this.conversationTypeChoice.getText());
|
||||
// }
|
||||
|
||||
// sampler.setAddTimestamp(this.timestamp.isSelected());
|
||||
// sampler.setMessageType(this.messageTypes.getText());
|
||||
// sampler.setMessageLength(this.stringLength.getText());
|
||||
sampler.setConvType(this.conversationTypeChoice.getSelectedIndex() + "");
|
||||
sampler.setMessage(this.sendMessage.getText());
|
||||
}
|
||||
|
||||
@@ -199,11 +175,7 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
||||
connUI.clearUI();
|
||||
connUI.connNamePrefix.setText(DEFAULT_CONN_PREFIX_FOR_PUB);
|
||||
this.target.setText(DEFAULT_TARGET);
|
||||
this.conversationTypeChoice.setText(CONV_TYPE_SINGLE);
|
||||
// this.timestamp.setSelected(false);
|
||||
|
||||
// this.messageTypes.setSelectedIndex(0);
|
||||
// this.stringLength.setText(String.valueOf(DEFAULT_MESSAGE_FIX_LENGTH));
|
||||
this.conversationTypeChoice.setSelectedIndex(0);
|
||||
this.sendMessage.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
package net.xmeter.samplers;
|
||||
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.gson.Gson;
|
||||
import cn.wildfirechat.pojos.InputRoute;
|
||||
import cn.wildfirechat.pojos.InputGetToken;
|
||||
import cn.wildfirechat.pojos.OutputGetIMTokenData;
|
||||
import io.moquette.spi.impl.security.AES;
|
||||
import net.xmeter.IMResult;
|
||||
import net.xmeter.Util;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.jmeter.samplers.AbstractSampler;
|
||||
|
||||
@@ -24,11 +19,9 @@ import org.apache.jorphan.logging.LoggingManager;
|
||||
import org.apache.log.Logger;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Base64;
|
||||
|
||||
public abstract class AbstractMQTTSampler extends AbstractSampler implements Constants {
|
||||
private transient static Logger logger = LoggingManager.getLoggerForClass();
|
||||
@@ -189,7 +182,7 @@ public abstract class AbstractMQTTSampler extends AbstractSampler implements Con
|
||||
protected String token;
|
||||
|
||||
protected boolean getToken(String userId, String clientId) {
|
||||
String url = "http://" + getServer() + ":18080/admin/user/token";
|
||||
String url = "http://" + getServer() + ":18080/admin/user/get_token";
|
||||
String adminSecret = "123456";
|
||||
HttpPost post = null;
|
||||
try {
|
||||
|
||||
@@ -191,8 +191,11 @@ public class SendMessageSampler extends AbstractMQTTSampler implements ThreadLis
|
||||
result.sampleStart();
|
||||
|
||||
final Object lock = new Object();
|
||||
|
||||
WFCMessage.Conversation conversation = WFCMessage.Conversation.newBuilder().setType(0).setTarget(getTarget()).setLine(0).build();
|
||||
int converType = 0;
|
||||
if ("1".equals(getConvType())) {
|
||||
converType = 1;
|
||||
}
|
||||
WFCMessage.Conversation conversation = WFCMessage.Conversation.newBuilder().setType(converType).setTarget(getTarget()).setLine(0).build();
|
||||
WFCMessage.MessageContent messageContent = WFCMessage.MessageContent.newBuilder().setType(1).setSearchableContent(getMessage()).build();
|
||||
|
||||
final List<Long> ret = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user