@@ -6,6 +6,8 @@ import { Errands, Rooms, Messages } from '../../../models/server';
6
6
import { settings } from '../../../settings/server' ;
7
7
8
8
const createErrandMessage = ( rid , mid , dsc , expired_at , initiated_by , charged_to ) => Errands . createWithRoomIdMessageIdDescriptionEndDateAndUsers ( rid , mid , dsc , expired_at , initiated_by , charged_to ) ;
9
+ const createErrandWithoutMentionInMessage = ( rid , mid , dsc , expired_at , initiated_by , charged_to ) =>
10
+ Errands . createWithDescriptionAndDataAndUsers ( rid , mid , dsc , expired_at , initiated_by , charged_to )
9
11
10
12
const getRoom = ( rid ) => {
11
13
const room = Rooms . findOne ( rid ) ;
@@ -40,15 +42,21 @@ const create = ({ rid, mid, errandDescription, expired_at, initiated_by, charged
40
42
} else {
41
43
rid = message . rid ;
42
44
}
43
- }
44
45
45
- if ( ! rid ) {
46
- throw new Meteor . Error ( 'error-invalid-arguments' , { method : 'ErrandCreation' } ) ;
46
+ if ( ! rid ) {
47
+ throw new Meteor . Error ( 'error-invalid-arguments' , { method : 'ErrandCreation' } ) ;
48
+ }
47
49
}
48
-
49
- const p_room = Rooms . findOne ( rid ) ;
50
- if ( ! p_room ) {
51
- throw new Meteor . Error ( 'error-invalid-room' , 'Invalid room' , { method : 'ErrandCreation' } ) ;
50
+
51
+ if ( rid ) {
52
+ const p_room = Rooms . findOne ( rid ) ;
53
+ if ( ! p_room ) {
54
+ throw new Meteor . Error ( 'error-invalid-room' , 'Invalid room' , { method : 'ErrandCreation' } ) ;
55
+ }
56
+ var errand = createErrandMessage ( rid , mid , errandDescription , expired_at , initiated_by , charged_to ) ; //Создание поручения с привязкой к сообщению
57
+ mentionMessage ( mid , errand . _id ) ; //Присваивание поручения к сообщению
58
+ } else {
59
+ var errand = createErrandWithoutMentionInMessage ( rid , mid , errandDescription , expired_at , initiated_by , charged_to ) //Создание поручения без привязки к сообщению
52
60
}
53
61
54
62
// Этот блок не позволяет согздавать много поручений на одном и том же сообщении
@@ -64,7 +72,7 @@ const create = ({ rid, mid, errandDescription, expired_at, initiated_by, charged
64
72
throw new Meteor.Error('error-errand-exists', { method: 'ErrandCreation' });
65
73
}
66
74
}*/
67
- const errand = createErrandMessage ( rid , mid , errandDescription , expired_at , initiated_by , charged_to ) ;
75
+
68
76
69
77
70
78
/* const errand = createErrandMessage('p', name, user.username, [...new Set(invitedUsers)], false, {
@@ -89,9 +97,6 @@ const create = ({ rid, mid, errandDescription, expired_at, initiated_by, charged
89
97
sendMessage(user, { msg: reply }, errand);
90
98
}*/
91
99
92
-
93
- mentionMessage ( mid , errand . _id ) ;
94
-
95
100
return errand ;
96
101
} ;
97
102
@@ -108,6 +113,7 @@ Meteor.methods({
108
113
* @param {string } reply - The reply, optional
109
114
*/
110
115
createErrand ( { rid, mid, errandDescription, expired_at, initiated_by, charged_to, reply } ) {
116
+
111
117
if ( ! settings . get ( 'Errand_enabled' ) ) {
112
118
throw new Meteor . Error ( 'error-action-not-allowed' , 'You are not allowed to create a errand' , { method : 'createErrand' } ) ;
113
119
}
0 commit comments