Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
updateProfileLink(link, content) {
// add or remove from meta record list if this is a new record
if (get(link, 'isNew')) {
const action = isEmpty(content) ? 'removeRecord' : 'addRecord';
invokeAction(this, action, link);
} else if (get(link, 'isDeleted')) {
link.rollbackAttributes();
}
// update the URL content
set(link, 'url', content);
},
deletedComment(comment) {
// if we're on the permalink page then redirect after deletion
if (get(this, 'comment')) {
get(this, 'router').transitionTo('posts', get(this, 'post'));
} else {
get(this, 'comments').removeObject(comment);
invokeAction(this, 'countUpdate', get(this, 'post.topLevelCommentsCount') - 1);
}
},
deletedComment(comment) {
// if we're on the permalink page then redirect after deletion
if (get(this, 'comment')) {
get(this, 'router').transitionTo('posts', [get(this, 'post.id')]);
} else {
get(this, 'comments').removeObject(comment);
invokeAction(this, 'countUpdate', get(this, 'post.topLevelCommentsCount') - 1);
}
},
destroyLike: task(function* () {
const like = get(this, 'likes').findBy('user.id', get(this, 'session.account.id'));
// instant feedback
set(this, 'isLiked', false);
invokeAction(this, 'likesCountUpdate', get(this, 'likesCount') - 1);
// commit and handle error
yield like.destroyRecord().then(() => {
get(this, 'likes').removeObject(like);
const type = get(this, 'resouceLikeType');
get(this, 'queryCache').invalidateQuery(type, this._getRequestOptions());
}).catch(() => {
set(this, 'isLiked', true);
invokeAction(this, 'likesCountUpdate', get(this, 'likesCount') + 1);
});
}).drop(),
createComment: task(function* (content, embedUrl = undefined) {
const data = {
content,
embedUrl,
post: get(this, 'post'),
user: get(this, 'session.account'),
};
const upload = get(this, 'upload');
if (upload) {
data.uploads = [upload];
}
const comment = get(this, 'store').createRecord('comment', data);
get(this, 'comments').addObject(comment);
// update comments count
invokeAction(this, 'countUpdate', get(this, 'post.topLevelCommentsCount') + 1);
get(this, 'session.account').incrementProperty('commentsCount');
yield comment.save().then(() => {
invokeAction(this, 'trackEngagement', 'comment');
get(this, 'metrics').trackEvent({ category: 'comment', action: 'create', value: get(this, 'post.id') });
}).catch((err) => {
get(this, 'comments').removeObject(comment);
invokeAction(this, 'countUpdate', get(this, 'post.topLevelCommentsCount') - 1);
get(this, 'session.account').decrementProperty('commentsCount');
get(this, 'notify').error(errorMessages(err));
});
}).drop(),
token() {
invokeAction(component, 'onToken', ...arguments);
// Add deprecation for previous `action` callback
if (!isBlank(component.attrs.action)) {
deprecate('Using `action` callback is deprecated and will be removed in future versions. Please use `onToken` with a closure action instead',
false,
{ id: 'ember-cli-stripe.action-callback', until: '1.1.0' }
);
invokeAction(component, 'action', ...arguments);
}
},
opened() {
token() {
invokeAction(component, 'onToken', ...arguments);
// Add deprecation for previous `action` callback
if (!isBlank(component.attrs.action)) {
deprecate('Using `action` callback is deprecated and will be removed in future versions. Please use `onToken` with a closure action instead',
false,
{ id: 'ember-cli-stripe.action-callback', until: '1.1.0' }
);
invokeAction(component, 'action', ...arguments);
}
},
opened() {
.then(() => {
// this post is being deleted from its permalink page
if (get(this, 'group') === undefined) {
get(this, 'router').transitionTo('dashboard');
} else {
// try to find the activity-group that references this post
let record = get(this, 'store').peekRecord('activity-group', get(this, 'group.id'));
// might be a new activity-group that doesn't have a set id
if (record === null || record === undefined) {
record = get(this, 'store').peekAll('activity-group')
.find(group => get(group, 'activities').findBy('foreignId', `Post:${get(this, 'post.id')}`));
}
invokeAction(this, 'removeGroup', record);
}
get(this, 'notify').success('Success! Your post has been deleted.');
})
.catch((err) => {
updateTask: task(function* (status) {
const entry = get(this, 'entry');
if (entry === undefined) {
yield invokeAction(this, 'create', status.key);
} else if (status.key === REMOVE_KEY) {
yield invokeAction(this, 'delete');
} else {
yield invokeAction(this, 'update', status.key);
}
}).drop(),
transitionTo(item) {
invokeAction(this, 'close');
if (typeOf(item) === 'string') {
get(this, 'router').transitionTo(item);
} else {
const type = get(item, 'kind');
if (type === 'user') {
get(this, 'router').transitionTo('users.index', get(item, 'slug'));
} else if (type === 'group') {
get(this, 'router').transitionTo('groups.group.group-page.index', get(item, 'slug'));
} else {
get(this, 'router').transitionTo(`${type}.show`, get(item, 'slug'));
}
}
}
}