diff --git a/src/mixins/socketMixin.js b/src/mixins/socketMixin.js index 69b4f2b..8262d49 100644 --- a/src/mixins/socketMixin.js +++ b/src/mixins/socketMixin.js @@ -1,4 +1,4 @@ -import { wsType2messageType } from "@/utils/common"; +import { wsType2messageType, wsType2type } from "@/utils/common"; export default { mounted() { @@ -10,7 +10,7 @@ export default { message: m.content, }); m["contentType"] = wsType2messageType(m.ws_type); - this.$store.state.messages["user" + m.fromId].push(m); + this.$store.state.messages[wsType2type(m)].push(m); this.$bus.$emit("scrollToBottom"); } }; diff --git a/src/utils/common.js b/src/utils/common.js index 26cdf74..0d21925 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -1,11 +1,15 @@ export function wsType2messageType(wsType) { - return (wsType - 3) / 2; + return parseInt((wsType - 3) / 2); } export function messageType2wsType(messageType, isGroup) { return messageType * 2 + 3 + isGroup; } +export function wsType2type(m) { + return m.ws_type % 2 === 0 ? "group" + m.toId : "user" + m.fromId; +} + import { audioExtensions, videoExtensions } from "@/config/file-extensions"; export function getFileSpecificType(fileName) { if (isIncludeExtension(audioExtensions, fileName)) {