Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #49 from symphonyoss/room-management
Browse files Browse the repository at this point in the history
Room management
  • Loading branch information
jonfreedman committed Mar 25, 2017
2 parents af11d38 + 15f8d6b commit df77626
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 61 deletions.
12 changes: 9 additions & 3 deletions .eslintrc
@@ -1,7 +1,13 @@
{
"parser": "babel-eslint",
"extends": [
"canonical",
"canonical/flowtype",
"canonical/mocha"
"eslint:recommended",
"google",
"plugin:flowtype/recommended",
"plugin:mocha/recommended"
],
"plugins": [
"flowtype",
"mocha"
]
}
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -16,7 +16,6 @@ Hubot is a [chatops](http://lmgtfy.com/?q=chatops+hubot) tool developed by GitHu

[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)

[![NPM](https://nodei.co/npm/hubot-symphony.png?downloads=true&stars=true)](https://nodei.co/npm/hubot-symphony/)

Expand Down
4 changes: 2 additions & 2 deletions flow-typed/npm/chai_v3.5.x.js
Expand Up @@ -168,10 +168,10 @@ declare module "chai" {
static notInstanceOf(val: mixed, constructor: Function, msg?: string): void;

static include(exp: string, inc: mixed, msg?: string): void;
static include(exp: Array<mixed>, inc: mixed, msg?: string): void;
static include<T>(exp: Array<T>, inc: T, msg?: string): void;

static notInclude(exp: string, inc: mixed, msg?: string): void;
static notInclude(exp: Array<mixed>, inc: mixed, msg?: string): void;
static notInclude<T>(exp: Array<T>, inc: T, msg?: string): void;

static match(exp: mixed, re: RegExp, msg?: string): void;
static notMatch(exp: mixed, re: RegExp, msg?: string): void;
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -54,7 +54,9 @@
"cz-conventional-changelog": "2.0.0",
"eslint": "3.18.0",
"eslint-config-canonical": "8.0.2",
"eslint-config-google": "0.7.1",
"eslint-plugin-flowtype": "2.30.4",
"eslint-plugin-mocha": "4.9.0",
"flow-bin": "0.42.0",
"ghooks": "2.0.0",
"hubot": "2.19.0",
Expand Down
167 changes: 165 additions & 2 deletions src/symphony.js
Expand Up @@ -18,6 +18,7 @@

import fs from 'fs';
import request from 'request';
import querystring from 'querystring';
import memoize from 'memoizee';
import Log from 'log';

Expand Down Expand Up @@ -86,13 +87,97 @@ export type CreateIMResponseType = {
id: string
};

type KeyValuePairType = {
key: string,
value: string
};

type CreateRoomFeaturesType = {
membersCanInvite?: boolean,
discoverable?: boolean,
public?: boolean,
readOnly?: boolean,
copyProtected?: boolean
};

export type CreateRoomType = {
name: string,
description: string,
keywords: Map<string, string>,
features?: CreateRoomFeaturesType
};

type UpdateRoomFeaturesType = {
membersCanInvite?: boolean,
discoverable?: boolean,
copyProtected?: boolean
};

export type UpdateRoomType = {
name: string,
description: string,
keywords: Map<string, string>,
features?: UpdateRoomFeaturesType
};

export type RoomInfoType = {
roomAttributes: {
name: string,
keywords: Array<KeyValuePairType>,
description: string,
membersCanInvite: boolean,
discoverable: boolean,
readOnly: boolean,
copyProtected: boolean,
public: boolean
},
roomSystemInfo: {
id: string,
creationDate: number,
createdByUserId: number,
active: boolean
}
};

export type RoomInfoAlternateType = {
roomAttributes: {
name: string,
keywords: Array<KeyValuePairType>,
description: string,
membersCanInvite: boolean,
discoverable: boolean
},
roomSystemInfo: {
id: string,
creationDate: number,
createdByUserId: number,
active: boolean
},
immutableRoomAttributes: {
readOnly: boolean,
copyProtected: boolean,
public: boolean
}
};

export type RoomMembershipType = {
id: number,
owner: boolean,
joinDate: number
};

export type RoomMemberActionType = {
format: string,
message: string
}

type HttpHeaderType = {
[key:string]: string
[key: string]: string
};

type HttpResponseType = {
statusCode: number
}
};

class Symphony {
host: string;
Expand Down Expand Up @@ -182,6 +267,84 @@ class Symphony {
return this._httpPodPost('/pod/v1/im/create', [userId]);
}

createRoom (roomInfo: CreateRoomType): Promise<RoomInfoType> {
const getFeature = function(feature: string): boolean {
if (roomInfo.features) {
return roomInfo.features[feature] || false;
}
return false;
};
const body = {
name: roomInfo.name,
description: roomInfo.description,
keywords: [],
membersCanInvite: getFeature('membersCanInvite'),
discoverable: getFeature('discoverable'),
public: getFeature('public'),
readOnly: getFeature('readOnly'),
copyProtected: getFeature('copyProtected')
};
for (const [key, value] of roomInfo.keywords.entries()) {
body.keywords.push({
key: key,
value: value
});
}
return this._httpPodPost('/pod/v2/room/create', body);
}

getRoomInfo (roomId: string): Promise<RoomInfoType> {
return this._httpPodGet(`/pod/v2/room/${roomId}/info`)
}

updateRoom (roomId: string, roomInfo: UpdateRoomType): Promise<RoomInfoType> {
const getFeature = function(feature: string): boolean {
if (roomInfo.features) {
return roomInfo.features[feature] || false;
}
return false;
};
const body = {
name: roomInfo.name,
description: roomInfo.description,
keywords: [],
membersCanInvite: getFeature('membersCanInvite'),
discoverable: getFeature('discoverable'),
copyProtected: getFeature('copyProtected')
};
for (const [key, value] of roomInfo.keywords.entries()) {
body.keywords.push({
key: key,
value: value
});
}
return this._httpPodPost(`/pod/v2/room/${roomId}/update`, body);
}

setRoomActiveStatus (roomId: string, status: boolean): Promise<RoomInfoAlternateType> {
return this._httpPodPost(`/pod/v1/room/${roomId}/setActive?${querystring.stringify({active: status})}`);
}

getMembers (roomId: string): Promise<Array<RoomMembershipType>> {
return this._httpPodGet(`/pod/v2/room/${roomId}/membership/list`);
}

addMember (roomId: string, userId: number): Promise<RoomMemberActionType> {
return this._httpPodPost(`/pod/v1/room/${roomId}/membership/add`, {id: userId})
}

removeMember (roomId: string, userId: number): Promise<RoomMemberActionType> {
return this._httpPodPost(`/pod/v1/room/${roomId}/membership/remove`, {id: userId})
}

promoteMember (roomId: string, userId: number): Promise<RoomMemberActionType> {
return this._httpPodPost(`/pod/v1/room/${roomId}/membership/promoteOwner`, {id: userId})
}

demoteMember (roomId: string, userId: number): Promise<RoomMemberActionType> {
return this._httpPodPost(`/pod/v1/room/${roomId}/membership/demoteOwner`, {id: userId})
}

_httpPodGet<T> (path: string): Promise<T> {
return this.sessionAuth().then((sessionToken: AuthenticateResponseType): Promise<T> => {
let headers = {
Expand Down

0 comments on commit df77626

Please sign in to comment.