diff --git a/src/views/info-view.jsx b/src/views/info-view.jsx index 836bd82c..dbc00a10 100644 --- a/src/views/info-view.jsx +++ b/src/views/info-view.jsx @@ -61,6 +61,16 @@ const messages = defineMessages({ defaultMessage: 'Are you sure you want to delete all messages for everyone? It cannot be undone.', description: 'Alert dialog warning when hard-deleting all messages.' }, + topic_delete: { + id: 'topic_delete', + defaultMessage: 'Delete Conversation', + description: 'Alert title when deleting the topic.' + }, + topic_delete_warning: { + id: 'topic_delete_warning', + defaultMessage: 'Are you sure you want to delete this conversation? It cannot be undone.', + description: 'Alert warning when deleting entire topic' + }, leave_chat: { id: 'action_leave_chat', defaultMessage: 'Leave Conversation', @@ -143,6 +153,7 @@ class InfoView extends React.Component { this.handleShowAddMembers = this.handleShowAddMembers.bind(this); this.handleHideAddMembers = this.handleHideAddMembers.bind(this); this.handleMemberUpdateRequest = this.handleMemberUpdateRequest.bind(this); + this.handleDeleteTopic = this.handleDeleteTopic.bind(this); this.handleDeleteMessages = this.handleDeleteMessages.bind(this); this.handleLeave = this.handleLeave.bind(this); this.handleBlock = this.handleBlock.bind(this); @@ -422,6 +433,19 @@ class InfoView extends React.Component { this.setState({showMemberPanel: false}); } + handleDeleteTopic(e) { + e.preventDefault(); + const {formatMessage} = this.props.intl; + this.props.onShowAlert( + formatMessage(messages.topic_delete), // title + formatMessage(messages.topic_delete_warning), // content + (() => { this.props.onDeleteTopic(this.props.topic); }), // onConfirm + null, // "OK" + true, // Show Reject button + null // "Cancel" + ); + } + handleDeleteMessages(e) { e.preventDefault(); const {formatMessage} = this.props.intl; @@ -717,9 +741,15 @@ class InfoView extends React.Component { : null } - - exit_to_app  {formatMessage(messages.leave_chat)} - + {this.state.owner ? + + delete  {formatMessage(messages.topic_delete)} + + : + + exit_to_app  {formatMessage(messages.leave_chat)} + + } {!this.state.groupTopic ? block  {formatMessage(messages.block_contact)} diff --git a/src/views/tinode-web.jsx b/src/views/tinode-web.jsx index 3e8e6c55..b86e7ca3 100644 --- a/src/views/tinode-web.jsx +++ b/src/views/tinode-web.jsx @@ -123,6 +123,7 @@ class TinodeWeb extends React.Component { this.handleTagsUpdated = this.handleTagsUpdated.bind(this); this.handleLogout = this.handleLogout.bind(this); this.handleDeleteAccount = this.handleDeleteAccount.bind(this); + this.handleDeleteTopicRequest = this.handleDeleteTopicRequest.bind(this); this.handleDeleteMessagesRequest = this.handleDeleteMessagesRequest.bind(this); this.handleLeaveUnsubRequest = this.handleLeaveUnsubRequest.bind(this); this.handleBlockTopicRequest = this.handleBlockTopicRequest.bind(this); @@ -1290,6 +1291,21 @@ class TinodeWeb extends React.Component { }); } + handleDeleteTopicRequest(topicName) { + const topic = this.tinode.getTopic(topicName); + if (!topic) { + return; + } + + // Request to hard-delete topic. + topic.delTopic(true).then((ctrl) => { + // Hide MessagesView and InfoView panels. + HashNavigation.navigateTo(HashNavigation.setUrlTopic(window.location.hash, '')); + }).catch((err) => { + this.handleError(err.message, 'err'); + }); + } + handleDeleteMessagesRequest(topicName) { const topic = this.tinode.getTopic(topicName); if (!topic) { @@ -1655,6 +1671,7 @@ class TinodeWeb extends React.Component { onShowAlert={this.handleShowAlert} onChangePermissions={this.handleChangePermissions} onMemberUpdateRequest={this.handleMemberUpdateRequest} + onDeleteTopic={this.handleDeleteTopicRequest} onDeleteMessages={this.handleDeleteMessagesRequest} onLeaveTopic={this.handleLeaveUnsubRequest} onBlockTopic={this.handleBlockTopicRequest}