- 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
This commit is contained in:
shockrah 2021-04-14 22:58:03 -07:00
parent 40351f934e
commit 68e22e1b38
4 changed files with 29 additions and 25 deletions

View File

@ -1,4 +1,4 @@
// Requesting channel data here const { ipcRenderer } = require('electron')
const { Channel } = require('./types') const { Channel } = require('./types')
const $ = require('jquery') const $ = require('jquery')
const got = require('got') const got = require('got')
@ -98,15 +98,6 @@ async function list(server, user, kind) {
} }
} }
/**
* @param {List<Channel>}
*/
async function assemble_channels_dom(channels) {
for(const channel of channels) {
console.log(channel)
push(server, user, channel)
}
}
/** /**
* @param {String} remote.url * @param {String} remote.url
@ -118,7 +109,22 @@ exports.server_button_cb = async function(remote, user) {
let tc = await list(remote, user, TEXT_KIND) let tc = await list(remote, user, TEXT_KIND)
vc.push(...tc) vc.push(...tc)
// Assemble the DOM
for(const chan of vc) { for(const chan of vc) {
push(remote, user, chan) 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
})
} }

View File

@ -17,9 +17,8 @@ class Config {
this.data = data this.data = data
} }
// TODO: this function basically
async write_disk() { 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) await fs.writeFile(this.path, str)
} }
} }

View File

@ -1,13 +1,12 @@
const { ipcRenderer } = require('electron') const { ipcRenderer } = require('electron')
const { Message } = require('./types') const { Message } = require('./types')
const URL = require('url')
const got = require('got') const got = require('got')
const $ = require('jquery') const $ = require('jquery')
/** /**
* @param {String} server.hostname | Hostname of target server * @param {String} server.url | Hostname of target server
* @param {u16} server.port | Port to use for server
* @param {String} server.protocol | http/https (no colon)
* *
* @param {String} auth.jwt | jwt for quick auth * @param {String} auth.jwt | jwt for quick auth
* @param {u64} auth.id user | id required by most/all endpoints * @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 * @param {Any} body
*/ */
async function send(server, auth, channel_id, 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 // using callbacks for finer grain control of error messages
got.post(url, { got.post(url, {
searchParams: { searchParams: {
@ -154,9 +153,8 @@ async function send(server, auth, channel_id, body) {
.then( .then(
response => { response => {
console.log(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) }
) )
} }

View File

@ -7,15 +7,16 @@ const MESSAGE_TYPES: Array<String> = [
] ]
export class Message { export class Message {
id: Number id: BigInt //u64
time: Number time: BigInt//i64
uid: BigInt //u64
cid: BigInt //u64
type: String type: String
content: String|null content: String|null
uid: Number
uname: String 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.id = id
this.time = time this.time = time
this.uid = uid this.uid = uid
@ -36,10 +37,10 @@ export class Message {
export class Channel { export class Channel {
name: String name: String
type: Number type: Number
id: Number id: BigInt
description: String|null 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.name = name
this.type = type this.type = type
this.id = id this.id = id