Commit 19a72930 by Sixong.Zhu

移除一些多余代码

parent ef2be082
...@@ -54,9 +54,6 @@ export default class ChatList extends Vue { ...@@ -54,9 +54,6 @@ export default class ChatList extends Vue {
@chatStore.Getter(ChatStore.STATE_CHAT_MSG_HISTORY) @chatStore.Getter(ChatStore.STATE_CHAT_MSG_HISTORY)
protected readonly historyMessage!: ChatStore.STATE_CHAT_MSG_HISTORY; protected readonly historyMessage!: ChatStore.STATE_CHAT_MSG_HISTORY;
@chatStore.Getter(ChatStore.STATE_CHAT_SENDING_MESSAGES)
protected readonly sendingMessages!: ChatStore.STATE_CHAT_SENDING_MESSAGES;
@chatStore.Mutation(ChatStore.MUTATION_CLEAR_CURRENT_CHAT_ID) @chatStore.Mutation(ChatStore.MUTATION_CLEAR_CURRENT_CHAT_ID)
protected readonly clearCurrentChatId!: ChatStore.MUTATION_CLEAR_CURRENT_CHAT_ID; protected readonly clearCurrentChatId!: ChatStore.MUTATION_CLEAR_CURRENT_CHAT_ID;
......
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
MESSAGE_FILE_EMPTY, MESSAGE_FILE_EMPTY,
MESSAGE_FILE_TOO_LARGE, MESSAGE_FILE_TOO_LARGE,
MESSAGE_IMAGE_TOO_LARGE, MESSAGE_IMAGE_TOO_LARGE,
} from "../components/message-item/file-controller"; } from "./message-item/file-controller";
import { EmojiItem, EmojiService } from "../service/emoji"; import { EmojiItem, EmojiService } from "../service/emoji";
import { ChatStore } from "../store/model"; import { ChatStore } from "../store/model";
import { formatFileSize } from "../utils"; import { formatFileSize } from "../utils";
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
width="90%" width="90%"
top="60px" top="60px"
> >
<div class="d-flex flex-column"> <div class="d-flex flex-column" v-if="value">
<div class="d-flex justify-content-center align-items-start"> <div class="d-flex justify-content-center align-items-start">
<img v-if="file" :src="file.url" :style="imgStyle" /> <img v-if="file" :src="file.url" :style="imgStyle" />
<i class="el-icon-close" @click="close"></i> <i class="el-icon-close" @click="close"></i>
......
...@@ -8,17 +8,13 @@ ...@@ -8,17 +8,13 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Ref, Vue, Watch } from "vue-property-decorator"; import { Component, Ref, Vue, Watch } from "vue-property-decorator";
import ChatInput, { import ChatInput, { isFileElement, isImageOrFile } from "./hybrid-input.vue";
isFileElement, import { MessageType } from "../model";
isImageOrFile,
} from "../hybrid-input/index.vue";
import { Message, MessageType } from "../model";
import { uploadFile } from "../service/upload"; import { uploadFile } from "../service/upload";
import xim from "../xim/xim"; import xim from "../xim/xim";
import Chat from "../xim";
import { ChatStore, chatStore } from "@/customer-service/store/model"; import { ChatStore, chatStore } from "@/customer-service/store/model";
let sendingMessageIndex = 1;
@Component({ components: { ChatInput } }) @Component({ components: { ChatInput } })
export default class MessageInput extends Vue { export default class MessageInput extends Vue {
@chatStore.State(ChatStore.STATE_CHAT_DIALOG_VISIBLE) @chatStore.State(ChatStore.STATE_CHAT_DIALOG_VISIBLE)
...@@ -39,15 +35,6 @@ ...@@ -39,15 +35,6 @@
@chatStore.Getter(ChatStore.STATE_CHAT_SOURCE) @chatStore.Getter(ChatStore.STATE_CHAT_SOURCE)
private readonly source!: ChatStore.STATE_CHAT_SOURCE; private readonly source!: ChatStore.STATE_CHAT_SOURCE;
@chatStore.Mutation(ChatStore.MUTATION_APPEND_SENDING_MESSAGE)
private readonly appendSendingMessages!: ChatStore.MUTATION_APPEND_SENDING_MESSAGE;
@chatStore.Mutation(ChatStore.MUTATION_FAILED_SENDING_MESSAGE)
private readonly failedSendingMessage!: ChatStore.MUTATION_FAILED_SENDING_MESSAGE;
@chatStore.Mutation(ChatStore.MUTATION_REMOVE_SENDING_MESSAGE)
private readonly removeSendingMessages!: ChatStore.MUTATION_REMOVE_SENDING_MESSAGE;
@Ref("chat-input") @Ref("chat-input")
private readonly chatInput!: ChatInput; private readonly chatInput!: ChatInput;
...@@ -128,7 +115,6 @@ ...@@ -128,7 +115,6 @@
size: number; size: number;
}; };
if (src) { if (src) {
const index = this.sendSendingMessage(type, src);
const file = await this.readBlobUrl2Base64(src.url, src.name); const file = await this.readBlobUrl2Base64(src.url, src.name);
if (file) { if (file) {
let w = 0; let w = 0;
...@@ -168,18 +154,11 @@ ...@@ -168,18 +154,11 @@
msgType: type, msgType: type,
msg: JSON.stringify(msg), msg: JSON.stringify(msg),
}); });
this.removeSendingMessages(index);
URL.revokeObjectURL(src.url); URL.revokeObjectURL(src.url);
return index;
} else {
this.setMsg2Failed(index);
} }
}) })
.catch((e) => { .catch(() => {
// eslint-disable-next-line no-console Chat.error("发送文件失败");
console.error(e);
this.setMsg2Failed(index);
this.chatInput && this.chatInput &&
this.chatInput.updateUploadProgress(0); this.chatInput.updateUploadProgress(0);
}); });
...@@ -187,28 +166,6 @@ ...@@ -187,28 +166,6 @@
} }
} }
private setMsg2Failed(index: number) {
this.failedSendingMessage(index);
}
private sendSendingMessage(type: string, msg: any) {
const index = sendingMessageIndex++;
if (this.source) {
Object.assign(msg, { source: this.source, eid: this.chatMyId });
}
if (this.chatId) {
this.appendSendingMessages({
id: -index,
chat_id: this.chatId,
ts: Date.now(),
type,
msg: JSON.stringify(msg),
} as Message);
return -index;
}
return 0;
}
private readBlobUrl2Base64(url: string, name: string) { private readBlobUrl2Base64(url: string, name: string) {
return fetch(url) return fetch(url)
.then((r) => r.blob()) .then((r) => r.blob())
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
{{ format2Time(item.ts) }} {{ format2Time(item.ts) }}
</div> </div>
<message <message
:is-sending-message="item.id < 0"
:failed="item.status === -1"
:key="item.id" :key="item.id"
:data="item" :data="item"
:shape="shape" :shape="shape"
...@@ -50,15 +48,13 @@ ...@@ -50,15 +48,13 @@
import { dbController } from "../database"; import { dbController } from "../database";
import { getLastMessageId } from "../store"; import { getLastMessageId } from "../store";
import { CustomerServiceEvent } from "../event"; import { CustomerServiceEvent } from "../event";
import xim from "../xim/xim";
@Component({ components: { message, ImagePreview, VideoPreview } }) @Component({ components: { message, ImagePreview, VideoPreview } })
export default class MessageList extends Vue { export default class MessageList extends Vue {
@chatStore.Getter(ChatStore.STATE_CHAT_MSG_HISTORY) @chatStore.Getter(ChatStore.STATE_CHAT_MSG_HISTORY)
private readonly historyMessage!: ChatStore.STATE_CHAT_MSG_HISTORY; private readonly historyMessage!: ChatStore.STATE_CHAT_MSG_HISTORY;
@chatStore.Getter(ChatStore.STATE_CHAT_SENDING_MESSAGES)
private readonly sendingMessages!: ChatStore.STATE_CHAT_SENDING_MESSAGES;
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_CHAT_ID) @chatStore.State(ChatStore.STATE_CHAT_CURRENT_CHAT_ID)
private readonly chatId!: ChatStore.STATE_CHAT_CURRENT_CHAT_ID; private readonly chatId!: ChatStore.STATE_CHAT_CURRENT_CHAT_ID;
...@@ -77,9 +73,6 @@ ...@@ -77,9 +73,6 @@
@chatStore.Mutation(ChatStore.MUTATION_CLEAR_FUNC_SCROLL_TO_BOTTOM) @chatStore.Mutation(ChatStore.MUTATION_CLEAR_FUNC_SCROLL_TO_BOTTOM)
private readonly clearScrollToBottomFunc!: ChatStore.MUTATION_CLEAR_FUNC_SCROLL_TO_BOTTOM; private readonly clearScrollToBottomFunc!: ChatStore.MUTATION_CLEAR_FUNC_SCROLL_TO_BOTTOM;
@chatStore.Mutation(ChatStore.MUTATION_SAVE_FUNC_ON_NEW_MSG)
private readonly onNewMessage!: ChatStore.MUTATION_SAVE_FUNC_ON_NEW_MSG;
@chatStore.Mutation(ChatStore.MUTATION_CLEAR_FUNC_ON_NEW_MSG) @chatStore.Mutation(ChatStore.MUTATION_CLEAR_FUNC_ON_NEW_MSG)
private readonly clearNewMessage!: ChatStore.MUTATION_CLEAR_FUNC_ON_NEW_MSG; private readonly clearNewMessage!: ChatStore.MUTATION_CLEAR_FUNC_ON_NEW_MSG;
...@@ -93,22 +86,7 @@ ...@@ -93,22 +86,7 @@
private shape!: string; private shape!: string;
private get messages() { private get messages() {
if (this.historyMessage) { return this.historyMessage || [];
if (this.sendingMessages && this.sendingMessages.length) {
return [...this.historyMessage, ...this.sendingMessages].filter(
(i) => i.chat_id === this.chatId && i.id > 0
);
}
return this.historyMessage;
}
if (this.sendingMessages && this.sendingMessages.length) {
return this.sendingMessages.filter(
(i) => i.chat_id === this.chatId && i.id > 0
);
}
return [];
} }
// 添加时间戳的最大间隔消息数 // 添加时间戳的最大间隔消息数
...@@ -338,7 +316,8 @@ ...@@ -338,7 +316,8 @@
const removingIds: number[] = []; const removingIds: number[] = [];
for (const item of data) { for (const item of data) {
if (item.type === MessageType.Withdraw) { if (item.type === MessageType.Withdraw) {
item.msg && removingIds.push(...JSON.parse(item.msg)); const o = xim.withDrawMsgHandle(item);
item.msg && removingIds.push(...o);
} }
} }
......
...@@ -99,13 +99,6 @@ ...@@ -99,13 +99,6 @@
> >
</div> </div>
<i
class="el-icon-warning text-danger"
v-if="failed"
title="发送失败"
></i>
<i class="el-icon-loading" v-else-if="isSendingMessage"></i>
<span class="withdraw" v-if="showWithdraw" @click="withdraw" <span class="withdraw" v-if="showWithdraw" @click="withdraw"
>撤回此消息</span >撤回此消息</span
> >
...@@ -247,12 +240,6 @@ ...@@ -247,12 +240,6 @@
@Prop({ type: Object, default: () => Object.create(null) }) @Prop({ type: Object, default: () => Object.create(null) })
private readonly data!: dto.Message; private readonly data!: dto.Message;
@Prop()
private readonly isSendingMessage!: boolean;
@Prop()
private readonly failed!: boolean;
@Prop({ default: "circle" }) @Prop({ default: "circle" })
private readonly shape!: string; private readonly shape!: string;
...@@ -371,10 +358,6 @@ ...@@ -371,10 +358,6 @@
} }
private get isMyMessage() { private get isMyMessage() {
if (this.isSendingMessage) {
return true;
}
// 系统推送的消息或老用户(一般是客服,eid为负数),默认为客服发送 // 系统推送的消息或老用户(一般是客服,eid为负数),默认为客服发送
if ( if (
this.messageBody && this.messageBody &&
...@@ -554,12 +537,6 @@ ...@@ -554,12 +537,6 @@
} }
private openFile(url: string) { private openFile(url: string) {
if (this.isSendingMessage) {
return;
}
if (this.failed) {
return;
}
const copy = { ...this.messageBody.msg }; const copy = { ...this.messageBody.msg };
copy.url = url; copy.url = url;
this.$emit("open", { type: this.messageType, msg: copy }); this.$emit("open", { type: this.messageType, msg: copy });
......
...@@ -390,7 +390,7 @@ class ChatCacheDatabaseController { ...@@ -390,7 +390,7 @@ class ChatCacheDatabaseController {
} }
public removeMessage(chat: number, msgs: number[]) { public removeMessage(chat: number, msgs: number[]) {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve) => {
if (this.db) { if (this.db) {
const store = this.buildChatMessageStore(chat); const store = this.buildChatMessageStore(chat);
let count = 0; let count = 0;
......
...@@ -153,7 +153,6 @@ export default { ...@@ -153,7 +153,6 @@ export default {
[ChatStore.STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID]: null, [ChatStore.STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID]: null,
[ChatStore.STATE_CHAT_CURRENT_USER_UID]: null, [ChatStore.STATE_CHAT_CURRENT_USER_UID]: null,
[ChatStore.STATE_CHAT_MSG_HISTORY]: null, [ChatStore.STATE_CHAT_MSG_HISTORY]: null,
[ChatStore.STATE_CHAT_SENDING_MESSAGES]: [],
[ChatStore.STATE_MY_CHAT_ROOM_LIST]: [], [ChatStore.STATE_MY_CHAT_ROOM_LIST]: [],
[ChatStore.STATE_SINGLE_CHAT]: null, [ChatStore.STATE_SINGLE_CHAT]: null,
[ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION]: null, [ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION]: null,
...@@ -277,7 +276,7 @@ export default { ...@@ -277,7 +276,7 @@ export default {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (!chatId) return; if (!chatId) return;
state[ChatStore.STATE_CHAT_MSG_HISTORY] = Object.freeze( state[ChatStore.STATE_CHAT_MSG_HISTORY] = Object.freeze(
combineMessages(data || [], old, chatId) combineMessages(old, data || [], chatId)
); );
}, },
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS]( [ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS](
...@@ -325,58 +324,6 @@ export default { ...@@ -325,58 +324,6 @@ export default {
[ChatStore.MUTATION_CLEAR_FUNC_ON_NEW_MSG](state) { [ChatStore.MUTATION_CLEAR_FUNC_ON_NEW_MSG](state) {
state[ChatStore.STATE_FUNC_ON_NEW_MSG] = () => true; state[ChatStore.STATE_FUNC_ON_NEW_MSG] = () => true;
}, },
[ChatStore.MUTATION_APPEND_SENDING_MESSAGE]: (
state,
payload: ChatStore.STATE_CHAT_SENDING_MESSAGE
) => {
const current = state[
ChatStore.STATE_CHAT_SENDING_MESSAGES
] as ChatStore.STATE_CHAT_SENDING_MESSAGE[];
if (current) {
current.push(payload);
const chat = state[
ChatStore.STATE_CHAT_CURRENT_CHAT_ID
] as number;
dbController.appendMessages(chat, [payload]);
}
preCacheImgs([payload]).then(() => {
setTimeout(
() => state[ChatStore.STATE_FUNC_SCROLL_TO_BOTTOM](),
100
);
});
},
[ChatStore.MUTATION_REMOVE_SENDING_MESSAGE]: (
state,
payload: number
) => {
const current = state[
ChatStore.STATE_CHAT_SENDING_MESSAGES
] as ChatStore.STATE_CHAT_SENDING_MESSAGE[];
if (current) {
const target = current.find((i) => i.id === payload);
if (target) {
const index = current.indexOf(target);
current.splice(index, 1);
}
}
},
[ChatStore.MUTATION_FAILED_SENDING_MESSAGE]: (
state,
payload: number
) => {
const current = state[
ChatStore.STATE_CHAT_SENDING_MESSAGES
] as ChatStore.STATE_CHAT_SENDING_MESSAGE[];
if (current) {
const target = current.find((i) => i.id === payload);
if (target) {
target.status = -1;
}
state[ChatStore.STATE_CHAT_SENDING_MESSAGES] = [...current];
}
},
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function () { [ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function () {
const setTimeoutId: { [key: string]: number } = {}; const setTimeoutId: { [key: string]: number } = {};
return ( return (
...@@ -1180,9 +1127,6 @@ export default { ...@@ -1180,9 +1127,6 @@ export default {
[ChatStore.STATE_CHAT_MSG_HISTORY](state) { [ChatStore.STATE_CHAT_MSG_HISTORY](state) {
return state[ChatStore.STATE_CHAT_MSG_HISTORY] ?? []; return state[ChatStore.STATE_CHAT_MSG_HISTORY] ?? [];
}, },
[ChatStore.STATE_CHAT_SENDING_MESSAGES](state) {
return state[ChatStore.STATE_CHAT_SENDING_MESSAGES] || [];
},
[ChatStore.STATE_CURRENT_CHAT_MEMBERS](state) { [ChatStore.STATE_CURRENT_CHAT_MEMBERS](state) {
return state[ChatStore.STATE_CURRENT_CHAT_MEMBERS] ?? []; return state[ChatStore.STATE_CURRENT_CHAT_MEMBERS] ?? [];
}, },
......
...@@ -25,11 +25,6 @@ export namespace ChatStore { ...@@ -25,11 +25,6 @@ export namespace ChatStore {
export type STATE_SINGLE_CHAT = ChatType | null; export type STATE_SINGLE_CHAT = ChatType | null;
export const STATE_CHAT_MSG_HISTORY = "某个会话聊天记录"; export const STATE_CHAT_MSG_HISTORY = "某个会话聊天记录";
export type STATE_CHAT_MSG_HISTORY = dto.MessageRequestResult | null; export type STATE_CHAT_MSG_HISTORY = dto.MessageRequestResult | null;
export const STATE_CHAT_SENDING_MESSAGES = "sendingMessages";
export type STATE_CHAT_SENDING_MESSAGES = dto.MessageRequestResult | null;
export type STATE_CHAT_SENDING_MESSAGE = dto.Message;
export const STATE_CHAT_CURRENT_CHAT_ID = "当前chat-id"; export const STATE_CHAT_CURRENT_CHAT_ID = "当前chat-id";
export type STATE_CHAT_CURRENT_CHAT_ID = number; export type STATE_CHAT_CURRENT_CHAT_ID = number;
export const STATE_CHAT_CURRENT_CHAT_VERSION = "当前chat的Uniplat version"; export const STATE_CHAT_CURRENT_CHAT_VERSION = "当前chat的Uniplat version";
...@@ -222,17 +217,6 @@ export namespace ChatStore { ...@@ -222,17 +217,6 @@ export namespace ChatStore {
export const MUTATION_CLEAR_FUNC_ON_NEW_MSG = "删除收到新消息后的方法"; export const MUTATION_CLEAR_FUNC_ON_NEW_MSG = "删除收到新消息后的方法";
export type MUTATION_CLEAR_FUNC_ON_NEW_MSG = () => void; export type MUTATION_CLEAR_FUNC_ON_NEW_MSG = () => void;
export const MUTATION_APPEND_SENDING_MESSAGE = "appendSendingMessage";
export type MUTATION_APPEND_SENDING_MESSAGE = (
payload: dto.Message
) => void;
export const MUTATION_REMOVE_SENDING_MESSAGE = "removeSendingMessage";
export type MUTATION_REMOVE_SENDING_MESSAGE = (id: number) => void;
export const MUTATION_FAILED_SENDING_MESSAGE = "failedSendingMessage";
export type MUTATION_FAILED_SENDING_MESSAGE = (id: number) => void;
export const MUTATION_SAVE_CURRENT_CHAT_INPUTING = "保存正在输入"; export const MUTATION_SAVE_CURRENT_CHAT_INPUTING = "保存正在输入";
export type MUTATION_SAVE_CURRENT_CHAT_INPUTING = ( export type MUTATION_SAVE_CURRENT_CHAT_INPUTING = (
params: chatDto.NotifyMessage params: chatDto.NotifyMessage
...@@ -394,7 +378,6 @@ export namespace ChatStore { ...@@ -394,7 +378,6 @@ export namespace ChatStore {
export interface ChatStoreState { export interface ChatStoreState {
[ChatStore.STATE_CHAT_MSG_HISTORY]: ChatStore.STATE_CHAT_MSG_HISTORY; [ChatStore.STATE_CHAT_MSG_HISTORY]: ChatStore.STATE_CHAT_MSG_HISTORY;
[ChatStore.STATE_CHAT_SENDING_MESSAGES]: ChatStore.STATE_CHAT_SENDING_MESSAGES;
[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]: ChatStore.STATE_CHAT_CURRENT_CHAT_ID; [ChatStore.STATE_CHAT_CURRENT_CHAT_ID]: ChatStore.STATE_CHAT_CURRENT_CHAT_ID;
[ChatStore.STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID]: ChatStore.STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID; [ChatStore.STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID]: ChatStore.STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID;
[ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION]: ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION; [ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION]: ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION;
......
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