fixed bugs in tags editing
This commit is contained in:
@@ -50,6 +50,10 @@ function stringToColorHash(value) {
|
||||
}
|
||||
|
||||
// Converts user or topic ID to a CSS color class. Ideally it should produce the same color value as Java version.
|
||||
export function idToColorClass(string, light) {
|
||||
return (light ? 'light-color' : 'dark-color') + (Math.abs(stringToColorHash(string)) % 16);
|
||||
// params:
|
||||
// - {string} id: user or topic ID
|
||||
// - {boolean} light: light or dark version of the color.
|
||||
// - {boolean} fg: foreground or background color.
|
||||
export function idToColorClass(id, light, fg) {
|
||||
return (light ? 'lt-' : 'dk-') + (fg ? 'fg-' : 'bg-') + (Math.abs(stringToColorHash(id)) % 16);
|
||||
}
|
||||
|
||||
+12
-6
@@ -115,6 +115,7 @@ class InfoView extends React.Component {
|
||||
|
||||
this.resetSubs = this.resetSubs.bind(this);
|
||||
this.resetDesc = this.resetDesc.bind(this);
|
||||
this.resetTags = this.resetTags.bind(this);
|
||||
this.onMetaDesc = this.onMetaDesc.bind(this);
|
||||
this.onSubsUpdated = this.onSubsUpdated.bind(this);
|
||||
this.handleImageChanged = this.handleImageChanged.bind(this);
|
||||
@@ -147,6 +148,7 @@ class InfoView extends React.Component {
|
||||
this.setState({topic: props.topic});
|
||||
this.resetDesc(topic, props);
|
||||
this.resetSubs(topic, props);
|
||||
this.resetTags(topic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,8 +217,15 @@ class InfoView extends React.Component {
|
||||
auth: defacs.auth,
|
||||
anon: defacs.anon
|
||||
});
|
||||
}
|
||||
|
||||
if (topic.getType() == 'grp' && acs && acs.isOwner()) {
|
||||
resetTags(topic) {
|
||||
if (topic.getType() != 'grp') {
|
||||
return;
|
||||
}
|
||||
|
||||
const acs = topic.getAccessMode();
|
||||
if (acs && acs.isOwner()) {
|
||||
// Requesting tags: owner is editing the topic.
|
||||
topic.getMeta(topic.startMetaQuery().withTags().build());
|
||||
}
|
||||
@@ -257,7 +266,6 @@ class InfoView extends React.Component {
|
||||
}
|
||||
|
||||
handlePermissionsChanged(which, perm) {
|
||||
console.log("handlePermissionsChanged", which, perm);
|
||||
switch (which) {
|
||||
case 'auth':
|
||||
this.props.onTopicDescUpdate(this.props.topic, null, null, {auth: perm});
|
||||
@@ -279,7 +287,6 @@ class InfoView extends React.Component {
|
||||
}
|
||||
|
||||
handleLaunchPermissionsEditor(which, uid) {
|
||||
console.log(which, uid);
|
||||
const {formatMessage} = this.props.intl;
|
||||
let toEdit, toCompare, toSkip, titleEdit, titleCompare, userTitle, userAvatar;
|
||||
switch (which) {
|
||||
@@ -468,11 +475,10 @@ class InfoView extends React.Component {
|
||||
tinode={this.props.tinode}
|
||||
topic={this.props.topic}
|
||||
onCredAdd={this.props.onCredAdd}
|
||||
onTopicTagsUpdate={this.props.onTopicTagsUpdate}
|
||||
onTopicTagsUpdateRequest={this.props.onTopicTagsUpdateRequest}
|
||||
onCredConfirm={this.props.onCredConfirm}
|
||||
onCredDelete={this.props.onCredDelete}
|
||||
onUpdateTopicDesc={this.props.onTopicDescUpdate}
|
||||
onUpdateTags={this.props.onUpdateTags}
|
||||
onUpdateTopicDesc={this.props.onTopicDescUpdateRequest}
|
||||
onError={this.props.onError} />
|
||||
:
|
||||
view == 'security' ?
|
||||
|
||||
@@ -121,7 +121,7 @@ class TinodeWeb extends React.Component {
|
||||
this.handleNewTopicCreated = this.handleNewTopicCreated.bind(this);
|
||||
this.handleTopicUpdateRequest = this.handleTopicUpdateRequest.bind(this);
|
||||
this.handleChangePermissions = this.handleChangePermissions.bind(this);
|
||||
this.handleTagsUpdated = this.handleTagsUpdated.bind(this);
|
||||
this.handleTagsUpdateRequest = this.handleTagsUpdateRequest.bind(this);
|
||||
this.handleLogout = this.handleLogout.bind(this);
|
||||
this.handleDeleteAccount = this.handleDeleteAccount.bind(this);
|
||||
this.handleDeleteTopicRequest = this.handleDeleteTopicRequest.bind(this);
|
||||
@@ -225,7 +225,7 @@ class TinodeWeb extends React.Component {
|
||||
serviceWorkerChannel.addEventListener('message', this.handlePushMessage);
|
||||
} else {
|
||||
// Safari is broken by design.
|
||||
console.warn('Your browser does not support BroadcastChannel. Some features will not be available');
|
||||
console.warn("Your browser does not support BroadcastChannel. Some features will not be available");
|
||||
}
|
||||
|
||||
// Window/tab visible or invisible for pausing timers.
|
||||
@@ -1269,7 +1269,7 @@ class TinodeWeb extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
handleTagsUpdated(topicName, tags) {
|
||||
handleTagsUpdateRequest(topicName, tags) {
|
||||
const topic = this.tinode.getTopic(topicName);
|
||||
if (topic) {
|
||||
topic.setMeta({tags: tags}).catch((err) => {
|
||||
@@ -1686,7 +1686,7 @@ class TinodeWeb extends React.Component {
|
||||
errorActionText={this.state.errorActionText}
|
||||
|
||||
onNavigate={this.infoNavigator}
|
||||
onTopicDescUpdate={this.handleTopicUpdateRequest}
|
||||
onTopicDescUpdateRequest={this.handleTopicUpdateRequest}
|
||||
onShowAlert={this.handleShowAlert}
|
||||
onChangePermissions={this.handleChangePermissions}
|
||||
onMemberUpdateRequest={this.handleMemberUpdateRequest}
|
||||
@@ -1696,7 +1696,7 @@ class TinodeWeb extends React.Component {
|
||||
onBlockTopic={this.handleBlockTopicRequest}
|
||||
onReportTopic={this.handleReportTopic}
|
||||
onAddMember={this.handleManageGroupMembers}
|
||||
onTopicTagsUpdate={this.handleTagsUpdated}
|
||||
onTopicTagsUpdateRequest={this.handleTagsUpdateRequest}
|
||||
onInitFind={this.tnInitFind}
|
||||
onError={this.handleError}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import LetterTile from './letter-tile.jsx';
|
||||
import ReceivedMarker from './received-marker.jsx'
|
||||
import UploadingImage from './uploading-image.jsx'
|
||||
|
||||
import { idToColorClass } from '../lib/strformat.js';
|
||||
import { sanitizeImageUrl, sanitizeUrl } from '../lib/utils.js';
|
||||
|
||||
export default class ChatMessage extends React.Component {
|
||||
@@ -154,7 +153,7 @@ export default class ChatMessage extends React.Component {
|
||||
}
|
||||
</div>
|
||||
{fullDisplay ?
|
||||
<div className={'author' + (this.props.userName ? idToColorClass(this.props.userFrom) : '')}>
|
||||
<div className="author">
|
||||
{this.props.userName ||
|
||||
<i><FormattedMessage id="user_not_found" defaultMessage="Not found"
|
||||
description="In place of a user's full name when the user is not found." /></i>
|
||||
|
||||
@@ -21,10 +21,11 @@ export default class TopicCommon extends React.Component {
|
||||
addCredActive: false,
|
||||
addCredInvalid: false,
|
||||
newCred: '',
|
||||
tags: [],
|
||||
previousTagsUpdated: undefined
|
||||
tags: []
|
||||
};
|
||||
|
||||
this.previousTagsUpdated = undefined;
|
||||
|
||||
this.onTagsUpdated = this.onTagsUpdated.bind(this);
|
||||
this.handleTagsUpdated = this.handleTagsUpdated.bind(this);
|
||||
this.tnCredsUpdated = this.tnCredsUpdated.bind(this);
|
||||
@@ -105,17 +106,19 @@ export default class TopicCommon extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
// Server informs that the tags have been updated.
|
||||
onTagsUpdated(tags) {
|
||||
this.setState({tags: tags});
|
||||
|
||||
if (this.previousTagsUpdated && this.previousTagsUpdated != this.onTagsUpdated) {
|
||||
this.previousTagsUpdated();
|
||||
this.previousTagsUpdated(tags);
|
||||
}
|
||||
}
|
||||
|
||||
// Request server to change tags.
|
||||
handleTagsUpdated(tags) {
|
||||
if (!arrayEqual(this.state.tags.slice(0), tags.slice(0))) {
|
||||
this.props.onTopicTagsUpdate(this.props.topic, tags);
|
||||
this.props.onTopicTagsUpdateRequest(this.props.topic, tags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +146,7 @@ export default class TopicCommon extends React.Component {
|
||||
tinode={this.props.tinode}
|
||||
topic={this.props.topic}
|
||||
onUpdateTopicDesc={this.props.onUpdateTopicDesc}
|
||||
onUpdateTags={this.props.onUpdateTags}
|
||||
onUpdateTags={this.handleTagsUpdated}
|
||||
onError={this.props.onError} />
|
||||
{this.state.isMe ?
|
||||
<>
|
||||
|
||||
@@ -28,12 +28,13 @@ export default class TopicDescEdit extends React.Component {
|
||||
private: topic.private ? topic.private.comment : null,
|
||||
description: topic.public ? topic.public.note : undefined,
|
||||
avatar: makeImageUrl(topic.public ? topic.public.photo : null),
|
||||
tags: topic.tags(),
|
||||
tags: topic.tags() || [],
|
||||
newAvatar: null,
|
||||
newAvatarMime: null,
|
||||
previousOnTags: topic.onTagsUpdated
|
||||
newAvatarMime: null
|
||||
};
|
||||
|
||||
this.previousOnTags = null;
|
||||
|
||||
this.tnNewTags = this.tnNewTags.bind(this);
|
||||
this.handleFullNameUpdate = this.handleFullNameUpdate.bind(this);
|
||||
this.handleImageUpdated = this.handleImageUpdated.bind(this);
|
||||
@@ -47,12 +48,13 @@ export default class TopicDescEdit extends React.Component {
|
||||
|
||||
componentDidMount() {
|
||||
const topic = this.props.tinode.getTopic(this.props.topic);
|
||||
this.previousOnTags = topic.onTagsUpdated;
|
||||
topic.onTagsUpdated = this.tnNewTags;
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
const topic = this.props.tinode.getTopic(this.props.topic);
|
||||
topic.onTagsUpdated = this.state.previousOnTags;
|
||||
topic.onTagsUpdated = this.previousOnTags;
|
||||
}
|
||||
|
||||
tnNewTags(tags) {
|
||||
|
||||
Reference in New Issue
Block a user