-
Notifications
You must be signed in to change notification settings - Fork 1
/
add-group-key.js
61 lines (49 loc) · 1.66 KB
/
add-group-key.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module.exports = function (ssbSingleton, getGroupKeysFeed) {
const { replicateSubfeeds } = require('./helpers')
return {
template: `
<div id="app">
<h2>Add group key</h2>
<input type='text' style='width: 500px;' v-model="groupKey" @keyup.enter="addKey()">
<button v-on:click="addKey">Add key</button>
</div>`,
data: function() {
return {
groupKey: ''
}
},
methods: {
addKey: function() {
ssbSingleton.getSimpleSSBEventually(
(err, SSB) => {
if (err) return console.error(err)
getGroupKeysFeed(SSB, async (err, keysFeed) => {
const groupId = this.groupKey + '.groupies'
const { where, type, toPromise } = SSB.db.operators
const existing = (await SSB.db.query(
where(type('groupkey')),
toPromise()
)).filter(msg => msg.value.content.id === groupId)
if (existing.length !== 0) return alert('Key already added!')
SSB.db.publishAs(keysFeed.keys, {
type: 'groupkey',
key: this.groupKey,
id: groupId,
recps: [SSB.id]
}, (err, msg) => {
if (err) return console.error(err)
const groupKey = Buffer.from(this.groupKey, 'hex')
SSB.box2.addGroupKey(groupId, groupKey)
SSB.db.reindexEncrypted(() => {
// live can have problems with reindex
replicateSubfeeds(false)
})
alert('Key added!')
})
})
}
)
}
}
}
}