From 68e22e1b38f6978789947c43bf0f61379f4b2dd3 Mon Sep 17 00:00:00 2001 From: shockrah Date: Wed, 14 Apr 2021 22:58:03 -0700 Subject: [PATCH] - removing uninportant things + messages module was for some reason still using legacy url generation(fixed that) + switching types to use bigint since everything is u64/i64 on the backend --- freechat-client/src/channels.js | 26 ++++++++++++++++---------- freechat-client/src/config.js | 3 +-- freechat-client/src/messages.js | 10 ++++------ freechat-client/src/types.ts | 15 ++++++++------- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/freechat-client/src/channels.js b/freechat-client/src/channels.js index cdc1f8e..11e1813 100644 --- a/freechat-client/src/channels.js +++ b/freechat-client/src/channels.js @@ -1,4 +1,4 @@ -// Requesting channel data here +const { ipcRenderer } = require('electron') const { Channel } = require('./types') const $ = require('jquery') const got = require('got') @@ -98,15 +98,6 @@ async function list(server, user, kind) { } } -/** - * @param {List} - */ -async function assemble_channels_dom(channels) { - for(const channel of channels) { - console.log(channel) - push(server, user, channel) - } -} /** * @param {String} remote.url @@ -118,7 +109,22 @@ exports.server_button_cb = async function(remote, user) { let tc = await list(remote, user, TEXT_KIND) vc.push(...tc) + // Assemble the DOM for(const chan of vc) { push(remote, user, chan) } + // Finally update the cache + let parts = URL.parse(remote.url) + await ipcRenderer.invoke('cache-new-server', { + cfg: remote, + channels: vc, //weirdly named but it really _is_ the collection of channels + messages: [], + active_target: remote['wsurl'] + }) + let jwt_value = encodeURIComponent(user.jwt) + let url = `${remote.wsurl}/text?jwt=${jwt_value}` + await ipcRenderer.invoke('open-socket', { + url: url, + conf: remote + }) } diff --git a/freechat-client/src/config.js b/freechat-client/src/config.js index 5dcb645..a5d0809 100644 --- a/freechat-client/src/config.js +++ b/freechat-client/src/config.js @@ -17,9 +17,8 @@ class Config { this.data = data } - // TODO: this function basically async write_disk() { - const str = JSON.stringify(this.data, null, 4) + const str = JSONBig.stringify(this.data, null, 4) await fs.writeFile(this.path, str) } } diff --git a/freechat-client/src/messages.js b/freechat-client/src/messages.js index 709f4cd..284ca5d 100644 --- a/freechat-client/src/messages.js +++ b/freechat-client/src/messages.js @@ -1,13 +1,12 @@ const { ipcRenderer } = require('electron') const { Message } = require('./types') +const URL = require('url') const got = require('got') const $ = require('jquery') /** - * @param {String} server.hostname | Hostname of target server - * @param {u16} server.port | Port to use for server - * @param {String} server.protocol | http/https (no colon) + * @param {String} server.url | Hostname of target server * * @param {String} auth.jwt | jwt for quick auth * @param {u64} auth.id user | id required by most/all endpoints @@ -141,7 +140,7 @@ exports.recent_messages = async function (auth, server, channel, start_time, end * @param {Any} body */ async function send(server, auth, channel_id, body) { - const url = `${server.protocol}://${server.hostname}:${server.port}/message/send` + const url = `${server.url}/message/send` // using callbacks for finer grain control of error messages got.post(url, { searchParams: { @@ -154,9 +153,8 @@ async function send(server, auth, channel_id, body) { .then( response => { console.log(response); - //await ipcRenderer.invoke('cache-sent-message', {host: server.hostname, message: response.body } }, - failure => { console.log('Failed to send: ', server, auth, channel_id, failure.options) } + failure => { console.log('Failed to send: ', server, auth, channel_id, failure) } ) } diff --git a/freechat-client/src/types.ts b/freechat-client/src/types.ts index ba6e346..e960fbe 100644 --- a/freechat-client/src/types.ts +++ b/freechat-client/src/types.ts @@ -7,15 +7,16 @@ const MESSAGE_TYPES: Array = [ ] export class Message { - id: Number - time: Number + id: BigInt //u64 + time: BigInt//i64 + uid: BigInt //u64 + cid: BigInt //u64 + type: String content: String|null - uid: Number uname: String - cid: Number - constructor(id: Number, time: Number, content: String, type: String, uid: Number, uname: String, cid: Number) { + constructor(id: BigInt, time: BigInt, content: String, type: String, uid: BigInt, uname: String, cid: BigInt) { this.id = id this.time = time this.uid = uid @@ -36,10 +37,10 @@ export class Message { export class Channel { name: String type: Number - id: Number + id: BigInt description: String|null - constructor(name: String, type: Number, id: Number, desc: String) { + constructor(name: String, type: Number, id: BigInt, desc: String) { this.name = name this.type = type this.id = id