mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-06 21:45:36 +00:00
perf: [notice|tag|todo]类型的消息静默推送
This commit is contained in:
parent
d9696d2398
commit
97d041076d
@ -593,18 +593,20 @@ class WebSocketDialogMsg extends AbstractModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送消息、修改消息
|
* 发送消息、修改消息
|
||||||
* @param string $action 动作
|
* @param string $action 动作
|
||||||
* - reply-98:回复消息ID-98
|
* - reply-98:回复消息ID=98
|
||||||
* - update-99:更新消息ID-99
|
* - update-99:更新消息ID=99
|
||||||
* @param int $dialog_id 会话ID(即 聊天室ID)
|
* @param int $dialog_id 会话ID(即 聊天室ID)
|
||||||
* @param string $type 消息类型
|
* @param string $type 消息类型
|
||||||
* @param array $msg 发送的消息
|
* @param array $msg 发送的消息
|
||||||
* @param int $sender 发送的会员ID(默认自己,0为系统)
|
* @param int $sender 发送的会员ID(默认自己,0为系统)
|
||||||
* @param bool $push_self 是否推送给自己
|
* @param bool $push_self 推送-是否推给自己
|
||||||
* @param bool $push_retry 推送失败后重试1次(有时候在事务里执行,数据还没生成时会出现找不到消息的情况)
|
* @param bool $push_retry 推送-失败后重试1次(有时候在事务里执行,数据还没生成时会出现找不到消息的情况)
|
||||||
|
* @param bool|null $push_silence 推送-静默
|
||||||
|
* - type = [notice|tag|todo] 默认为:true
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function sendMsg($action, $dialog_id, $type, $msg, $sender = 0, $push_self = false, $push_retry = false)
|
public static function sendMsg($action, $dialog_id, $type, $msg, $sender = 0, $push_self = false, $push_retry = false, $push_silence = null)
|
||||||
{
|
{
|
||||||
$link = 0;
|
$link = 0;
|
||||||
$mtype = $type;
|
$mtype = $type;
|
||||||
@ -620,6 +622,9 @@ class WebSocketDialogMsg extends AbstractModel
|
|||||||
$mtype = 'image';
|
$mtype = 'image';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($push_silence === null) {
|
||||||
|
$push_silence = in_array($type, ['notice', 'tag', 'todo']);
|
||||||
|
}
|
||||||
//
|
//
|
||||||
$update_id = preg_match("/^update-(\d+)$/", $action, $match) ? $match[1] : 0;
|
$update_id = preg_match("/^update-(\d+)$/", $action, $match) ? $match[1] : 0;
|
||||||
$reply_id = preg_match("/^reply-(\d+)$/", $action, $match) ? $match[1] : 0;
|
$reply_id = preg_match("/^reply-(\d+)$/", $action, $match) ? $match[1] : 0;
|
||||||
@ -691,6 +696,9 @@ class WebSocketDialogMsg extends AbstractModel
|
|||||||
if ($push_retry) {
|
if ($push_retry) {
|
||||||
$task->setMsgNotExistRetry(true);
|
$task->setMsgNotExistRetry(true);
|
||||||
}
|
}
|
||||||
|
if ($push_silence) {
|
||||||
|
$task->setSilence($push_silence);
|
||||||
|
}
|
||||||
Task::deliver($task);
|
Task::deliver($task);
|
||||||
//
|
//
|
||||||
return Base::retSuccess('发送成功', $dialogMsg);
|
return Base::retSuccess('发送成功', $dialogMsg);
|
||||||
|
|||||||
@ -21,7 +21,8 @@ class WebSocketDialogMsgTask extends AbstractTask
|
|||||||
{
|
{
|
||||||
protected $id;
|
protected $id;
|
||||||
protected $ignoreFd;
|
protected $ignoreFd;
|
||||||
protected $msgNotExistRetry = false;
|
protected $msgNotExistRetry = false; // 推送失败后重试
|
||||||
|
protected $silence = false; // 静默推送(1:前端不通知、2:App不推送)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebSocketDialogMsgTask constructor.
|
* WebSocketDialogMsgTask constructor.
|
||||||
@ -50,6 +51,14 @@ class WebSocketDialogMsgTask extends AbstractTask
|
|||||||
$this->msgNotExistRetry = $msgNotExistRetry;
|
$this->msgNotExistRetry = $msgNotExistRetry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $silence
|
||||||
|
*/
|
||||||
|
public function setSilence(bool $silence): void
|
||||||
|
{
|
||||||
|
$this->silence = $silence;
|
||||||
|
}
|
||||||
|
|
||||||
public function start()
|
public function start()
|
||||||
{
|
{
|
||||||
global $_A;
|
global $_A;
|
||||||
@ -120,6 +129,7 @@ class WebSocketDialogMsgTask extends AbstractTask
|
|||||||
'msg' => [
|
'msg' => [
|
||||||
'type' => 'dialog',
|
'type' => 'dialog',
|
||||||
'mode' => 'add',
|
'mode' => 'add',
|
||||||
|
'silence' => $this->silence ? 1 : 0,
|
||||||
'data' => array_merge($msg->toArray(), [
|
'data' => array_merge($msg->toArray(), [
|
||||||
'mention' => $mention,
|
'mention' => $mention,
|
||||||
]),
|
]),
|
||||||
@ -127,23 +137,25 @@ class WebSocketDialogMsgTask extends AbstractTask
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// umeng推送app
|
// umeng推送app
|
||||||
$umengUserid = $array;
|
if (!$this->silence) {
|
||||||
if (isset($umengUserid[$msg->userid])) {
|
$umengUserid = $array;
|
||||||
unset($umengUserid[$msg->userid]);
|
if (isset($umengUserid[$msg->userid])) {
|
||||||
|
unset($umengUserid[$msg->userid]);
|
||||||
|
}
|
||||||
|
$umengUserid = array_keys($umengUserid);
|
||||||
|
$umengTitle = User::userid2nickname($msg->userid);
|
||||||
|
if ($dialog->type == 'group') {
|
||||||
|
$umengTitle = "{$dialog->getGroupName()} ($umengTitle)";
|
||||||
|
}
|
||||||
|
$umengMsg = new PushUmengMsg($umengUserid, [
|
||||||
|
'title' => $umengTitle,
|
||||||
|
'body' => $msg->previewMsg(),
|
||||||
|
'description' => "MID:{$msg->id}",
|
||||||
|
'seconds' => 3600,
|
||||||
|
'badge' => 1,
|
||||||
|
]);
|
||||||
|
Task::deliver($umengMsg);
|
||||||
}
|
}
|
||||||
$umengUserid = array_keys($umengUserid);
|
|
||||||
$umengTitle = User::userid2nickname($msg->userid);
|
|
||||||
if ($dialog->type == 'group') {
|
|
||||||
$umengTitle = "{$dialog->getGroupName()} ($umengTitle)";
|
|
||||||
}
|
|
||||||
$umengMsg = new PushUmengMsg($umengUserid, [
|
|
||||||
'title' => $umengTitle,
|
|
||||||
'body' => $msg->previewMsg(),
|
|
||||||
'description' => "MID:{$msg->id}",
|
|
||||||
'seconds' => 3600,
|
|
||||||
'badge' => 1,
|
|
||||||
]);
|
|
||||||
Task::deliver($umengMsg);
|
|
||||||
|
|
||||||
// 推送目标②:正在打开这个任务会话的会员
|
// 推送目标②:正在打开这个任务会话的会员
|
||||||
if ($dialog->type == 'group' && $dialog->group_type == 'task') {
|
if ($dialog->type == 'group' && $dialog->group_type == 'task') {
|
||||||
@ -162,6 +174,7 @@ class WebSocketDialogMsgTask extends AbstractTask
|
|||||||
'msg' => [
|
'msg' => [
|
||||||
'type' => 'dialog',
|
'type' => 'dialog',
|
||||||
'mode' => 'chat',
|
'mode' => 'chat',
|
||||||
|
'silence' => $this->silence ? 1 : 0,
|
||||||
'data' => $msg->toArray(),
|
'data' => $msg->toArray(),
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|||||||
6
resources/assets/js/store/actions.js
vendored
6
resources/assets/js/store/actions.js
vendored
@ -2492,7 +2492,7 @@ export default {
|
|||||||
*/
|
*/
|
||||||
case "dialog": // 更新会话
|
case "dialog": // 更新会话
|
||||||
(function (msg) {
|
(function (msg) {
|
||||||
const {mode, data} = msg;
|
const {mode, silence, data} = msg;
|
||||||
const {dialog_id} = data;
|
const {dialog_id} = data;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 'delete':
|
case 'delete':
|
||||||
@ -2548,7 +2548,9 @@ export default {
|
|||||||
dispatch("saveDialog", newData)
|
dispatch("saveDialog", newData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Store.set('dialogMsgPush', data);
|
if (!silence) {
|
||||||
|
Store.set('dialogMsgPush', data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 更新消息列表
|
// 更新消息列表
|
||||||
dispatch("saveDialogMsg", data)
|
dispatch("saveDialogMsg", data)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user