2008-02-04 12:55:13 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* "$Id: p3face-msgs.cc,v 1.7 2007-05-05 16:10:06 rmf24 Exp $"
|
|
|
|
*
|
|
|
|
* RetroShare C++ Interface.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2006 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
2008-07-10 12:29:18 -04:00
|
|
|
#include "util/rsdir.h"
|
|
|
|
#include "util/rsdebug.h"
|
2008-02-04 12:55:13 -05:00
|
|
|
const int p3facemsgzone = 11453;
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2008-06-24 00:22:42 -04:00
|
|
|
#include "rsiface/rstypes.h"
|
2008-02-04 12:55:13 -05:00
|
|
|
#include "rsserver/p3msgs.h"
|
|
|
|
|
2008-06-24 00:22:42 -04:00
|
|
|
#include "services/p3msgservice.h"
|
|
|
|
#include "services/p3chatservice.h"
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
#include "pqi/authgpg.h"
|
2010-01-13 15:56:55 -05:00
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
/* external reference point */
|
|
|
|
RsMsgs *rsMsgs = NULL;
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
/****************************************/
|
|
|
|
|
|
|
|
bool p3Msgs::getMessageSummaries(std::list<MsgInfoSummary> &msgList)
|
|
|
|
{
|
|
|
|
return mMsgSrv->getMessageSummaries(msgList);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool p3Msgs::getMessage(std::string mid, MessageInfo &msg)
|
|
|
|
{
|
|
|
|
return mMsgSrv->getMessage(mid, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
/****************************************/
|
|
|
|
/* Message Items */
|
|
|
|
bool p3Msgs::MessageSend(MessageInfo &info)
|
|
|
|
{
|
|
|
|
return mMsgSrv->MessageSend(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
/****************************************/
|
|
|
|
bool p3Msgs::MessageDelete(std::string mid)
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
//std::cerr << "p3Msgs::MessageDelete() ";
|
|
|
|
//std::cerr << "mid: " << mid << std::endl;
|
2008-02-04 12:55:13 -05:00
|
|
|
|
|
|
|
mMsgSrv -> removeMsgId(mid);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Msgs::MessageRead(std::string mid)
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
//std::cerr << "p3Msgs::MessageRead() ";
|
|
|
|
//std::cerr << "mid: " << mid << std::endl;
|
2008-02-04 12:55:13 -05:00
|
|
|
|
|
|
|
mMsgSrv -> markMsgIdRead(mid);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
/****************************************/
|
|
|
|
bool p3Msgs::ChatSend(ChatInfo &ci)
|
|
|
|
{
|
|
|
|
/* send a message to all for now */
|
|
|
|
if (ci.chatflags & RS_CHAT_PRIVATE)
|
|
|
|
{
|
|
|
|
mChatSrv -> sendPrivateChat(ci.msg, ci.rsid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* global */
|
|
|
|
mChatSrv -> sendChat(ci.msg);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
void p3Msgs::sendGroupChatStatusString(const std::string& status_string)
|
|
|
|
{
|
|
|
|
mChatSrv->sendGroupChatStatusString(status_string);
|
|
|
|
}
|
2009-05-05 09:18:53 -04:00
|
|
|
void p3Msgs::sendStatusString(const std::string& peer_id,const std::string& status_string)
|
|
|
|
{
|
|
|
|
mChatSrv->sendStatusString(peer_id,status_string);
|
|
|
|
}
|
|
|
|
|
2008-04-04 08:19:50 -04:00
|
|
|
bool p3Msgs::chatAvailable()
|
|
|
|
{
|
|
|
|
return mChatSrv->receivedItems();
|
|
|
|
}
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
bool p3Msgs::getNewChat(std::list<ChatInfo> &chats)
|
|
|
|
{
|
|
|
|
/* get any messages and push them to iface */
|
|
|
|
|
|
|
|
// get the items from the list.
|
2009-05-05 09:18:53 -04:00
|
|
|
std::list<RsChatMsgItem *> clist = mChatSrv -> getChatQueue();
|
2008-02-04 12:55:13 -05:00
|
|
|
if (clist.size() < 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-05 09:18:53 -04:00
|
|
|
std::list<RsChatMsgItem *>::iterator it;
|
2008-02-04 12:55:13 -05:00
|
|
|
for(it = clist.begin(); it != clist.end(); it++)
|
|
|
|
{
|
|
|
|
ChatInfo ci;
|
|
|
|
initRsChatInfo((*it), ci);
|
|
|
|
chats.push_back(ci);
|
|
|
|
delete (*it);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**** HELPER FNS For Chat/Msg/Channel Lists ************
|
|
|
|
*
|
|
|
|
* The iface->Mutex is required to be locked
|
|
|
|
* for intAddChannel / intAddChannelMsg.
|
|
|
|
*/
|
|
|
|
|
2009-05-05 09:18:53 -04:00
|
|
|
void p3Msgs::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i)
|
2008-02-04 12:55:13 -05:00
|
|
|
{
|
|
|
|
i.rsid = c -> PeerId();
|
2010-01-13 16:22:52 -05:00
|
|
|
i.name = rsPeers->getPeerName(c -> PeerId());
|
2009-01-30 14:52:47 -05:00
|
|
|
i.chatflags = 0 ;
|
2008-02-04 12:55:13 -05:00
|
|
|
i.msg = c -> message;
|
2009-01-30 14:52:47 -05:00
|
|
|
|
|
|
|
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
|
2008-02-04 12:55:13 -05:00
|
|
|
{
|
2009-01-30 14:52:47 -05:00
|
|
|
i.chatflags |= RS_CHAT_PRIVATE;
|
2008-07-10 12:29:18 -04:00
|
|
|
//std::cerr << "RsServer::initRsChatInfo() Chat Private!!!";
|
2008-02-04 12:55:13 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-30 14:52:47 -05:00
|
|
|
i.chatflags |= RS_CHAT_PUBLIC;
|
2008-07-10 12:29:18 -04:00
|
|
|
//std::cerr << "RsServer::initRsChatInfo() Chat Public!!!";
|
2008-02-04 12:55:13 -05:00
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void p3Msgs::getOwnAvatarData(unsigned char *& data,int& size)
|
|
|
|
{
|
|
|
|
mChatSrv->getOwnAvatarJpegData(data,size) ;
|
2008-02-04 12:55:13 -05:00
|
|
|
}
|
|
|
|
|
2009-01-30 14:52:47 -05:00
|
|
|
void p3Msgs::setOwnAvatarData(const unsigned char *data,int size)
|
|
|
|
{
|
|
|
|
mChatSrv->setOwnAvatarJpegData(data,size) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void p3Msgs::getAvatarData(std::string pid,unsigned char *& data,int& size)
|
|
|
|
{
|
|
|
|
mChatSrv->getAvatarJpegData(pid,data,size) ;
|
|
|
|
}
|
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
std::string p3Msgs::getCustomStateString(const std::string& peer_id)
|
|
|
|
{
|
|
|
|
return mChatSrv->getCustomStateString(peer_id) ;
|
|
|
|
}
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
std::string p3Msgs::getCustomStateString()
|
|
|
|
{
|
2009-10-04 18:27:42 -04:00
|
|
|
return mChatSrv->getOwnCustomStateString() ;
|
2009-09-29 16:37:20 -04:00
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
void p3Msgs::setCustomStateString(const std::string& state_string)
|
|
|
|
{
|
2009-10-04 18:27:42 -04:00
|
|
|
mChatSrv->setOwnCustomStateString(state_string) ;
|
2009-09-29 16:37:20 -04:00
|
|
|
}
|
2009-10-04 18:27:42 -04:00
|
|
|
|