Skip to content

Commit

Permalink
[IMPROVE] Join channels by sending a message or join button (RocketCh…
Browse files Browse the repository at this point in the history
  • Loading branch information
bhardwajaditya authored and ggazzo committed Mar 22, 2019
1 parent f21a969 commit f776cf6
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { AutoComplete } from 'meteor/mizzao:autocomplete';
Expand Down
1 change: 1 addition & 0 deletions app/discussion/server/hooks/propagateDiscussionMetadata.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { callbacks } from '../../../callbacks/server';
import { Messages, Rooms } from '../../../models/server';
import { deleteRoom } from '../../../lib/server';

/**
* We need to propagate the writing of new message in a discussion to the linking
* system message
Expand Down
1 change: 0 additions & 1 deletion app/discussion/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import './config';
import './authorization';
import './permissions';

import './hooks/joinDiscussionOnMessage';
import './hooks/propagateDiscussionMetadata';
import './publications/discussionParentAutocomplete';
import './publications/discussionsOfRoom';
Expand Down
5 changes: 0 additions & 5 deletions app/lib/lib/roomTypes/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ export class PrivateRoomType extends RoomTypeConfig {
}

canSendMessage(roomId) {
const room = ChatRoom.findOne({ _id: roomId, t: 'p' }, { fields: { prid: 1 } });
if (room.prid) {
return true;
}

// TODO: remove duplicated code
return ChatSubscription.find({
rid: roomId,
Expand Down
30 changes: 18 additions & 12 deletions app/ui-message/client/messageBox.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template name="messageBox">
<div class="rc-message-box rc-new {{#if isEmbedded}}rc-message-box--embedded{{/if}}">
{{#if subscribed}}
{{#unless isAnonymousOrJoinCode}}
{{> messageBoxTyping rid=_id}}

{{#if canSend}}
Expand All @@ -25,16 +25,22 @@
{{> icon block="rc-input__icon-svg" icon="send"}}
</span>
{{else}}
{{#if isAudioMessageAllowed}}
{{> messageBoxAudioMessage rid=_id}}
{{/if}}
<span class="rc-message-box__action-menu" data-desktop>
{{#if actions}}
<span class="rc-message-box__icon">
{{> icon block="rc-input__icon-svg" icon="plus"}}
</span>
{{#if subscribed}}
{{#if isAudioMessageAllowed}}
{{> messageBoxAudioMessage rid=_id}}
{{/if}}
</span>
<span class="rc-message-box__action-menu" data-desktop>
{{#if actions}}
<span class="rc-message-box__icon">
{{> icon block="rc-input__icon-svg" icon="plus"}}
</span>
{{/if}}
</span>
{{else}}
<span class="rc-message-box__icon">
<strong><a href="#" class="js-join"> {{_"join"}}</a></strong>
</span>
{{/if}}
{{/unless}}
<span class="rc-message-box__action-label js-message-actions" data-small>
{{#each actions}}
Expand Down Expand Up @@ -75,7 +81,7 @@
</div>
{{/if}}
{{else}}
{{> messageBoxNotSubscribed rid=_id}}
{{/if}}
{{> messageBoxNotSubscribed _id=_id}}
{{/unless}}
</div>
</template>
21 changes: 19 additions & 2 deletions app/ui-message/client/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
fileUpload,
KonchatNotification,
} from '../../ui';
import { Layout, messageBox, popover, RoomManager } from '../../ui-utils';
import { Layout, messageBox, popover, RoomManager, call } from '../../ui-utils';
import { t, roomTypes, getUserPreference } from '../../utils';
import moment from 'moment';

import './messageBoxReplyPreview';
import './messageBoxTyping';
import './messageBoxAudioMessage';
Expand Down Expand Up @@ -253,6 +254,12 @@ Template.messageBox.helpers({
return Object.values(actionGroups)
.reduce((actions, actionGroup) => [...actions, ...actionGroup], []);
},
isAnonymousOrJoinCode() {
const room = Session.get(`roomData${ this._id }`);
return !Meteor.userId() || (!ChatSubscription.findOne({
rid: this._id,
}) && room && room.joinCodeRequired);
},
showFormattingTips() {
return settings.get('Message_ShowFormattingTips');
},
Expand All @@ -278,6 +285,16 @@ Template.messageBox.helpers({
});

Template.messageBox.events({
'click .js-join'(event) {
event.stopPropagation();
event.preventDefault();

const joinCodeInput = Template.instance().find('[name=joinCode]');
const joinCode = joinCodeInput && joinCodeInput.value;

call('joinRoom', this._id, joinCode);
},

'click .emoji-picker-icon'(event) {
event.stopPropagation();
event.preventDefault();
Expand Down Expand Up @@ -373,7 +390,7 @@ Template.messageBox.events({
chatMessages[this._id].valueChanged(this._id, event, Template.instance());
}
},
'click .js-send'(event, instance) {
async 'click .js-send'(event, instance) {
const { input } = chatMessages[RoomManager.openedRoom];
chatMessages[this._id].send(this._id, input, () => {
input.updateAutogrow();
Expand Down
9 changes: 4 additions & 5 deletions app/ui-message/client/messageBoxNotSubscribed.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<template name="messageBoxNotSubscribed" args="rid">
<template name="messageBoxNotSubscribed" args="_id">
{{#if customTemplate}}
{{> Template.dynamic customTemplate }}
{{else}}
{{#if canJoinRoom}}
<div class="rc-message-box__join">
{{{_ "you_are_in_preview_mode_of" room_name=roomName}}}
{{#if isJoinCodeRequired}}
<input type="password" name="joinCode" placeholder="{{_ 'Password'}}" class="rc-input__element rc-message-box__join-code">
{{/if}}

<button class="rc-button rc-button--primary rc-button--small rc-message-box__join-button js-join">{{_ "join"}}</button>
<input type="password" name="joinCode" placeholder="{{_ 'Password'}}" class="rc-input__element rc-message-box__join-code">

<button class="rc-button rc-button--primary rc-button--small rc-message-box__join-button js-join-code">{{_ "join"}}</button>
</div>
{{/if}}

Expand Down
36 changes: 17 additions & 19 deletions app/ui-message/client/messageBoxNotSubscribed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import { Template } from 'meteor/templating';
import { settings } from '../../settings';
import { RoomHistoryManager, RoomManager, call } from '../../ui-utils';
import { t, roomTypes } from '../../utils';
import { call } from '../../ui-utils';
import { roomTypes } from '../../utils';
import { RoomManager, RoomHistoryManager } from '../../ui-utils';
import { hasAllPermission } from '../../authorization';
import toastr from 'toastr';
import './messageBoxNotSubscribed.html';


Template.messageBoxNotSubscribed.helpers({
customTemplate() {
return roomTypes.getNotSubscribedTpl(this.rid);
return roomTypes.getNotSubscribedTpl(this._id);
},
canJoinRoom() {
return Meteor.userId() && roomTypes.verifyShowJoinLink(this.rid);
return Meteor.userId() && roomTypes.verifyShowJoinLink(this._id);
},
roomName() {
const room = Session.get(`roomData${ this.rid }`);
const room = Session.get(`roomData${ this._id }`);
return roomTypes.getRoomName(room.t, room);
},
isJoinCodeRequired() {
const room = Session.get(`roomData${ this.rid }`);
const room = Session.get(`roomData${ this._id }`);
return room && room.joinCodeRequired;
},
isAnonymousReadAllowed() {
Expand All @@ -36,26 +36,24 @@ Template.messageBoxNotSubscribed.helpers({
});

Template.messageBoxNotSubscribed.events({
async 'click .js-join'(event) {
async 'click .js-join-code'(event) {
event.stopPropagation();
event.preventDefault();

const joinCodeInput = Template.instance().find('[name=joinCode]');
const joinCode = joinCodeInput && joinCodeInput.value;

try {
await call('joinRoom', this.rid, joinCode);
if (hasAllPermission('preview-c-room') === false && RoomHistoryManager.getRoom(this.rid).loaded === 0) {
RoomManager.getOpenedRoomByRid(this.rid).streamActive = false;
RoomManager.getOpenedRoomByRid(this.rid).ready = false;
RoomHistoryManager.getRoom(this.rid).loaded = null;
RoomManager.computation.invalidate();
}
} catch (error) {
toastr.error(t(error.reason));
await call('joinRoom', this._id, joinCode);

if (hasAllPermission('preview-c-room') === false && RoomHistoryManager.getRoom(this._id).loaded === 0) {
RoomManager.getOpenedRoomByRid(this._id).streamActive = false;
RoomManager.getOpenedRoomByRid(this._id).ready = false;
RoomHistoryManager.getRoom(this._id).loaded = null;
RoomManager.computation.invalidate();
}
},


},
'click .js-register'(event) {
event.stopPropagation();
event.preventDefault();
Expand Down
9 changes: 7 additions & 2 deletions app/ui/client/lib/chatMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { FlowRouter } from 'meteor/kadira:flow-router';
import { Session } from 'meteor/session';
import { TAPi18n } from 'meteor/tap:i18n';
import { t, getUserPreference, slashCommands, handleError } from '../../../utils';
import { MessageAction, messageProperties, MessageTypes, readMessage, modal } from '../../../ui-utils';
import { MessageAction, messageProperties, MessageTypes, readMessage, modal, call } from '../../../ui-utils';
import { settings } from '../../../settings';
import { callbacks } from '../../../callbacks';
import { promises } from '../../../promises';
import { hasAtLeastOnePermission } from '../../../authorization';
import { Messages, Rooms, ChatMessage } from '../../../models';
import { Messages, Rooms, ChatMessage, ChatSubscription } from '../../../models';
import { emoji } from '../../../emoji';
import { KonchatNotification } from './notification';
import { MsgTyping } from './msgTyping';
Expand Down Expand Up @@ -239,6 +239,11 @@ export const ChatMessages = class ChatMessages {
* * @param {function?} done callback
*/
async send(rid, input, done = function() {}) {

if (!ChatSubscription.findOne({ rid })) {
await call('joinRoom', rid);
}

if (s.trim(input.value) !== '') {
readMessage.enable();
readMessage.readNow();
Expand Down
1 change: 1 addition & 0 deletions server/startup/migrations/v139.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Migrations } from '../../../app/migrations/server';

import { Messages, Permissions, Rooms, Settings } from '../../../app/models/server';

const getField = (msg, fieldType, fieldName) => {
Expand Down

0 comments on commit f776cf6

Please sign in to comment.