diff --git a/freechat-client/pages/index.html b/freechat-client/pages/index.html index d11ec73..3e76d32 100644 --- a/freechat-client/pages/index.html +++ b/freechat-client/pages/index.html @@ -45,7 +45,7 @@
').append(a_tag, content).attr('class', 'message') @@ -99,6 +130,31 @@ exports.recent_messages = async function (auth, server, channel, start_time, end } } -exports.send = async function() { - console.log('todo') +/** + * @param {String} server.protocol + * @param {String} server.hostname + * @param {String} server.port + * + * @param {String} auth.jwt + * @param {Number} auth.id + * + * @param {Number} channel_id + */ +async function send(server, auth, channel_id, body) { + const url = `${server.protocol}://${server.hostname}:${server.port}/message/send` + console.log('sending: ', url) + // using callbacks for finer grain control of error messages + got.post(url, { + searchParams: { + id: auth.id, jwt: auth.jwt, + channel_id: channel_id, + type: 'text' + }, + body: body + }) + .then( + response => console.log('Sucess: ', response), // all good + failure => { console.log('Failed to send: ', server, auth, channel_id, failure.options) } + ) + } diff --git a/freechat-client/src/types.ts b/freechat-client/src/types.ts index 4668322..9e82d2b 100644 --- a/freechat-client/src/types.ts +++ b/freechat-client/src/types.ts @@ -20,7 +20,7 @@ export class Message { this.type = type // throw away the content if its not of a valid type - if(this.TYPES.indexOf(content) == -1) { + if(this.TYPES.indexOf(type) < 0) { this.content = null } else { this.content = content