mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-05-21 22:36:37 +00:00
Add new POST: Poll
This commit is contained in:
parent
64a87127a0
commit
c317b04d08
14
src/post/Poll.js
Normal file
14
src/post/Poll.js
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const Post = require('./BasePost');
|
||||
|
||||
// A poll / vote
|
||||
class Poll extends Post {
|
||||
constructor(question, options) {
|
||||
super("poll");
|
||||
this.question = question;
|
||||
this.options = options;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Poll;
|
@ -1,14 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const async = require('asyncawait/async');
|
||||
const await = require('asyncawait/await');
|
||||
|
||||
const Post = require('./BasePost');
|
||||
const TextPost = require('./TextPost');
|
||||
const FilePost = require('./FilePost');
|
||||
const DirectoryPost = require('./DirectoryPost');
|
||||
const OrbitDBItem = require('./OrbitDBItem');
|
||||
const MetaInfo = require('./MetaInfo');
|
||||
const Poll = require('./Poll');
|
||||
|
||||
const PostTypes = {
|
||||
Message: TextPost,
|
||||
@ -16,7 +14,8 @@ const PostTypes = {
|
||||
File: FilePost,
|
||||
Directory: DirectoryPost,
|
||||
Link: "link",
|
||||
OrbitDBItem: OrbitDBItem
|
||||
OrbitDBItem: OrbitDBItem,
|
||||
Poll: Poll
|
||||
};
|
||||
|
||||
// Factory
|
||||
@ -33,13 +32,16 @@ class Posts {
|
||||
post = new PostTypes.Directory(data.name, data.hash, data.size);
|
||||
} else if(type == PostTypes.OrbitDBItem) {
|
||||
post = new PostTypes.OrbitDBItem(data.operation, data.key, data.value);
|
||||
} else if(type == PostTypes.Poll) {
|
||||
post = new PostTypes.Poll(data.question, data.options);
|
||||
}
|
||||
|
||||
const size = data.size ? data.size : Buffer.byteLength(data, 'utf8');
|
||||
post.meta = new MetaInfo(post.type, size, new Date().getTime(), data.from);
|
||||
if(post.type) delete post.type;
|
||||
const res = await(ipfs.object.put(new Buffer(JSON.stringify({ Data: JSON.stringify(post) })), "json"));
|
||||
resolve({ Post: post, Hash: res.Hash });
|
||||
ipfs.object.put(new Buffer(JSON.stringify({ Data: JSON.stringify(post) })), "json")
|
||||
.then((res) => resolve({ Post: post, Hash: res.Hash }))
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user