Edits and new messages functional
This commit is contained in:
parent
4804cd6ccb
commit
7a82d9e860
|
@ -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 { }
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue