消息转发功能

This commit is contained in:
kuaifan 2022-06-03 10:43:46 +08:00
parent a2dcd69efd
commit c08240db42
3 changed files with 105 additions and 1 deletions

View File

@ -650,6 +650,35 @@ class DialogController extends AbstractController
]);
}
/**
* @api {get} api/dialog/msg/forward 13. 转发消息给
*
* @apiDescription 需要token身份
* @apiVersion 1.0.0
* @apiGroup dialog
* @apiName msg__forward
*
* @apiParam {Number} msg_id 消息ID
* @apiParam {Array} userids 转发给的成员
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function msg__forward()
{
$user = User::auth();
//
$msg_id = intval(Request::input("msg_id"));
$userids = Request::input('userids');
//
$msg = WebSocketDialogMsg::whereId($msg_id)->whereUserid($user->userid)->first();
if (empty($msg)) {
return Base::retError("消息不存在或已被删除");
}
return $msg->forwardMsg($userids, $user->userid);
}
/**
* @api {get} api/dialog/group/add 16. 新增群组
*

View File

@ -161,6 +161,34 @@ class WebSocketDialogMsg extends AbstractModel
return true;
}
/**
* 转发消息
* @param $userids
* @param int $sender 发送的会员ID
* @return mixed
*/
public function forwardMsg($userids, $sender)
{
return AbstractModel::transaction(function() use ($sender, $userids) {
$msgs = [];
foreach ($userids as $userid) {
if (!User::whereUserid($userid)->exists()) {
continue;
}
$dialog = WebSocketDialog::checkUserDialog($sender, $userid);
if ($dialog) {
$res = self::sendMsg($dialog->id, $this->type, $this->getOriginal('msg'), $sender);
if (Base::isSuccess($res)) {
$msgs[] = $res['data'];
}
}
}
return Base::retSuccess('转发成功', [
'msgs' => $msgs
]);
});
}
/**
* 删除消息
* @return void

View File

@ -185,6 +185,22 @@
</div>
</Modal>
<!-- 转发 -->
<Modal
v-model="forwardShow"
:title="$L('转发')"
:mask-closable="false">
<Form ref="forwardForm" :model="forwardData" label-width="auto" @submit.native.prevent>
<FormItem prop="userids" :label="$L('转发给')">
<UserInput v-model="forwardData.userids" :multiple-max="20" :placeholder="$L('选择转发成员')"/>
</FormItem>
</Form>
<div slot="footer" class="adaption">
<Button type="default" @click="forwardShow=false">{{$L('取消')}}</Button>
<Button type="primary" :loading="forwardLoad" @click="onForward('submit')">{{$L('转发')}}</Button>
</div>
</Modal>
<!--群设置-->
<DrawerOverlay
v-model="groupInfoShow"
@ -252,6 +268,12 @@ export default {
createGroupData: {},
createGroupLoad: 0,
forwardShow: false,
forwardLoad: false,
forwardData: {
userids: [],
},
dialogDrag: false,
groupInfoShow: false,
@ -711,6 +733,31 @@ export default {
});
},
onForward(type) {
if (type === 'open') {
this.forwardData = {
userids: [],
msg_id: this.operateItem.id
};
this.forwardShow = true;
} else if (type === 'submit') {
this.forwardLoad = true;
this.$store.dispatch("call", {
url: 'dialog/msg/forward',
data: this.forwardData
}).then(({data, msg}) => {
this.forwardShow = false;
this.$store.dispatch("saveDialogMsg", data.msgs);
this.$store.dispatch("updateDialogLastMsg", data.msgs);
$A.messageSuccess(msg);
}).catch(({msg}) => {
$A.modalError(msg);
}).finally(_ => {
this.forwardLoad = false;
});
}
},
scrollInfo() {
if (!this.isReady) {
return {
@ -769,7 +816,7 @@ export default {
onOperate(name) {
switch (name) {
case "forward":
// todo
this.onForward('open')
break;
case "withdraw":