Commit c76f58e8d7c5335c6e7c7f0d9b9c697687c91e59
validate types while building model
Dominic Tarr committed on 12/15/2018, 11:22:30 PMParent: efc1d2b9aecc8c0e48e3cd406f2c03038046a33c
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -4,8 +4,9 @@ | ||
4 | 4 … | var deepEquals = require('deep-equals') |
5 | 5 … | var crypto = require('crypto') |
6 | 6 … | var ssbKeys = require('ssb-keys') |
7 | 7 … | var ssbClient = require('ssb-client') |
8 … | +var types = require('./types') | |
8 | 9 … | |
9 | 10 … | function code(err, c) { |
10 | 11 … | err.code = 'user-invites:'+c |
11 | 12 … | return err |
@@ -51,18 +52,18 @@ | ||
51 | 52 … | function reduce (acc, data, _seq) { |
52 | 53 … | if(!acc) acc = {invited: {}, invites:{}, accepts: {}, hosts: {}} |
53 | 54 … | var msg = data.value |
54 | 55 … | var invite, accept |
55 | - if(msg.content.type === 'user-invite') { | |
56 … | + if(types.isInvite(msg)) { | |
56 | 57 … | //TODO: validate that this is a msg we understand! |
57 | 58 … | invite = msg |
58 | 59 … | accept = acc.accepts[data.key] |
59 | 60 … | } |
60 | - else if(msg.content.type === 'user-invite/accept') { | |
61 … | + else if(types.isAccept(msg)) { | |
61 | 62 … | accept = msg |
62 | 63 … | invite = acc.invites[accept.content.receipt] |
63 | 64 … | } |
64 | - else if(msg.content.type === 'user-invite/confirm') { | |
65 … | + else if(types.isConfirm(msg)) { | |
65 | 66 … | //TODO: just for when we are the guest, but we need to make sure at least one confirm exists. |
66 | 67 … | accept = msg.content.embed |
67 | 68 … | invite = acc.invites[accept.content.receipt] |
68 | 69 … | } |
Built with git-ssb-web