diff --git a/customize.dist/src/less2/include/mediatag.less b/customize.dist/src/less2/include/mediatag.less index 704fd71bd..f8255aab3 100644 --- a/customize.dist/src/less2/include/mediatag.less +++ b/customize.dist/src/less2/include/mediatag.less @@ -7,6 +7,13 @@ text-align: center; } + media-tag:empty { + width: 100px; + height: 100px; + display: inline-block; + border: 1px solid #BBB; + } + media-tag img { flex: 1; max-height: 100% !important; diff --git a/customize.dist/src/less2/include/messenger.less b/customize.dist/src/less2/include/messenger.less index 7f4f7c342..4b89b967d 100644 --- a/customize.dist/src/less2/include/messenger.less +++ b/customize.dist/src/less2/include/messenger.less @@ -121,6 +121,10 @@ } } } + .cp-app-contacts-muted-button { + display: none; + order: 3; + } } } #cp-app-contacts-container.cp-app-contacts-inapp { diff --git a/www/code/app-code.less b/www/code/app-code.less index f07ef534d..219143a34 100644 --- a/www/code/app-code.less +++ b/www/code/app-code.less @@ -98,6 +98,13 @@ max-height: 90vh; } } + media-tag:empty { + width: 100px; + height: 100px; + display: inline-block; + border: 1px solid #BBB; + } + .markdown_main(); .cp-app-code-preview-empty { display: none; diff --git a/www/common/media-tag.js b/www/common/media-tag.js index a2beb3b4a..27683c54e 100644 --- a/www/common/media-tag.js +++ b/www/common/media-tag.js @@ -435,8 +435,6 @@ return mediaObject; } - mediaObject.tag.innerHTML = ''; - // Download the encrypted blob download(src, function (err, u8Encrypted) { if (err) { diff --git a/www/common/messenger-ui.js b/www/common/messenger-ui.js index 1979bae66..7c437969b 100644 --- a/www/common/messenger-ui.js +++ b/www/common/messenger-ui.js @@ -3,9 +3,10 @@ define([ '/customize/messages.js', '/common/common-util.js', '/common/common-interface.js', + '/common/common-ui-elements.js', '/common/hyperscript.js', '/common/diffMarked.js', -], function ($, Messages, Util, UI, h, DiffMd) { +], function ($, Messages, Util, UI, UIElements, h, DiffMd) { 'use strict'; var debug = console.log; @@ -67,8 +68,9 @@ define([ h('div.cp-app-contacts-category-content') ]), h('div.cp-app-contacts-friends.cp-app-contacts-category', [ - h('div.cp-app-contacts-category-content'), + h('div.cp-app-contacts-category-content.cp-contacts-friends'), h('h2.cp-app-contacts-category-title', Messages.contacts_friends), + h('button.cp-app-contacts-muted-button', Messages.contacts_manageMuted || 'MANAGE MUTED') // XXX ]), h('div.cp-app-contacts-rooms.cp-app-contacts-category', [ h('div.cp-app-contacts-category-content'), @@ -486,6 +488,15 @@ define([ } }; + var muteUser = function (data) { + execCommand('MUTE_USER', { + curvePublic: data.curvePublic, + name: data.displayName || data.name, + avatar: data.avatar + }, function (e /*, removed */) { + if (e) { return void console.error(e); } + }); + }; var removeFriend = function (curvePublic) { execCommand('REMOVE_FRIEND', curvePublic, function (e /*, removed */) { if (e) { return void console.error(e); } @@ -529,13 +540,16 @@ define([ if (!channel.isFriendChat) { return; } var curvePublic = channel.curvePublic; var friend = contactsData[curvePublic] || friendData; - UI.confirm(Messages._getKey('contacts_confirmRemove', [ - Util.fixHTML(friend.name) - ]), function (yes) { + var muteBox = UI.createCheckbox('cp-contacts-mute', Messages.contacts_mute, false); + var content = h('div', [ + h('p', Messages._getKey('contacts_confirmRemove', [Util.fixHTML(friend.name)])), + muteBox + ]); + UI.confirm(content, function (yes) { if (!yes) { return; } - removeFriend(curvePublic, function (e) { - if (e) { return void console.error(e); } - }); + var mute = Util.isChecked($(content).find('#cp-contacts-mute')); + muteUser(friend); + removeFriend(curvePublic); // TODO remove friend from userlist ui // FIXME seems to trigger EJOINED from netflux-websocket (from server); // (tried to join a channel in which you were already present) @@ -806,6 +820,40 @@ define([ rooms.forEach(initializeRoom); }); + execCommand('GET_MUTED_USERS', null, function (err, muted) { + if (err) { return void console.error(err); } + + if (!muted || Object.keys(muted).length === 0) { return; } + + var $button = $userlist.find('.cp-app-contacts-muted-button'); + var rows = Object.keys(muted).map(function (curve) { + var data = muted[curve]; + var avatar = h('div.cp-avatar'); + var button = h('td', h('i.fa.fa-times', {title: Messages.contacts_unmute})); + UIElements.displayAvatar(common, $(avatar), data.avatar, data.name); + $(button).click(function () { + execCommand('UNMUTE_USER', { + curvePublic: curve, + }, function (e /*, removed */) { + if (e) { return void console.error(e); } + $(button).closest('tr').remove(); + }); + }); + return h('tr', [ + h('td', avatar), + h('td', data.name), + button + ]); + }); + var content = h('div', [ + h('p', Messages.contacts_mutedUsers), + h('table', rows) + ]); + $button.click(function () { + UI.alert(content); + }).show(); + }); + $container.removeClass('cp-app-contacts-initializing'); }; diff --git a/www/common/outer/messenger.js b/www/common/outer/messenger.js index d0e200deb..90884198e 100644 --- a/www/common/outer/messenger.js +++ b/www/common/outer/messenger.js @@ -458,6 +458,29 @@ define([ } }; + var muteUser = function (ctx, data, _cb) { + var cb = Util.once(Util.mkAsync(_cb)); + var proxy = ctx.store.proxy; + var muted = proxy.mutedUsers = proxy.mutedUsers || {}; + if (muted[data.curvePublic]) { return void cb(); } + muted[data.curvePublic] = data; + cb(); + }; + var unmuteUser = function (ctx, curvePublic, _cb) { + var cb = Util.once(Util.mkAsync(_cb)); + var proxy = ctx.store.proxy; + var muted = proxy.mutedUsers = proxy.mutedUsers || {}; + delete muted[curvePublic]; + cb(); + }; + var getMutedUsers = function (ctx, cb) { + var proxy = ctx.store.proxy; + if (cb) { + return void cb(proxy.mutedUsers || {}); + } + return proxy.mutedUsers || {}; + }; + var openChannel = function (ctx, data) { var proxy = ctx.store.proxy; var network = ctx.store.network; @@ -990,6 +1013,9 @@ define([ if (cmd === 'GET_ROOMS') { return void getRooms(ctx, data, cb); } + if (cmd === 'GET_MUTED_USERS') { + return void getMutedUsers(ctx, cb); + } if (cmd === 'GET_USERLIST') { return void getUserList(ctx, data, cb); } @@ -1002,6 +1028,12 @@ define([ if (cmd === 'REMOVE_FRIEND') { return void removeFriend(ctx, data, cb); } + if (cmd === 'MUTE_USER') { + return void muteUser(ctx, data, cb); + } + if (cmd === 'UNMUTE_USER') { + return void unmuteUser(ctx, data, cb); + } if (cmd === 'GET_STATUS') { return void getStatus(ctx, data, cb); }