diff --git a/freechat-client/src/channels.js b/freechat-client/src/channels.js index 7d56d8f..aa3bd78 100644 --- a/freechat-client/src/channels.js +++ b/freechat-client/src/channels.js @@ -1,10 +1,7 @@ // Requesting channel data here -const { ipcRenderer } = require('electron') const $ = require('jquery') const got = require('got') -const auth = require('./auth.js') -const { Request, BuildUrl } = require('./request.js') const msg = require('./messages.js') @@ -52,7 +49,6 @@ function update_channels_list(proto, hostname, port, params) { ) // why not jquery? Because the callback doesn't register // (I have no idea why) - console.log(channel) let ref = document.getElementById(channel['name']) ref.addEventListener('click', function() { // Collect parameters to pass into the actual handler @@ -67,7 +63,13 @@ function update_channels_list(proto, hostname, port, params) { } // now for the actual handler where we deal with clicks - msg.recent_messages(user, server, channel) + console.log('fetching', channel) + const now = Math.floor(new Date().getTime() / 1000) + const yesterday = now - (60 * 60 * 48) + msg.recent_messages(user, server, channel, yesterday , now, 1000) + .then(()=>{},reason => { + console.log(reason) + }) }) } }, diff --git a/freechat-client/src/members.js b/freechat-client/src/members.js new file mode 100644 index 0000000..b2bbb8c --- /dev/null +++ b/freechat-client/src/members.js @@ -0,0 +1,29 @@ +const got = require('got') + +/** + * @param {String} auth.jwt + * @param {u64} auth.id + * + * @param {String server.protocol + * @param {String} server.hostname + * @param {u16} server.port + * + * @param {u64} id + * + * @return {Sucess} {id: u64, name: String, joindate: i64, permissions: u64} + * @returns {Failure} null + */ +exports.get_member = async function(auth, server, id) { + try { + const url = `${server.protocol}://${server.hostname}:${server.port}/members/single` + const response = await got(url, { + searchParams: { id: auth.id, jwt: auth.jwt, member_id: id }, + responseType: 'json', + }) + + return response.body['member'] + } catch (err) { + return null + } +} + diff --git a/freechat-client/src/messages.js b/freechat-client/src/messages.js index 139d6a5..20852e6 100644 --- a/freechat-client/src/messages.js +++ b/freechat-client/src/messages.js @@ -1,3 +1,4 @@ +const members = require('./members.js') const got = require('got') const $ = require('jquery') @@ -5,10 +6,11 @@ class Message { static TYPES = ['text', 'jpeg', 'png', 'webm', 'mp4'] - constructor(id, time, content, type, uid, cid) { + constructor(id, time, content, type, uid, uname, cid) { this.id = id this.time = time this.uid = uid + this.uname = uname this.cid = cid this.type = type @@ -19,6 +21,7 @@ class Message { this.content = null } else { this.content = content + } } @@ -65,6 +68,7 @@ async function get_range(auth, server, channel_id, start_time, end_time, limit) msg['content'], msg['type'], msg['author_id'], + msg['name'], msg['channel_id'] )) } @@ -72,6 +76,31 @@ async function get_range(auth, server, channel_id, start_time, end_time, limit) return messages } +/** + * @param {Message} message + * + * @description Basically pushes the required html to the dom + * @returns void + */ +function push_message(message) { + let a_tag = $('').attr({ + id: `message-${message.uid}`, + href: '#', + 'class': 'btn btn-link author-name' + }).text(message.uname) + + // next the content itself + let content + if(message.content) { + content = message.content + } else { + content = $('
  • ').text('Unsupported content') + } + + let container = $('

    ').append(a_tag, content).attr('class', 'message') + $('#messages-list').append( $('

  • ').append(container) ) +} + /** * @param {String} auth.jwt | jwt for quick auth * @param {u64} auth.id user | id required by most/all endpoints @@ -84,39 +113,12 @@ async function get_range(auth, server, channel_id, start_time, end_time, limit) * @params {u64} channel.id | channel id to query * @returns void */ -exports.recent_messages = function (auth, server, channel, start_time, end_time, limit) { - +exports.recent_messages = async function (auth, server, channel, start_time, end_time, limit) { $('#channel-name').text('#' + channel['id']) $('#channel-description').text(channel['description']) + $('#messages-list').html('') - const now = Math.floor(new Date().getTime() / 1000) - const yesterday = now - (60 * 60 * 48) + const messages = await get_range(auth, server, channel['id'], start_time, end_time, limit) - get_range(auth, server, channel['id'], yesterday, now, 1000) - .then(messages => { -// TODO: this shit right here brother here we go html farming wew lad -//
  • resident tweeker some bs content

  • - for(const message of messages) { - $('#messages-list').append( - $('
  • ').append( - $('

    ').append( - $('').attr({ - id: message.uid, - href: '#', - 'class': 'btn btn-link author-name' - }).text(message.uid), - message.content - ).attr('class', 'message') - ) - ) - console.log(message) - } - }, - http_err => { - console.log('Couldn\'t fetch data from server', http_err) - console.log(http_err.request) - }) - .catch(err => { - console.log('Hanlding built in error') - }) + for(const message of messages) { push_message(message) } } diff --git a/freechat-client/src/request.js b/freechat-client/src/request.js index ef4a517..7ca1c97 100644 --- a/freechat-client/src/request.js +++ b/freechat-client/src/request.js @@ -1,6 +1,5 @@ const got = require('got') const { Response } = require('./response.js') -const fs = require('fs') /** *