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

wip(push): revert

上级 0ea54487
......@@ -54,17 +54,12 @@ export function invokePushCallback(
cidErrMsg = args.errMsg
invokeGetPushCidCallbacks(cid, args.errMsg)
} else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg: OnPushMessageSuccess = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message),
}
onPushMessageCallbacks[i](msg)
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break
}
}
})
})
} else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
callback({
......@@ -111,7 +106,6 @@ export const getPushClientId = defineAsyncApi(
interface OnPushMessageSuccess {
type: 'click' | 'receive'
data: unknown
stopped?: boolean
}
type OnPushMessageCallback = (result: OnPushMessageSuccess) => void
......
......@@ -11096,17 +11096,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg);
}
else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message),
};
onPushMessageCallbacks[i](msg);
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
});
});
}
else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
......
......@@ -4625,16 +4625,12 @@ function invokePushCallback(args) {
cidErrMsg = args.errMsg;
invokeGetPushCidCallbacks(cid, args.errMsg);
} else if (args.type === "pushMsg") {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: "receive",
data: normalizePushMessage(args.message)
};
onPushMessageCallbacks[i](msg);
if (msg.stopped) {
break;
}
}
});
});
} else if (args.type === "click") {
onPushMessageCallbacks.forEach((callback) => {
callback({
......
......@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg);
}
else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message),
};
onPushMessageCallbacks[i](msg);
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
});
});
}
else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
......
......@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg);
}
else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message),
};
onPushMessageCallbacks[i](msg);
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
});
});
}
else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
......
......@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg);
}
else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message),
};
onPushMessageCallbacks[i](msg);
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
});
});
}
else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
......
......@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg);
}
else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message),
};
onPushMessageCallbacks[i](msg);
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
});
});
}
else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
......
......@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg);
}
else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message),
};
onPushMessageCallbacks[i](msg);
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
});
});
}
else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
......
......@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg);
}
else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message),
};
onPushMessageCallbacks[i](msg);
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
});
});
}
else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
......
......@@ -635,17 +635,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg);
}
else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message),
};
onPushMessageCallbacks[i](msg);
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
});
});
}
else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
......
......@@ -100,41 +100,6 @@ e?.onClose(t);
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) {
// GtPush.setDebugMode(true)
// }
......@@ -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
uni.invokePushCallback({
type: 'enabled',
});
initPushRoute();
Promise.resolve().then(() => {
plus.push.setAutoNotification && plus.push.setAutoNotification(false);
const info = plus.push.getClientInfo();
......
import GtPush from '../lib/gtpush-min'
import { initPushRoute } from './route'
// if (process.env.UNI_PUSH_DEBUG) {
// GtPush.setDebugMode(true)
......@@ -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
uni.invokePushCallback({
type: 'enabled',
})
initPushRoute()
Promise.resolve().then(() => {
plus.push.setAutoNotification && plus.push.setAutoNotification(false)
const info = plus.push.getClientInfo()
......
......@@ -7,41 +7,23 @@ interface OnPushMessageSuccess {
forceNotification?: boolean
path?: string
}
stopped?: boolean
}
export function initPushRoute() {
// @ts-expect-error
uni.onPushMessage((res: OnPushMessageSuccess) => {
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,
} as any
)
// 内部属性,停止传播
res.stopped = true
}
if (res.data && res.data.path && 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,
forceNotification: true,
path: res.data.path,
} as any
)
}
}
})
......
......@@ -671,17 +671,12 @@ function invokePushCallback(args) {
invokeGetPushCidCallbacks(cid, args.errMsg);
}
else if (args.type === 'pushMsg') {
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const msg = {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message),
};
onPushMessageCallbacks[i](msg);
if (msg.stopped) {
// 消息被中断,比如页面直达的 push 信息
break;
}
}
});
});
}
else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册