删除会话之后要将未读消息给清零

This commit is contained in:
kuaifan
2021-06-23 15:47:47 +08:00
parent 72ca5579fb
commit 3eb22784d5
3 changed files with 26 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Models;
use App\Exceptions\ApiException;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
@@ -47,6 +48,21 @@ class WebSocketDialog extends AbstractModel
return $this->hasMany(WebSocketDialogUser::class, 'dialog_id', 'id');
}
/**
* 删除会话
* @return bool
*/
public function deleteDialog()
{
AbstractModel::transaction(function () {
WebSocketDialogMsgRead::whereDialogId($this->id)->whereNull('read_at')->update([
'read_at' => Carbon::now()
]);
$this->delete();
});
return true;
}
/**
* 获取对话(同时检验对话身份)
* @param $id