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->transform(function (WebSocketDialogMsg $item) {
return $item->sendSuccess();
});
//
return Base::retSuccess('success', $list);
}

View File

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

View File

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

View File

@ -6,7 +6,7 @@
<div v-if="msgData.created_at" class="message-foot">
<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" />
</div>
<div v-else class="message-foot"><Loading/></div>
@ -15,6 +15,8 @@
</template>
<script>
import {mapState} from "vuex";
export default {
name: "MessageView",
props: {
@ -26,7 +28,32 @@ export default {
},
},
mounted() {
this.readMarking()
},
computed: {
...mapState(['userId']),
},
watch: {
msgData() {
this.readMarking()
}
},
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) {
let time = Math.round(new Date(date).getTime() / 1000),
string = '';