mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 16:39:29 -05:00
Extract getPlainText method
This commit is contained in:
parent
ebd5da5e83
commit
b8c3c89ae0
@ -294,13 +294,54 @@ void ChatHandler::tick()
|
||||
|
||||
// remove html tags from chat message
|
||||
// extract links form href
|
||||
const std::string& in = msg.msg;
|
||||
std::string out;
|
||||
getPlainText(msg.msg, m.msg, m.links);
|
||||
m.recv_time = msg.recvTime;
|
||||
m.send_time = msg.sendTime;
|
||||
|
||||
m.id = RSRandom::random_u32();
|
||||
|
||||
mMsgs[msg.chat_id].push_back(m);
|
||||
done.push_back(lit);
|
||||
|
||||
changed = true;
|
||||
}
|
||||
for(std::vector<std::list<ChatMessage>::iterator>::iterator vit = done.begin(); vit != done.end(); ++vit)
|
||||
mRawMsgs.erase(*vit);
|
||||
|
||||
// send changes
|
||||
|
||||
if(changed)
|
||||
{
|
||||
mStateTokenServer->replaceToken(mMsgStateToken);
|
||||
mStateTokenServer->replaceToken(mUnreadMsgsStateToken);
|
||||
}
|
||||
|
||||
for(std::vector<RsPeerId>::iterator vit = peers_changed.begin(); vit != peers_changed.end(); ++vit)
|
||||
{
|
||||
const std::list<Msg>& msgs = mMsgs[ChatId(*vit)];
|
||||
uint32_t count = 0;
|
||||
for(std::list<Msg>::const_iterator lit = msgs.begin(); lit != msgs.end(); ++lit)
|
||||
if(!lit->read)
|
||||
count++;
|
||||
if(mUnreadMsgNotify)
|
||||
mUnreadMsgNotify->notifyUnreadMsgCountChanged(*vit, count);
|
||||
}
|
||||
|
||||
std::sort(lobbies.begin(), lobbies.end(), &compare_lobby_id);
|
||||
if(lobby_unread_count_changed || mLobbies != lobbies)
|
||||
{
|
||||
mStateTokenServer->replaceToken(mLobbiesStateToken);
|
||||
mLobbies = lobbies;
|
||||
}
|
||||
}
|
||||
|
||||
void ChatHandler::getPlainText(const std::string& in, std::string &out, std::vector<Triple> &links)
|
||||
{
|
||||
bool ignore = false;
|
||||
|
||||
bool keep_link = false;
|
||||
std::string last_six_chars;
|
||||
Triple current_link;
|
||||
std::vector<Triple> links;
|
||||
for(unsigned int i = 0; i < in.size(); ++i)
|
||||
{
|
||||
if(keep_link && in[i] == '"')
|
||||
@ -348,46 +389,6 @@ void ChatHandler::tick()
|
||||
current_link = Triple();
|
||||
}
|
||||
}
|
||||
m.msg = out;
|
||||
m.links = links;
|
||||
m.recv_time = msg.recvTime;
|
||||
m.send_time = msg.sendTime;
|
||||
|
||||
m.id = RSRandom::random_u32();
|
||||
|
||||
mMsgs[msg.chat_id].push_back(m);
|
||||
done.push_back(lit);
|
||||
|
||||
changed = true;
|
||||
}
|
||||
for(std::vector<std::list<ChatMessage>::iterator>::iterator vit = done.begin(); vit != done.end(); ++vit)
|
||||
mRawMsgs.erase(*vit);
|
||||
|
||||
// send changes
|
||||
|
||||
if(changed)
|
||||
{
|
||||
mStateTokenServer->replaceToken(mMsgStateToken);
|
||||
mStateTokenServer->replaceToken(mUnreadMsgsStateToken);
|
||||
}
|
||||
|
||||
for(std::vector<RsPeerId>::iterator vit = peers_changed.begin(); vit != peers_changed.end(); ++vit)
|
||||
{
|
||||
const std::list<Msg>& msgs = mMsgs[ChatId(*vit)];
|
||||
uint32_t count = 0;
|
||||
for(std::list<Msg>::const_iterator lit = msgs.begin(); lit != msgs.end(); ++lit)
|
||||
if(!lit->read)
|
||||
count++;
|
||||
if(mUnreadMsgNotify)
|
||||
mUnreadMsgNotify->notifyUnreadMsgCountChanged(*vit, count);
|
||||
}
|
||||
|
||||
std::sort(lobbies.begin(), lobbies.end(), &compare_lobby_id);
|
||||
if(lobby_unread_count_changed || mLobbies != lobbies)
|
||||
{
|
||||
mStateTokenServer->replaceToken(mLobbiesStateToken);
|
||||
mLobbies = lobbies;
|
||||
}
|
||||
}
|
||||
|
||||
void ChatHandler::handleWildcard(Request &req, Response &resp)
|
||||
|
@ -102,6 +102,8 @@ private:
|
||||
void handleSendStatus(Request& req, Response& resp);
|
||||
void handleUnreadMsgs(Request& req, Response& resp);
|
||||
|
||||
void getPlainText(const std::string& in, std::string &out, std::vector<Triple> &links);
|
||||
|
||||
StateTokenServer* mStateTokenServer;
|
||||
RsNotify* mNotify;
|
||||
RsMsgs* mRsMsgs;
|
||||
|
Loading…
Reference in New Issue
Block a user