<commit_before>import {
  isFn,
  isPlainObject
} from 'uni-shared'
import {
  getApiCallbacks
} from 'uni-helpers/utils'

let cid
let cidErrMsg

function normalizePushMessage (message) {
  try {
    return JSON.parse(message)
  } catch (e) {}
  return message
}

export function invokePushCallback (
  args
) {
  if (args.type === 'clientId') {
    cid = args.cid
    cidErrMsg = args.errMsg
    invokeGetPushCidCallbacks(cid, args.errMsg)
  } else if (args.type === 'pushMsg') {
    onPushMessageCallbacks.forEach((callback) => {
      callback({
        type: 'receive',
        data: normalizePushMessage(args.message)
      })
    })
  } else if (args.type === 'click') {
    onPushMessageCallbacks.forEach((callback) => {
      callback({
        type: 'click',
        data: normalizePushMessage(args.message)
      })
    })
  }<commit_msg>feat(push): normalize message<commit_after>import {
  isFn,
  isPlainObject
} from 'uni-shared'
import {
  getApiCallbacks
} from 'uni-helpers/utils'

let cid
let cidErrMsg

function normalizePushMessage (type, message) {
  try {
    const res = JSON.parse(message)
    if (type === 'receive') {
      if (res.payload) {
        if (res.aps) {
          res.payload.aps = res.aps
        }
        return res.payload
      }
    } else if (type === 'click') {
      delete res.type
      delete res.__UUID__
      delete res.appid
      if (res.aps && res.aps.alert) {
        res.title = res.aps.alert.title
      }
    }
  } catch (e) {}
  return message
}

export function invokePushCallback (
  args
) {
  if (args.type === 'clientId') {
    cid = args.cid
    cidErrMsg = args.errMsg
    invokeGetPushCidCallbacks(cid, args.errMsg)
  } else if (args.type === 'pushMsg') {
    onPushMessageCallbacks.forEach((callback) => {
      callback({
        type: 'receive',
        data: normalizePushMessage('receive', args.message)
      })
    })
  } else if (args.type === 'click') {
    onPushMessageCallbacks.forEach((callback) => {
      callback({
        type: 'click',
        data: normalizePushMessage('click', args.message)
      })
    })
  }
{'fraction_non_alphanumeric': 0.13476190476190475, 'fraction_numerical': 0.0, 'mean_word_length': 2.5792163543441227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6120451', 'n_tokens_mistral': 696, 'n_tokens_neox': 690, 'n_words': 144}