鸿蒙推送聊天消息时,支持打开具体的会话页面
This commit is contained in:
@@ -88,13 +88,10 @@ public class HMPushServiceImpl implements HMPushService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_VOIP_INVITE || pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_VOIP_INVITE) {
|
if (pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_VOIP_INVITE || pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_VOIP_INVITE) {
|
||||||
// TODO
|
VoipPayload voipPayload = VoipPayload.buildAlertPayload(pushMessage);
|
||||||
String data = "TODO";
|
|
||||||
VoipPayload voipPayload = VoipPayload.buildAlertPayload(pushMessage.getDeviceToken(), data);
|
|
||||||
httpPost(this.pushUrl, jwt, 10, voipPayload.toString(), 10000, 10000);
|
httpPost(this.pushUrl, jwt, 10, voipPayload.toString(), 10000, 10000);
|
||||||
} else {
|
} else {
|
||||||
String[] titleAndContent = Utility.getPushTitleAndContent(pushMessage);
|
AlertPayload alertPayload = AlertPayload.buildAlertPayload(pushMessage);
|
||||||
AlertPayload alertPayload = AlertPayload.buildAlertPayload(pushMessage.getDeviceToken(), titleAndContent[0], titleAndContent[1]);
|
|
||||||
String response = httpPost(this.pushUrl, jwt, 0, alertPayload.toString(), 10000, 10000);
|
String response = httpPost(this.pushUrl, jwt, 0, alertPayload.toString(), 10000, 10000);
|
||||||
LOG.info("Push to {} response {}", pushMessage.getDeviceToken(), response);
|
LOG.info("Push to {} response {}", pushMessage.getDeviceToken(), response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package cn.wildfirechat.push.hm.payload;
|
package cn.wildfirechat.push.hm.payload;
|
||||||
|
|
||||||
|
import cn.wildfirechat.push.PushMessage;
|
||||||
|
import cn.wildfirechat.push.PushMessageType;
|
||||||
|
import cn.wildfirechat.push.Utility;
|
||||||
import cn.wildfirechat.push.hm.payload.internal.ClickAction;
|
import cn.wildfirechat.push.hm.payload.internal.ClickAction;
|
||||||
import cn.wildfirechat.push.hm.payload.internal.Notification;
|
import cn.wildfirechat.push.hm.payload.internal.Notification;
|
||||||
import cn.wildfirechat.push.hm.payload.internal.Payload;
|
import cn.wildfirechat.push.hm.payload.internal.Payload;
|
||||||
import cn.wildfirechat.push.hm.payload.internal.Target;
|
import cn.wildfirechat.push.hm.payload.internal.Target;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
@@ -18,17 +23,31 @@ public class AlertPayload {
|
|||||||
return new Gson().toJson(this);
|
return new Gson().toJson(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AlertPayload buildAlertPayload(String token, String title, String body) {
|
public static AlertPayload buildAlertPayload(PushMessage pushMessage) {
|
||||||
Notification notification = new Notification();
|
Notification notification = new Notification();
|
||||||
notification.title = title;
|
String[] titleAndBody = Utility.getPushTitleAndContent(pushMessage);
|
||||||
notification.body = body;
|
notification.title = titleAndBody[0];
|
||||||
|
notification.body = titleAndBody[1];
|
||||||
|
|
||||||
ClickAction clickAction = new ClickAction();
|
ClickAction clickAction = new ClickAction();
|
||||||
|
|
||||||
|
if (pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_NORMAL) {
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
JSONObject conv = new JSONObject();
|
||||||
|
conv.put("type", pushMessage.convType);
|
||||||
|
conv.put("target", pushMessage.target);
|
||||||
|
conv.put("line", pushMessage.line);
|
||||||
|
data.put("conversation", conv);
|
||||||
|
clickAction.data = data;
|
||||||
|
} else {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
notification.clickAction = clickAction;
|
notification.clickAction = clickAction;
|
||||||
|
|
||||||
Target target = new Target();
|
Target target = new Target();
|
||||||
target.token = new ArrayList<>();
|
target.token = new ArrayList<>();
|
||||||
target.token.add(token);
|
target.token.add(pushMessage.deviceToken);
|
||||||
|
|
||||||
AlertPayload alertPayload = new AlertPayload();
|
AlertPayload alertPayload = new AlertPayload();
|
||||||
alertPayload.payload = new Payload();
|
alertPayload.payload = new Payload();
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cn.wildfirechat.push.hm.payload;
|
package cn.wildfirechat.push.hm.payload;
|
||||||
|
|
||||||
import cn.wildfirechat.push.hm.payload.internal.ClickAction;
|
import cn.wildfirechat.push.PushMessage;
|
||||||
import cn.wildfirechat.push.hm.payload.internal.Notification;
|
|
||||||
import cn.wildfirechat.push.hm.payload.internal.Payload;
|
import cn.wildfirechat.push.hm.payload.internal.Payload;
|
||||||
import cn.wildfirechat.push.hm.payload.internal.Target;
|
import cn.wildfirechat.push.hm.payload.internal.Target;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -18,14 +17,14 @@ public class VoipPayload {
|
|||||||
return new Gson().toJson(this);
|
return new Gson().toJson(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VoipPayload buildAlertPayload(String token, String extraData) {
|
public static VoipPayload buildAlertPayload(PushMessage pushMessage) {
|
||||||
Target target = new Target();
|
Target target = new Target();
|
||||||
target.token = new ArrayList<>();
|
target.token = new ArrayList<>();
|
||||||
target.token.add(token);
|
target.token.add(pushMessage.deviceToken);
|
||||||
|
|
||||||
VoipPayload voipPayload = new VoipPayload();
|
VoipPayload voipPayload = new VoipPayload();
|
||||||
voipPayload.payload = new Payload();
|
voipPayload.payload = new Payload();
|
||||||
voipPayload.payload.extraData = extraData;
|
voipPayload.payload.extraData = "TODO";
|
||||||
voipPayload.target = target;
|
voipPayload.target = target;
|
||||||
|
|
||||||
return voipPayload;
|
return voipPayload;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package cn.wildfirechat.push.hm.payload.internal;
|
package cn.wildfirechat.push.hm.payload.internal;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
public class ClickAction {
|
public class ClickAction {
|
||||||
/**
|
/**
|
||||||
* 0:打开应用首页
|
* 0:打开应用首页
|
||||||
@@ -10,5 +12,5 @@ public class ClickAction {
|
|||||||
|
|
||||||
public String action;
|
public String action;
|
||||||
public String uri;
|
public String uri;
|
||||||
public String data;
|
public JSONObject data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user