edit messages, embeds

This commit is contained in:
supertiger1234 2019-07-19 17:07:21 +01:00
parent 5d1f101019
commit aa76b15a31
6 changed files with 126 additions and 37 deletions

View file

@ -23,6 +23,8 @@
:embed="msg.embed" :embed="msg.embed"
:files="msg.files" :files="msg.files"
:status="msg.status" :status="msg.status"
:messageID="msg.messageID"
:channelID="msg.channelID"
:type="msg.type" :type="msg.type"
/> />
<uploadsQueue v-if="uploadQueue !== undefined" :queue="uploadQueue"/> <uploadsQueue v-if="uploadQueue !== undefined" :queue="uploadQueue"/>

View file

@ -18,8 +18,7 @@
</div> </div>
<div class="content"> <div class="content">
<div class="user-info"> <div class="user-info">
<div <div class="username"
class="username"
@click="openUserInformation" @click="openUserInformation"
> >
{{ this.$props.username }} {{ this.$props.username }}
@ -28,14 +27,12 @@
{{ getDate }} {{ getDate }}
</div> </div>
</div> </div>
<div <div class="content-message"
class="content-message"
v-html="formatMessage" v-html="formatMessage"
/> />
<div <div class="file-content"
v-if="getFile" v-if="getFile"
class="file-content"
> >
<div class="icon"> <div class="icon">
<i class="material-icons">insert_drive_file</i> <i class="material-icons">insert_drive_file</i>
@ -53,9 +50,8 @@
</div> </div>
</div> </div>
<div <div class="image-content"
v-if="getImage" v-if="getImage"
class="image-content"
> >
<img <img
:src="getImage" :src="getImage"
@ -64,18 +60,24 @@
</div> </div>
<message-embed-template v-if="embed" :embed="embed"/> <message-embed-template v-if="embed" :embed="embed"/>
</div> </div>
<div <div class="other-information">
class="sending-status" <div class="drop-down-button" ref="drop-down-button" @click="dropDownVisable = !dropDownVisable"><i class="material-icons">more_vert</i></div>
v-html="statusMessage" <div class="drop-down-menu" v-click-outside="closeDropDown" v-if="dropDownVisable">
/> <!-- <div class="drop-item">Edit</div> -->
<div class="drop-item warn" @click="deleteMessage">Delete</div>
</div>
<div class="sending-status" v-if="status === 0"><i class="material-icons">hourglass_full</i></div>
<div class="sending-status" v-if="status === 1"><i class="material-icons">done</i></div>
<div class="sending-status" v-if="status === 2"><i class="material-icons">close</i> Failed</div>
</div>
</div> </div>
<div <div
v-if="type && (type === 1 || type === 2)" v-if="type && (type === 1 || type === 2)"
:class="{'presence-message': true, green: type === 1, red: type === 2}" :class="{'presence-message': true, green: type === 1, red: type === 2}"
> >
<span> <span>
<span <span class="username"
class="username"
@click="openUserInformation" @click="openUserInformation"
>{{ this.$props.username }}</span> >{{ this.$props.username }}</span>
<span <span
@ -102,12 +104,18 @@ import friendlyDate from "@/utils/date";
import path from "path"; import path from "path";
import { mapState } from "vuex"; import { mapState } from "vuex";
import messagesService from '../../services/messagesService';
export default { export default {
components: { components: {
ProfilePicture, ProfilePicture,
messageEmbedTemplate messageEmbedTemplate
}, },
data() {
return {
dropDownVisable: false
}
},
props: [ props: [
"message", "message",
"status", "status",
@ -118,7 +126,9 @@ export default {
"files", "files",
"admin", "admin",
"type", "type",
"embed" "embed",
"messageID",
"channelID"
], ],
methods: { methods: {
openUserInformation() { openUserInformation() {
@ -126,6 +136,16 @@ export default {
}, },
imageClicked(event) { imageClicked(event) {
this.$store.dispatch("setImagePreviewURL", event.target.src); this.$store.dispatch("setImagePreviewURL", event.target.src);
},
closeDropDown(event) {
const dropDownButton = this.$refs['drop-down-button'];
if (!dropDownButton || dropDownButton.contains(event.target)) return;
this.dropDownVisable = false
},
async deleteMessage() {
this.dropDownVisable = false;
const {ok, error, result} = await messagesService.delete(this.messageID, this.channelID);
} }
}, },
computed: { computed: {
@ -160,19 +180,6 @@ export default {
userAvatar() { userAvatar() {
return config.domain + "/avatars/" + this.$props.avatar; return config.domain + "/avatars/" + this.$props.avatar;
}, },
statusMessage() {
let status = this.$props.status;
if (status == 0) {
return `<i class="material-icons">hourglass_full</i>`;
} else if (status == 1) {
return `<i class="material-icons">done</i>`;
} else if (status == 2) {
return `<i class="material-icons">close</i> Failed`;
} else {
return "";
}
},
user() { user() {
return this.$store.getters.user; return this.$store.getters.user;
} }
@ -184,7 +191,39 @@ export default {
<style scoped> <style scoped>
.container { .container {
position: relative; position: relative;
}
.drop-down-button{
opacity: 0;
transition: 0.2s;
}
.drop-down-menu {
position: absolute;
z-index: 999; z-index: 999;
background: rgba(0, 0, 0, 0.918);
border-radius: 10px;
padding: 5px;
margin-top: 25px;
margin-left: -24px;
color: white;
}
.drop-item {
padding: 3px;
border-radius: 5px;
cursor: pointer;
user-select: none;
font-size: 13px;
}
.drop-item:hover {
background: rgb(41, 41, 41);
}
.warn {
color: red;
}
.container:hover .drop-down-button{
opacity: 1;
} }
.presence-message { .presence-message {
margin: 10px; margin: 10px;
@ -364,6 +403,10 @@ export default {
overflow-wrap: anywhere; overflow-wrap: anywhere;
margin-top: 3px; margin-top: 3px;
} }
.other-information {
display: flex;
flex-direction: column;
}
.message .sending-status { .message .sending-status {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
@ -375,17 +418,32 @@ export default {
transition: 0.5; transition: 0.5;
align-content: center; align-content: center;
} }
.message .other-information div .material-icons {
font-size: 15px;
color: rgb(306, 306, 306);
display: block;
}
.drop-down-button .material-icons {
font-size: 17px !important;
user-select: none;
cursor: pointer;
margin-top: 5px;
}
@media (max-width: 468px) {
}
</style> </style>
<style> <style>
.msg-link { .msg-link {
color: rgb(86, 159, 253); color: rgb(86, 159, 253);
} }
.message .sending-status .material-icons {
font-size: 15px;
color: rgb(306, 306, 306);
display: block;
}
.codeblock { .codeblock {
background-color: rgba(0, 0, 0, 0.397); background-color: rgba(0, 0, 0, 0.397);
padding: 5px; padding: 5px;

View file

@ -3,11 +3,14 @@ import filesize from "filesize";
export default { export default {
// TODO: add ?continue=id // TODO: add ?continue=id
get ( channelID ) { get ( channelID ) {
return wrapper(instance().get(`messages/${channelID}`)); return wrapper(instance().get(`messages/channels/${channelID}`));
},
delete ( messageID, channelID ) {
return wrapper(instance().delete(`messages/${messageID}/channels/${channelID}`));
}, },
post (channelID, data, onProgress) { post (channelID, data, onProgress) {
const url = `messages/${channelID}`; const url = `messages/channels/${channelID}`;
var start = +new Date(); var start = +new Date();

View file

@ -77,8 +77,16 @@ const actions = {
replaceMessage(context, data) { replaceMessage(context, data) {
context.commit("replaceMessage", data); context.commit("replaceMessage", data);
}, },
deleteMessage(context, {channelID, messageID}) {
const messages = context.state.messages[channelID];
messages.find((obj, index) => {
if (obj.messageID === messageID){
context.commit('deleteMessage', {channelID, index});
return true;
}
})
},
updateMessage(context, {channelID, messageID, message}) { updateMessage(context, {channelID, messageID, message}) {
console.log(message)
const messages = context.state.messages[channelID]; const messages = context.state.messages[channelID];
messages.find((obj, index) => { messages.find((obj, index) => {
if (obj.messageID === messageID){ if (obj.messageID === messageID){
@ -111,8 +119,10 @@ async function getMessages(context, channelID, isServerChannel) {
const mutations = { const mutations = {
deleteMessage(state, {channelID, index}) {
Vue.delete(state.messages[channelID], index)
},
updateMessage(state, {message, index}) { updateMessage(state, {message, index}) {
console.log(message);
Vue.set(state.messages[message.channelID], index, message); Vue.set(state.messages[message.channelID], index, message);
}, },
messages(state, data) { messages(state, data) {

View file

@ -274,6 +274,9 @@ const actions = {
['socket_updateMessage'](context, data) { ['socket_updateMessage'](context, data) {
context.dispatch('updateMessage', {channelID: data.channelID, messageID: data.messageID, message: data}); context.dispatch('updateMessage', {channelID: data.channelID, messageID: data.messageID, message: data});
}, },
['socket_deleteMessage'](context, {channelID, messageID}) {
context.dispatch('deleteMessage', {channelID, messageID})
},
} }
export default { export default {

View file

@ -18,6 +18,19 @@ const config = [
{
version: 5.2,
title: "Delete messages, URL Embeds",
shortTitle: "",
date: "19/07/2019",
headColor: "rgba(155, 79, 0, 0.77)",
new: [
"You can now delete your own messages.",
"URLs now show open graph embeds.",
],
next: ["Edit messages."],
},
{ {
version: 5.1, version: 5.1,
title: "Change server avatar!", title: "Change server avatar!",