fixes for bugs in starting new topics
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
export default class HashNavigation {
|
||||
static parseUrlHash(hash) {
|
||||
// Split path from args, path -> parts[0], args->path[1]
|
||||
let parts = hash.split('?', 2);
|
||||
let params = {};
|
||||
const parts = hash.split('?', 2);
|
||||
const params = {};
|
||||
let path = [];
|
||||
if (parts[0]) {
|
||||
path = parts[0].substr(1).split('/');
|
||||
@@ -27,9 +27,9 @@ export default class HashNavigation {
|
||||
}
|
||||
|
||||
static composeUrlHash(path, params) {
|
||||
var url = path.join('/');
|
||||
var args = [];
|
||||
for (var key in params) {
|
||||
let url = path.join('/');
|
||||
const args = [];
|
||||
for (const key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
args.push(key + '=' + params[key]);
|
||||
}
|
||||
@@ -41,25 +41,25 @@ export default class HashNavigation {
|
||||
}
|
||||
|
||||
static addUrlParam(hash, key, value) {
|
||||
var parsed = this.parseUrlHash(hash);
|
||||
const parsed = this.parseUrlHash(hash);
|
||||
parsed.params[key] = value;
|
||||
return this.composeUrlHash(parsed.path, parsed.params);
|
||||
}
|
||||
|
||||
static removeUrlParam(hash, key) {
|
||||
var parsed = this.parseUrlHash(hash);
|
||||
const parsed = this.parseUrlHash(hash);
|
||||
delete parsed.params[key];
|
||||
return this.composeUrlHash(parsed.path, parsed.params);
|
||||
}
|
||||
|
||||
static setUrlSidePanel(hash, sidepanel) {
|
||||
var parsed = this.parseUrlHash(hash);
|
||||
const parsed = this.parseUrlHash(hash);
|
||||
parsed.path[0] = sidepanel;
|
||||
return this.composeUrlHash(parsed.path, parsed.params);
|
||||
}
|
||||
|
||||
static setUrlTopic(hash, topic) {
|
||||
var parsed = this.parseUrlHash(hash);
|
||||
const parsed = this.parseUrlHash(hash);
|
||||
parsed.path[1] = topic;
|
||||
// Close InfoView on topic change.
|
||||
delete parsed.params.info;
|
||||
|
||||
@@ -19,6 +19,7 @@ import { DEFAULT_P2P_ACCESS_MODE, KEYPRESS_DELAY, MESSAGES_PAGE, MAX_EXTERN_ATTA
|
||||
MAX_IMAGE_DIM, MAX_INBAND_ATTACHMENT_SIZE, READ_DELAY } from '../config.js';
|
||||
import { SUPPORTED_IMAGE_FORMATS, filePasted, fileToBase64, imageFileToBase64,
|
||||
imageFileScaledToBase64, makeImageUrl } from '../lib/blob-helpers.js';
|
||||
import HashNavigation from '../lib/navigation.js';
|
||||
import { bytesToHumanSize, shortDateFormat } from '../lib/strformat.js';
|
||||
|
||||
// Run timer with this frequency (ms) for checking notification queue.
|
||||
@@ -169,6 +170,11 @@ class MessagesView extends React.Component {
|
||||
const setQuery = newTopic ? this.props.newTopicParams : undefined;
|
||||
topic.subscribe(getQuery.build(), setQuery)
|
||||
.then((ctrl) => {
|
||||
if (ctrl.code == 303) {
|
||||
// Redirect to another topic requested.
|
||||
HashNavigation.navigateTo(HashNavigation.setUrlTopic('', ctrl.params.topic));
|
||||
return;
|
||||
}
|
||||
if (this.state.topic != ctrl.topic) {
|
||||
this.setState({topic: ctrl.topic});
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class NewTopicView extends React.Component {
|
||||
handleContactSelected(sel) {
|
||||
if (this.state.tabSelected === 'p2p') {
|
||||
HashNavigation.navigateTo(HashNavigation.removeUrlParam(window.location.hash, 'tab'));
|
||||
this.props.onCreateTopic(sel, undefined);
|
||||
this.props.onCreateTopic(sel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-11
@@ -108,7 +108,7 @@ class TinodeWeb extends React.Component {
|
||||
this.togglePushToken = this.togglePushToken.bind(this);
|
||||
this.requestPushToken = this.requestPushToken.bind(this);
|
||||
this.handleSidepanelCancel = this.handleSidepanelCancel.bind(this);
|
||||
this.handleNewTopicRequest = this.handleNewTopicRequest.bind(this);
|
||||
this.handleStartTopicRequest = this.handleStartTopicRequest.bind(this);
|
||||
this.handleNewTopicCreated = this.handleNewTopicCreated.bind(this);
|
||||
this.handleTopicUpdateRequest = this.handleTopicUpdateRequest.bind(this);
|
||||
this.handleChangePermissions = this.handleChangePermissions.bind(this);
|
||||
@@ -634,7 +634,7 @@ class TinodeWeb extends React.Component {
|
||||
// For chatList topics merge only p2p topics and convert them to the
|
||||
// same format as foundContacts.
|
||||
for (const c of chatList) {
|
||||
if (Tinode.topicType(c.topic) == 'p2p') {
|
||||
if (Tinode.isP2PTopicName(c.topic)) {
|
||||
merged[c.topic] = {
|
||||
user: c.topic,
|
||||
updated: c.updated,
|
||||
@@ -813,7 +813,7 @@ class TinodeWeb extends React.Component {
|
||||
// Accept given permissions.
|
||||
const mode = topic.getAccessMode().getGiven();
|
||||
response = topic.setMeta({sub: {mode: mode}});
|
||||
if (topic.getType() == 'p2p') {
|
||||
if (topic.isP2P()) {
|
||||
// For P2P topics change 'given' permission of the peer too.
|
||||
// In p2p topics the other user has the same name as the topic.
|
||||
response = response.then((ctrl) => {
|
||||
@@ -1060,22 +1060,26 @@ class TinodeWeb extends React.Component {
|
||||
HashNavigation.navigateTo(HashNavigation.setUrlSidePanel(window.location.hash, hash));
|
||||
}
|
||||
|
||||
// Request to start a new topic. New P2P topic requires peer's name.
|
||||
handleNewTopicRequest(peerName, pub, priv, tags, isChannel) {
|
||||
// Request to start a topic, new or selected from search results.
|
||||
handleStartTopicRequest(topicName, pub, priv, tags, isChannel) {
|
||||
// Check if topic is indeed new. If not, launch it.
|
||||
if (topicName && this.tinode.getTopic(topicName)) {
|
||||
this.handleTopicSelected(topicName);
|
||||
return;
|
||||
}
|
||||
|
||||
const topicName = peerName || this.tinode.newGroupTopicName(isChannel);
|
||||
const params = {
|
||||
_topicName: topicName,
|
||||
};
|
||||
if (peerName) {
|
||||
const params = {};
|
||||
if (Tinode.isP2PTopicName(topicName)) {
|
||||
// Because we are initialing the subscription, set 'want' to all permissions.
|
||||
params.sub = {mode: DEFAULT_P2P_ACCESS_MODE};
|
||||
// Give the other user all permissions too.
|
||||
params.desc = {defacs: {auth: DEFAULT_P2P_ACCESS_MODE}};
|
||||
} else {
|
||||
topicName = topicName || this.tinode.newGroupTopicName(isChannel);
|
||||
params.desc = {public: pub, private: {comment: priv}};
|
||||
params.tags = tags;
|
||||
}
|
||||
params._topicName = topicName;
|
||||
this.setState({newTopicParams: params}, () => {this.handleTopicSelected(topicName)});
|
||||
}
|
||||
|
||||
@@ -1458,7 +1462,7 @@ class TinodeWeb extends React.Component {
|
||||
onCredDelete={this.handleCredDelete}
|
||||
onCredConfirm={this.handleCredConfirm}
|
||||
onTopicSelected={this.handleTopicSelected}
|
||||
onCreateTopic={this.handleNewTopicRequest}
|
||||
onCreateTopic={this.handleStartTopicRequest}
|
||||
onLogout={this.handleLogout}
|
||||
onDeleteAccount={this.handleDeleteAccount}
|
||||
onShowAlert={this.handleShowAlert}
|
||||
|
||||
Reference in New Issue
Block a user