moved openchat to friends template

This commit is contained in:
supertiger1234 2019-04-09 21:18:13 +01:00
parent 52c57ebd06
commit 9e4897d36b
6 changed files with 105 additions and 82 deletions

Binary file not shown.

View file

@ -92,23 +92,26 @@ export default {
.change-log { .change-log {
background: rgba(0, 0, 0, 0.137); background: rgba(0, 0, 0, 0.137);
padding: 20px; padding: 20px;
flex: 1;
overflow-y: auto; overflow-y: auto;
max-width: 700px;
margin: auto;
} }
.plan-list { .plan-list {
color: white; color: white;
} }
.date { .date {
text-align: left; text-align: right;
margin-right: 50px; font-size: 19px;
margin-right: 10px;
color: rgba(255, 255, 255, 0.692); color: rgba(255, 255, 255, 0.692);
} }
.changes-title { .changes-title {
font-size: 20px; font-size: 30px;
color: rgba(255, 255, 255, 0.979); color: rgba(255, 255, 255, 0.979);
margin-bottom: 10px; text-align: center;
margin-top: 10px;
font-weight: bold; font-weight: bold;
margin-top: -5px;
margin-bottom: 10px;
} }
@media (max-width: 840px) { @media (max-width: 840px) {

View file

@ -25,38 +25,19 @@ import {bus} from '@/main'
export default { export default {
props: ['username', 'tag', 'channelID', 'uniqueID', 'recipient'], props: ['username', 'tag', 'channelID', 'uniqueID', 'recipient'],
methods: { methods: {
async getMessages() {
const {ok, error, result} = await messagesService.get(this.$props.channelID);
if ( ok ) {
this.$store.dispatch('messages', {channelID: result.data.channelID, messages: result.data.messages});
} else {
// TODO handle this
console.log (error.response)
}
},
async openChat(event) { async openChat(event) {
if (event.target.classList[0] === "profile-picture") return; if (event.target.classList[0] === "profile-picture") return;
bus.$emit('closeLeftMenu'); bus.$emit('closeLeftMenu');
// dismiss notification if exists // dismiss notification if exists
// TODO move this into openchat or something :/
if (this.notifications && this.notifications >= 1 && document.hasFocus()) { if (this.notifications && this.notifications >= 1 && document.hasFocus()) {
this.$socket.emit('notification:dismiss', {channelID: this.channelID}); this.$socket.emit('notification:dismiss', {channelID: this.channelID});
} }
// this.$store.dispatch('openChat', { this.$store.dispatch('openChat', {
// channelID: this.channelID, channelID: this.channelID,
// channelName: this.channel channelName: this.recipient.username
// }) })
this.$store.dispatch('selectedChannelID', this.$props.channelID);
this.$store.dispatch('setChannelName', this.recipient.username);
if (this.$store.getters.messages[this.$props.channelID]) return;
if (this.$store.getters.channels[this.$props.channelID] && !this.$store.getters.messages[this.$props.channelID]) return this.getMessages();
const {ok, error, result} = await channelService.post(this.$props.channelID);
if ( ok ) {
this.$store.dispatch('channel', result.data.channel);
this.getMessages();
} else {
// TODO handle this
console.log(error)
}
}, },
openUserInformation() { openUserInformation() {
this.$store.dispatch('setUserInformationPopout', this.recipient.uniqueID) this.$store.dispatch('setUserInformationPopout', this.recipient.uniqueID)

View file

@ -19,7 +19,6 @@
</div> </div>
</div> </div>
<div class="bottom" v-if="selfUniqueID !== user.uniqueID"> <div class="bottom" v-if="selfUniqueID !== user.uniqueID">
<div class="button valid" v-if="this.relationshipStatus == null" @click="AddFriendButton"> <div class="button valid" v-if="this.relationshipStatus == null" @click="AddFriendButton">
<div class="material-icons">person_add</div>Add friend <div class="material-icons">person_add</div>Add friend
</div> </div>
@ -36,7 +35,7 @@
<div class="material-icons">person_add_disabled</div>End Friendship <div class="material-icons">person_add_disabled</div>End Friendship
</div> </div>
<div class="button"> <div class="button" @click="openChat">
<div class="material-icons">chat</div>Send Message <div class="material-icons">chat</div>Send Message
</div> </div>
<div class="button warn"> <div class="button warn">
@ -48,7 +47,6 @@
</div> </div>
</template> </template>
<script> <script>
import config from "@/config.js"; import config from "@/config.js";
import Spinner from "@/components/Spinner.vue"; import Spinner from "@/components/Spinner.vue";
import profilePicture from "@/components/ProfilePictureTemplate.vue"; import profilePicture from "@/components/ProfilePictureTemplate.vue";
@ -69,13 +67,27 @@ export default {
} }
}, },
async AddFriendButton() { async AddFriendButton() {
const {ok, error, result} = await relationshipService.post({username: this.user.username, tag: this.user.tag}); const { ok, error, result } = await relationshipService.post({
username: this.user.username,
tag: this.user.tag
});
}, },
async AcceptFriendButton() { async AcceptFriendButton() {
const {ok, error, result} = await relationshipService.put(this.uniqueID); const { ok, error, result } = await relationshipService.put(
this.uniqueID
);
}, },
async RemoveFriendButton() { async RemoveFriendButton() {
const {ok, error, result} = await relationshipService.delete(this.uniqueID); const { ok, error, result } = await relationshipService.delete(
this.uniqueID
);
},
openChat() {
// todo: find from friends array and later, create new channels for people who are not friends.
this.$store.dispatch("openChat", {
channelID: this.channelID,
channelName: this.user.username
});
} }
}, },
async mounted() { async mounted() {
@ -94,8 +106,8 @@ export default {
relationshipStatus() { relationshipStatus() {
const userUniqueID = this.$store.getters.popouts.userInformationPopoutID; const userUniqueID = this.$store.getters.popouts.userInformationPopoutID;
const allFriend = this.$store.getters.user.friends; const allFriend = this.$store.getters.user.friends;
if (!allFriend[userUniqueID]) return null if (!allFriend[userUniqueID]) return null;
return allFriend[userUniqueID].status return allFriend[userUniqueID].status;
} }
} }
}; };

View file

@ -1,12 +1,12 @@
import {bus} from '../../main' import { bus } from "../../main";
import {router} from './../../router' import { router } from "./../../router";
import Vue from 'vue'; import Vue from "vue";
const state = { const state = {
selectedChannelID: null, selectedChannelID: null,
channelName: null, channelName: null,
channels: {} channels: {}
} };
const getters = { const getters = {
selectedChannelID(state) { selectedChannelID(state) {
@ -18,29 +18,29 @@ const getters = {
channelName(state) { channelName(state) {
return state.channelName; return state.channelName;
} }
} };
const actions = { const actions = {
channel(context, channel) { channel(context, channel) {
context.commit('channel', channel) context.commit("channel", channel);
}, },
selectedChannelID(context, channelID) { selectedChannelID(context, channelID) {
context.commit('selectedChannelID', channelID) context.commit("selectedChannelID", channelID);
}, },
setChannelName(context, name) { setChannelName(context, name) {
context.commit('setChannelName', name) context.commit("setChannelName", name);
}, },
updateChannelLastMessage(context, channelID) { updateChannelLastMessage(context, channelID) {
context.commit('updateChannelLastMessage', channelID) context.commit("updateChannelLastMessage", channelID);
} }
} };
const mutations = { const mutations = {
updateChannelLastMessage(state, channelID){ updateChannelLastMessage(state, channelID) {
Vue.set(state.channels[channelID], 'lastMessaged', Date.now()); Vue.set(state.channels[channelID], "lastMessaged", Date.now());
}, },
addAllChannels(state, channels){ addAllChannels(state, channels) {
Vue.set(state, 'channels', channels); Vue.set(state, "channels", channels);
}, },
channel(state, channel) { channel(state, channel) {
Vue.set(state.channels, channel.channelID, channel); Vue.set(state.channels, channel.channelID, channel);
@ -51,7 +51,7 @@ const mutations = {
setChannelName(state, name) { setChannelName(state, name) {
state.channelName = name; state.channelName = name;
} }
} };
export default { export default {
namespace: true, namespace: true,
@ -59,4 +59,4 @@ export default {
actions, actions,
mutations, mutations,
getters getters
} };

View file

@ -1,66 +1,93 @@
import {bus} from '../../main' import { bus } from "../../main";
import {router} from '../../router' import { router } from "../../router";
import Vue from 'vue'; import Vue from "vue";
import channelService from "@/services/channelService";
import messagesService from "@/services/messagesService";
const state = { const state = {
messages: {} messages: {}
} };
const getters = { const getters = {
messages(state) { messages(state) {
return state.messages; return state.messages;
} }
};
}
const actions = { const actions = {
async openChat(context, { channelID, channelName }) {
context.commit("selectedChannelID", channelID);
if (channelName) context.commit("setChannelName", channelName);
const messages = context.state.messages[channelID];
const channel = context.rootState.channelModule.channels[channelID];
if (messages) return;
if (channel && !messages) return getMessages();
const { ok, error, result } = await channelService.post(channelID);
if (ok) {
context.commit("channel", result.data.channel);
getMessages();
} else {
// TODO handle this
console.log(error);
}
async function getMessages() {
const { ok, error, result } = await messagesService.get(channelID);
if (ok) {
context.commit("messages", {
channelID: result.data.channelID,
messages: result.data.messages.reverse()
});
} else {
// TODO handle this
console.log(error.response);
}
}
},
messages(context, data) { messages(context, data) {
context.commit('messages', data) context.commit("messages", data);
}, },
addMessage(context, data) { addMessage(context, data) {
// if the message is sent by this client, add additional information. // if the message is sent by this client, add additional information.
if (data.sender) { if (data.sender) {
data.message.creator = context.getters.user data.message.creator = context.getters.user;
data.message.status = 0; data.message.status = 0;
} }
// send notification if message is not ours // send notification if message is not ours
context.commit('addMessage', data); context.commit("addMessage", data);
}, },
replaceMessage(context, data) { replaceMessage(context, data) {
context.commit('replaceMessage', data) context.commit("replaceMessage", data);
} }
} };
const mutations = { const mutations = {
messages(state, data) { messages(state, data) {
Vue.set(state.messages, data.channelID, data.messages.reverse()) Vue.set(state.messages, data.channelID, data.messages.reverse());
}, },
addMessage(state, data) { addMessage(state, data) {
bus.$emit('newMessage', data); bus.$emit("newMessage", data);
Vue.set( Vue.set(
state.messages[data.channelID], state.messages[data.channelID],
state.messages[data.channelID].length, state.messages[data.channelID].length,
data.message data.message
); );
}, },
replaceMessage (state, data) { replaceMessage(state, data) {
const {tempID, message} = data; const { tempID, message } = data;
state.messages[message.channelID].find((o, i) => { state.messages[message.channelID].find((o, i) => {
if(o.tempID === tempID) { if (o.tempID === tempID) {
Vue.set( Vue.set(state.messages[message.channelID], i, message);
state.messages[message.channelID],
i,
message
)
return true; return true;
} }
}) });
} }
} };
export default { export default {
namespace: true, namespace: true,
@ -68,4 +95,4 @@ export default {
actions, actions,
mutations, mutations,
getters getters
} };