update iris-lib, fix signup by pressing enter

This commit is contained in:
Martti Malmi 2020-04-06 15:17:25 +03:00
parent a757b75f9c
commit 0f8e7420de
3 changed files with 486 additions and 255 deletions

View File

@ -62,16 +62,16 @@
<div class="chat"> <div class="chat">
<section id="login" class="hidden"> <section id="login" class="hidden">
<div id="login-content"> <div id="login-content">
<div id="login-form" autocomplete="off"> <form id="login-form" autocomplete="off">
<div id="create-account"> <div id="create-account">
<img style="width: 86px" src="img/android-chrome-192x192.png" alt="Iris"> <img style="width: 86px" src="img/android-chrome-192x192.png" alt="Iris">
<h1>Iris Messenger</h1> <h1>Iris Messenger</h1>
<input autofocus autocomplete="off" autocorrect="off" autocapitalize="sentences" spellcheck="off" id="login-form-name" type="text" name="name" placeholder="What's your name?"> <input autofocus autocomplete="off" autocorrect="off" autocapitalize="sentences" spellcheck="off" id="login-form-name" type="text" name="name" placeholder="What's your name?">
<p><button id="sign-up" type="input">Go</button></p> <p><button id="sign-up" type="submit">Go</button></p>
<br> <br>
<p><a href="#" id="show-existing-account-login">Already have an account?</a></p> <p><a href="#" id="show-existing-account-login">Already have an account?</a></p>
</div> </div>
</div> </form>
<div id="existing-account-login" class="hidden"> <div id="existing-account-login" class="hidden">
<p><a href="#" id="show-create-account">&lt; Back</a></p> <p><a href="#" id="show-create-account">&lt; Back</a></p>
<input id="paste-privkey" placeholder="Paste a private key"> <input id="paste-privkey" placeholder="Paste a private key">

View File

@ -130,7 +130,8 @@ async function addPeer(peer) {
function newUserLogin() { function newUserLogin() {
$('#login').show(); $('#login').show();
$('#login-form-name').focus(); $('#login-form-name').focus();
$('#sign-up').click(function() { $('#login-form').submit(function(e) {
e.preventDefault();
var name = $('#login-form-name').val(); var name = $('#login-form-name').val();
if (name.length) { if (name.length) {
$('#login').hide(); $('#login').hide();
@ -148,13 +149,13 @@ function login(k) {
key = k; key = k;
localStorage.setItem('chatKeyPair', JSON.stringify(k)); localStorage.setItem('chatKeyPair', JSON.stringify(k));
$('#login').hide(); $('#login').hide();
iris.Chat.initUser(gun, key); iris.Channel.initUser(gun, key);
$('#my-chat-links').empty(); $('#my-chat-links').empty();
iris.Chat.getMyChatLinks(gun, key, undefined, chatLink => { iris.Channel.getMyChannelLinks(gun, key, undefined, chatLink => {
var row = $('<div>').addClass('flex-row'); var row = $('<div>').addClass('flex-row');
var text = $('<div>').addClass('flex-cell').text(chatLink.url); var text = $('<div>').addClass('flex-cell').text(chatLink.url);
var btn = $('<button>Remove</button>').click(() => { var btn = $('<button>Remove</button>').click(() => {
iris.Chat.removeChatLink(gun, key, chatLink.id); iris.Channel.removeChannelLink(gun, key, chatLink.id);
hideAndRemove(row); hideAndRemove(row);
}); });
row.append(text); row.append(text);
@ -178,7 +179,7 @@ function login(k) {
} }
}); });
setOurOnlineStatus(); setOurOnlineStatus();
iris.Chat.getChats(gun, key, addChat); iris.Channel.getChannels(gun, key, addChat);
var chatWith = getUrlParameter('chatWith'); var chatWith = getUrlParameter('chatWith');
if (chatWith) { if (chatWith) {
addChat(chatWith, window.location.href); addChat(chatWith, window.location.href);
@ -223,7 +224,7 @@ function login(k) {
} }
async function createChatLink() { async function createChatLink() {
latestChatLink = await iris.Chat.createChatLink(gun, key); latestChatLink = await iris.Channel.createChannelLink(gun, key);
setChatLinkQrCode(latestChatLink); setChatLinkQrCode(latestChatLink);
} }
@ -344,24 +345,24 @@ $('#settings-about').on('input', event => {
}); });
function setOurOnlineStatus() { function setOurOnlineStatus() {
iris.Chat.setOnline(gun, areWeOnline = true); iris.Channel.setOnline(gun, areWeOnline = true);
document.addEventListener("mousemove", () => { document.addEventListener("mousemove", () => {
if (!areWeOnline && activeChat) { if (!areWeOnline && activeChat) {
chats[activeChat].setMyMsgsLastSeenTime(); chats[activeChat].setMyMsgsLastSeenTime();
} }
iris.Chat.setOnline(gun, areWeOnline = true); iris.Channel.setOnline(gun, areWeOnline = true);
clearTimeout(onlineTimeout); clearTimeout(onlineTimeout);
onlineTimeout = setTimeout(() => iris.Chat.setOnline(gun, areWeOnline = false), 60000); onlineTimeout = setTimeout(() => iris.Channel.setOnline(gun, areWeOnline = false), 60000);
}); });
document.addEventListener("visibilitychange", () => { document.addEventListener("visibilitychange", () => {
if (document.visibilityState === 'visible') { if (document.visibilityState === 'visible') {
iris.Chat.setOnline(gun, areWeOnline = true); iris.Channel.setOnline(gun, areWeOnline = true);
if (activeChat) { if (activeChat) {
chats[activeChat].setMyMsgsLastSeenTime(); chats[activeChat].setMyMsgsLastSeenTime();
changeChatUnseenCount(activeChat, 0); changeChatUnseenCount(activeChat, 0);
} }
} else { } else {
iris.Chat.setOnline(gun, areWeOnline = false); iris.Channel.setOnline(gun, areWeOnline = false);
} }
}); });
} }
@ -884,7 +885,7 @@ function addMessage(msg) {
} }
function deleteChat(pub) { function deleteChat(pub) {
iris.Chat.deleteChat(gun, key, pub); iris.Channel.deleteChannel(gun, key, pub);
if (activeChat === pub) { if (activeChat === pub) {
showNewChat(); showNewChat();
showMenu(); showMenu();
@ -902,7 +903,7 @@ function addChat(pub, chatLink) {
el.attr('data-pub', pub); el.attr('data-pub', pub);
var latestEl = el.find('.latest'); var latestEl = el.find('.latest');
var typingIndicator = el.find('.typing-indicator').text('Typing...'); var typingIndicator = el.find('.typing-indicator').text('Typing...');
chats[pub] = new iris.Chat({gun, key, chatLink: chatLink, participants: pub, onMessage: (msg, info) => { chats[pub] = new iris.Channel({gun, key, chatLink: chatLink, participants: pub, onMessage: (msg, info) => {
msg.selfAuthored = info.selfAuthored; msg.selfAuthored = info.selfAuthored;
chats[pub].messages[msg.time] = msg; chats[pub].messages[msg.time] = msg;
msg.time = new Date(msg.time); msg.time = new Date(msg.time);
@ -1007,7 +1008,7 @@ function addChat(pub, chatLink) {
latestEl.toggle(!isTyping); latestEl.toggle(!isTyping);
}); });
chats[pub].online = {}; chats[pub].online = {};
iris.Chat.getOnline(gun, pub, (online) => { iris.Channel.getOnline(gun, pub, (online) => {
if (chats[pub]) { if (chats[pub]) {
chats[pub].online = online; chats[pub].online = online;
setTheirOnlineStatus(pub); setTheirOnlineStatus(pub);

File diff suppressed because it is too large Load Diff