Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled channels can be now loaded also using a remote json #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions plugin-conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ kiwi.plugin('conferencePlugin', (kiwi, log) => { /* eslint-disable-line no-undef
let captions = [];
let kiwiConferenceTag = '1';
let sharedData = { isOpen: false };
let enabledNotifyInChannels = ['*'];
let enabledInChannels = ['*'];
let inviteText = '';
let joinText = '';
Expand All @@ -70,10 +71,36 @@ kiwi.plugin('conferencePlugin', (kiwi, log) => { /* eslint-disable-line no-undef
let linkShortenerAPIToken = '';

const groupedNoticesTTL = 30000;

if (kiwi.state.setting('conference.enabledInChannels')) {

if (kiwi.state.setting('conference.enabledInChannelsJson')) {

var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function onLoad(temp) {
if (xmlhttp.status !== 200) {
console.error('plugin-conference: error loading enabled channels list');
return
}
try {
var json = JSON.parse(xmlhttp.responseText);
if (!json) {
return;
}
if (json.length > 0) {
enabledInChannels = json;
}
} catch (err) {
console.error('plugin-conference: error parsing enabled channels list:', err);
}
}
xmlhttp.open('GET', kiwi.state.setting('conference.enabledInChannelsJson'), true);
xmlhttp.send();
} else {
enabledInChannels = kiwi.state.setting('conference.enabledInChannels');
}

if (kiwi.state.setting('conference.enabledNotifyInChannels')) {
enabledNotifyInChannels = kiwi.state.setting('conference.enabledNotifyInChannels');
}

if (kiwi.state.setting('conference.inviteText')) {
inviteText = ' ' + kiwi.state.setting('conference.inviteText');
Expand Down Expand Up @@ -149,9 +176,30 @@ kiwi.plugin('conferencePlugin', (kiwi, log) => { /* eslint-disable-line no-undef
});

// Add the call button to the channel+query headers
const conferencingTool = document.createElement('div');
conferencingTool.style.cursor = 'pointer';
conferencingTool.innerHTML = '<a><i aria-hidden="true" class="fa fa-phone"></i></a>';

var button = new kiwi.Vue({
template: '<div><a v-if="allowed"><i aria-hidden="true" class="fa fa-phone"></i></a></div>',
data: function(){
return {
allowed:true,
}
}
});
button.$mount();
let conferencingTool = button.$el;

if (enabledInChannels.indexOf('*') !== -1) {
kiwi.state.$watch('ui.active_buffer', function(newVal){
if(enabledInChannels.indexOf(kiwi.state.getActiveBuffer().name) > -1) {
button.allowed = true;
} else {
button.allowed = false;
}
if(kiwi.state.getActiveBuffer().isQuery()) {
button.allowed = true;
}
});
}
if (kiwi.state.setting('conference.channels') !== false) {
kiwi.addUi('header_channel', conferencingTool);
}
Expand Down Expand Up @@ -188,7 +236,7 @@ kiwi.plugin('conferencePlugin', (kiwi, log) => { /* eslint-disable-line no-undef
}
}
});

kiwi.on('message.new', (newMessage, buffer) => {
let messageTemplate = null;
let message = '';
Expand Down Expand Up @@ -317,7 +365,7 @@ kiwi.plugin('conferencePlugin', (kiwi, log) => { /* eslint-disable-line no-undef
m = new network.ircClient.Message('PRIVMSG', buffer.name, '* ' + network.nick + ' ' + inviteText + ' ' + await shareLink());
} else {
roomName = buffer.name;
if (enabledInChannels.indexOf('*') !== -1 || enabledInChannels.indexOf(roomName) !== -1) {
if (enabledNotifyInChannels.indexOf('*') !== -1 || enabledNotifyInChannels.indexOf(roomName) !== -1) {
m = new network.ircClient.Message('PRIVMSG', buffer.name, '* ' + network.nick + ' ' + joinText + ' ' + await shareLink());
} else {
hideCams(false);
Expand Down