mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-07 16:45:11 -04:00
Changed the chat service from a timer tick from the gui to a service tick.
Created a new notifier for new chat available - NOTIFY_LIST_CHAT. Removed the QTimer in PeersDialog and connect the signal. Created news feed for public chat (prework of defnax, need still some gui changes) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3413 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
c7c6f6d36a
commit
b6b5fa5cd6
18 changed files with 832 additions and 175 deletions
|
@ -227,6 +227,7 @@ const int NOTIFY_LIST_DIRLIST_LOCAL = 9;
|
|||
const int NOTIFY_LIST_DIRLIST_FRIENDS = 10;
|
||||
const int NOTIFY_LIST_FORUMLIST_LOCKED = 11; // use connect with Qt::QueuedConnection
|
||||
const int NOTIFY_LIST_MESSAGE_TAGS = 12;
|
||||
const int NOTIFY_LIST_CHAT = 13;
|
||||
|
||||
const int NOTIFY_TYPE_SAME = 0x01;
|
||||
const int NOTIFY_TYPE_MOD = 0x02; /* general purpose, check all */
|
||||
|
|
|
@ -127,7 +127,6 @@ class ChatInfo
|
|||
public:
|
||||
std::string rsid;
|
||||
unsigned int chatflags;
|
||||
std::string name;
|
||||
std::wstring msg;
|
||||
};
|
||||
|
||||
|
@ -175,9 +174,8 @@ virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0;
|
|||
|
||||
/****************************************/
|
||||
/* Chat */
|
||||
virtual bool chatAvailable() = 0;
|
||||
virtual bool ChatSend(ChatInfo &ci) = 0;
|
||||
virtual bool getNewChat(std::list<ChatInfo> &chats) = 0;
|
||||
virtual bool ChatSend(ChatInfo &ci) = 0;
|
||||
virtual bool getNewChat(std::list<ChatInfo> &chats) = 0;
|
||||
virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ;
|
||||
virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;
|
||||
|
||||
|
|
|
@ -159,56 +159,9 @@ void p3Msgs::sendStatusString(const std::string& peer_id,const std::string& stat
|
|||
mChatSrv->sendStatusString(peer_id,status_string);
|
||||
}
|
||||
|
||||
bool p3Msgs::chatAvailable()
|
||||
{
|
||||
return mChatSrv->receivedItems();
|
||||
}
|
||||
|
||||
bool p3Msgs::getNewChat(std::list<ChatInfo> &chats)
|
||||
{
|
||||
/* get any messages and push them to iface */
|
||||
|
||||
// get the items from the list.
|
||||
std::list<RsChatMsgItem *> clist = mChatSrv -> getChatQueue();
|
||||
if (clist.size() < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<RsChatMsgItem *>::iterator it;
|
||||
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.
|
||||
*/
|
||||
|
||||
void p3Msgs::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i)
|
||||
{
|
||||
i.rsid = c -> PeerId();
|
||||
i.name = rsPeers->getPeerName(c -> PeerId());
|
||||
i.chatflags = 0 ;
|
||||
i.msg = c -> message;
|
||||
|
||||
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
|
||||
{
|
||||
i.chatflags |= RS_CHAT_PRIVATE;
|
||||
//std::cerr << "RsServer::initRsChatInfo() Chat Private!!!";
|
||||
}
|
||||
else
|
||||
{
|
||||
i.chatflags |= RS_CHAT_PUBLIC;
|
||||
//std::cerr << "RsServer::initRsChatInfo() Chat Public!!!";
|
||||
}
|
||||
return mChatSrv->getChatQueue(chats);
|
||||
}
|
||||
|
||||
void p3Msgs::getOwnAvatarData(unsigned char *& data,int& size)
|
||||
|
|
|
@ -107,9 +107,9 @@ class p3Msgs: public RsMsgs
|
|||
/****************************************/
|
||||
/* Chat */
|
||||
/*!
|
||||
* @return whether chat is available
|
||||
* sends chat (public and private)
|
||||
* @param ci chat info
|
||||
*/
|
||||
virtual bool chatAvailable();
|
||||
virtual bool ChatSend(ChatInfo &ci);
|
||||
|
||||
/*!
|
||||
|
@ -135,8 +135,6 @@ class p3Msgs: public RsMsgs
|
|||
|
||||
private:
|
||||
|
||||
void initRsChatInfo(RsChatMsgItem *c, ChatInfo &i);
|
||||
|
||||
p3MsgService *mMsgSrv;
|
||||
p3ChatService *mChatSrv;
|
||||
};
|
||||
|
|
|
@ -52,6 +52,10 @@ p3ChatService::p3ChatService(p3ConnectMgr *cm)
|
|||
|
||||
int p3ChatService::tick()
|
||||
{
|
||||
if (receivedItems()) {
|
||||
receiveChatQueue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -277,24 +281,24 @@ int p3ChatService::sendPrivateChat( std::wstring msg, std::string id)
|
|||
return 1;
|
||||
}
|
||||
|
||||
std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
||||
void p3ChatService::receiveChatQueue()
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
RsItem *item ;
|
||||
std::list<RsChatMsgItem *> ilist;
|
||||
|
||||
|
||||
while(NULL != (item=recvItem()))
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::getChatQueue() Item:" << (void*)item << std::endl ;
|
||||
std::cerr << "p3ChatService::receiveChatQueue() Item:" << (void*)item << std::endl ;
|
||||
#endif
|
||||
RsChatMsgItem *ci = dynamic_cast<RsChatMsgItem*>(item) ;
|
||||
|
||||
if(ci != NULL) // real chat message
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::getChatQueue() Item:";
|
||||
std::cerr << "p3ChatService::receiveChatQueue() Item:";
|
||||
std::cerr << std::endl;
|
||||
ci->print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
|
@ -318,9 +322,9 @@ std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
|||
|
||||
std::map<std::string,AvatarInfo *>::const_iterator it = _avatars.find(ci->PeerId()) ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3chatservice:: avatar requested from above. " << std::endl ;
|
||||
#endif
|
||||
#endif
|
||||
// has avatar. Return it strait away.
|
||||
//
|
||||
if(it!=_avatars.end() && it->second->_peer_is_new)
|
||||
|
@ -329,9 +333,22 @@ std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
|||
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||
}
|
||||
|
||||
ci->recvTime = now;
|
||||
ilist.push_back(ci); // don't delete the item !!
|
||||
if ((ci->chatFlags & RS_CHAT_FLAG_PRIVATE) == 0) {
|
||||
std::string message;
|
||||
message.assign(ci->message.begin(), ci->message.end());
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAT_NEW, ci->PeerId(), message, "");
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
ci->recvTime = now;
|
||||
ilist.push_back(ci); // don't delete the item !!
|
||||
} /* UNLOCK */
|
||||
|
||||
changed = true;
|
||||
}
|
||||
|
||||
continue ;
|
||||
}
|
||||
|
||||
|
@ -385,7 +402,54 @@ std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
|||
}
|
||||
}
|
||||
|
||||
return ilist;
|
||||
if (changed) {
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHAT, NOTIFY_TYPE_ADD);
|
||||
}
|
||||
}
|
||||
|
||||
bool p3ChatService::getChatQueue(std::list<ChatInfo> &chats)
|
||||
{
|
||||
/* get any messages and push them to iface */
|
||||
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
// get the items from the list.
|
||||
if (ilist.size() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<RsChatMsgItem *>::iterator it;
|
||||
while (ilist.size())
|
||||
{
|
||||
RsChatMsgItem *c = ilist.front();
|
||||
ilist.pop_front();
|
||||
|
||||
ChatInfo ci;
|
||||
initRsChatInfo(c, ci);
|
||||
chats.push_back(ci);
|
||||
|
||||
delete c;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void p3ChatService::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i)
|
||||
{
|
||||
i.rsid = c -> PeerId();
|
||||
i.chatflags = 0 ;
|
||||
i.msg = c -> message;
|
||||
|
||||
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
|
||||
{
|
||||
i.chatflags |= RS_CHAT_PRIVATE;
|
||||
//std::cerr << "RsServer::initRsChatInfo() Chat Private!!!";
|
||||
}
|
||||
else
|
||||
{
|
||||
i.chatflags |= RS_CHAT_PUBLIC;
|
||||
//std::cerr << "RsServer::initRsChatInfo() Chat Public!!!";
|
||||
}
|
||||
}
|
||||
|
||||
void p3ChatService::setOwnCustomStateString(const std::string& s)
|
||||
|
|
|
@ -27,15 +27,13 @@
|
|||
#ifndef SERVICE_CHAT_HEADER
|
||||
#define SERVICE_CHAT_HEADER
|
||||
|
||||
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "serialiser/rsmsgitems.h"
|
||||
#include "services/p3service.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
#include "retroshare/rsmsgs.h"
|
||||
|
||||
//!The basic Chat service.
|
||||
/**
|
||||
|
@ -50,6 +48,13 @@ class p3ChatService: public p3Service, public p3Config
|
|||
p3ChatService(p3ConnectMgr *cm);
|
||||
|
||||
/* overloaded */
|
||||
/*!
|
||||
* This retrieves all chat msg items and also (important!)
|
||||
* processes chat-status items that are in service item queue. chat msg item requests are also processed and not returned
|
||||
* (important! also) notifications sent to notify base on receipt avatar, immediate status and custom status
|
||||
* : notifyCustomState, notifyChatStatus, notifyPeerHasNewAvatar
|
||||
* @see NotifyBase
|
||||
*/
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
|
@ -112,13 +117,9 @@ class p3ChatService: public p3Service, public p3Config
|
|||
|
||||
|
||||
/*!
|
||||
* This retrieves all chat msg items and also (important!)
|
||||
* processes chat-status items that are in service item queue. chat msg item requests are also processed and not returned
|
||||
* (important! also) notifications sent to notify base on receipt avatar, immediate status and custom status
|
||||
* : notifyCustomState, notifyChatStatus, notifyPeerHasNewAvatar
|
||||
* @see NotifyBase
|
||||
* This retrieves all chat msg items
|
||||
*/
|
||||
std::list<RsChatMsgItem *> getChatQueue();
|
||||
bool getChatQueue(std::list<ChatInfo> &chats);
|
||||
|
||||
/************* from p3Config *******************/
|
||||
virtual RsSerialiser *setupSerialiser() ;
|
||||
|
@ -135,6 +136,12 @@ class p3ChatService: public p3Service, public p3Config
|
|||
class AvatarInfo ;
|
||||
class StateStringInfo ;
|
||||
|
||||
// Receive chat queue
|
||||
void receiveChatQueue();
|
||||
|
||||
void initRsChatInfo(RsChatMsgItem *c, ChatInfo &i);
|
||||
|
||||
|
||||
/// Send avatar info to peer in jpeg format.
|
||||
void sendAvatarJpegData(const std::string& peer_id) ;
|
||||
|
||||
|
@ -156,6 +163,8 @@ class p3ChatService: public p3Service, public p3Config
|
|||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
|
||||
std::list<RsChatMsgItem *> ilist;
|
||||
|
||||
AvatarInfo *_own_avatar ;
|
||||
std::map<std::string,AvatarInfo *> _avatars ;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue