Edits and new messages functional

This commit is contained in:
Jiiks 2018-03-08 14:45:31 +02:00
parent 4804cd6ccb
commit 7a82d9e860
3 changed files with 38 additions and 11 deletions

View File

@ -9,6 +9,7 @@
*/
import DiscordEvent from './discordevent';
import { Reflection } from 'ui';
export class MESSAGE_CREATE extends DiscordEvent {
get author() { return this.args.author }
@ -26,6 +27,14 @@ export class MESSAGE_CREATE extends DiscordEvent {
get timestamp() { return this.args.timestamp }
get tts() { return this.args.tts }
get type() { return this.args.type }
get element() {
const find = document.querySelector(`[message-id="${this.id}"]`);
if (find) return find;
const messages = document.querySelectorAll('.message');
const lastMessage = messages[messages.length - 1];
if (Reflection(lastMessage).prop('message.id') === this.id) return lastMessage;
return null;
}
}
export class MESSAGE_UPDATE extends MESSAGE_CREATE { }

View File

@ -62,6 +62,18 @@ export default class {
console.log(err);
}
});
Events.on('discord:MESSAGE_CREATE', e => {
if (!e.element) return;
this.setId(e.element);
const markup = e.element.querySelector('.markup:not(.mutable)');
if (markup) this.injectMarkup(markup, this.cloneMarkup(markup), false);
});
Events.on('discord:MESSAGE_UPDATE', e => {
if (!e.element) return;
this.setId(e.element);
const markup = e.element.querySelector('.markup:not(.mutable)');
if (markup) this.injectMarkup(markup, this.cloneMarkup(markup), false);
});
}
getEts(node) {
@ -120,6 +132,7 @@ export default class {
Events.emit('ui:mutable:.markup', markup.clone);
if (reinject) return;
/*
new MutationObserver(() => {
this.injectMarkup(sibling, this.cloneMarkup(sibling), true);
}).observe(sibling, { characterData: false, attributes: false, childList: true, subtree: false });
@ -127,23 +140,27 @@ export default class {
new MutationObserver(() => {
this.injectMarkup(sibling, this.cloneMarkup(sibling), true);
}).observe(sibling, { characterData: true, attributes: false, childList: false, subtree: true });
*/
}
setIds() {
for (let msg of document.querySelectorAll('.message')) {
if (msg.hasAttribute('message-id')) continue;
const r = Reflection(msg);
const message = r.prop('message');
if (!message) continue;
const { id, author } = message;
if (!id || !author) continue;
const currentUser = author.id === TempApi.currentUserId;
DOM.setAttributes(msg, [{ name: 'message-id', value: message.id }]);
const msgGroup = msg.closest('.message-group');
if (!msgGroup) continue;
DOM.setAttributes(msgGroup, [{ name: 'author-id', value: author.id }, { name: 'author-is-currentuser', value: currentUser }]);
this.setId(msg);
}
}
setId(msg) {
if (msg.hasAttribute('message-id')) return;
const r = Reflection(msg);
const message = r.prop('message');
if (!message) return;
const { id, author } = message;
if (!id || !author) return;
const currentUser = author.id === TempApi.currentUserId;
DOM.setAttributes(msg, [{ name: 'message-id', value: message.id }]);
const msgGroup = msg.closest('.message-group');
if (!msgGroup) return;
DOM.setAttributes(msgGroup, [{ name: 'author-id', value: author.id }, { name: 'author-is-currentuser', value: currentUser }]);
}
get appMount() {
return document.getElementById('app-mount');

View File

@ -3,3 +3,4 @@ export { default as BdUI } from './bdui';
export { default as VueInjector } from './vueinjector';
export { default as Modals } from './modals';
export { default as ProfileBadges } from './profilebadges';
export { default as Reflection } from './reflection';