Skip to content

Instantly share code, notes, and snippets.

@iskenxan
iskenxan / client.js
Created April 7, 2019 19:12
Instantiate new client
const client = stream.connect(STREAM_KEY, STREAM_SECRET, APP_ID);
@iskenxan
iskenxan / activity.js
Created April 7, 2019 19:15
Getting Activity
const getTimelineFeed = (username) => {
const timeLineFeed = client.feed('timeline', username);
return timeLineFeed.get({
limit: 25,
reactions: {
counts: true,
},
}).then((result) => {
return result;
});
@iskenxan
iskenxan / response.json
Created April 7, 2019 19:16
GetStream response
[
{
"author": "toyjake74737",
"id": "ELBQLRyUFfTn1BkPxMsm",
"title": "Creepy Uber",
"lastUpdated": 1554394376612,
"favoriteCount": 1
},
{
"author": "toyjake74737",
@iskenxan
iskenxan / add_activity.js
Created April 7, 2019 19:17
Adding activity
const addPostActivity = (username, postId, postTitle, timestamp) => {
const userFeed = client.feed('user', username);
return userFeed.addActivity({
actor: username,
verb: 'post',
object: postId,
foreign_id: `post:${postId}`,
postTitle,
timestamp,
});
@iskenxan
iskenxan / reaction.js
Created April 7, 2019 19:17
Adding reactions
const addReaction = (username, type, postActivityId) => {
const userClient = getClient();
return userClient.reactions.add(type, postActivityId, {
actor: username,
timestamp: new Date().getTime(),
});
}
@iskenxan
iskenxan / get_reactions.js
Created April 7, 2019 19:18
Getting reactions
const reactions = client.reactions.filter({
'activity_id': postActivityId
});
jwt = require('jsonwebtoken');
module.exports = function createToken(userEmail) {
const token = jwt.sign({
access: userEmail
}, 'secret');
}
jwt = require('jsonwebtoken');
const ADMINS = ['iskander@example.com'];
module.exports = function createToken(userEmail) {
let access = userEmail;
ADMINS.forEach(email => {
if (email === userEmail)
access = 'admin'
});
const stampit = require('stampit');
const Character = stampit({
props: {
name: null,
health: 100,
stamina: 100,
},
init({ name = this.name }) {
this.name = name
const Flying = stampit(Character, {
methods: {
fly() {
console.log(`${this.name} takes off in the sky!`)
stamina --;
}
}
});