Skip to content

Commit e3882c9

Browse files
committed
change notifications
1 parent 6843507 commit e3882c9

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/topics/local-topic-host.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,39 @@ class LocalTopicHost {
5757

5858
async subscribe(peer, path){
5959
debug('sub', path)
60+
const exists = this.getTopic(path, false)
6061
const topic = this.getTopic(path)
6162
const node = this.getNodeByPeer(peer)
6263

6364
debug('subscribe', path, peer.uuid)
6465

6566
topic.subscribe(node)
6667
node.subscribe(topic)
68+
69+
if(topic.path.indexOf('/dataparty/document/') != -1 && !exists){
70+
const [arg0, arg1, docType, docId] = topic.path.substr(1).split('/')
71+
72+
peer.hostParty.db.on(docType+':'+docId, async (event)=>{
73+
await this.handleDocChange(topic.path, event)
74+
})
75+
}
76+
}
77+
78+
async handleDocChange(path, event){
79+
const topic = this.getTopic(path,false)
80+
81+
if(!topic){return}
82+
83+
const [arg0, arg1, docType, docId] = topic.path.substr(1).split('/')
84+
85+
if(topic.subscribers.size > 0){
86+
await topic.publish({
87+
id: event.msg.id,
88+
type: event.msg.type,
89+
revision: event.msg.revision,
90+
operationType: event.change
91+
})
92+
}
6793
}
6894

6995
async unadvertise(peer, path){

0 commit comments

Comments
 (0)