From adb3a186506ec35fb081da7683b119c01dbb6a19 Mon Sep 17 00:00:00 2001 From: Beatrice Olivera Date: Wed, 5 Sep 2018 15:39:17 +0100 Subject: [PATCH 1/4] key --- .gitignore | 1 - translation-credentials.json | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 translation-credentials.json diff --git a/.gitignore b/.gitignore index 127293d..2a08fef 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,3 @@ yarn-error.log .byebug_history .env* .env* -translation-credentials.json diff --git a/translation-credentials.json b/translation-credentials.json new file mode 100644 index 0000000..b065dda --- /dev/null +++ b/translation-credentials.json @@ -0,0 +1,14 @@ +{ + "type": "service_account", + "project_id": "booming-banner-212315", + "private_key_id": "9c2ce218223666d974da8f33e8329e5c6d40a471", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC4jSV/s2mp2nri\nJkD4W62aSithmFgd0dNZbPBuDNkhscGXfI4HAYzbWGBHw9gAuN59ezIVFZ3W3IsB\na3scJHup58ZV6zIaeEY5uFhgIlwdohi0iMKvY0eClTBiabu5Drn4OE8IlFX99Ab1\nwhV7WRjGG8YEQ2d1pUHHvS98QeQvb1Km6M9E/4GFib3xcBU0VFO2Evk3AJzK9K1z\nT+DsduloNxAaZfcygWvzhDez2sxftR9PXE1Ek/KQSuATACn11rPUyr/CuHfGSUh6\nypKMUnaYb8EnjrNW/bea/GKjGMzvHubjN/lPEEovXTYANfCXvVMy7ThdQLjS6YIW\nEPvEhS2jAgMBAAECggEAEbiT8jgzHDk7dX3A3VhISjl3Au8S/wIH7l1UlOys6Nxd\nv4MZTDjs4p8Q17NJiYA29QugWn/x4RDaVC+S6bfjHASCefuUmxAThjVaXxjNiZbo\nEmXTc+3vju1ucPTALtvoJZqalDNSMol9JZoWX/rFMzi1gfFK/PP6ZgiXh7H4DEnV\nDtwI8uXs6xGpC5Kr2u2N64RDqk9DbZ6lP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ting-account-c76g3v5fh5js@booming-banner-212315.iam.gserviceaccount.com", + "client_id": "105634639063680583591", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/starting-account-c76g3v5fh5js%40booming-banner-212315.iam.gserviceaccount.com" +} + + From a0ef7458aa37c7baf8c8b95ee6e5dab12093959a Mon Sep 17 00:00:00 2001 From: Beatrice Olivera Date: Wed, 5 Sep 2018 18:17:13 +0100 Subject: [PATCH 2/4] chat css --- app/assets/stylesheets/pages/_index.scss | 1 + app/assets/stylesheets/pages/_messages.scss | 19 +++++++++++++++++ app/controllers/pages_controller.rb | 5 ++++- app/javascript/packs/chatrooms.js | 23 +++++++++++++++------ app/javascript/packs/scroll.js | 10 +++++++++ app/views/chat_rooms/show.html.erb | 19 ++++++++--------- 6 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 app/assets/stylesheets/pages/_messages.scss create mode 100644 app/javascript/packs/scroll.js diff --git a/app/assets/stylesheets/pages/_index.scss b/app/assets/stylesheets/pages/_index.scss index 52316dd..96bb455 100644 --- a/app/assets/stylesheets/pages/_index.scss +++ b/app/assets/stylesheets/pages/_index.scss @@ -2,6 +2,7 @@ @import "home"; @import "contacts"; @import "settings"; +@import "messages"; .accept-call-button { border-style: none; diff --git a/app/assets/stylesheets/pages/_messages.scss b/app/assets/stylesheets/pages/_messages.scss new file mode 100644 index 0000000..3f2d4fa --- /dev/null +++ b/app/assets/stylesheets/pages/_messages.scss @@ -0,0 +1,19 @@ +.messages-container-container { + background-color: $card-background; + width: 100%; + height: 100vh; + position: relative; + .chat { + position: absolute; + bottom: 10px; + } +} + +#messages-container { + overflow: scroll; + height: 80%; + padding: 10px; + .message { + color: white; + } +} diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 9577412..c1e8bcd 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -39,6 +39,7 @@ class PagesController < ApplicationController chatroom = 'chat_room_' + params[:chat_room_id] puts params user_info = {} + photo_url = current_user.photo.url || "https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png" if current_user.first_name.nil? || current_user.last_name.nil? user_info[:name] = current_user.email @@ -50,7 +51,9 @@ class PagesController < ApplicationController chat_message: { message: 'test', user_info: user_info, - time_stamp: Time.now } + time_stamp: Time.now, + photo_url: photo_url + } }) head :ok end diff --git a/app/javascript/packs/chatrooms.js b/app/javascript/packs/chatrooms.js index c5e1267..3a1932a 100644 --- a/app/javascript/packs/chatrooms.js +++ b/app/javascript/packs/chatrooms.js @@ -1,5 +1,5 @@ import ActionCable from 'actioncable' - +// import { scrollLastMessageIntoView } from './chatrooms' // create App object with key cable == new cosumer (function() { window.App || (window.App = {}); @@ -24,11 +24,20 @@ App['chatroom' + chatroomId] = App.cable.subscriptions.create({ const chatMessage = data["chat_message"] const message = `${chatMessage["message"]}` const messagesContainer = document.getElementById('messages-container') + + + const messageDiv = document.createElement("div") + const photo = document.createElement("img") + photo.src = chatMessage["photo_url"] + + // messageDiv.appendChild(photo) + const messageElement = document.createElement("p") + messageElement.classList.add("message") messageElement.innerText = message messagesContainer.appendChild(messageElement) - } - else if (data["chat_message"] && data["chat_message"]["userId"] != userId) { + + } else if (data["chat_message"] && data["chat_message"]["userId"] != userId) { const chatMessage = data["chat_message"] const target = document.getElementById('language-1').value @@ -51,9 +60,11 @@ App['chatroom' + chatroomId] = App.cable.subscriptions.create({ } } else if (data["translated_message"] && data["userId"] == userId) { const messagesContainer = document.getElementById('messages-container') - const message = document.createElement("p") - message.innerText = data["translated_message"] - messagesContainer.appendChild(message) + const messageElement = document.createElement("p") + messageElement.classList.add("message") + messageElement.innerText = data["translated_message"] + messagesContainer.appendChild(messageElement) + scrollLastMessageIntoView(); } else { // console.log(data) } diff --git a/app/javascript/packs/scroll.js b/app/javascript/packs/scroll.js new file mode 100644 index 0000000..9a8f982 --- /dev/null +++ b/app/javascript/packs/scroll.js @@ -0,0 +1,10 @@ +function scrollLastMessageIntoView() { + const messages = document.querySelectorAll('.message'); + const lastMessage = messages[messages.length - 1]; + + if (lastMessage !== undefined) { + lastMessage.scrollIntoView(); + } +} + +export { scrollLastMessageIntoView } diff --git a/app/views/chat_rooms/show.html.erb b/app/views/chat_rooms/show.html.erb index 304a277..a7b7ea0 100644 --- a/app/views/chat_rooms/show.html.erb +++ b/app/views/chat_rooms/show.html.erb @@ -4,6 +4,11 @@
+ +
@@ -13,23 +18,17 @@
-
- -
-
+
- -
+
- -
- -
+ +
From 9ddbd38bce721176c1ae7a0c5548126b58ea53e3 Mon Sep 17 00:00:00 2001 From: Beatrice Olivera Date: Wed, 5 Sep 2018 23:23:10 +0100 Subject: [PATCH 3/4] implemented inline form --- app/assets/stylesheets/pages/_messages.scss | 18 ++++++- app/views/chat_rooms/show.html.erb | 55 ++++++++++++--------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/app/assets/stylesheets/pages/_messages.scss b/app/assets/stylesheets/pages/_messages.scss index 3f2d4fa..9cd1d8b 100644 --- a/app/assets/stylesheets/pages/_messages.scss +++ b/app/assets/stylesheets/pages/_messages.scss @@ -5,15 +5,29 @@ position: relative; .chat { position: absolute; - bottom: 10px; + bottom: 0px; } } #messages-container { overflow: scroll; - height: 80%; + height: 95%; padding: 10px; .message { color: white; } } + +select:not([multiple]) { + -webkit-appearance: none; + -moz-appearance: none; + background-position: right 50%; + background-repeat: no-repeat; + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEge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AASUVORK5CYII=); + padding: .5em; + padding-right: 1.5em; +} + +#language-1 { + border-radius: 0; +} diff --git a/app/views/chat_rooms/show.html.erb b/app/views/chat_rooms/show.html.erb index a7b7ea0..adcfc50 100644 --- a/app/views/chat_rooms/show.html.erb +++ b/app/views/chat_rooms/show.html.erb @@ -5,34 +5,43 @@
- -
-
-
- +
+
+
+
+
+ +
+ + +
- - -
- -
-
-
-
- - - +
+
+
+
+
+
+ + + + + + + +
+
+
+ +
<%= javascript_pack_tag 'chatrooms' %> From bb2a8ad1b97a0d03b12e67df906dc971adf00ca5 Mon Sep 17 00:00:00 2001 From: Beatrice Olivera Date: Thu, 6 Sep 2018 01:52:00 +0100 Subject: [PATCH 4/4] added profile images and colors to the chat messages --- app/assets/stylesheets/components/_hand.scss | 2 +- app/assets/stylesheets/pages/_home.scss | 8 ++++ app/assets/stylesheets/pages/_messages.scss | 40 ++++++++++++++-- app/controllers/pages_controller.rb | 8 ++-- app/javascript/packs/chatrooms.js | 50 ++++++++++++++------ app/views/chat_rooms/show.html.erb | 1 + 6 files changed, 87 insertions(+), 22 deletions(-) diff --git a/app/assets/stylesheets/components/_hand.scss b/app/assets/stylesheets/components/_hand.scss index 49312e2..74a3a5f 100644 --- a/app/assets/stylesheets/components/_hand.scss +++ b/app/assets/stylesheets/components/_hand.scss @@ -2,7 +2,7 @@ position: absolute; bottom: 20px; z-index: 10000000000; - left: 48%; + left: 10%; font-size: 26px; cursor: pointer; } diff --git a/app/assets/stylesheets/pages/_home.scss b/app/assets/stylesheets/pages/_home.scss index a3fa38e..ee6d1a9 100755 --- a/app/assets/stylesheets/pages/_home.scss +++ b/app/assets/stylesheets/pages/_home.scss @@ -6,6 +6,14 @@ video { #remote-video-container { float: left; + i { + text-align: center; + background-color: $primary; + border-radius: 50%; + padding: 15px; + z-index: 999999; + color: white; + } } #local-video { diff --git a/app/assets/stylesheets/pages/_messages.scss b/app/assets/stylesheets/pages/_messages.scss index 9cd1d8b..8c2b0b7 100644 --- a/app/assets/stylesheets/pages/_messages.scss +++ b/app/assets/stylesheets/pages/_messages.scss @@ -1,5 +1,5 @@ .messages-container-container { - background-color: $card-background; + background-color: $light-gray; width: 100%; height: 100vh; position: relative; @@ -13,9 +13,6 @@ overflow: scroll; height: 95%; padding: 10px; - .message { - color: white; - } } select:not([multiple]) { @@ -31,3 +28,38 @@ select:not([multiple]) { #language-1 { border-radius: 0; } + +.avatar-sm { + width: 35px; + height: 35px; +} + +.messageDiv { + display: flex; + align-items: center; + padding-top: 10px; + padding-bottom: 10px; + + p { + padding-top: 2px; + padding-bottom: 2px; + padding-left: 8px; + padding-right: 8px; + background-color: #d4d5d6; + color: $navbar-background; + border-radius: 2px; + } + + &.right { + flex-direction: row-reverse; + p { + background-color: $primary; + color: white !important; + } + } + +} + +.margin-left { + margin-left: 10px; +} diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index c1e8bcd..1ad249d 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -39,7 +39,6 @@ class PagesController < ApplicationController chatroom = 'chat_room_' + params[:chat_room_id] puts params user_info = {} - photo_url = current_user.photo.url || "https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png" if current_user.first_name.nil? || current_user.last_name.nil? user_info[:name] = current_user.email @@ -83,7 +82,8 @@ class PagesController < ApplicationController ActionCable.server.broadcast "chat_room_#{params[:chat_room_id]}", { translated_message: translated_message, - userId: userId + userId: userId, + photo_url: params[:photo_url] } end @@ -93,6 +93,7 @@ class PagesController < ApplicationController chatroom = 'chat_room_' + params[:chat_room_id] puts params user_info = {} + photo_url = current_user.photo.url || "https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png" if current_user.first_name.nil? || current_user.last_name.nil? user_info[:name] = current_user.email @@ -105,7 +106,8 @@ class PagesController < ApplicationController message: params[:message], user_info: user_info, time_stamp: Time.now.strftime("%H:%M"), - userId: current_user.id + userId: current_user.id, + photo_url: photo_url } }) head :ok diff --git a/app/javascript/packs/chatrooms.js b/app/javascript/packs/chatrooms.js index 3a1932a..8853946 100644 --- a/app/javascript/packs/chatrooms.js +++ b/app/javascript/packs/chatrooms.js @@ -25,22 +25,34 @@ App['chatroom' + chatroomId] = App.cable.subscriptions.create({ const message = `${chatMessage["message"]}` const messagesContainer = document.getElementById('messages-container') - + // Div Settings const messageDiv = document.createElement("div") + messageDiv.classList.add("messageDiv") + messageDiv.classList.add("right") + + // Photo Settings const photo = document.createElement("img") photo.src = chatMessage["photo_url"] + photo.classList.add("img-circle") + photo.classList.add("avatar-sm") + photo.classList.add("margin-left") - // messageDiv.appendChild(photo) - + // Text Settings const messageElement = document.createElement("p") messageElement.classList.add("message") + messageElement.classList.add("no-margin") messageElement.innerText = message - messagesContainer.appendChild(messageElement) + + // Add message and photo to div + messageDiv.appendChild(photo) + messageDiv.appendChild(messageElement) + + // Add message to container + messagesContainer.appendChild(messageDiv) } else if (data["chat_message"] && data["chat_message"]["userId"] != userId) { const chatMessage = data["chat_message"] const target = document.getElementById('language-1').value - const message = `${chatMessage["message"]}` fetch(`/chat_rooms/${chatroomId}/translate_message` , { @@ -48,23 +60,33 @@ App['chatroom' + chatroomId] = App.cable.subscriptions.create({ body: JSON.stringify({ message: message, target: target, - userId: userId + userId: userId, + photo_url: chatMessage["photo_url"] }), headers: { "content-type": "application/json", "X-CSRF-Token": document.querySelector('meta[name=csrf-token]').content } }) - } else if (data["translation"] && data["userId"] == userId) { - if (data["input"] == 1) { - document.getElementById('language-2-input').value = data["translation"].text - } else { - document.getElementById('language-1-input').value = data["translation"].text - } } else if (data["translated_message"] && data["userId"] == userId) { const messagesContainer = document.getElementById('messages-container') + + const messageDiv = document.createElement("div") + messageDiv.classList.add("messageDiv") + + const photo = document.createElement("img") + photo.src = data["photo_url"] + photo.classList.add("img-circle") + photo.classList.add("avatar-sm") + photo.classList.add("margin-right") + const messageElement = document.createElement("p") messageElement.classList.add("message") + messageElement.classList.add("message") + messageElement.classList.add("no-margin") messageElement.innerText = data["translated_message"] - messagesContainer.appendChild(messageElement) - scrollLastMessageIntoView(); + + messageDiv.appendChild(photo) + messageDiv.appendChild(messageElement) + + messagesContainer.appendChild(messageDiv) } else { // console.log(data) } diff --git a/app/views/chat_rooms/show.html.erb b/app/views/chat_rooms/show.html.erb index adcfc50..d75555e 100644 --- a/app/views/chat_rooms/show.html.erb +++ b/app/views/chat_rooms/show.html.erb @@ -14,6 +14,7 @@
+