This commit is contained in:
supertiger1234 2019-05-27 16:33:07 +01:00
parent c605270950
commit 9a9dd41caf
4 changed files with 50 additions and 10 deletions

View file

@ -34,14 +34,12 @@ export default {
return `<strong>${this.escapeHtml( return `<strong>${this.escapeHtml(
arr[0].username arr[0].username
)}</strong> is typing...`; )}</strong> is typing...`;
break;
case arr.length == 2: case arr.length == 2:
return `<strong>${this.escapeHtml( return `<strong>${this.escapeHtml(
arr[0].username arr[0].username
)}</strong> and <strong>${this.escapeHtml( )}</strong> and <strong>${this.escapeHtml(
arr[1].username arr[1].username
)}</strong> are typing...`; )}</strong> are typing...`;
break;
case arr.length == 3: case arr.length == 3:
return `<strong>${this.escapeHtml( return `<strong>${this.escapeHtml(
arr[0].username arr[0].username
@ -50,10 +48,8 @@ export default {
)}</strong> and <strong>${this.escapeHtml( )}</strong> and <strong>${this.escapeHtml(
arr[2].username arr[2].username
)}</strong> are typing...`; )}</strong> are typing...`;
break;
case arr.length > 3: case arr.length > 3:
return `<strong>${arr.length}</strong> people are typing...`; return `<strong>${arr.length}</strong> people are typing...`;
break;
default: default:
break; break;
} }

View file

@ -4,6 +4,8 @@ import Vue from "vue";
const state = { const state = {
selectedChannelID: null, selectedChannelID: null,
DMChannelID: null,
serverChannelID: null,
channelName: null, channelName: null,
channels: {} channels: {}
}; };
@ -30,6 +32,12 @@ const actions = {
setChannelName(context, name) { setChannelName(context, name) {
context.commit("setChannelName", name); context.commit("setChannelName", name);
}, },
setDMChannelID(context, channelID) {
context.commit("setDMChannelID", channelID);
},
setServerChannelID(context, channelID) {
context.commit("setServerChannelID", channelID);
},
updateChannelLastMessage(context, channelID) { updateChannelLastMessage(context, channelID) {
context.commit("updateChannelLastMessage", channelID); context.commit("updateChannelLastMessage", channelID);
} }
@ -48,6 +56,12 @@ const mutations = {
selectedChannelID(state, channelID) { selectedChannelID(state, channelID) {
state.selectedChannelID = channelID; state.selectedChannelID = channelID;
}, },
setDMChannelID(state, channelID) {
state.DMChannelID = channelID;
},
setServerChannelID(state, channelID) {
state.serverChannelID = channelID;
},
setChannelName(state, name) { setChannelName(state, name) {
state.channelName = name; state.channelName = name;
} }

View file

@ -15,16 +15,21 @@ const getters = {
}; };
const actions = { const actions = {
// server channel
async openChannel(context, channel) { async openChannel(context, channel) {
context.commit("setChannelName", channel.name); context.commit("setChannelName", channel.name);
const messages = context.state.messages[channel.channelID]; const messages = context.state.messages[channel.channelID];
if (messages) return context.commit("selectedChannelID", channel.channelID); if (messages) {
context.commit("selectedChannelID", channel.channelID);
context.commit("setServerChannelID", channel.channelID);
return;
}
context.commit("selectedChannelID", "loading") context.commit("selectedChannelID", "loading")
getMessages(context, channel.channelID); getMessages(context, channel.channelID, true);
}, },
//dm channel
async openChat(context, { uniqueID, channelID, channelName }) { async openChat(context, { uniqueID, channelID, channelName }) {
if (channelName) context.commit("setChannelName", channelName); if (channelName) context.commit("setChannelName", channelName);
const channels = context.rootState.channelModule.channels; const channels = context.rootState.channelModule.channels;
@ -35,6 +40,7 @@ const actions = {
const channel = channels[channelID]; const channel = channels[channelID];
if (channelID) { if (channelID) {
context.commit("setDMChannelID", channelID);
context.commit("selectedChannelID", channelID); context.commit("selectedChannelID", channelID);
} else { } else {
context.commit("selectedChannelID", "Loading"); context.commit("selectedChannelID", "Loading");
@ -47,7 +53,7 @@ const actions = {
const { ok, error, result } = await channelService.post(uniqueID); const { ok, error, result } = await channelService.post(uniqueID);
if (ok) { if (ok) {
context.commit("channel", result.data.channel); context.commit("channel", result.data.channel);
getMessages(context, result.data.channel.channelID); getMessages(context, result.data.channel.channelID, false);
} else { } else {
// TODO handle this // TODO handle this
console.log(error); console.log(error);
@ -74,10 +80,15 @@ const actions = {
} }
}; };
async function getMessages(context, channelID) { async function getMessages(context, channelID, isServerChannel) {
const { ok, error, result } = await messagesService.get(channelID); const { ok, error, result } = await messagesService.get(channelID);
if (ok) { if (ok) {
context.commit("selectedChannelID", channelID); context.commit("selectedChannelID", channelID);
if (isServerChannel) {
context.commit("setServerChannelID", channelID);
} else {
context.commit("setDMChannelID", channelID);
}
context.commit("messages", { context.commit("messages", {
channelID: result.data.channelID, channelID: result.data.channelID,
messages: result.data.messages.reverse() messages: result.data.messages.reverse()

View file

@ -89,10 +89,29 @@ export default {
}; };
}, },
methods: { methods: {
switchChannel(isServer) {
const serverChannelID = this.$store.state.channelModule.serverChannelID;
const DMChannelID = this.$store.state.channelModule.DMChannelID;
if (isServer) {
this.$store.dispatch('selectedChannelID', serverChannelID)
const channel = this.$store.state.channelModule.channels[serverChannelID];
this.$store.dispatch("setChannelName", channel ? channel.name : "")
} else {
const channel = this.$store.state.channelModule.channels[DMChannelID];
this.$store.dispatch("setChannelName", channel ? channel.recipients[0].username : "");
this.$store.dispatch('selectedChannelID', DMChannelID)
}
},
switchTab(index) { switchTab(index) {
localStorage.setItem("currentTab", index); localStorage.setItem("currentTab", index);
this.currentTab = index; this.currentTab = index;
} if (index == 1) { //1: direct message tab.
this.switchChannel(false)
} else if (index === 2) { //2: server tab
this.switchChannel(true)
}
},
}, },
mounted() { mounted() {
// check if changelog is updated // check if changelog is updated