The first time Rep. Nancy Pelosi served as House speaker in 2007, she had to tamp down occasional skirmishes between her moderate and liberal factions. Now in her second time as speaker more than a decade later, Pelosi is struggling to rein in intraparty fights that have expanded to Twitter.

The California Democrat, who turned 79 in March, is contending with the headaches of running a 235-member caucus that communicates not only in the hallways of Congress but in public on social media.

The new dynamic is a double-edged sword. It allows immediate messaging to millions of followers (and voters). Pelosi herself has 2.7 million Twitter followers and uses the platform regularly to promote the Democratic agenda.

But there’s a downside. It makes it much more difficult for Pelosi to keep a lid on fights within the party and to keep differences private within the caucus.

In a closed-door meeting last week, Pelosi urged Democrats to show more civility to one another, particularly in public, even when they disagree on key issues.

She ended her speech with a warning: Don’t attack each other on social media.

"You got a complaint? You come and talk to me about it,” Pelosi said. “But do not tweet about our members and expect us to think that that is just OK."

The Twitter war among Democrats exploded in late June when House Democrats were backed into voting on a $4.6 billion border funding bill approved by both Republicans and Democrats in the Senate.

House liberals wanted a bill with far more stringent safeguards for illegal immigrant children picked up along the border, but that bill had no chance of clearing the Senate or gaining President Trump’s signature.

Pelosi, in a move to protect her moderate faction, brought the Senate bill to the floor over liberals' objections. It passed with bipartisan support.

The party feud ahead of the vote spilled onto Twitter, with liberal Mark Pocan, a Democratic congressman from Wisconsin, accusing Democrats on the moderate Problem Solvers Caucus of not caring about illegal immigrants, and worse.

“Since when did the Problem Solvers Caucus become the Child Abuse Caucus?” Pocan said. “Wouldn't they want to at least fight against contractors who run deplorable facilities? Kids are the only ones who could lose today.”

The fight, which escalated on social media in the following weeks, had been simmering for months. Pelosi has made a string of comments this year dismissing the social media prowess of a small group of freshman liberal stars, such as Rep. Alexandria Ocasio-Cortez.

The New York Democrat famously unseated moderate Joe Crowley from his 14th District seat in the Democratic primary and is a social media phenomenon with 4.7 million Twitter followers and 3.8 million followers on Instagram.

Democratic lawmakers admire her social media skills. She held a training session this year to teach less-savvy members how to use the platform more effectively.

But her Twitter celebrity has caused tensions with some lawmakers because Ocasio-Cortez and others in the party have used the platform to push an ultra-left-wing agenda that not every Democrat can support.

“While there are people who have a large number of Twitter followers, what’s important is that we have large numbers of votes on the floor of the House,” Pelosi told USA Today in April.

During the border funding fight, Ocasio-Cortez’s chief of staff, Saikat Chakrabarti, took to Twitter to criticize moderates.

“They certainly seem hell bent to do to black and brown people today what the old Southern Democrats did in the 40s,” Chakrabarti tweeted.

A week later, he attacked Pelosi following media interviews in which she appeared again dismissive of Ocasio-Cortez. Pelosi told the New York Times that Ocasio-Cortez and her “squad” of ultra-left-wing fellow freshmen couldn’t get anyone to back their efforts to block a House version of the border funding bill.

Pelosi was referring to three other freshman Democrats, Reps. Ayanna Pressley of Massachusetts, Rashida Tlaib of Michigan, and Ilhan Omar of Minnesota, who voted against the House bill. All three are ultraliberal and active on social media. They opposed any border funding, arguing it could be used to deport illegal immigrants.

Chakrabarti fired back on Twitter.

“All these articles want to claim what a legislative mastermind Pelosi is, but I'm seeing way more strategic smarts from freshman members like @AOC, @IlhanMN, @RashidaTlaib and @AyannaPressley. Pelosi is just mad that she got outmaneuvered (again) by Republicans,” Chakrabarti tweeted on July 6.

Pelosi told reporters last week that Democratic lawmakers are unhappy about Chakrabarti’s social media commentary, which she referred to as “an offensive tweet that came out of one office.”

Rep. Pramila Jayapal, a Washington Democrat, who describes herself as a progressive activist, said that lawmakers are grappling with how to reconcile the old way of conducting politics with the emergence of social media, but that Ocasio-Cortez and other young liberals should not be ignored.

“They are on the vanguard of people who are really reengaging a whole part of democracy that felt hopeless before,” Jayapal said. “To dismiss any members’ force, and particularly these four members who do have a tremendous following in the progressive base, is not the best for us.”