no message

This commit is contained in:
kuaifan 2021-06-05 00:23:22 +08:00
parent b78e30c2f0
commit 3670e2ce2c
4 changed files with 41 additions and 11 deletions

View File

@ -44,9 +44,6 @@ class DialogController extends AbstractController
} }
// //
$list = WebSocketDialogMsg::whereDialogId($dialog_id)->orderByDesc('id')->paginate(Base::getPaginate(100, 50)); $list = WebSocketDialogMsg::whereDialogId($dialog_id)->orderByDesc('id')->paginate(Base::getPaginate(100, 50));
$list->transform(function (WebSocketDialogMsg $item) {
return $item->sendSuccess();
});
// //
return Base::retSuccess('success', $list); return Base::retSuccess('success', $list);
} }

View File

@ -15,7 +15,7 @@ use Carbon\Carbon;
* @property int|null $userid 发送会员ID * @property int|null $userid 发送会员ID
* @property string|null $type 消息类型 * @property string|null $type 消息类型
* @property array|mixed $msg 详细消息 * @property array|mixed $msg 详细消息
* @property int|null $send 是否已送达 * @property int|null $read 是否已读
* @property int|null $extra_int 额外数字参数 * @property int|null $extra_int 额外数字参数
* @property string|null $extra_str 额外字符参数 * @property string|null $extra_str 额外字符参数
* @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $created_at
@ -29,7 +29,7 @@ use Carbon\Carbon;
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereExtraStr($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereExtraStr($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereMsg($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereMsg($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereSend($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereRead($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereType($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereUserid($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereUserid($value)
@ -58,10 +58,10 @@ class WebSocketDialogMsg extends AbstractModel
* 标记已送达 同时 告诉发送人已送达 * 标记已送达 同时 告诉发送人已送达
* @return $this * @return $this
*/ */
public function sendSuccess() public function readSuccess()
{ {
if (empty($this->send)) { if (empty($this->read)) {
$this->send = 1; $this->read = 1;
$this->save(); $this->save();
PushTask::push([ PushTask::push([
'userid' => $this->userid, 'userid' => $this->userid,

View File

@ -114,8 +114,14 @@ class WebSocketService implements WebSocketHandlerInterface
* 收到回执 * 收到回执
*/ */
case 'receipt': case 'receipt':
$dialogMsg = WebSocketDialogMsg::whereId(intval($msgId))->first(); return;
$dialogMsg && $dialogMsg->sendSuccess();
/**
* 已阅消息
*/
case 'readMsg':
$dialogMsg = WebSocketDialogMsg::whereId(intval($data['id']))->first();
$dialogMsg && $dialogMsg->readSuccess();
return; return;
} }
// //

View File

@ -6,7 +6,7 @@
<div v-if="msgData.created_at" class="message-foot"> <div v-if="msgData.created_at" class="message-foot">
<div class="time">{{formatTime(msgData.created_at)}}</div> <div class="time">{{formatTime(msgData.created_at)}}</div>
<Icon v-if="msgData.send" class="done-all" type="md-done-all" /> <Icon v-if="msgData.read" class="done-all" type="md-done-all" />
<Icon v-else class="done" type="md-checkmark" /> <Icon v-else class="done" type="md-checkmark" />
</div> </div>
<div v-else class="message-foot"><Loading/></div> <div v-else class="message-foot"><Loading/></div>
@ -15,6 +15,8 @@
</template> </template>
<script> <script>
import {mapState} from "vuex";
export default { export default {
name: "MessageView", name: "MessageView",
props: { props: {
@ -26,7 +28,32 @@ export default {
}, },
}, },
mounted() {
this.readMarking()
},
computed: {
...mapState(['userId']),
},
watch: {
msgData() {
this.readMarking()
}
},
methods: { methods: {
readMarking() {
if (this.msgData.read === 0 && this.msgData.userid != this.userId) {
this.$store.commit('wsSend', {
type: 'readMsg',
data: {
id: this.msgData.id
}
});
}
},
formatTime(date) { formatTime(date) {
let time = Math.round(new Date(date).getTime() / 1000), let time = Math.round(new Date(date).getTime() / 1000),
string = ''; string = '';