How to use the twitter-text.extractMentions function in twitter-text

To help you get started, we’ve selected a few twitter-text examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wejs / we-core / api / controllers / PostController.js View on Github external
// validation error is encountered, w/ validation info.
        if (err) return res.negotiate(err);


        // Because this should only update a single record and update
        // returns an array, just use the first item.  If more than one
        // record was returned, something is amiss.
        if (!records || !records.length || records.length > 1) {
          req._sails.log.warn(
          util.format('Unexpected output from `%s.update`.', Model.globalId)
          );
        }

        var updatedRecord = records[0];

        var mentions = twitter.extractMentions(values.body);
        // update post mentions
        Mention.updateModelMentions(req.user, 'body', mentions, 'post', pk, function(err, mentionedUsers) {
          if (err) {
            sails.log.error('Error on updateModelMentions', err);
            return res.serverError();
          }

          updatedRecord.mentions = mentionedUsers;

          // If we have the pubsub hook, use the Model's publish method
          // to notify all subscribers about the update.
          if (req._sails.hooks.pubsub) {
            if ( updatedRecord.creator ) {
              // send the change to others user connected devices
              sails.io.sockets.in('follow_user_' + updatedRecord.creator).emit(
                'post', {
github wejs / we-core / api / controllers / PostController.js View on Github external
.exec(function found(err, newInstance) {

        if (err) return res.serverError(err);
        if (!newInstance) return res.notFound();

        var mentions = twitter.extractMentions(newInstance.body);
        // update post mentions
        Mention.updateModelMentions(req.user, 'body', mentions, 'post', newInstance.id, function(err, mentionedUsers) {
          if (err) {
            sails.log.error('post:create:Error on updateModelMentions', err);
            return res.serverError();
          }

          newInstance.mentions = mentionedUsers;

          // If we have the pubsub hook, use the model class's publish method
          // to notify all subscribers about the created item
          if (req._sails.hooks.pubsub) {
            if (req.isSocket) {
              Model.subscribe(req, newInstance);
              Model.introduce(newInstance);
            }
github sokcuri / Kureha / app / tweet.js View on Github external
id: tweet.retweeted_status.id_str,
          timestamp: new Date(Date.parse(tweet.retweeted_status.created_at)).getTime(),
          isFavorited: tweet.retweeted_status.favorited,
          favoriteCount: tweet.retweeted_status.favorite_count,
          isRetweeted: tweet.retweeted_status.retweeted,
          retweetCount: tweet.retweeted_status.retweet_count
        };

      a.className = 'tweet_wrapper';

      a.setAttribute('data-tweet-id', tweet.id_str);
      a.setAttribute('data-tweet-timestamp', tweet.timestamp_ms);

      var mentioned_me = false;
      if (!tweet.retweeted_status)
        for (var name of Twitter_text.extractMentions(tweet.text))
          if (name == App.screen_name) mentioned_me = true;
      if (mentioned_me) className += ' tweet_emp blue';

      // retweeted / favorited
      var retweeted = '';
      var favorited = '';
      if (tweet.favorited)
        favorited = 'favorited';
      if (tweet.retweeted || tweet.retweeted_status && tweet.user.id_str == App.id_str)
        retweeted = 'retweeted';

      var id_str_org = tweet.id_str;

      var div = document.createElement('div');
      div.className = className;
github DefinitelyTyped / DefinitelyTyped / twitter-text / twitter-text-tests.ts View on Github external
const len: number = twitter.getTweetLength(text);

const linked: string = twitter.autoLink("link @user, and expand url... http://t.co/0JG5Mcq", {
    urlEntities: [
        {
            url: "http://t.co/0JG5Mcq",
            display_url: "blog.twitter.com/2011/05/twitte…",
            expanded_url: "http://blog.twitter.com/2011/05/twitter-for-mac-update.html",
            indices: [
                30,
                48
            ]
        }
    ]});

const usernames: string[] = twitter.extractMentions("Mentioning @twitter and @jack");
github DefinitelyTyped / DefinitelyTyped / types / twitter-text / twitter-text-tests.ts View on Github external
const len: number = twitter.getTweetLength(text);

const linked: string = twitter.autoLink("link @user, and expand url... http://t.co/0JG5Mcq", {
    urlEntities: [
        {
            url: "http://t.co/0JG5Mcq",
            display_url: "blog.twitter.com/2011/05/twitte…",
            expanded_url: "http://blog.twitter.com/2011/05/twitter-for-mac-update.html",
            indices: [
                30,
                48
            ]
        }
    ]});

const usernames: string[] = twitter.extractMentions("Mentioning @twitter and @jack");
github GetStream / react-activity-feed / src / utils.js View on Github external
.map((word, i) => {
      if (onClickMention && word.includes('@')) {
        const mention = twitter.extractMentions(word);
        if (!mention.length) return word;

        return (
          
            {!word.startsWith(`@${mention[0]}`) &&
              word.slice(0, word.indexOf(mention[0]) - 1)}
            <a> onClickMention &amp;&amp; onClickMention(mention[0])}
              className={`${parentClass}__mention`}
            &gt;
              @{mention[0]}
            </a>
            {!word.endsWith(mention[0]) &amp;&amp;
              word.slice(word.indexOf(mention[0]) + mention[0].length)}
          
        );
github mozillach / gh-projects-content-queue / lib / twitter-account.js View on Github external
async tweet(content, media = '', inReplyTo = null) {
        if(TwitterAccount.tweetTooLong(content)) {
            return Promise.reject("Tweet content too long");
        }

        const args = {
            status: content
        };

        if(inReplyTo) {
            const tweetId = TwitterAccount.getTweetIDFromURL(inReplyTo);
            if(tweetId) {
                args.in_reply_to_status_id = tweetId;
                const recipient = TwitterAccount.getUserFromURL(inReplyTo);
                const mentions = twitter.extractMentions(content).map((m) => m.toLowerCase());
                if(!mentions.length || !mentions.includes(recipient.toLowerCase())) {
                    args.auto_populate_reply_metadata = "true";
                }
            }
        }
        if(media.length) {
            args.media_ids = media;
        }
        await this.ready;

        const [
            res,
            username
        ] = await Promise.all([
            this._twitterClient.post('statuses/update', args),
            this.getUsername()