no message

This commit is contained in:
kuaifan 2021-06-23 11:31:06 +08:00
parent e761820df1
commit f9031aec57
5 changed files with 54 additions and 44 deletions

View File

@ -111,12 +111,14 @@ class DialogController extends AbstractController
return $item; return $item;
}); });
// //
if ($dialog->type == 'group' && $dialog->group_type == 'task') {
$user->task_dialog_id = $dialog->id;
$user->save();
}
//
$data = $list->toArray(); $data = $list->toArray();
if ($list->currentPage() === 1) { if ($list->currentPage() === 1) {
$data['dialog'] = WebSocketDialog::formatData($dialog, $user->userid); $data['dialog'] = WebSocketDialog::formatData($dialog, $user->userid);
//
$user->dialog_id = $dialog->id;
$user->save();
} }
return Base::retSuccess('success', $data); return Base::retSuccess('success', $data);
} }

View File

@ -27,7 +27,7 @@ use Carbon\Carbon;
* @property string|null $last_at 最后登录时间 * @property string|null $last_at 最后登录时间
* @property string|null $line_ip 最后在线IP接口 * @property string|null $line_ip 最后在线IP接口
* @property string|null $line_at 最后在线时间(接口) * @property string|null $line_at 最后在线时间(接口)
* @property int|null $dialog_id 最后打开的会话ID * @property int|null $task_dialog_id 最后打开的任务会话ID
* @property string|null $created_ip 注册IP * @property string|null $created_ip 注册IP
* @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at * @property \Illuminate\Support\Carbon|null $updated_at
@ -38,7 +38,6 @@ use Carbon\Carbon;
* @method static \Illuminate\Database\Eloquent\Builder|User whereChangepass($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereChangepass($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedIp($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedIp($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereDialogId($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereEncrypt($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereEncrypt($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereIdentity($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereIdentity($value)
@ -50,6 +49,7 @@ use Carbon\Carbon;
* @method static \Illuminate\Database\Eloquent\Builder|User whereNickname($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereNickname($value)
* @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value) * @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereProfession($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereProfession($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereTaskDialogId($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereUserid($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereUserid($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereUserimg($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereUserimg($value)

View File

@ -63,13 +63,14 @@ class WebSocketDialogMsgTask extends AbstractTask
'ignoreFd' => $this->ignoreFd, 'ignoreFd' => $this->ignoreFd,
'msg' => [ 'msg' => [
'type' => 'dialog', 'type' => 'dialog',
'mode' => 'add1', 'mode' => 'add',
'data' => $msg->toArray(), 'data' => $msg->toArray(),
] ]
]); ]);
// 推送目标②:正在打开这个会话的会员 // 推送目标②:正在打开这个任务会话的会员
$list = User::whereDialogId($dialog->id)->pluck('userid')->toArray(); if ($dialog->type == 'group' && $dialog->group_type == 'task') {
$list = User::whereTaskDialogId($dialog->id)->pluck('userid')->toArray();
if ($list) { if ($list) {
$array = []; $array = [];
foreach ($list as $uid) { foreach ($list as $uid) {
@ -83,11 +84,12 @@ class WebSocketDialogMsgTask extends AbstractTask
'ignoreFd' => $this->ignoreFd, 'ignoreFd' => $this->ignoreFd,
'msg' => [ 'msg' => [
'type' => 'dialog', 'type' => 'dialog',
'mode' => 'add2', 'mode' => 'chat',
'data' => $msg->toArray(), 'data' => $msg->toArray(),
] ]
]); ]);
} }
} }
} }
}
} }

View File

@ -309,13 +309,9 @@ export default {
}, },
sendSuccess(data) { sendSuccess(data) {
this.$store.dispatch("saveDialog", {
id: this.dialogId,
last_msg: data,
last_at: $A.formatDate("Y-m-d H:i:s")
});
this.$store.dispatch("saveDialogMsg", data); this.$store.dispatch("saveDialogMsg", data);
this.$store.dispatch("dialogMoveTop", this.dialogId); this.$store.dispatch("updateDialogLastMsg", data);
this.$store.dispatch("moveDialogTop", this.dialogId);
this.$store.dispatch("increaseTaskMsgNum", this.dialogId); this.$store.dispatch("increaseTaskMsgNum", this.dialogId);
}, },

View File

@ -968,6 +968,25 @@ export default {
} }
}, },
/**
* 更新会话最后消息
* @param state
* @param dispatch
* @param data
*/
updateDialogLastMsg({state, dispatch}, data) {
let dialog = state.dialogs.find(({id}) => id == data.dialog_id);
if (dialog) {
dispatch("saveDialog", {
id: data.dialog_id,
last_msg: data,
last_at: state.method.formatDate("Y-m-d H:i:s")
});
} else {
dispatch("getDialogOne", data.dialog_id);
}
},
/** /**
* 获取会话列表 * 获取会话列表
* @param state * @param state
@ -1036,7 +1055,7 @@ export default {
* @param state * @param state
* @param dialog_id * @param dialog_id
*/ */
dialogMoveTop({state}, dialog_id) { moveDialogTop({state}, dialog_id) {
const index = state.dialogs.findIndex(({id}) => id == dialog_id); const index = state.dialogs.findIndex(({id}) => id == dialog_id);
if (index > -1) { if (index > -1) {
const tmp = state.method.cloneJSON(state.dialogs[index]); const tmp = state.method.cloneJSON(state.dialogs[index]);
@ -1271,27 +1290,18 @@ export default {
// 更新消息列表 // 更新消息列表
state.dialogMsgPush = data; state.dialogMsgPush = data;
dispatch("saveDialogMsg", data) dispatch("saveDialogMsg", data)
if (mode === "add2") { if (mode === "chat") {
return; return;
} }
// 更新最后消息 // 更新最后消息
let dialog = state.dialogs.find(({id}) => id == dialog_id); dispatch("updateDialogLastMsg", data);
if (dialog) { if (mode === "add") {
dispatch("saveDialog", {
id: dialog_id,
last_msg: data,
last_at: state.method.formatDate("Y-m-d H:i:s")
});
} else {
dispatch("getDialogOne", dialog_id);
}
if (mode === "add1") {
// 更新对话列表 // 更新对话列表
if (dialog) { if (dialog) {
// 新增未读数 // 新增未读数
if (data.userid !== state.userId) dialog.unread++; if (data.userid !== state.userId) dialog.unread++;
// 移动到首位 // 移动到首位
dispatch("dialogMoveTop", dialog_id); dispatch("moveDialogTop", dialog_id);
} }
// 新增任务消息数量 // 新增任务消息数量
dispatch("increaseTaskMsgNum", dialog_id); dispatch("increaseTaskMsgNum", dialog_id);