add socket.io back, cleanup

Change-Id: I74e043268c23fb45371f1e397ca2931ca177afc3
diff --git a/routes/jami.js b/routes/jami.js
index 5c92180..1ba568f 100644
--- a/routes/jami.js
+++ b/routes/jami.js
@@ -10,12 +10,12 @@
         //router.use(express.json());
 
         // Accounts
-        router.get(['/accounts'], (req, res, next) => {
+        router.get(['/accounts'], async (req, res, next) => {
             console.log("Get account list")
             let accounts = this.jami.getAccountList()
             if (req.user.accountFilter)
                 accounts = accounts.filter(account => req.user.accountFilter(account.getId()))
-            res.json(accounts.map(account => account.getSummary()))
+            res.json(await Promise.all(accounts.map(async account => await account.getSummary())))
         })
 
         const checkAccount = (req, res, next) => {
@@ -29,18 +29,20 @@
         const accountRouter = Router({mergeParams: true})
         router.use('/accounts/:accountId', checkAccount, accountRouter)
 
-        accountRouter.get(['/'], (req, res, next) => {
+        accountRouter.get(['/'], async (req, res) => {
             console.log(`Get account ${req.params.accountId}`)
             const account = this.jami.getAccount(req.params.accountId)
-            account.defaultModerators = this.jami.getDefaultModerators(account.getId())
-            if (account)
-                res.json(account.getObject())
-            else
+            if (account) {
+                account.defaultModerators = this.jami.getDefaultModerators(account.getId())
+                const obj = await account.getObject()
+                console.log(obj)
+                res.json(obj)
+            } else
                 res.status(404).end()
         })
 
         // Contacts
-        accountRouter.get(['/contacts'], (req, res, next) => {
+        accountRouter.get(['/contacts'], (req, res) => {
             console.log(`Get account ${req.params.accountId}`)
             const account = this.jami.getAccount(req.params.accountId)
             if (account)
@@ -49,6 +51,18 @@
                 res.status(404).end()
         })
 
+        // Default modertors
+        accountRouter.put('/defaultModerators/:contactId', async (req, res) => {
+            console.log(`Adding default moderator ${req.params.contactId} to account ${req.params.accountId}`)
+            this.jami.addDefaultModerator(req.params.accountId, req.params.contactId)
+            res.status(200).end()
+        })
+        accountRouter.delete('/defaultModerators/:contactId', async (req, res) => {
+            console.log(`Removing default moderator to account ${req.params.accountId}`)
+            this.jami.removeDefaultModerator(req.params.accountId, req.params.contactId)
+            res.status(200).end()
+        })
+
         // Conversations
         accountRouter.get('/conversations', async (req, res, next) => {
             console.log(`Get conversations for account ${req.params.accountId}`)
@@ -96,6 +110,16 @@
             }
         })
 
+        accountRouter.get('/conversations/:conversationId/messages', async (req, res) => {
+            console.log(`Get messages for conversation ${req.params.conversationId} for account ${req.params.accountId}`)
+            try {
+                const messages = await this.jami.loadMessages(req.params.accountId, req.params.conversationId)
+                res.json(messages).end()
+            } catch (e) {
+                res.status(400).json({ error: e.message })
+            }
+        })
+
         // Nameserver
         const nsRouter = Router({mergeParams: true})
         accountRouter.use('/ns', nsRouter)