Skip to content

Commit

Permalink
RocketChat#116 close request (RocketChat#122)
Browse files Browse the repository at this point in the history
* Don't remove the subscription on closing, only hide the room

* Add interface method for UI-texts.
Provide implementation for the confirmation dialogs on leave and hide

(cherry picked from commit a480c20)

* Added a closing text constant

(cherry picked from commit c5c0ece)

* Closing a request adds the comment properly and creates an automated message explaining what that means - fixes RocketChat#120

* fixed typo

* Fix frontend-exception once a room has been left

* Message that indicates a closed request room RocketChat#116
- improved messages
  • Loading branch information
mrsimpson authored and ruKurz committed Nov 2, 2017
1 parent 54633e8 commit f18a657
Show file tree
Hide file tree
Showing 18 changed files with 195 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.help-request-explanation {
margin: 0 20px 40px;

text-align: justify;

font-style: italic;

line-height: 1.4;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat, UiTextContext } from 'meteor/rocketchat:lib';

Template.HelpRequestActions.helpers({
helprequestOpen() {
const instance = Template.instance();
Expand All @@ -7,96 +9,43 @@ Template.HelpRequestActions.helpers({
}
},

helprequestClosed() {
const instance = Template.instance();
const helpRequest = instance.helpRequest.get();
if (helpRequest) {
return helpRequest.resolutionStatus && helpRequest.resolutionStatus === 'resolved'; //undefined in livechats
}
},

isLivechat() {
const instance = Template.instance();
const room = ChatSubscription.findOne({rid: instance.data.roomId});
return room.t === 'l';
return room && room.t === 'l';
},

livechatOpen() {
const instance = Template.instance();
const room = ChatSubscription.findOne({rid: instance.data.roomId});
return room.open;
return room && room.open;
},

isOpenLivechat() {
const instance = Template.instance();
const room = ChatSubscription.findOne({rid: instance.data.roomId});
return room.t === 'l' && room.open;
return room && room.t === 'l' && room.open;
}
});

Template.HelpRequestActions.dialogs = {
ClosingDialog: class {
/**
* @param room the room to get the values from
* @param properties (optional) SweetAlert options
*/
constructor(helpRequest, properties) {
this.room = ChatRoom.findOne(helpRequest.roomId);
this.properties = _.isObject(properties) ? properties : {};
}

/**
* @return Promise (keep in mind that native es6-promises aren't cancelable. So always provide a then & catch)
*/
display() {
const self = this;
return new Promise(function(resolve, reject) {
swal.withForm(_.extend({
title: t('Closing_chat'),
text: '',
formFields: [{
id: 'comment',
value: self.room.comment,
type: 'input',
label: t('comment'),
placeholder: t('Please_add_a_comment')
}, {
id: 'tags',
value: self.room.tags ? self.room.tags.join(', ') : '',
type: 'input',
placeholder: t('Please_add_a_tag')
}, {
id: 'knowledgeProviderUsage',
type: 'select',
options: [
{value: 'Unknown', text: t('knowledge_provider_usage_unknown')},
{value: 'Perfect', text: t('knowledge_provider_usage_perfect')},
{value: 'Helpful', text: t('knowledge_provider_usage_helpful')},
{value: 'NotUsed', text: t('knowledge_provider_usage_not_used')},
{value: 'Useless', text: t('knowledge_provider_usage_useless')}
]
}],
showCancelButton: true,
closeOnConfirm: false
}, self.properties), function(isConfirm) {
if (!isConfirm) { //on cancel
$('.swal-form').remove(); //possible bug? why I have to do this manually
reject();
return false;
}
const form = this.swalForm;
resolve(form);
});
}).then((r) => {
$('.sa-input-error').show();
return r;
}).catch((reason) => {
throw reason;
});
}
}
};

Template.HelpRequestActions.events({
'click .close-helprequest'(event, instance) {
event.preventDefault();
const warnText = RocketChat.roomTypes.roomTypes['r'].getUiText(UiTextContext.CLOSE_WARNING);

swal(_.extend({
title: t('Closing_chat'),
text: warnText ? t(warnText) : '',
type: 'input',
inputPlaceholder: t('Please_add_a_comment'),
inputPlaceholder: t('Close_request_comment'),
showCancelButton: true,
closeOnConfirm: false,
roomId: instance.data.roomId
Expand Down
26 changes: 26 additions & 0 deletions packages/assistify-help-request/lib/messageTypes/requestClosed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* globals RocketChat */

Meteor.startup(function() {
RocketChat.MessageTypes.registerType({
id: 'request_closed',
system: true,
message: 'Request_closed',
data(message) {
return {
user_by: message.u.username,
comment: message.msg
};
}
});

RocketChat.MessageTypes.registerType({
id: 'request_closed_explanation',
system: true,
message: 'Request_closed_explanation',
data(message) {
return {
user_by: message.u.username
};
}
});
});
14 changes: 12 additions & 2 deletions packages/assistify-help-request/lib/roomTypes/expertise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals openRoom */

import {RoomTypeConfig, RoomTypeRouteConfig} from 'meteor/rocketchat:lib';
import {RoomTypeConfig, RoomTypeRouteConfig, UiTextContext} from 'meteor/rocketchat:lib';

class ExpertiseRoomRoute extends RoomTypeRouteConfig {
constructor() {
Expand Down Expand Up @@ -70,9 +70,19 @@ export class ExpertiseRoomType extends RoomTypeConfig {
return true; //renaming an expertise will lead to new requests not finding answers to the previously named expertise
}


enableMembersListProfile() {
return true;
}

getUiText(context) {
switch (context) {
case UiTextContext.HIDE_WARNING:
return 'Hide_expertise_warning';
case UiTextContext.LEAVE_WARNING:
return 'Leave_expertise_warning';
default:
return '';
}
}
}

15 changes: 14 additions & 1 deletion packages/assistify-help-request/lib/roomTypes/request.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals openRoom */

import {RoomTypeConfig, RoomTypeRouteConfig} from 'meteor/rocketchat:lib';
import {RoomTypeConfig, RoomTypeRouteConfig, UiTextContext} from 'meteor/rocketchat:lib';

class RequestRoomRoute extends RoomTypeRouteConfig {
constructor() {
Expand Down Expand Up @@ -73,5 +73,18 @@ export class RequestRoomType extends RoomTypeConfig {
enableMembersListProfile() {
return true;
}

getUiText(context) {
switch (context) {
case UiTextContext.CLOSE_WARNING:
return 'Close_request_warning';
case UiTextContext.HIDE_WARNING:
return 'Hide_request_warning';
case UiTextContext.LEAVE_WARNING:
return 'Leave_request_warning';
default:
return '';
}
}
}

2 changes: 2 additions & 0 deletions packages/assistify-help-request/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Package.onUse(function(api) {
api.addFiles('config.js', 'server');
api.addFiles('startup/customRoomTypes.js');
api.addFiles('startup/rolesAndPermissions.js', 'server');
api.addFiles('lib/messageTypes/requestClosed.js');

// Libraries
api.addFiles('server/inject.js', 'server');
Expand Down Expand Up @@ -82,6 +83,7 @@ Package.onUse(function(api) {

//Assets
api.addAssets('assets/stylesheets/helpRequestContext.less', 'server'); //has to be done on the server, it exposes the completed css to the client
api.addFiles('client/public/stylesheets/help-request.css', 'client');

//global UI modifications
api.addFiles('client/views/tabbar/tabbarConfig.js', 'client');
Expand Down
20 changes: 17 additions & 3 deletions packages/assistify-help-request/server/methods/closeHelpRequest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* globals RocketChat, TAPi18n */

Meteor.methods({
'assistify:closeHelpRequest'(roomId, closingProps = {}) {
const room = RocketChat.models.Rooms.findOneByIdOrName(roomId);
Expand All @@ -16,14 +18,26 @@ Meteor.methods({
// delete subscriptions in order to make the room disappear from the user's clients
const nonOwners = RocketChat.models.Subscriptions.findByRoomIdAndNotUserId(roomId, room.u._id).fetch();
nonOwners.forEach((nonOwner) => {
RocketChat.models.Subscriptions.removeByRoomIdAndUserId(roomId, nonOwner.u._id);
RocketChat.models.Subscriptions.hideByRoomIdAndUserId(roomId, nonOwner.u._id);
});

//remove the subscription of the user closing the room as well - if he's the one who triggered the closing
// remove the subscription of the user closing the room as well - if he's the one who triggered the closing
if (Meteor.userId() === room.u._id) {
RocketChat.models.Subscriptions.removeByRoomIdAndUserId(roomId, Meteor.userId());
RocketChat.models.Subscriptions.hideByRoomIdAndUserId(roomId, Meteor.userId());
}

// add a message informing about the closed state and the comment
if (closingProps && closingProps.comment) {
RocketChat.models.Messages.createWithTypeRoomIdMessageAndUser('request_closed', roomId, `: ${ closingProps.comment }`, user);
} else {
RocketChat.models.Messages.createWithTypeRoomIdMessageAndUser('request_closed', roomId, ` ${ closingProps.comment }`, user);
}
const rocketCatUser = RocketChat.models.Users.findOneByUsername('rocket.cat');
if (rocketCatUser) {
RocketChat.models.Messages.createWithTypeRoomIdMessageAndUser('request_closed_explanation', roomId, '', rocketCatUser);
}

// trigger callback in order to send the conversation for learning to the knowledge adapter
Meteor.defer(() => {
RocketChat.callbacks.run('assistify.closeRoom', room, closingProps);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ application: Anwendung
Assistify_room_count: Letzte Raumnummer
Choose_experts: Die auswählen, die sich damit auskennen
Close_HelpRequest: Chat beenden
Close_request_comment: Werden Sie hier Ihre (berühmten) letzten Worte los!
Close_request_warning: Ist die Anfrage abschließend beantwortet, dann schließen Sie den Chat. So können wir aus dem Geschriebenen lernen.
create-e: Thema anlegen
create-r: Anfrage anlegen
delete-e: Thema löschen
Expand All @@ -15,6 +17,10 @@ Expertises: Themen
Experts_channel: Expertenkanal
Experts: Experten
gui_title: GUI-Titel
Hide_expertise_warning: Sind Sie sicher, dass Sie das Thema "%s" ausblenden wollen? Sie sind danach immer noch Experte zu dem Thema und werden bei neuen Anfragen gefragt werden.
Hide_request_warning: Sind Sie sicher, dass Sie die Anfrage "%s" ausblenden wollen? Sie können sie danach immer noch einsehen, wenn Sie möchten.
Leave_expertise_warning: Sind Sie sicher, dass Sie das Thema "%s" verlassen wollen? Sie sind danach kein Experte zu dem Thema mehr. Bei einer neuen Anfrage werden Sie nicht mehr gefragt werden!
Leave_request_warning: Sind sie Sicher, dass Sie die Anfrage "%s" verlassen wollen? Sie können sie danach nicht mehr einsehen und auch nicht in der Suche finden!
More_requests: Weitere Anfragen
New_expertise: Neues Thema
New_request_for_expertise: Neue Anfrage zum Thema
Expand All @@ -23,6 +29,8 @@ No_expertise_yet: Noch in keiner Expertengruppe
No_requests_yet: Keine Anfragen bisher
release: Version
Request_already_exists: Eine Anfrage mit der nächsten laufenen Nummer existiert bereits. Bitte erneut versuchen.
Request_closed: Anfrage geschlossen__comment__
Request_closed_explanation: Die Anfrage wurde geschlossen. Sie können weiter schreiben, aber daraus wird nicht gelernt. Sollte es weitere Fragen geben, bitte eine neue Anfrage eröffnen.
Request_description: Eine Anfrage richtet sich automatisch an die Experten eines Themas. Eine KI hilft dabei.
Request_explanation: Eine Anfrage richtet sich an Experten eines Themas: Gemeinsam mit dem Fragesteller wird versucht, eine Frage aus dem Wissensgebiet zu beantworten. Eine KI beschleunigt den Problemlösungsprozess. Aus abgeschlossenen Anfragen lernt das System und hilft, Fragen zu dem Thema in Zukunft schneller zu beantworten.
Request: Anfrage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ application: Application
Asssitify_room_count: Roomcount
Choose_experts: Choose those who know
Close_HelpRequest: Close chat
Close_request_comment: You can add (famous) last words
Close_request_warning: Please do close the request once you are finished answering the questions asked. This way, we can learn from what you have written.
Expertise_description: A topic is an area of knowledge with known experts.
Expertise_explanation: A topic is an area of knowledge. Experts join a topic in order to help others solve their question in that area.
Expertise_needs_experts: Select some experts in order to define an topic
Expand All @@ -11,6 +13,10 @@ Expertises: Topics
Experts_channel: Experts channel
Experts: Experts
gui_title: GUI-Title
Hide_expertise_warning: Are you sure you want to hide the topic "%s"? You'll still be a an expert for it and will be asked for new requests though.
Hide_request_warning: Are you sure you want to hide the request "%s"? You'll still be able to see and join the conversation lateron.
Leave_expertise_warning: Are you sure you want to leave the topic "%s"? You'll not be a an expert for it anymore and won't be asked for new requests!
Leave_request_warning: Are you sure you want to leave the request "%s"? You'll not be able to see and join the conversation lateron, neither you'll find it searching for it!
More_requests: Other requests
New_expertise: New topic
New_request_for_expertise: New request for topic
Expand All @@ -19,6 +25,8 @@ No_expertise_yet: No topics yet
No_requests_yet: No requests yet
release: Version
Request_already_exists: A request with the next rawn number already exists. Please try again.
Request_closed: Request closed__comment__
Request_closed_explanation: You can keep on chatting, but we'll not learn from that. In case of additional questions, please create new requests.
Request_explanation: A request is automatically being adressed towards topic experts. AI helps solving it.
Request_description: A request is a conversation starting with a question on a particular topic. When finishing such a conversation, our system is going to learn from it in order to accelerate further request-solutions on that topic.
Request: Request
Expand Down
6 changes: 3 additions & 3 deletions packages/rocketchat-i18n/i18n/de-AT.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
"Archive": "Archivieren",
"are_also_typing": "schreiben auch",
"are_typing": "schreiben",
"Are_you_sure": "Sind Sie sicher?",
"Are_you_sure": "Raum verstecken",
"Are_you_sure_you_want_to_delete_your_account": "Sind Sie sicher, dass Sie Ihr Konto löschen möchten?",
"at": "am",
"Auth_Token": "Auth-Token",
Expand Down Expand Up @@ -251,7 +251,7 @@
"Close": "Schließen",
"Closed": "Geschlossen",
"Closed_by_visitor": "Durch Besucher geschlossen",
"Closing_chat": "Schließe Chat",
"Closing_chat": "Chat beenden",
"Collapse_Embedded_Media_By_Default": "Eingebettete Medien standardmäßig ausblenden",
"Color": "Farbe",
"Commands": "Befehle",
Expand Down Expand Up @@ -1260,4 +1260,4 @@
"your_message_optional": "ihre optionale Nachricht",
"Your_password_is_wrong": "Falsches Passwort",
"Your_push_was_sent_to_s_devices": "Die Push-Nachricht wurde an %s Geräte gesendet."
}
}
2 changes: 1 addition & 1 deletion packages/rocketchat-i18n/i18n/de.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
"close-others-livechat-room_description": "Berechtigung, andere Livechat-Räume zu schließen",
"Closed": "Geschlossen",
"Closed_by_visitor": "Durch Besucher geschlossen",
"Closing_chat": "Schließe Chat",
"Closing_chat": "Chat beenden",
"Collapse_Embedded_Media_By_Default": "Eingebettete Medien standardmäßig ausblenden",
"Color": "Farbe",
"Commands": "Befehle",
Expand Down
5 changes: 3 additions & 2 deletions packages/rocketchat-lib/client/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/

import { RocketChatTabBar } from './RocketChatTabBar';
import { RoomSettingsEnum, RoomTypeConfig, RoomTypeRouteConfig } from '../../lib/RoomTypeConfig';
import { RoomSettingsEnum, RoomTypeConfig, RoomTypeRouteConfig, UiTextContext } from '../../lib/RoomTypeConfig';


export {
RocketChatTabBar,
RoomSettingsEnum,
RoomTypeConfig,
RoomTypeRouteConfig
RoomTypeRouteConfig,
UiTextContext
};
16 changes: 16 additions & 0 deletions packages/rocketchat-lib/lib/RoomTypeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export const RoomSettingsEnum = {
JOIN_CODE: 'joinCode'
};

export const UiTextContext = {
CLOSE_WARNING: 'closeWarning',
HIDE_WARNING: 'hideWarning',
LEAVE_WARNING: 'leaveWarning'
};

export class RoomTypeRouteConfig {
constructor({name, path}) {
if (typeof name !== 'undefined' && (typeof name !== 'string' || name.length === 0)) {
Expand Down Expand Up @@ -184,4 +190,14 @@ export class RoomTypeConfig {
enableMembersListProfile() {
return false;
}

/**
* Returns a text which can be used in generic UIs.
* @param context The role of the text in the UI-Element
* @return {string} A text or a translation key - the consumers of this method will pass the
* returned value to an internationalization library
*/
getUiText(/* context */) {
return '';
}
}
Loading

0 comments on commit f18a657

Please sign in to comment.