Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
[PLT-6707] /header [text] slash command: Edit the channel header (#6566)
Browse files Browse the repository at this point in the history
* add /header slash command

* update websocket

* updater per review
  • Loading branch information
cpanato authored and jwilander committed Jun 29, 2017
1 parent 3074a82 commit 4e9c7b2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
8 changes: 8 additions & 0 deletions actions/global_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ export function showDeletePostModal(post, commentCount = 0) {
});
}

export function showChannelHeaderUpdateModal(channel) {
AppDispatcher.handleViewAction({
type: ActionTypes.TOGGLE_CHANNEL_HEADER_UPDATE_MODAL,
value: true,
channel
});
}

export function showGetPostLinkModal(post) {
AppDispatcher.handleViewAction({
type: ActionTypes.TOGGLE_GET_POST_LINK_MODAL,
Expand Down
10 changes: 5 additions & 5 deletions actions/websocket_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ function handleEvent(msg) {
}
}

function handleChannelUpdatedEvent(msg) {
const channel = JSON.parse(msg.data.channel);
dispatch({type: ChannelTypes.RECEIVED_CHANNEL, data: channel});
}

function handleNewPostEvent(msg) {
const post = JSON.parse(msg.data.post);
handleNewPost(post, msg);
Expand Down Expand Up @@ -341,11 +346,6 @@ function handleUserRemovedEvent(msg) {
}
}

function handleChannelUpdatedEvent(msg) {
const channel = JSON.parse(msg.data.channel);
dispatch({type: ChannelTypes.RECEIVED_CHANNEL, data: channel});
}

function handleUserUpdatedEvent(msg) {
const user = msg.data.user;
if (UserStore.getCurrentId() !== user.id) {
Expand Down
15 changes: 12 additions & 3 deletions components/create_post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ export default class CreatePost extends React.Component {

PostStore.clearDraftUploads();

const channelId = ChannelStore.getCurrentId();
const draft = PostStore.getDraft(channelId);

const channel = ChannelStore.getCurrent();
const channelId = channel.id;
const draft = PostStore.getPostDraft(channelId);
const stats = ChannelStore.getCurrentStats();
const members = stats.member_count - 1;

this.state = {
channelId,
channel,
message: draft.message,
uploadsInProgress: draft.uploadsInProgress,
fileInfos: draft.fileInfos,
Expand Down Expand Up @@ -213,12 +214,20 @@ export default class CreatePost extends React.Component {
handleSubmit(e) {
const stats = ChannelStore.getCurrentStats();
const members = stats.member_count - 1;
const updateChannel = ChannelStore.getCurrent();

if ((this.state.message.includes('@all') || this.state.message.includes('@channel')) && members >= Constants.NOTIFY_ALL_MEMBERS) {
this.setState({totalMembers: members});
this.showNotifyAllModal();
return;
}

if (this.state.message.endsWith('/header ')) {
GlobalActions.showChannelHeaderUpdateModal(updateChannel);
this.setState({message: ''});
return;
}

this.doSubmit(e);
}

Expand Down
9 changes: 9 additions & 0 deletions components/navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class Navbar extends React.Component {
this.showSearch = this.showSearch.bind(this);

this.showEditChannelHeaderModal = this.showEditChannelHeaderModal.bind(this);
this.hideEditChannelHeaderModal = this.hideEditChannelHeaderModal.bind(this);
this.showRenameChannelModal = this.showRenameChannelModal.bind(this);
this.hideRenameChannelModal = this.hideRenameChannelModal.bind(this);
this.isStateValid = this.isStateValid.bind(this);
Expand Down Expand Up @@ -110,6 +111,7 @@ export default class Navbar extends React.Component {
UserStore.addChangeListener(this.onChange);
PreferenceStore.addChangeListener(this.onChange);
ModalStore.addModalListener(ActionTypes.TOGGLE_QUICK_SWITCH_MODAL, this.toggleQuickSwitchModal);
ModalStore.addModalListener(ActionTypes.TOGGLE_CHANNEL_HEADER_UPDATE_MODAL, this.showEditChannelHeaderModal);
$('.inner-wrap').click(this.hideSidebars);
document.addEventListener('keydown', this.handleQuickSwitchKeyPress);
}
Expand All @@ -121,6 +123,7 @@ export default class Navbar extends React.Component {
UserStore.removeChangeListener(this.onChange);
PreferenceStore.removeChangeListener(this.onChange);
ModalStore.removeModalListener(ActionTypes.TOGGLE_QUICK_SWITCH_MODAL, this.toggleQuickSwitchModal);
ModalStore.addModalListener(ActionTypes.TOGGLE_CHANNEL_HEADER_UPDATE_MODAL, this.hideEditChannelHeaderModal);
document.removeEventListener('keydown', this.handleQuickSwitchKeyPress);
}

Expand Down Expand Up @@ -193,6 +196,12 @@ export default class Navbar extends React.Component {
});
}

hideEditChannelHeaderModal() {
this.setState({
showEditChannelHeaderModal: false
});
}

showRenameChannelModal(e) {
e.preventDefault();

Expand Down
1 change: 1 addition & 0 deletions stores/modal_store.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ModalStoreClass extends EventEmitter {
case ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL:
case ActionTypes.TOGGLE_DM_MODAL:
case ActionTypes.TOGGLE_QUICK_SWITCH_MODAL:
case ActionTypes.TOGGLE_CHANNEL_HEADER_UPDATE_MODAL:
this.emit(type, value, args);
break;
}
Expand Down
1 change: 1 addition & 0 deletions utils/constants.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export const ActionTypes = keyMirror({
TOGGLE_GET_PUBLIC_LINK_MODAL: null,
TOGGLE_DM_MODAL: null,
TOGGLE_QUICK_SWITCH_MODAL: null,
TOGGLE_CHANNEL_HEADER_UPDATE_MODAL: null,

SUGGESTION_PRETEXT_CHANGED: null,
SUGGESTION_RECEIVED_SUGGESTIONS: null,
Expand Down

0 comments on commit 4e9c7b2

Please sign in to comment.