diff --git a/freechat-client/src/channels.js b/freechat-client/src/channels.js index 0d6d6c6..619d9eb 100644 --- a/freechat-client/src/channels.js +++ b/freechat-client/src/channels.js @@ -1,65 +1,86 @@ // Requesting channel data here const { ipcRenderer } = require('electron') const auth = require('./auth.js') -const { Request } = require('./request.js') +const { Request, BuildUrl } = require('./request.js') + +const $ = require('jquery') +const got = require('got') const VOICE_KIND = 1 const TEXT_KIND = 2 -class Channel { - constructor(name, id, type, description) { - this.name = name - this.id = id - this.type = type - this.description = description - } - -} /** * + * @param {String} proto | http/https * @param {String} domain | domain of the instance we're looking at * @param {Number} port | Should always be the default value of 4536 but other owner - * @param {Object} params | basic object with jwt + id fields + * @param {Object} params | object with jwt + id fields + * + * @note This function fails quietly for the sake of not destroying the UI instantly + * Errors get logged for now since those are in the debugger anyway but everything else + * is basically really quiet + * */ -function update_channels_list(domain, port, params) { +function update_channels_list(proto, hostname, port, params) { + const url = `${proto}://${hostname}:${port}/channels/list` - Request('get', domain, port, '/channels/list', params).then( + got(url, { + searchParams: { id: params['id'], jwt: params['jwt'] }, + responseType: 'json' + }) + .then( response => { - if(response.status_code != 200) { - document.getElementById('channels-list').textContent = 'Could not fetch channels' - } - else { - const channels = response.body - const voice = channels.filter(chan => chan.kind == VOICE_KIND) - const text = channels.filter(chan => chan.kind == TEXT_KIND) + const channels_json = response.body['channels'] + const voice = channels_json.filter(chan => chan.kind == VOICE_KIND) + const text = channels_json.filter(chan => chan.kind == TEXT_KIND) - const chans = voice.concat(text) - for(const channel of chans) { - const name = channel.name - let item = `