How to get the mentioned users from react draft-js-mention-plugin? - draftjs

I gone through the documentation of draft-js-mention-plugin but couldn't figure a way to read all the mentions from the content. Is there a way can find all the mentions as array?. I need to store all the mentions seperately and send email.Your help is highly appreciated. I am using the example given in here

You can do like below :
const rawEditorContent = convertToRaw(this.state.editorState.getCurrentContent());
const entityMap = rawEditorContent.entityMap;
enter code here
Then loop through entityMap to get mentioned users:
Object.values(entityMap).map(entity => {
console.log(entity.data.mention);
});

Related

How to get access to Developer: Inspect TM Scopes data? [duplicate]

I have used the tokenizer in monaco but I do not see that it is accessible in vscode. This would be helpful for completion/signature help providers, how can I tokenize a grammar?
It doesn't seem like there's an official way of doing this right now. There is an open feature request for adding the ability to retrieve tmLanguage scopes at a position here: #580
There is one potential workaround, which requires adding a dependency to the scope-info extension. This extension exposes an API of its own that other extension can use. Here's a code example posted by the author in the linked issue:
import * as api from 'scope-info'
async function example(doc : vscode.TextDocument, pos: vscode.Position) {
const siExt = vscode.extensions.getExtension<api.ScopeInfoAPI>('siegebell.scope-info');
const si = await siExt.activate();
const t1 : api.Token = si.getScopeAt(doc, pos);
}
Update: unfortunately, it looks like scope-info is no longer compatible with current VSCode versions.

why using var {google} instead of var google in google.auth.OAuth

This code is from oauth nodesjs.
I want to ask why we are using '{}' around the var google? I also tried using it without '{}' and got error OAuth2 is undefined. i can't understand what is happening here.
var {google} = require('googleapis');
var OAuth2 = google.auth.OAuth2;
To add a little to this answer - this is what's called a destructuring assignment. You can read about them here:
http://2ality.com/2015/01/es6-destructuring.html
The code you're looking at here:
const {google} = require('googleapis');
Is the same as code that looks like this:
const google = require('googleapis').google;
This is just a convenient shorthand that was added in es6. We made the change in the googleapis package when we moved towards ES modules, which don't play nicely with the export=foo style syntax. Hope this helps!
According to the Changelog from google-api-nodejs-client, there are some changes from V26.0.0 onwards that you have to implement in your code, precisely the issue you are experiencing is mentioned. I also took a while to figure this one out...
BREAKING CHANGE: This library is now optimized for es6 modules. In previous versions you would import the library like this:
const google = require('googleapis');
In this and future versions, you must use a named import:
const {google} = require('googleapis');
You may also reference the type to instantiate a new instance:
const {GoogleApis} = require('googleapis');
const google = new GoogleApis();

How to tokenize grammars, like in monaco.editor.tokenize for use in extension

I have used the tokenizer in monaco but I do not see that it is accessible in vscode. This would be helpful for completion/signature help providers, how can I tokenize a grammar?
It doesn't seem like there's an official way of doing this right now. There is an open feature request for adding the ability to retrieve tmLanguage scopes at a position here: #580
There is one potential workaround, which requires adding a dependency to the scope-info extension. This extension exposes an API of its own that other extension can use. Here's a code example posted by the author in the linked issue:
import * as api from 'scope-info'
async function example(doc : vscode.TextDocument, pos: vscode.Position) {
const siExt = vscode.extensions.getExtension<api.ScopeInfoAPI>('siegebell.scope-info');
const si = await siExt.activate();
const t1 : api.Token = si.getScopeAt(doc, pos);
}
Update: unfortunately, it looks like scope-info is no longer compatible with current VSCode versions.

How to retrieve youtube comments from a specific video using Eclipse

I have set up everything according from the guide here : https://developers.google.com/gdata/articles/eclipse
From there on, how do I start to retrieve the comments?
I'm sort of a beginner so it would be great if anyone could provide some codes to start off.
Firstly, you should download libraries and install required libraries shown in the page your link has.
To get comments from a youtube video you should send this URL : http://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments
YouTubeService service = new YouTubeService(
YOUR_CLIENT_ID);
String url="http://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments";
VideoEntry videoEntry = service.getEntry(new URL(url),
VideoEntry.class);
String commentUrl = videoEntry.getComments().getFeedLink().getHref();
CommentFeed commentFeed = service.getFeed(new URL(commentUrl),
CommentFeed.class);
for (CommentEntry comment : commentFeed.getEntries()) {
System.out.println(comment.getPlainTextContent());
}
You can get last 25 comments via this code. If you want to get more than 25 comments, you should read about pagination, max-results, start-index parameters.

How to remove an Embed Document from an Embed Document?

I'm currently working on a project with Symfony 2 and MongoDB and I'm facing a problem while removing an Embed Document using is ID.
I'm working with Activities. An Activity embed a list of Comment and list of Vote.
A Comment can embed a list of Vote too.
To remove a Comment or a Vote from an Activity I do stuff like that :
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$activity = $dm->getRepository('SocialNetworkActivityBundle:Activity')
->findOneBy(array("votes.id" => $voteId));
$votes = $activity->getVotes();
$targetVote = null;
foreach ($votes as $vote)
if($vote->getId() == $voteId) {
$targetVote = $vote;
break;
}
$activity->removeVote($vote);
$dm->flush();
First of all, I know that the method I use isn't the best so I'm looking for an alternative.
Second of all, I can't use that method to remove a Vote embed in a Comment embed in an Activity, so I'm looking for a way to do that.
I don't find any solution in Doctrine documentation or on Stack (or other forum).
If you have some clues or advises for me I'll be really glad to read about :D