messages can be deleted one by one now
This commit is contained in:
+66
-37
@@ -300,18 +300,18 @@
|
|||||||
/* BEGIN Context Menu: popup/dropdown menu */
|
/* BEGIN Context Menu: popup/dropdown menu */
|
||||||
|
|
||||||
// Function is used by context menu to set permissions.
|
// Function is used by context menu to set permissions.
|
||||||
function topicPermissionSetter(mode, topicName, uid, errorHandler) {
|
function topicPermissionSetter(mode, params, errorHandler) {
|
||||||
var topic = Tinode.getTopic(topicName);
|
var topic = Tinode.getTopic(params.topicName);
|
||||||
if (!topic) {
|
if (!topic) {
|
||||||
console.log("Topic not found: " + topicName);
|
console.log("Topic not found: " + params.topicName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var am;
|
var am;
|
||||||
if (uid) {
|
if (params.user) {
|
||||||
var user = topic.subscriber(uid);
|
var user = topic.subscriber(params.user);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
console.log("Subscriber not found: " + topicName + "[" + uid + "]");
|
console.log("Subscriber not found: " + params.topicName + "[" + params.user + "]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
am = user.acs.updateGiven(mode).getGiven();
|
am = user.acs.updateGiven(mode).getGiven();
|
||||||
@@ -332,40 +332,71 @@
|
|||||||
var ContextMenuItems = {
|
var ContextMenuItems = {
|
||||||
"topic_info": {title: "Info", handler: null},
|
"topic_info": {title: "Info", handler: null},
|
||||||
|
|
||||||
"messages_clear": {title: "Clear messages", handler: function(topicName) {
|
"messages_clear": {title: "Clear messages", handler: function(params, errorHandler) {
|
||||||
var topic = Tinode.getTopic(topicName);
|
var topic = Tinode.getTopic(params.topicName);
|
||||||
if (!topic) {
|
if (!topic) {
|
||||||
console.log("Topic not found: " + topicName);
|
console.log("Topic not found: " + params.topicName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
topic.delMessagesAll(false).then(function(){
|
topic.delMessagesAll(false).then(function(){
|
||||||
console.log("refresh message list");
|
console.log("refresh message list");
|
||||||
|
}).catch(function(err) {
|
||||||
|
if (errorHandler) {
|
||||||
|
errorHandler(err.message, "err");
|
||||||
|
} else {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}},
|
||||||
|
"message_delete": {title: "Delete", handler: function(params, errorHandler) {
|
||||||
|
var topic = Tinode.getTopic(params.topicName);
|
||||||
|
if (!topic) {
|
||||||
|
console.log("Topic not found: " + params.topicName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
topic.delMessagesList([params.seq], false).catch(function(err) {
|
||||||
|
if (errorHandler) {
|
||||||
|
errorHandler(err.message, "err");
|
||||||
|
} else {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}},
|
}},
|
||||||
"message_delete": {title: "Delete", handler: null},
|
|
||||||
|
|
||||||
"topic_unmute": {title: "Unmute", handler: topicPermissionSetter.bind(this, "+P")},
|
"topic_unmute": {title: "Unmute", handler: topicPermissionSetter.bind(this, "+P")},
|
||||||
"topic_mute": {title: "Mute", handler: topicPermissionSetter.bind(this, "-P")},
|
"topic_mute": {title: "Mute", handler: topicPermissionSetter.bind(this, "-P")},
|
||||||
"topic_unblock": {title: "Unblock", handler: topicPermissionSetter.bind(this, "+J")},
|
"topic_unblock": {title: "Unblock", handler: topicPermissionSetter.bind(this, "+J")},
|
||||||
"topic_block": {title: "Block", handler: topicPermissionSetter.bind(this, "-J")},
|
"topic_block": {title: "Block", handler: topicPermissionSetter.bind(this, "-J")},
|
||||||
"topic_delete": {title: "Delete", handler: function(topicName) {
|
"topic_delete": {title: "Delete", handler: function(params, errorHandler) {
|
||||||
var topic = Tinode.getTopic(topicName);
|
var topic = Tinode.getTopic(params.topicName);
|
||||||
if (!topic) {
|
if (!topic) {
|
||||||
console.log("Topic not found: " + topicName);
|
console.log("Topic not found: " + params.topicName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
topic.delTopic();
|
topic.delTopic().catch(function(err) {
|
||||||
|
if (errorHandler) {
|
||||||
|
errorHandler(err.message, "err");
|
||||||
|
} else {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
}},
|
}},
|
||||||
|
|
||||||
"permissions": {title: "Edit permissions", handler: null},
|
"permissions": {title: "Edit permissions", handler: null},
|
||||||
"member_delete": {title: "Remove", handler: function(topicName, user) {
|
"member_delete": {title: "Remove", handler: function(params, errorHandler) {
|
||||||
var topic = Tinode.getTopic(topicName);
|
var topic = Tinode.getTopic(params.topicName);
|
||||||
if (!topic || !user) {
|
if (!topic || !params.user) {
|
||||||
console.log("Topic or user not found: '" + topicName + "', '" + user + "'");
|
console.log("Topic or user not found: '" + params.topicName + "', '" + params.user + "'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
topic.delSubscription(user);
|
topic.delSubscription(params.user).catch(function(err) {
|
||||||
|
if (errorHandler) {
|
||||||
|
errorHandler(err.message, "err");
|
||||||
|
} else {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
}},
|
}},
|
||||||
"member_mute": {title: "Mute", handler: topicPermissionSetter.bind(this, "-P")},
|
"member_mute": {title: "Mute", handler: topicPermissionSetter.bind(this, "-P")},
|
||||||
"member_unmute": {title: "Unmute", handler: topicPermissionSetter.bind(this, "+P")},
|
"member_unmute": {title: "Unmute", handler: topicPermissionSetter.bind(this, "+P")},
|
||||||
@@ -407,7 +438,7 @@
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.props.hide();
|
this.props.hide();
|
||||||
var item = this.props.items[e.currentTarget.dataset.id];
|
var item = this.props.items[e.currentTarget.dataset.id];
|
||||||
item.handler(this.props.topic, this.props.user, this.props.onError);
|
item.handler(this.props.params, this.props.onError);
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
@@ -1382,7 +1413,7 @@
|
|||||||
handleContextClick: function(e) {
|
handleContextClick: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.props.showContextMenu(this.props.item, e.pageY, e.pageX);
|
this.props.showContextMenu({ topicName: this.props.item, y: e.pageY, x: e.pageX });
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
@@ -2266,7 +2297,7 @@
|
|||||||
user.acs.isMuted() ? ContextMenuItems["member_unmute"] : ContextMenuItems["member_mute"],
|
user.acs.isMuted() ? ContextMenuItems["member_unmute"] : ContextMenuItems["member_mute"],
|
||||||
user.acs.isJoiner() ? ContextMenuItems["member_block"] : ContextMenuItems["member_unblock"]
|
user.acs.isJoiner() ? ContextMenuItems["member_block"] : ContextMenuItems["member_unblock"]
|
||||||
];
|
];
|
||||||
this.props.showContextMenu(this.props.topic, x, y, item, menuItems);
|
this.props.showContextMenu({ topicName: this.props.topic, x: x, y: y, user: item }, menuItems);
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
@@ -2461,7 +2492,7 @@
|
|||||||
handleContextClick: function(e) {
|
handleContextClick: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.props.showContextMenu(this.props.seq, e.pageY, e.pageX);
|
this.props.showContextMenu({ seq: this.props.seq, y: e.pageY, x: e.pageX });
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
@@ -2804,11 +2835,12 @@
|
|||||||
handleContextClick: function(e) {
|
handleContextClick: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.props.showContextMenu(this.state.topic, e.pageY, e.pageX);
|
this.props.showContextMenu({ topicName: this.state.topic, y: e.pageY, x: e.pageX });
|
||||||
},
|
},
|
||||||
|
|
||||||
handleMessageContextMenu: function(seq, y, x) {
|
handleShowContextMenuMessage: function(params) {
|
||||||
console.log("Message cklicked", seq, x, y);
|
params.topicName = this.state.topic;
|
||||||
|
this.props.showContextMenu(params, [ContextMenuItems["message_delete"]]);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleBackNavigation: function() {
|
handleBackNavigation: function() {
|
||||||
@@ -2867,7 +2899,7 @@
|
|||||||
userFrom={userFrom} userName={userName} userAvatar={userAvatar}
|
userFrom={userFrom} userName={userName} userAvatar={userAvatar}
|
||||||
sequence={sequence} received={msgReceived}
|
sequence={sequence} received={msgReceived}
|
||||||
viewportWidth={this.props.viewportWidth}
|
viewportWidth={this.props.viewportWidth}
|
||||||
showContextMenu={this.handleMessageContextMenu}
|
showContextMenu={this.handleShowContextMenuMessage}
|
||||||
onImagePreview={this.handleImagePreview} key={msg.seq} />
|
onImagePreview={this.handleImagePreview} key={msg.seq} />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -3173,7 +3205,7 @@
|
|||||||
contextMenuVisible: false,
|
contextMenuVisible: false,
|
||||||
contextMenuBounds: null,
|
contextMenuBounds: null,
|
||||||
contextMenuClickAt: null,
|
contextMenuClickAt: null,
|
||||||
contextMenuTopic: '',
|
contextMenuParams: null,
|
||||||
contextMenuItems: [],
|
contextMenuItems: [],
|
||||||
serverVersion: 'no connection',
|
serverVersion: 'no connection',
|
||||||
contactsSearchQuery: '',
|
contactsSearchQuery: '',
|
||||||
@@ -3544,13 +3576,12 @@
|
|||||||
this.setState({dialogSelected: null});
|
this.setState({dialogSelected: null});
|
||||||
},
|
},
|
||||||
|
|
||||||
handleShowContextMenu: function(topicName, y, x, uid, menuItems) {
|
handleShowContextMenu: function(params, menuItems) {
|
||||||
this.setState({
|
this.setState({
|
||||||
contextMenuVisible: true,
|
contextMenuVisible: true,
|
||||||
contextMenuClickAt: {x: x, y: y},
|
contextMenuClickAt: {x: params.x, y: params.y},
|
||||||
contextMenuTopic: topicName,
|
contextMenuParams: params,
|
||||||
contextMenuUser: uid,
|
contextMenuItems: menuItems || this.defaultTopicContextMenu(params.topicName),
|
||||||
contextMenuItems: menuItems || this.defaultTopicContextMenu(topicName),
|
|
||||||
contextMenuBounds: ReactDOM.findDOMNode(this).getBoundingClientRect()
|
contextMenuBounds: ReactDOM.findDOMNode(this).getBoundingClientRect()
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -3580,8 +3611,7 @@
|
|||||||
this.setState({
|
this.setState({
|
||||||
contextMenuVisible: false,
|
contextMenuVisible: false,
|
||||||
contextMenuClickAt: null,
|
contextMenuClickAt: null,
|
||||||
contextMenuTopic: null,
|
contextMenuParams: null,
|
||||||
contextMenuUser: null,
|
|
||||||
contextMenuBounds: null
|
contextMenuBounds: null
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -3625,8 +3655,7 @@
|
|||||||
bounds={this.state.contextMenuBounds}
|
bounds={this.state.contextMenuBounds}
|
||||||
clickAt={this.state.contextMenuClickAt}
|
clickAt={this.state.contextMenuClickAt}
|
||||||
visible={this.state.contextMenuVisible}
|
visible={this.state.contextMenuVisible}
|
||||||
topic={this.state.contextMenuTopic}
|
params={this.state.contextMenuParams}
|
||||||
user={this.state.contextMenuUser}
|
|
||||||
items={this.state.contextMenuItems}
|
items={this.state.contextMenuItems}
|
||||||
hide={this.handleHideContextMenu}
|
hide={this.handleHideContextMenu}
|
||||||
onAction={this.handleContextMenuAction}
|
onAction={this.handleContextMenuAction}
|
||||||
|
|||||||
Reference in New Issue
Block a user