webui: chat: sending messages

This commit is contained in:
zeners 2016-02-20 19:37:31 +01:00
parent fdb93c3f8d
commit b8a8f34a48
3 changed files with 67 additions and 26 deletions

View File

@ -43,7 +43,7 @@ google material design has nice rules for color, spacing and everything: https:/
should provide forward, backward and follow-list-end should provide forward, backward and follow-list-end
[ ] backend: view/create identities [ ] backend: view/create identities
[ ] backend: chat lobby participants list [ ] backend: chat lobby participants list
[ ] chat: send_message [X] chat: send_message
[ ] backend: chat typing notifications [ ] backend: chat typing notifications
[ ] make routines to handle retroshare links [ ] make routines to handle retroshare links
[ ] backend: edit shared folders [ ] backend: edit shared folders

View File

@ -45,7 +45,11 @@
padding-top: 0px padding-top: 0px
padding-left: 0px padding-left: 0px
padding-right: 0px padding-right: 0px
&.bottom
position: absolute
bottom: 0px
right: $right_width
left: $left_width
&.msg &.msg
padding: 0px padding: 0px
$author_width: 100px $author_width: 100px

View File

@ -3,7 +3,9 @@
var m = require("mithril"); var m = require("mithril");
var rs = require("retroshare"); var rs = require("retroshare");
function msg(from, when, text){ var msg = null;
function dspmsg(from, when, text){
return m(".chat.msg.container",[ return m(".chat.msg.container",[
m(".chat.msg.from", from), m(".chat.msg.from", from),
m(".chat.msg.when", when), m(".chat.msg.when", when),
@ -45,6 +47,15 @@ function getLobbyDetails(lobbyid){
return null; return null;
} }
function sendmsg(msgid){
var txtmsg = document.getElementById("txtNewMsg");
rs.request("chat/send_message", {
chat_id: msgid,
msg: txtmsg.value
});
txtmsg.value="";
}
function lobby(lobbyid){ function lobby(lobbyid){
var msgs; var msgs;
var lobby = getLobbyDetails(lobbyid); var lobby = getLobbyDetails(lobbyid);
@ -100,12 +111,30 @@ function lobby(lobbyid){
},"subscribe as " + item.name); },"subscribe as " + item.name);
}), }),
]; ];
} else {
msg = m(".chat.bottom",[
m("div","enter new message:"),
m("input",{
id:"txtNewMsg",
onkeydown: function(event){
if (event.keyCode == 13){
sendmsg(lobbyid);
}
}
}),
m("div.btn2", {
style: {textAlign:"center"},
onclick: function(){
sendmsg(lobbyid);
}
},"submit")
]);
} }
return [ return [
intro, intro,
mem.msg.map(function(item){ mem.msg.map(function(item){
var d = new Date(new Number(item.send_time)*1000); var d = new Date(new Number(item.send_time)*1000);
return msg( return dspmsg(
item.author_name, item.author_name,
d.toLocaleDateString() + " " + d.toLocaleTimeString(), d.toLocaleDateString() + " " + d.toLocaleTimeString(),
item.msg item.msg
@ -116,7 +145,8 @@ function lobby(lobbyid){
module.exports = { module.exports = {
frame: function(content, right){ frame: function(content, right){
return m(".chat.container", [ return m("div", [
m(".chat.container", [
m(".chat.header", [ m(".chat.header", [
m( m(
"h2", "h2",
@ -132,13 +162,19 @@ module.exports = {
m(".chat.right", right), m(".chat.right", right),
m(".chat.middle", content), m(".chat.middle", content),
m(".chat.clear", ""), m(".chat.clear", ""),
]),
msg != null
? msg
: [],
]); ]);
}, },
view: function(){ view: function(){
var lobbyid = m.route.param("lobby"); var lobbyid = m.route.param("lobby");
msg = null;
if (lobbyid != undefined ) { if (lobbyid != undefined ) {
return this.frame( return this.frame(
lobby(lobbyid),[] lobby(lobbyid),
[]
); );
}; };
return this.frame( return this.frame(
@ -147,6 +183,7 @@ module.exports = {
{style: {margin:"10px"}}, {style: {margin:"10px"}},
"please select lobby" "please select lobby"
), ),
m("div","right")); m("div","right")
);
} }
} }