Commit 1ee879ff by Sixong.Zhu

update

parent 8b24464a
......@@ -31,7 +31,7 @@
class="chat-input flex-none h-100"
v-if="hasInput"
>
<message-input @error="onError" />
<message-input @error="onError" @sent="onMessageSent" />
</div>
</div>
</div>
......@@ -70,6 +70,11 @@
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR)
private readonly chatError!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR;
@chatStore.Getter(ChatStore.GETTER_CURRENT_CURRENT_CHAT)
private readonly currentChat!: ChatStore.GETTER_CURRENT_CURRENT_CHAT;
private setting = 0;
private get hasInput() {
return this.isChatMember && this.chatError !== this.chatId;
}
......@@ -131,6 +136,21 @@
private openPayMessage(id: number) {
this.$emit("open-pay-message", id);
}
private onMessageSent() {
if (this.setting) {
clearTimeout(this.setting);
}
this.setting = setTimeout(
() =>
this.currentChat &&
Chat.setRead(
this.currentChat.model_name,
this.currentChat.obj_id
),
300
);
}
}
</script>
......
......@@ -146,14 +146,16 @@ class Chat {
return Promise.resolve(uri);
}
return new Promise<void>((resolve, reject) => {
xim.open(uri, this.token).catch(reject).finally(() => {
this.registerXimEvent();
if (xim.isConnected()) {
resolve();
} else {
reject(new Error(`xim is not connected`));
}
});
xim.open(uri, this.token)
.catch(reject)
.finally(() => {
this.registerXimEvent();
if (xim.isConnected()) {
resolve();
} else {
reject(new Error(`xim is not connected`));
}
});
});
}
......@@ -203,6 +205,15 @@ class Chat {
public getAvatar() {
return this.defaultAvatar;
}
public setRead(model: string, obj: string) {
if (this.isBackend()) {
const sdk = this.getSdk();
if (sdk) {
sdk.getAxios().post(`/general/xim/model/${model}/${obj}/read`);
}
}
}
}
export default new Chat();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment