diff --git a/examples/iris-chat/index.html b/examples/iris-chat/index.html
index 09a2eac8..bfd32b85 100644
--- a/examples/iris-chat/index.html
+++ b/examples/iris-chat/index.html
@@ -11,13 +11,10 @@
'
);
el.toggleClass('our', msg.selfAuthored ? true : false);
- $(".message-list").append(el);
+ $(".message-list").append(el); // TODO: jquery insertAfter element with smaller timestamp
});
});
$(".chat-list").append(el);
- chats[pub] = new irisLib.Chat({gun, key, participants: pub, onMessage: (msg, info) => {
- chats[pub].messages = chats[pub].messages || [];
- msg.selfAuthored = info.selfAuthored;
- chats[pub].messages[msg.time] = msg;
- console.log(msg);
- }});
}
- $(".chat__submit").on('click', submit);
- $(".chat_form").on('keydown', enter);
- function enter(e) {
- if (e.which !== 13) { return }
- submit(e);
+ function formatDate(date) {
+ var s = date.toISOString().split('T');
+ return s[0] + ' ' + s[1].slice(0,5);
}
- function submit(e) {
- e.preventDefault();
-
- var msg = { when: Gun.time.is() };
-
- msg.who = $('.chat__name-input').val();
- if (!msg.who) {
- msg.who = 'user' + Gun.text.random(3);
- $('.chat__name-input').val(msg.who);
- }
-
- msg.what = $('.chat__message-input').val();
- if (!msg.what) { return }
-
- chat.set(msg);
- $('.chat__message-input').val('').focus();
- }
-
- chat.map().val(function (msg, id) {
- if (!msg) { return }
- var messageList = $('.chat__message-list');
- var last = sort(msg.when, messageList.children('li').last());
-
- var li = $("#msg-" + id)[0]; // grab if exists
- if (!li) {
- li = $('.model li').clone(true) // else create it
- .attr('id', 'msg-' + id)
- .insertAfter(last);
- }
-
- // bind the message data into the UI
- li = $(li);
- li.find('.chat__name').text(msg.who);
- li.find('.chat__message-text').text(msg.what);
- li.find('.sort').text(msg.when);
-
- var time = new Date(msg.when);
- li.find('.chat__when').text(time.toDateString() + ', ' + time.toLocaleTimeString());
-
- $('html, body').stop(true, true)
- .animate({ scrollTop: messageList.height() });
- });
-
- function sort(num, li) { return parseFloat(num) >= parseFloat($(li).find('.sort').text() || -Infinity) ? li : sort(num, li.prev()) }
diff --git a/examples/iris-chat/style.css b/examples/iris-chat/style.css
index b7aadf8d..bc885c6f 100644
--- a/examples/iris-chat/style.css
+++ b/examples/iris-chat/style.css
@@ -1,3 +1,5 @@
+* { box-sizing: border-box; }
+
body {
font-size: 15px;
color: #262626;
@@ -6,6 +8,31 @@ body {
margin: 0;
}
+input, button {
+ padding: 15px;
+ border-radius: 50px;
+ outline: none;
+ border: 0;
+ font-size: 15px;
+}
+
+input {
+ margin-right: 7px;
+}
+
+button {
+ background: #ddd;
+}
+
+button:hover {
+ background: #ccc;
+ cursor: pointer;
+}
+
+.iris-identicon {
+ margin-right: 15px !important;
+}
+
.chat {
display: flex;
flex-direction: row;
@@ -24,7 +51,7 @@ body {
.main {
display: flex;
flex-direction: column;
- flex: 10 0 10em;
+ flex: 4 0 10em;
}
/*----- Main------- */
@@ -32,31 +59,30 @@ body {
.online-user-list {
flex:1;
background-color: #efefef;
- max-height:50px;
- padding: 10px;
+ max-height:60px;
+ padding: 10px 15px;
font-size: 12px;
}
.message-list {
flex:1;
overflow-y: scroll;
- padding: 10px;
+ padding: 10px 15px;
background-color: #e5ddd5;
}
.msg {
background-color: #ffffff;
- margin: 0 40px 10px 0;
- padding: 10px;
+ margin: 0 90px 15px 0;
+ padding: 8px 10px;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.1);
- border-radius: 10px;
+ border-radius: 15px;
}
.msg.our {
- text-align: right;
background-color: #d7f7c5;
- border-radius: 10px 0px 10px 10px;
- margin: 0 0px 10px 40px;
+ border-radius: 15px 0px 15px 15px;
+ margin: 0 0px 15px 90px;
}
.msg .time {
@@ -65,38 +91,35 @@ body {
color: rgba(0, 0, 0, 0.45);
}
-.typing-indicator {
- flex:1;
- max-height:30px;
- background-color: #ccc;
- padding: 10px;
-}
-
.message-form {
flex:1;
flex-direction: row;
max-height:70px;
background-color: #efefef;
- padding: 10px;
+ padding: 10px 15px;
+}
+
+.message-form form {
+ display: flex;
}
.message-form input {
- flex: 5;
+ flex: 1;
width: auto;
}
.message-form button {
- flex: 1;
+ flex: none;
}
/*----- Sidebar------- */
.user-info {
flex:1;
- max-height:50px;
+ max-height:60px;
overflow-y: hidden;
- overflow-x: wrap;
- padding: 10px;
+ overflow-x: hidden;
+ padding: 10px 15px;
background-color: #efefef;
}
@@ -110,12 +133,25 @@ body {
}
.chat-item {
- padding: 20px 10px;
+ padding: 10px 15px;
overflow-x: hidden;
border-bottom: 1px solid #efefef;
cursor: pointer;
}
+.chat-item .latest {
+ font-size: 12px;
+ color: rgba(0, 0, 0, 0.45);
+}
+
.chat-item:hover {
background: #f3f3f3;
}
+
+.chat-item.new {
+ background-color: #9ee8ff;
+}
+
+.chat-item.new:hover {
+ background-color: #99e1f7;
+}