diff --git a/index.html b/index.html index 1cf3441..4f511fd 100644 --- a/index.html +++ b/index.html @@ -48,13 +48,13 @@
-
-
+
+
-
+
@@ -70,11 +70,16 @@
- You - Error - @<{{ message.source_hash }}> + You + Error + @<{{ chatItem.source_hash }}> +
+
{{ chatItem.message.content }}
+
+
+ +
-
{{ message.text }}
@@ -111,7 +116,7 @@ isSendingMessage: false, autoScrollOnNewMessage: true, - messages: [], + chatItems: [], }; }, @@ -137,10 +142,9 @@ const json = JSON.parse(message.data); switch(json.type){ case 'lxmf.delivery': { - this.messages.push({ - "type": "text", + this.chatItems.push({ "source_hash": json.source_hash, - "text": json.message, + "message": json.message, }) if(this.autoScrollOnNewMessage){ this.scrollMessagesToBottom(); @@ -208,11 +212,12 @@ })); // add sent message to ui - this.messages.push({ + this.chatItems.push({ "is_outbound": true, "source_hash": "todo", // FIXME - "type": "text", - "text": messageText, + "message": { + "content": messageText, + }, }); // clear message input @@ -222,7 +227,7 @@ console.error(e); - this.messages.push({ + this.chatItems.push({ "source_hash": "error", "type": "text", "text": e.message ?? e ?? "Unknown Error...", @@ -254,6 +259,18 @@ onShiftEnterPressed: function() { this.addNewLine(); }, + openImage: async function(url) { + + // convert data uri to blob + const blob = await (await fetch(url)).blob(); + + // create blob url + const fileUrl = window.URL.createObjectURL(blob); + + // open new tab + window.open(fileUrl); + + }, }, computed: { isMobile() { diff --git a/web.py b/web.py index 915c9e7..a057e6f 100644 --- a/web.py +++ b/web.py @@ -101,16 +101,35 @@ def lxmf_delivery(message): message_content = message.content.decode('utf-8') source_hash_text = RNS.hexrep(message.source_hash, delimit=False) + fields = [] + message_fields = message.get_fields() + for field_type in message_fields: + + value = message_fields[field_type] + + # handle image field + if field_type == LXMF.FIELD_IMAGE: + image_type = value[0] + image_bytes = base64.b64encode(value[1]).decode("utf-8") + fields.append({ + "type": "image", + "image_type": image_type, + "image_bytes": image_bytes, + }) + # send received lxmf message data to all websocket clients websocket_broadcast(json.dumps({ "type": "lxmf.delivery", "source_hash": source_hash_text, - "message": message_content, + "message": { + "content": message_content, + "fields": fields, + }, })) except Exception as e: # do nothing on error - print(e) + print("lxmf_delivery error: {}".format(e)) def send_message(destination_hash, message_content):