From 22d754d514354dde0fdb8ee8032d0b850462b936 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 25 Aug 2017 14:42:05 +0200 Subject: [PATCH] handle user renames --- www/common/common-messenger.js | 18 +++++++++++++----- www/contacts2/messenger-ui.js | 24 +++++++++++++++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/www/common/common-messenger.js b/www/common/common-messenger.js index 3117c60c1..129c27935 100644 --- a/www/common/common-messenger.js +++ b/www/common/common-messenger.js @@ -395,9 +395,9 @@ define([ }); if (typeof(idx) !== 'undefined') { - console.error('found old message at %s', idx); + //console.error('found old message at %s', idx); } else { - console.error("did not find desired message"); + //console.error("did not find desired message"); } // TODO improve performance @@ -439,9 +439,8 @@ define([ return true; } if (parsedMsg[0] === Types.update) { - // TODO emit update event - if (parsedMsg[1] === proxy.curvePublic) { return; } + var curvePublic = parsedMsg[1]; var newdata = parsedMsg[3]; var data = getFriend(proxy, parsedMsg[1]); var types = []; @@ -451,13 +450,19 @@ define([ data[k] = newdata[k]; } }); - //channel.updateUI(types); + + eachHandler('update', function (f) { + f(clone(newdata), curvePublic); + }); return; } if (parsedMsg[0] === Types.unfriend) { + console.log('UNFRIEND'); removeFromFriendList(proxy, realtime, channel.friendEd, function () { channel.wc.leave(Types.unfriend); //channel.removeUI(); + + }); return; } @@ -483,6 +488,9 @@ define([ channel.wc.bcast(cryptMsg).then(function () { // TODO send event //channel.refresh(); + eachHandler('update', function (f) { + f(myData, myData.curvePublic); + }); }, function (err) { console.error(err); }); diff --git a/www/contacts2/messenger-ui.js b/www/contacts2/messenger-ui.js index 759db183c..573ac2110 100644 --- a/www/contacts2/messenger-ui.js +++ b/www/contacts2/messenger-ui.js @@ -13,7 +13,12 @@ define([ var m = function (md) { var d = h('div.content'); - d.innerHTML = Marked(md || ''); + try { + d.innerHTML = Marked(md || ''); + } catch (e) { + console.error(md); + console.error(e); + } return d; }; @@ -82,7 +87,7 @@ define([ return a; } return b; - }); + }, []); }; markup.chatbox = function (curvePublic, data) { @@ -106,6 +111,11 @@ define([ fetching = false; if (e) { return void console.error(e); } history.forEach(function (msg) { + if (msg.type !== 'MSG') { + // handle other types of messages? + return; + } + channel.messages.unshift(msg); var el_message = markup.message(msg); $messagebox.prepend(el_message); @@ -386,7 +396,15 @@ define([ // change in your friend list messenger.on('update', function (info, curvePublic) { - curvePublic = curvePublic; + console.log(info, curvePublic); + var name = displayNames[curvePublic] = info.displayName; + + // update label in friend list + find.inList(curvePublic).find('.name').text(name); + + // update title bar and messages + $messages.find(dataQuery(curvePublic) + ' .header .name, div.message'+ + dataQuery(curvePublic) + ' div.sender').text(name).text(name); }); Cryptpad.onDisplayNameChanged(function () {