Kaynağa Gözat

Setup dev env and poc

Brendan Abolivier 7 yıl önce
ebeveyn
işleme
219c3c4cc3
İmzalayan: Brendan Abolivier <contact@brendanabolivier.com> GPC anahtar kimliği: 8EF1500759F70623
7 değiştirilmiş dosya ile 3958 ekleme ve 4 silme
  1. 15
    0
      .editorconfig
  2. 3
    0
      .gitignore
  3. 3833
    0
      package-lock.json
  4. 16
    3
      package.json
  5. 2
    1
      src/index.html
  6. 74
    0
      src/index.js
  7. 15
    0
      webpack.config.js

+ 15
- 0
.editorconfig Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+root = true
2
+
3
+[*]
4
+charset = utf-8
5
+
6
+end_of_line = lf
7
+insert_final_newline = true
8
+trim_trailing_whitespace = true
9
+
10
+[*.{js,json}]
11
+indent_style = tab
12
+indent_size = 4
13
+
14
+[*.md]
15
+trim_trailing_whitespace = false

+ 3
- 0
.gitignore Dosyayı Görüntüle

@@ -1,6 +1,9 @@
1 1
 # npm modules
2 2
 node_modules
3 3
 
4
+# built files
5
+dist
6
+
4 7
 # tmp files
5 8
 .*.swp
6 9
 

+ 3833
- 0
package-lock.json
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 16
- 3
package.json Dosyayı Görüntüle

@@ -2,9 +2,9 @@
2 2
   "name": "sparrow",
3 3
   "version": "0.0.1",
4 4
   "description": "Sparrow is a libre front-end forum software powered by the Matrix protocol and using a Matrix homeserver as its back-end",
5
-  "main": "index.js",
6 5
   "scripts": {
7
-    "test": "echo \"Error: no test specified\" && exit 1"
6
+    "test": "echo \"Error: no test specified\" && exit 1",
7
+    "build": "webpack"
8 8
   },
9 9
   "repository": {
10 10
     "type": "git",
@@ -15,5 +15,18 @@
15 15
   "bugs": {
16 16
     "url": "https://github.com/babolivier/sparrow/issues"
17 17
   },
18
-  "homepage": "https://github.com/babolivier/sparrow#readme"
18
+  "homepage": "https://github.com/babolivier/sparrow",
19
+  "devDependencies": {
20
+    "babel-core": "6.26.0",
21
+    "babel-loader": "7.1.2",
22
+    "babel-polyfill": "6.26.0",
23
+    "babel-preset-env": "1.6.0",
24
+    "babel-preset-flow": "6.23.0",
25
+    "flow-bin": "0.55.0",
26
+    "html-webpack-plugin": "^2.30.1",
27
+    "webpack": "3.6.0"
28
+  },
29
+  "dependencies": {
30
+    "matrix-js-sdk": "^0.8.4"
31
+  }
19 32
 }

index.html → src/index.html Dosyayı Görüntüle

@@ -5,6 +5,7 @@
5 5
         <title>Sparrow</title>
6 6
     </head>
7 7
     <body>
8
-        In progress...
8
+        <p>List of topics:</p>
9
+        <ul id="topics"></ul>
9 10
     </body>
10 11
 </html>

+ 74
- 0
src/index.js Dosyayı Görüntüle

@@ -0,0 +1,74 @@
1
+import * as matrixSDK from 'matrix-js-sdk'
2
+
3
+function fetchTopics() {
4
+    matrixSDK.createClient({
5
+        baseUrl: 'https://matrix.trancendances.fr',
6
+    })
7
+    .registerGuest()
8
+    .then((data) => {
9
+        return matrixSDK.createClient({
10
+            baseUrl: 'https://matrix.trancendances.fr',
11
+            accessToken: data['access_token'],
12
+            userId: data['user_id'],
13
+            deviceId: data['device_id'],
14
+        })
15
+    })
16
+    .then((client) => {
17
+        client.publicRooms(function(err, data) {
18
+            for (let publicRoom of data.chunk) {
19
+                if (!publicRoom['guest_can_join']) {
20
+                    continue
21
+                }
22
+
23
+                client.roomInitialSync(publicRoom["room_id"], 20)
24
+                .then(async (syncData) => {
25
+                    let name, creator, creationDate, categories
26
+                    let nbMessages = 0
27
+                    for (let stateEvent of syncData.state) {
28
+                        if (stateEvent.type === "m.room.create") {
29
+                            let userID = stateEvent.content.creator
30
+                            let profileInfo = await client.getProfileInfo(stateEvent.content.creator, 'displayname')
31
+                            creator = {
32
+                                userID: userID,
33
+                                displayName: profileInfo.displayname,
34
+                            }
35
+                            creationDate = new Date(stateEvent['origin_server_ts'])
36
+
37
+                        }
38
+                        if (stateEvent.type === "m.room.name") {
39
+                            name = stateEvent.content.name
40
+                        }
41
+                        if (stateEvent.type === "m.forum.topic.categories") {
42
+                            categories = stateEvent.content.categories.join(',')
43
+                        }
44
+                    }
45
+                    for (let messageEvent of syncData.messages.chunk) {
46
+                        if (messageEvent.type === "m.room.message") {
47
+                            nbMessages++;
48
+                        }
49
+                    }
50
+
51
+                    appendTopic(name, publicRoom['room_id'], creator, creationDate, nbMessages, categories)
52
+                })
53
+            }
54
+        });
55
+    })
56
+    .catch((err) => {
57
+        console.log(err);
58
+    })
59
+}
60
+
61
+function appendTopic(name, roomID, creator, creationDate, nbMessages, categories) {
62
+    let list = document.getElementById('topics')
63
+    let el = document.createElement('li')
64
+    let topicMsg = "Topic " + name + " (id " + roomID + ") created by "
65
+        + creator.displayName + " (" + creator.userID + ") on "
66
+        + creationDate.toString() + " containing " + nbMessages + " messages"
67
+    if (categories) {
68
+        topicMsg += ", listed in categorie(s) " + categories
69
+    }
70
+    el.innerHTML = topicMsg
71
+    list.appendChild(el)
72
+}
73
+
74
+fetchTopics()

+ 15
- 0
webpack.config.js Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+const path				= require('path');
2
+const HtmlWebpackPlugin = require('html-webpack-plugin');
3
+
4
+module.exports = {
5
+	entry: './src/index.js',
6
+ 	output: {
7
+		filename: 'sparrow.js',
8
+		path: path.resolve(__dirname, 'dist')
9
+	},
10
+	plugins: [
11
+		new HtmlWebpackPlugin({
12
+			template: './src/index.html'
13
+		})
14
+	]
15
+};