提交 6e931a91 编写于 作者: fxy060608's avatar fxy060608

wip(push): revert

上级 0ea54487
...@@ -54,17 +54,12 @@ export function invokePushCallback( ...@@ -54,17 +54,12 @@ export function invokePushCallback(
cidErrMsg = args.errMsg cidErrMsg = args.errMsg
invokeGetPushCidCallbacks(cid, args.errMsg) invokeGetPushCidCallbacks(cid, args.errMsg)
} else if (args.type === 'pushMsg') { } else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg: OnPushMessageSuccess = { callback({
type: 'receive', type: 'receive',
data: normalizePushMessage(args.message), data: normalizePushMessage(args.message),
} })
onPushMessageCallbacks[i](msg) })
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break
}
}
} else if (args.type === 'click') { } else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
callback({ callback({
...@@ -111,7 +106,6 @@ export const getPushClientId = defineAsyncApi( ...@@ -111,7 +106,6 @@ export const getPushClientId = defineAsyncApi(
interface OnPushMessageSuccess { interface OnPushMessageSuccess {
type: 'click' | 'receive' type: 'click' | 'receive'
data: unknown data: unknown
stopped?: boolean
} }
type OnPushMessageCallback = (result: OnPushMessageSuccess) => void type OnPushMessageCallback = (result: OnPushMessageSuccess) => void
......
...@@ -11096,17 +11096,12 @@ function invokePushCallback(args) { ...@@ -11096,17 +11096,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg); invokeGetPushCidCallbacks(cid, args.errMsg);
} }
else if (args.type === 'pushMsg') { else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg = { callback({
type: 'receive', type: 'receive',
data: normalizePushMessage(args.message), data: normalizePushMessage(args.message),
}; });
onPushMessageCallbacks[i](msg); });
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
} }
else if (args.type === 'click') { else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
......
...@@ -4625,16 +4625,12 @@ function invokePushCallback(args) { ...@@ -4625,16 +4625,12 @@ function invokePushCallback(args) {
cidErrMsg = args.errMsg; cidErrMsg = args.errMsg;
invokeGetPushCidCallbacks(cid, args.errMsg); invokeGetPushCidCallbacks(cid, args.errMsg);
} else if (args.type === "pushMsg") { } else if (args.type === "pushMsg") {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg = { callback({
type: "receive", type: "receive",
data: normalizePushMessage(args.message) data: normalizePushMessage(args.message)
}; });
onPushMessageCallbacks[i](msg); });
if (msg.stopped) {
break;
}
}
} else if (args.type === "click") { } else if (args.type === "click") {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
callback({ callback({
......
...@@ -671,17 +671,12 @@ function invokePushCallback(args) { ...@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg); invokeGetPushCidCallbacks(cid, args.errMsg);
} }
else if (args.type === 'pushMsg') { else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg = { callback({
type: 'receive', type: 'receive',
data: normalizePushMessage(args.message), data: normalizePushMessage(args.message),
}; });
onPushMessageCallbacks[i](msg); });
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
} }
else if (args.type === 'click') { else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
......
...@@ -671,17 +671,12 @@ function invokePushCallback(args) { ...@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg); invokeGetPushCidCallbacks(cid, args.errMsg);
} }
else if (args.type === 'pushMsg') { else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg = { callback({
type: 'receive', type: 'receive',
data: normalizePushMessage(args.message), data: normalizePushMessage(args.message),
}; });
onPushMessageCallbacks[i](msg); });
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
} }
else if (args.type === 'click') { else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
......
...@@ -671,17 +671,12 @@ function invokePushCallback(args) { ...@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg); invokeGetPushCidCallbacks(cid, args.errMsg);
} }
else if (args.type === 'pushMsg') { else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg = { callback({
type: 'receive', type: 'receive',
data: normalizePushMessage(args.message), data: normalizePushMessage(args.message),
}; });
onPushMessageCallbacks[i](msg); });
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
} }
else if (args.type === 'click') { else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
......
...@@ -671,17 +671,12 @@ function invokePushCallback(args) { ...@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg); invokeGetPushCidCallbacks(cid, args.errMsg);
} }
else if (args.type === 'pushMsg') { else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg = { callback({
type: 'receive', type: 'receive',
data: normalizePushMessage(args.message), data: normalizePushMessage(args.message),
}; });
onPushMessageCallbacks[i](msg); });
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
} }
else if (args.type === 'click') { else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
......
...@@ -671,17 +671,12 @@ function invokePushCallback(args) { ...@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg); invokeGetPushCidCallbacks(cid, args.errMsg);
} }
else if (args.type === 'pushMsg') { else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg = { callback({
type: 'receive', type: 'receive',
data: normalizePushMessage(args.message), data: normalizePushMessage(args.message),
}; });
onPushMessageCallbacks[i](msg); });
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
} }
else if (args.type === 'click') { else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
......
...@@ -671,17 +671,12 @@ function invokePushCallback(args) { ...@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg); invokeGetPushCidCallbacks(cid, args.errMsg);
} }
else if (args.type === 'pushMsg') { else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg = { callback({
type: 'receive', type: 'receive',
data: normalizePushMessage(args.message), data: normalizePushMessage(args.message),
}; });
onPushMessageCallbacks[i](msg); });
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
} }
else if (args.type === 'click') { else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
......
...@@ -635,17 +635,12 @@ function invokePushCallback(args) { ...@@ -635,17 +635,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg); invokeGetPushCidCallbacks(cid, args.errMsg);
} }
else if (args.type === 'pushMsg') { else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg = { callback({
type: 'receive', type: 'receive',
data: normalizePushMessage(args.message), data: normalizePushMessage(args.message),
}; });
onPushMessageCallbacks[i](msg); });
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
} }
else if (args.type === 'click') { else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
......
...@@ -100,41 +100,6 @@ e?.onClose(t); ...@@ -100,41 +100,6 @@ e?.onClose(t);
var GtPush = /*@__PURE__*/getDefaultExportFromCjs(gtpushMin); var GtPush = /*@__PURE__*/getDefaultExportFromCjs(gtpushMin);
function initPushRoute() {
// @ts-expect-error
uni.onPushMessage((res) => {
if (res.data && res.data.path) {
if (res.type === 'click') {
const url = res.data.path;
// 优先使用 navigateTo
uni.navigateTo({
url,
fail(result) {
// 说明是 tabBar 页面,必须使用 switchTab
if (result.errMsg.indexOf('tabbar')) {
uni.switchTab({
url,
});
}
},
});
}
else if (res.type === 'receive') {
// 仅 App 端
if (typeof plus !== 'undefined' && plus.push) {
// 创建通知栏,并屏蔽消息的继续传递
plus.push.createMessage(res.data.content, JSON.stringify(res.data.payload), {
title: res.data.title,
path: res.data.path,
});
// 内部属性,停止传播
res.stopped = true;
}
}
}
});
}
// if (process.env.UNI_PUSH_DEBUG) { // if (process.env.UNI_PUSH_DEBUG) {
// GtPush.setDebugMode(true) // GtPush.setDebugMode(true)
// } // }
...@@ -187,15 +152,4 @@ else { ...@@ -187,15 +152,4 @@ else {
}); });
}, },
}); });
initPushRoute();
// 不用条件编译。App端仍需监听
if (typeof plus !== 'undefined' && plus.push) {
plus.push.addEventListener('click', (result) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'click',
message: result,
});
});
}
} }
function initPushRoute() {
// @ts-expect-error
uni.onPushMessage((res) => {
if (res.data && res.data.path) {
if (res.type === 'click') {
const url = res.data.path;
// 优先使用 navigateTo
uni.navigateTo({
url,
fail(result) {
// 说明是 tabBar 页面,必须使用 switchTab
if (result.errMsg.indexOf('tabbar')) {
uni.switchTab({
url,
});
}
},
});
}
else if (res.type === 'receive') {
// 仅 App 端
if (typeof plus !== 'undefined' && plus.push) {
// 创建通知栏,并屏蔽消息的继续传递
plus.push.createMessage(res.data.content, JSON.stringify(res.data.payload), {
title: res.data.title,
path: res.data.path,
});
// 内部属性,停止传播
res.stopped = true;
}
}
}
});
}
// @ts-expect-error // @ts-expect-error
uni.invokePushCallback({ uni.invokePushCallback({
type: 'enabled', type: 'enabled',
}); });
initPushRoute();
Promise.resolve().then(() => { Promise.resolve().then(() => {
plus.push.setAutoNotification && plus.push.setAutoNotification(false); plus.push.setAutoNotification && plus.push.setAutoNotification(false);
const info = plus.push.getClientInfo(); const info = plus.push.getClientInfo();
......
import GtPush from '../lib/gtpush-min' import GtPush from '../lib/gtpush-min'
import { initPushRoute } from './route'
// if (process.env.UNI_PUSH_DEBUG) { // if (process.env.UNI_PUSH_DEBUG) {
// GtPush.setDebugMode(true) // GtPush.setDebugMode(true)
...@@ -54,15 +53,4 @@ if (!appid) { ...@@ -54,15 +53,4 @@ if (!appid) {
}) })
}, },
}) })
initPushRoute()
// 不用条件编译。App端仍需监听
if (typeof plus !== 'undefined' && plus.push) {
plus.push.addEventListener('click', (result) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'click',
message: result,
})
})
}
} }
import { initPushRoute } from './route'
// @ts-expect-error // @ts-expect-error
uni.invokePushCallback({ uni.invokePushCallback({
type: 'enabled', type: 'enabled',
}) })
initPushRoute()
Promise.resolve().then(() => { Promise.resolve().then(() => {
plus.push.setAutoNotification && plus.push.setAutoNotification(false) plus.push.setAutoNotification && plus.push.setAutoNotification(false)
const info = plus.push.getClientInfo() const info = plus.push.getClientInfo()
......
...@@ -7,41 +7,23 @@ interface OnPushMessageSuccess { ...@@ -7,41 +7,23 @@ interface OnPushMessageSuccess {
forceNotification?: boolean forceNotification?: boolean
path?: string path?: string
} }
stopped?: boolean
} }
export function initPushRoute() { export function initPushRoute() {
// @ts-expect-error // @ts-expect-error
uni.onPushMessage((res: OnPushMessageSuccess) => { uni.onPushMessage((res: OnPushMessageSuccess) => {
if (res.data && res.data.path) { if (res.data && res.data.path && res.type === 'receive') {
if (res.type === 'click') { // 仅 App 端
const url = res.data.path if (typeof plus !== 'undefined' && plus.push) {
// 优先使用 navigateTo // 创建通知栏,并屏蔽消息的继续传递
uni.navigateTo({ plus.push.createMessage(
url, res.data.content,
fail(result) { JSON.stringify(res.data.payload),
// 说明是 tabBar 页面,必须使用 switchTab {
if (result.errMsg.indexOf('tabbar')) { title: res.data.title,
uni.switchTab({ forceNotification: true,
url, path: res.data.path,
}) } as any
} )
},
})
} else if (res.type === 'receive') {
// 仅 App 端
if (typeof plus !== 'undefined' && plus.push) {
// 创建通知栏,并屏蔽消息的继续传递
plus.push.createMessage(
res.data.content,
JSON.stringify(res.data.payload),
{
title: res.data.title,
path: res.data.path,
} as any
)
// 内部属性,停止传播
res.stopped = true
}
} }
} }
}) })
......
...@@ -671,17 +671,12 @@ function invokePushCallback(args) { ...@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg); invokeGetPushCidCallbacks(cid, args.errMsg);
} }
else if (args.type === 'pushMsg') { else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) { onPushMessageCallbacks.forEach((callback) => {
const msg = { callback({
type: 'receive', type: 'receive',
data: normalizePushMessage(args.message), data: normalizePushMessage(args.message),
}; });
onPushMessageCallbacks[i](msg); });
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
} }
else if (args.type === 'click') { else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => { onPushMessageCallbacks.forEach((callback) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册