Commit eda8b90a by giaogiao

消息撤回功能;

您收到一条新消息 系统推送修改为英文
parent c9bbd69c
......@@ -18,6 +18,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
......@@ -38,6 +39,15 @@ public class ImMessageController extends BaseController {
private ImMessageService imMessageService;
/**
* 消息撤回
*/
@PostMapping("/withdraw")
@ApiOperation(value = "消息撤回", notes = "只能撤回客户端自己发送的消息")
public ApiResult<Boolean> updateMsgWithdrawById(@RequestParam Long msgId) throws Exception {
return imMessageService.updateMsgWithdrawById(msgId);
}
/**
* 修改消息体
*/
@PostMapping("/updateMsgById")
......
......@@ -21,6 +21,15 @@ import java.util.List;
*/
public interface ImMessageService extends BaseService<ImMessage> {
/**
* 消息撤回 只能撤回客户端自己发送的消息
*
* @param msgId
* @return
*/
ApiResult<Boolean> updateMsgWithdrawById(Long msgId);
/**
* 修改消息体
*
......
......@@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
......@@ -50,6 +51,34 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
private ImConversationService imConversationService;
@Override
public ApiResult<Boolean> updateMsgWithdrawById(Long msgId) {
ImClient client = imClientService.getClient();
// 判断该消息是否是该客户端发送
ImMessage messageById = this.getById(msgId);
if (!messageById.getSender().equals(client.getId())) {
log.error("判断该消息是否是该客户端发送");
return ApiResult.fail();
}
if (messageById.getWithdraw()) {
return ApiResult.ok();
}
messageById.setWithdraw(Boolean.TRUE);
messageById.setWithdrawTime(new Date());
messageById.setContent("{}");
boolean b = this.updateById(messageById);
if (b) {
return ApiResult.ok();
} else {
return ApiResult.fail();
}
}
@Override
public ApiResult<Boolean> updateMsgById(ImMsgUpdate imMsgUpdate) {
ImClient client = imClientService.getClient();
......
......@@ -28,6 +28,13 @@ public class PushTask {
*/
private static final String API_URL_FCM = "https://fcm.googleapis.com/fcm/send";
//您收到一条新消息
String title = "You have received a new message";
//点击查看
String body = "Click to view";
/**
* 异步系统推送
*
......@@ -69,9 +76,8 @@ public class PushTask {
// 安卓 单推
String deviceTokenIOS = imClientReceiver.getDeviceToken();
String titleIOS = "收到新消息";
String titleIOS = title;
String subtitle = "";
String body = "点击查看";
try {
pushUtils.sendIOSUnicast(deviceTokenIOS, titleIOS, subtitle, body);
} catch (Exception e) {
......@@ -99,8 +105,10 @@ public class PushTask {
//推送到哪台客户端机器
json.put("to", imClientReceiver.getDeviceToken());
JSONObject info = new JSONObject();
info.put("title", "新消息");
info.put("body", "点击查看");
info.put("title", title);
info.put("body", body);
//数据消息data 通知消息 notification
json.put("notification", info);
......@@ -111,7 +119,6 @@ public class PushTask {
InputStream inputStream = conn.getInputStream();
InputStreamReader in = new InputStreamReader(inputStream);
BufferedReader reader = new BufferedReader(in);
// String line = null;
wr.close();
reader.close();
......@@ -141,8 +148,7 @@ public class PushTask {
// 安卓单推
String deviceToken = imClientReceiver.getDeviceToken();
String unicastText = "Android unicast text";
String unicastTicker = "点击查看";
String title = "收到新消息";
String unicastTicker = body;
try {
pushUtils.sendAndroidUnicast(deviceToken, unicastText, unicastTicker, title);
} catch (Exception e) {
......@@ -171,8 +177,8 @@ public class PushTask {
//推送到哪台客户端机器
json.put("to", imClientReceiver.getDeviceToken());
JSONObject info = new JSONObject();
info.put("title", "新消息");
info.put("body", "点击查看");
info.put("title", title);
info.put("body", body);
//数据消息data 通知消息 notification
json.put("notification", info);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment