diff --git a/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts b/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts index cc03e53557..0aa50f3d0e 100644 --- a/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts +++ b/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts @@ -98,9 +98,9 @@ export class Mattermost implements INodeType { description: 'Soft-deletes a channel', }, { - name: 'Members', + name: 'Member', value: 'members', - description: 'Returns the members of a channel.', + description: 'Get a page of members for a channel.', }, { name: 'Restore', @@ -317,6 +317,23 @@ export class Mattermost implements INodeType { }, description: 'The Mattermost Team.', }, + { + displayName: 'Resolve Data', + name: 'resolveData', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'channel', + ], + operation: [ + 'members', + ], + }, + }, + default: true, + description: 'By default the response only contain the ID of the user.
If this option gets activated it will resolve the user automatically.', + }, { displayName: 'Return All', name: 'returnAll', @@ -950,6 +967,11 @@ export class Mattermost implements INodeType { value: 'getByEmail', description: 'Get a user by email', }, + { + name: 'Get By ID', + value: 'getById', + description: 'Get a user by id', + }, ], default: '', description: 'The operation to perform.', @@ -1113,6 +1135,54 @@ export class Mattermost implements INodeType { default: '', description: `User's email`, }, + + // ---------------------------------- + // user:getById + // ---------------------------------- + { + displayName: 'User IDs', + name: 'userIds', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getById', + ], + }, + }, + default: '', + description: `User's ID`, + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getById', + ], + }, + }, + default: {}, + options: [ + { + displayName: 'Since', + name: 'since', + type: 'dateTime', + default: '', + description: 'Only return users that have been modified since the given Unix timestamp (in milliseconds).', + }, + ], + }, ], }; @@ -1245,6 +1315,10 @@ export class Mattermost implements INodeType { let resource: string; let requestMethod = 'POST'; let returnAll = false; + let userIds: string[] = []; + + resource = this.getNodeParameter('resource', 0) as string; + operation = this.getNodeParameter('operation', 0) as string; // For Post let body: IDataObject; @@ -1256,9 +1330,6 @@ export class Mattermost implements INodeType { body = {}; qs = {}; - resource = this.getNodeParameter('resource', i) as string; - operation = this.getNodeParameter('operation', i) as string; - if (resource === 'channel') { if (operation === 'create') { // ---------------------------------- @@ -1509,6 +1580,25 @@ export class Mattermost implements INodeType { endpoint = `users/email/${email}`; } + if (operation === 'getById') { + // ---------------------------------- + // user:getById + // ---------------------------------- + userIds = (this.getNodeParameter('userIds', i) as string).split(',') as string[]; + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + + if (additionalFields.since) { + qs.since = new Date(additionalFields.since as string).getTime(); + } + + requestMethod = 'POST'; + + endpoint = 'users/ids'; + + //@ts-ignore + body = userIds; + + } } else { throw new Error(`The resource "${resource}" is not known!`); @@ -1519,6 +1609,18 @@ export class Mattermost implements INodeType { responseData = await apiRequestAllItems.call(this, requestMethod, endpoint, body, qs); } else { responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs); + if (resource === 'channel' && operation === 'members') { + const resolveData = this.getNodeParameter('resolveData', i) as boolean; + if (resolveData) { + const userIds: string[] = []; + for (const data of responseData) { + userIds.push(data.user_id); + } + if (userIds.length > 0) { + responseData = await apiRequest.call(this, 'POST', 'users/ids', userIds , qs); + } + } + } } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData);