feat: 消息右键对话新增:标记已读、标记未读

This commit is contained in:
韦荣超 2022-03-08 09:06:38 +08:00
parent e5901f28e3
commit bc6fa7fd27
2 changed files with 64 additions and 0 deletions

View File

@ -487,4 +487,46 @@ class DialogController extends AbstractController
$dialogUser->save(); $dialogUser->save();
return Base::retSuccess("success", $dialogId); return Base::retSuccess("success", $dialogId);
} }
/**
* @api {get} api/dialog/msg/mark 13. 消息标记操作
*
* @apiDescription 需要token身份
* @apiVersion 1.0.0
* @apiGroup dialog
* @apiName msg__mark
*
* @apiParam {Number} dialog_id 消息ID
* @apiParam {String} type 类型
* - read
* - unread
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function msg__mark()
{
$user = User::auth();
$dialogId = intval(Request::input('dialog_id'));
$type = Request::input('type');
if ($type == 'read') {
WebSocketDialogMsgRead::whereUserid($user->userid)
->whereReadAt(null)
->whereDialogId($dialogId)
->update(
[
'read_at' => Carbon::now()
]);
} elseif ($type == 'unread') {
$msgRead = WebSocketDialogMsgRead::whereUserid(User::userid())->whereDialogId($dialogId)->orderByDesc('id')->first();
if (!$msgRead) {
return Base::retError("对方未发任何消息,没法设置未读");
}
$msgRead->read_at = null;
$msgRead->save();
}
return Base::retSuccess("success");
}
} }

View File

@ -85,6 +85,12 @@
<DropdownItem @click.native="handleTopClick"> <DropdownItem @click.native="handleTopClick">
{{ $L(topOperateItem.top_at ? '取消置顶' : '置顶该聊天') }} {{ $L(topOperateItem.top_at ? '取消置顶' : '置顶该聊天') }}
</DropdownItem> </DropdownItem>
<DropdownItem @click.native="updateRead('read')" v-if="topOperateItem.unread > 0">
{{ $L('标记已读') }}
</DropdownItem>
<DropdownItem @click.native="updateRead('unread')" v-else>
{{ $L('标记未读') }}
</DropdownItem>
</DropdownMenu> </DropdownMenu>
</Dropdown> </Dropdown>
</div> </div>
@ -480,6 +486,22 @@ export default {
$A.modalError(msg, 301); $A.modalError(msg, 301);
this.$Modal.remove(); this.$Modal.remove();
}); });
},
updateRead(type) {
this.$store.dispatch("call", {
url: 'dialog/msg/mark',
data: {
dialog_id: this.topOperateItem.id,
type: type
},
}).then(() => {
this.$store.dispatch("getDialogs");
this.$Modal.remove();
}).catch(({msg}) => {
$A.modalError(msg, 301);
this.$Modal.remove();
});
} }
} }
} }