From f782bc11cca4a3a45fbceba83906779fea936a4c Mon Sep 17 00:00:00 2001 From: or-else Date: Sun, 19 Aug 2018 10:58:22 +0300 Subject: [PATCH] simplifies InfoView parameters --- README.md | 1 - index.js | 44 ++++++++++++++++++-------------------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index c50d2550..8d546e6d 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ Background pattern from http://subtlepatterns.com/, commercial and non-commercia ## Missing functionality * Previews not generated for videos, audio, links or docs. -* No indication of some chat statuses (muted, blocked, etc.). * Browser push notifications are not implemented. * No end-to-end encryption. * Editing chat permissions is incomplete. diff --git a/index.js b/index.js index 281841ae..2cb5b9a8 100644 --- a/index.js +++ b/index.js @@ -418,7 +418,7 @@ function arrayEqual(a, b) { function topicPermissionSetter(mode, params, errorHandler) { var topic = Tinode.getTopic(params.topicName); if (!topic) { - console.log("Topic not found: " + params.topicName); + console.log("Topic not found", params.topicName); return; } @@ -426,7 +426,7 @@ function topicPermissionSetter(mode, params, errorHandler) { if (params.user) { user = topic.subscriber(params.user); if (!user) { - console.log("Subscriber not found: " + params.topicName + "[" + params.user + "]"); + console.log("Subscriber not found", params.topicName + "[" + params.user + "]"); return; } am = user.acs.updateGiven(mode).getGiven(); @@ -445,7 +445,7 @@ function topicPermissionSetter(mode, params, errorHandler) { function deleteMessages(all, hard, params, errorHandler) { var topic = Tinode.getTopic(params.topicName); if (!topic) { - console.log("Topic not found: " + params.topicName); + console.log("Topic not found: ", params.topicName); return; } var promise = all ? @@ -481,7 +481,7 @@ var ContextMenuItems = { "topic_delete": {title: "Delete", handler: function(params, errorHandler) { var topic = Tinode.getTopic(params.topicName); if (!topic) { - console.log("Topic not found: " + params.topicName); + console.log("Topic not found: ", params.topicName); return; } topic.delTopic().catch(function(err) { @@ -2117,11 +2117,12 @@ class ContactsView extends React.Component { if (this.props.topicSelected === cont.topic) { this.props.onAcsChange(cont.acs); } + } else if (what == "del") { + // messages deleted (hard or soft) -- update pill counter. } else { // TODO(gene): handle other types of notifications: // * ua -- user agent changes (maybe display a pictogram for mobile/desktop). // * upd -- topic 'public' updated, issue getMeta(). - // * del -- messages deleted (hard or soft) -- reset pill counter. console.log("Unsupported (yet) presence update:" + what + " in: " + cont.topic); } } @@ -2783,7 +2784,7 @@ class InfoView extends React.Component { anon: null, contactList: [], tags: [], - showMemberPanel: props.showMemberPanel, + showMemberPanel: false, showPermissionEditorFor: undefined, moreInfoExpanded: false, previousMetaDesc: undefined, @@ -2791,7 +2792,6 @@ class InfoView extends React.Component { previousTagsUpdated: undefined }; - this.initInfoView = this.initInfoView.bind(this); this.resetSubs = this.resetSubs.bind(this); this.resetDesc = this.resetDesc.bind(this); this.onMetaDesc = this.onMetaDesc.bind(this); @@ -2814,7 +2814,8 @@ class InfoView extends React.Component { this.handleContextMenu = this.handleContextMenu.bind(this); } - initInfoView(props) { + // No need to separately handle componentWillMount. + componentWillReceiveProps(props) { var topic = Tinode.getTopic(props.topic); if (!topic) { return; @@ -2842,11 +2843,6 @@ class InfoView extends React.Component { } } - // No need to separately handle componentWillMount. - componentWillReceiveProps(nextProps) { - this.initInfoView(nextProps); - } - componentWillUnmount() { var topic = Tinode.getTopic(this.props.topic); if (!topic) { @@ -2891,6 +2887,7 @@ class InfoView extends React.Component { private: topic.private ? topic.private.comment : null, address: topic.name, groupTopic: (topic.getType() === "grp"), + showMemberPanel: false, access: acs ? acs.getMode() : undefined, modeGiven: acs ? acs.getGiven() : undefined, modeWant: acs ? acs.getWant() : undefined, @@ -4331,7 +4328,6 @@ class TinodeWeb extends React.Component { loginDisabled: false, displayMobile: (window.innerWidth <= MEDIA_BREAKPOINT), showInfoPanel: false, - infoPanelShowMembers: false, mobilePanel: 'sidepanel', contextMenuVisible: false, contextMenuBounds: null, @@ -4658,7 +4654,7 @@ class TinodeWeb extends React.Component { mobilePanel: 'topic-view', topicSelectedOnline: online, topicSelectedAcs: acs, - infoPanelShowMembers: Tinode.topicType(topicName) === "grp" + showInfoPanel: false }); } else { if (this.state.topicSelected) { @@ -4671,7 +4667,7 @@ class TinodeWeb extends React.Component { mobilePanel: 'sidepanel', topicSelectedOnline: false, topicSelectedAcs: null, - infoPanelShowMembers: false + showInfoPanel: false }); } } @@ -4877,15 +4873,12 @@ class TinodeWeb extends React.Component { if (!topic) { return; } - var instance = this; - topic.leave(true).then(function(ctrl) { + + topic.leave(true).then((ctrl) => { // Hide MessagesView and InfoView panels. window.location.hash = setUrlTopic(window.location.hash, ''); - instance.setState({ - infoPanelShowMembers: false - }); - }).catch(function(err) { - instance.handleError(err.message, "err"); + }).catch((err) => { + this.handleError(err.message, "err"); }); } @@ -4937,12 +4930,12 @@ class TinodeWeb extends React.Component { handleShowInfoView() { window.location.hash = addUrlParam(window.location.hash, 'info', true); - this.setState({showInfoPanel: true, infoPanelShowMembers: false}); + this.setState({showInfoPanel: true}); } handleHideInfoView() { window.location.hash = removeUrlParam(window.location.hash, 'info'); - this.setState({showInfoPanel: false, infoPanelShowMembers: false}); + this.setState({showInfoPanel: false}); } handleMemberUpdateRequest(topicName, added, removed) { @@ -5065,7 +5058,6 @@ class TinodeWeb extends React.Component { errorText={this.state.errorText} errorLevel={this.state.errorLevel} - showMemberPanel={this.state.infoPanelShowMembers} onTopicDescUpdate={this.handleTopicUpdateRequest} onCancel={this.handleHideInfoView} onChangePermissions={this.handleChangePermissions}