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

Synchronise roster with Contacts app #158

Merged
merged 14 commits into from
Nov 23, 2014
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ phpunit.phar
/build
node_modules
js/vendor
js/main.min.js
js/main.min.js
/.project
12 changes: 12 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,23 @@ module.exports = function(grunt) {
src: 'js/src/bower_components/strophejs/strophe.js',
dest: 'js/vendor/strophe.js'
}
},
concat : {
dist : {
src: [
'js/src/chat.js',
'js/src/**/*.js',
'!js/src/bower_components/**/*.js',
'!js/src/vendor/**/*.js'
],
dest : 'js/main.min.js'
}
}
});

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('default', ['uglify', 'cssmin']);

};
3 changes: 2 additions & 1 deletion app/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function __construct(array $urlParams = array()) {
return new AppController(
$c->query('AppName'),
$c->query('Request'),
$app
$app,
$c->query('ContactsManager')
);
});

Expand Down
10 changes: 10 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
'name' => 'config#set',
'url' => '/config/set',
'verb' => 'post'
),
array(
'name' => 'app#addContact',
'url' => '/contacts/add/',
'verb' => 'post'
),
array(
'name' => 'app#removeContact',
'url' => '/contacts/remove/',
'verb' => 'post'
)
)
));
44 changes: 42 additions & 2 deletions controller/appcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
use \OCP\AppFramework\Http\JSONResponse;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCA\Chat\App\Chat;
use \OCP\Contacts\IManager;

class AppController extends Controller {

private $app;

private $c;

public function __construct($appName, IRequest $request, Chat $app){
public function __construct($appName, IRequest $request, Chat $app, IManager $cm){
parent::__construct($appName, $request);
$this->app = $app;
$this->c = $app->getContainer();
$this->cm = $cm;
}

/**
Expand All @@ -47,7 +49,6 @@ public function index() {
$backendsToArray[$backend->getId()] = $backend->toArray();
}
$initConvs = $this->app->getInitConvs();

$params = array(
"initvar" => json_encode(array(
"contacts" => $contacts['contacts'],
Expand All @@ -70,4 +71,43 @@ public function contacts(){
return new JSONResponse($this->app->getContacts());
}

/**
* @NoAdminRequired
* @return JSONResponse
*/
public function addContact($contacts){

$addressbooks = $this->cm->getAddressBooks();
$key = array_search('Contacts', $addressbooks);

// Create contacts
$ids = array();
foreach ($contacts as $contact){
$r = $this->cm->createOrUpdate($contact, $key);
$ids[] = $r->getId();
}

// Return just created contacts as contacts which can be used by the Chat app
$contacts = $this->app->getContacts();
$newContacts = array();
foreach ($ids as $id){
$newContacts[$id] = $contacts['contactsObj'][$id];
}

return $newContacts;
}

/**
* @NoAdminRequired
* @return JSONResponse
*/
public function removeContact($contacts){
// Create contacts
$ids = array();
foreach ($contacts as $contact){
$this->cm->delete($contact, 'local:1');
}

}

}
2 changes: 1 addition & 1 deletion css/main.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion css/src/app-navigation.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@
height: 60px;
}

.conv-list-item-buttons div {
float:right;
}
.conv-list-item-buttons{
float:right;
width:20px;
width:40px;
height: 40px !important;
}

.heightInvite {
Expand Down
5 changes: 5 additions & 0 deletions css/src/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@
.backend-config-save {
margin-left: 10px;
width:80px;
}

.setting-error {
color: red;
font-weight: bold;
}
Loading