add more attributes and file upload author

This commit is contained in:
Jiiks 2018-03-10 13:53:27 +02:00
parent ad522dd745
commit da6aecc3f2
1 changed files with 37 additions and 1 deletions

View File

@ -62,6 +62,18 @@ export default class extends EventListener {
this.setUserIds();
Events.emit('ui:loadedmoreusers', mutations.map(m => m.addedNodes[0]));
}, 'filter');
const channelFilter = function(m) {
return m.addedNodes &&
m.addedNodes.length &&
m.addedNodes[0].className &&
m.addedNodes[0].className.includes('container');
}
DOM.observer.subscribe('loading-more-channels-manip', channelFilter, mutations => {
this.setChannelIds();
Events.emit('ui:loadedmorechannels', mutations.map(m => m.addedNodes[0]));
}, 'filter');
}
bindings() {
@ -159,6 +171,7 @@ export default class extends EventListener {
setIds() {
this.setMessageIds();
this.setUserIds();
this.setChannelIds();
}
setMessageIds() {
@ -173,11 +186,25 @@ export default class extends EventListener {
}
}
setChannelIds() {
for (let channel of document.querySelectorAll('[class*=channels] [class*=containerDefault]')) {
this.setChannelId(channel);
}
}
setId(msg) {
if (msg.hasAttribute('message-id')) return;
const messageid = Reflection(msg).prop('message.id');
const authorid = Reflection(msg).prop('message.author.id');
if (!messageid || !authorid) return;
if (!messageid || !authorid) {
const msgGroup = msg.closest('.message-group');
if (!msgGroup) return;
const userTest = Reflection(msgGroup).prop('user');
if (!userTest) return;
msgGroup.setAttribute('data-author-id', userTest.id);
if (userTest.id === TempApi.currentUserId) msgGroup.setAttribute('data-currentuser', true);
return;
}
msg.setAttribute('data-message-id', messageid);
const msgGroup = msg.closest('.message-group');
if (!msgGroup) return;
@ -195,6 +222,15 @@ export default class extends EventListener {
Events.emit('ui:useridset', user);
}
setChannelId(channel) {
if (channel.hasAttribute('data-channel-id')) return;
const channelObj = Reflection(channel).prop('channel');
if (!channelObj) return;
channel.setAttribute('data-channel-id', channelObj.id);
if (channelObj.nsfw) channel.setAttribute('data-channel-nsfw', true);
if (channelObj.type && channelObj.type === 2) channel.setAttribute('data-channel-voice', true);
}
get appMount() {
return document.getElementById('app-mount');
}