mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 22:55:04 -04:00
simplification of the chat interface to libretroshare using a single unified class for chat IDs. Used a common chat widget for all chats including broadcast. Opens the way to having plugins send/recv chat messages. Patch from Electron.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7800 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
535fe875e4
commit
13d7866171
53 changed files with 1180 additions and 2280 deletions
|
@ -293,7 +293,7 @@ void DistantChatService::removeVirtualPeer(const TurtleFileHash& hash,const Turt
|
|||
|
||||
if(tunnel_dn)
|
||||
{
|
||||
RsServer::notify()->notifyChatStatus(virtual_peer_id.toStdString(),"tunnel is down...",true) ;
|
||||
RsServer::notify()->notifyChatStatus(ChatId(RsGxsId(virtual_peer_id)),"tunnel is down...") ;
|
||||
RsServer::notify()->notifyPeerStatusChanged(virtual_peer_id.toStdString(),RS_STATUS_OFFLINE) ;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -896,7 +896,7 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId&
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool DistributedChatService::sendLobbyChat(const RsPeerId &id, const std::string& msg, const ChatLobbyId& lobby_id)
|
||||
bool DistributedChatService::sendLobbyChat(const ChatLobbyId& lobby_id, const std::string& msg)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Sending chat lobby message to lobby " << std::hex << lobby_id << std::dec << std::endl;
|
||||
|
@ -923,7 +923,17 @@ bool DistributedChatService::sendLobbyChat(const RsPeerId &id, const std::string
|
|||
|
||||
RsPeerId ownId = rsPeers->getOwnId();
|
||||
|
||||
mHistMgr->addMessage(false, id, ownId, &item);
|
||||
ChatMessage message;
|
||||
message.chatflags = 0;
|
||||
message.chat_id = ChatId(lobby_id);
|
||||
message.msg = msg;
|
||||
message.lobby_peer_nickname = item.nick;
|
||||
message.recvTime = item.recvTime;
|
||||
message.sendTime = item.sendTime;
|
||||
message.incoming = false;
|
||||
message.online = true;
|
||||
RsServer::notify()->notifyChatMessage(message);
|
||||
mHistMgr->addMessage(message);
|
||||
|
||||
bounceLobbyObject(&item, ownId) ;
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ class DistributedChatService
|
|||
bool locked_checkAndRebuildPartialLobbyMessage(RsChatLobbyMsgItem *) ;
|
||||
void checkSizeAndSendLobbyMessage(RsChatLobbyMsgItem *) ;
|
||||
|
||||
bool sendLobbyChat(const RsPeerId &id, const std::string&, const ChatLobbyId&) ;
|
||||
bool sendLobbyChat(const ChatLobbyId &lobby_id, const std::string&) ;
|
||||
bool handleRecvChatLobbyMsgItem(RsChatMsgItem *item) ;
|
||||
|
||||
private:
|
||||
|
|
|
@ -91,14 +91,9 @@ int p3ChatService::tick()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int p3ChatService::status()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/***************** Chat Stuff **********************/
|
||||
|
||||
int p3ChatService::sendPublicChat(const std::string &msg)
|
||||
void p3ChatService::sendPublicChat(const std::string &msg)
|
||||
{
|
||||
/* go through all the peers */
|
||||
|
||||
|
@ -133,12 +128,16 @@ int p3ChatService::sendPublicChat(const std::string &msg)
|
|||
#endif
|
||||
|
||||
if (*it == ownId) {
|
||||
mHistoryMgr->addMessage(false, RsPeerId(), ownId, ci);
|
||||
//mHistoryMgr->addMessage(false, RsPeerId(), ownId, ci);
|
||||
ChatMessage message;
|
||||
initChatMessage(ci, message);
|
||||
message.incoming = false;
|
||||
message.online = true;
|
||||
RsServer::notify()->notifyChatMessage(message);
|
||||
mHistoryMgr->addMessage(message);
|
||||
}
|
||||
sendItem(ci);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -212,25 +211,36 @@ void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
|
|||
}
|
||||
}
|
||||
|
||||
void p3ChatService::sendStatusString( const RsPeerId& id , const std::string& status_string)
|
||||
void p3ChatService::sendStatusString(const ChatId& id , const std::string& status_string)
|
||||
{
|
||||
ChatLobbyId lobby_id ;
|
||||
if(isLobbyId(id,lobby_id))
|
||||
sendLobbyStatusString(lobby_id,status_string) ;
|
||||
else
|
||||
if(id.isLobbyId())
|
||||
sendLobbyStatusString(id.toLobbyId(),status_string) ;
|
||||
else if(id.isBroadcast())
|
||||
sendGroupChatStatusString(status_string);
|
||||
else if(id.isPeerId() || id.isGxsId())
|
||||
{
|
||||
RsChatStatusItem *cs = new RsChatStatusItem ;
|
||||
|
||||
cs->status_string = status_string ;
|
||||
cs->flags = RS_CHAT_FLAG_PRIVATE ;
|
||||
cs->PeerId(id);
|
||||
RsPeerId vpid;
|
||||
if(id.isGxsId())
|
||||
vpid = RsPeerId(id.toGxsId());
|
||||
else
|
||||
vpid = id.toPeerId();
|
||||
cs->PeerId(vpid);
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "sending chat status packet:" << std::endl ;
|
||||
cs->print(std::cerr) ;
|
||||
#endif
|
||||
sendChatItem(cs);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3ChatService::sendStatusString() Error: chat id of this type is not handled, is it empty?" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void p3ChatService::sendChatItem(RsChatItem *item)
|
||||
|
@ -275,116 +285,134 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg)
|
|||
bool p3ChatService::isOnline(const RsPeerId& pid)
|
||||
{
|
||||
// check if the id is a tunnel id or a peer id.
|
||||
|
||||
uint32_t status ;
|
||||
|
||||
if(getDistantChatStatus(RsGxsId(pid),status))
|
||||
return status == RS_DISTANT_CHAT_STATUS_CAN_TALK ;
|
||||
else
|
||||
return mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid);
|
||||
else
|
||||
return mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid);
|
||||
}
|
||||
|
||||
bool p3ChatService::sendPrivateChat(const RsPeerId &id, const std::string &msg)
|
||||
bool p3ChatService::sendChat(ChatId destination, std::string msg)
|
||||
{
|
||||
// look into ID. Is it a peer, or a chat lobby?
|
||||
|
||||
ChatLobbyId lobby_id ;
|
||||
|
||||
if(isLobbyId(id,lobby_id))
|
||||
return sendLobbyChat(id,msg,lobby_id) ;
|
||||
|
||||
// make chat item....
|
||||
if(destination.isLobbyId())
|
||||
return DistributedChatService::sendLobbyChat(destination.toLobbyId(), msg);
|
||||
else if(destination.isBroadcast())
|
||||
{
|
||||
sendPublicChat(msg);
|
||||
return true;
|
||||
}
|
||||
else if(destination.isPeerId()==false && destination.isGxsId()==false)
|
||||
{
|
||||
std::cerr << "p3ChatService::sendChat() Error: chat id type not handled. Is it empty?" << std::endl;
|
||||
return false;
|
||||
}
|
||||
// destination is peer or distant
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sendPrivateChat()";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3ChatService::sendChat()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsChatMsgItem *ci = new RsChatMsgItem();
|
||||
RsPeerId vpid;
|
||||
if(destination.isGxsId())
|
||||
vpid = RsPeerId(destination.toGxsId()); // convert to virtual peer id
|
||||
else
|
||||
vpid = destination.toPeerId();
|
||||
|
||||
ci->PeerId(id);
|
||||
ci->chatFlags = RS_CHAT_FLAG_PRIVATE;
|
||||
ci->sendTime = time(NULL);
|
||||
ci->recvTime = ci->sendTime;
|
||||
ci->message = msg;
|
||||
RsChatMsgItem *ci = new RsChatMsgItem();
|
||||
ci->PeerId(vpid);
|
||||
ci->chatFlags = RS_CHAT_FLAG_PRIVATE;
|
||||
ci->sendTime = time(NULL);
|
||||
ci->recvTime = ci->sendTime;
|
||||
ci->message = msg;
|
||||
|
||||
if(!isOnline(id))
|
||||
{
|
||||
/* peer is offline, add to outgoing list */
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
privateOutgoingList.push_back(ci);
|
||||
}
|
||||
ChatMessage message;
|
||||
initChatMessage(ci, message);
|
||||
message.incoming = false;
|
||||
message.online = true;
|
||||
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_PRIVATE_OUTGOING_CHAT, NOTIFY_TYPE_ADD);
|
||||
if(!isOnline(vpid))
|
||||
{
|
||||
/* peer is offline, add to outgoing list */
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
privateOutgoingList.push_back(ci);
|
||||
}
|
||||
|
||||
IndicateConfigChanged();
|
||||
message.online = false;
|
||||
RsServer::notify()->notifyChatMessage(message);
|
||||
|
||||
return false;
|
||||
}
|
||||
// use the history to load pending messages to the gui
|
||||
// this is not very nice, because the user may think the message was send, while it is still in the queue
|
||||
mHistoryMgr->addMessage(message);
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
std::map<RsPeerId,AvatarInfo*>::iterator it = _avatars.find(id) ;
|
||||
IndicateConfigChanged();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(it == _avatars.end())
|
||||
{
|
||||
_avatars[id] = new AvatarInfo ;
|
||||
it = _avatars.find(id) ;
|
||||
}
|
||||
if(it->second->_own_is_new)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
std::map<RsPeerId,AvatarInfo*>::iterator it = _avatars.find(vpid) ;
|
||||
|
||||
if(it == _avatars.end())
|
||||
{
|
||||
_avatars[vpid] = new AvatarInfo ;
|
||||
it = _avatars.find(vpid) ;
|
||||
}
|
||||
if(it->second->_own_is_new)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sendPrivateChat: new avatar never sent to peer " << id << ". Setting <new> flag to packet." << std::endl;
|
||||
std::cerr << "p3ChatService::sendChat: new avatar never sent to peer " << id << ". Setting <new> flag to packet." << std::endl;
|
||||
#endif
|
||||
|
||||
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||
it->second->_own_is_new = false ;
|
||||
}
|
||||
}
|
||||
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||
it->second->_own_is_new = false ;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Sending msg to peer " << id << ", flags = " << ci->chatFlags << std::endl ;
|
||||
std::cerr << "p3ChatService::sendPrivateChat() Item:";
|
||||
std::cerr << std::endl;
|
||||
ci->print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Sending msg to (maybe virtual) peer " << id << ", flags = " << ci->chatFlags << std::endl ;
|
||||
std::cerr << "p3ChatService::sendChat() Item:";
|
||||
std::cerr << std::endl;
|
||||
ci->print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
mHistoryMgr->addMessage(false, id, mServiceCtrl->getOwnId(), ci);
|
||||
RsServer::notify()->notifyChatMessage(message);
|
||||
mHistoryMgr->addMessage(message);
|
||||
|
||||
checkSizeAndSendMessage(ci);
|
||||
|
||||
// Check if custom state string has changed, in which case it should be sent to the peer.
|
||||
bool should_send_state_string = false ;
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
// Check if custom state string has changed, in which case it should be sent to the peer.
|
||||
bool should_send_state_string = false ;
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<RsPeerId,StateStringInfo>::iterator it = _state_strings.find(id) ;
|
||||
std::map<RsPeerId,StateStringInfo>::iterator it = _state_strings.find(vpid) ;
|
||||
|
||||
if(it == _state_strings.end())
|
||||
{
|
||||
_state_strings[id] = StateStringInfo() ;
|
||||
it = _state_strings.find(id) ;
|
||||
it->second._own_is_new = true ;
|
||||
}
|
||||
if(it->second._own_is_new)
|
||||
{
|
||||
should_send_state_string = true ;
|
||||
it->second._own_is_new = false ;
|
||||
}
|
||||
}
|
||||
if(it == _state_strings.end())
|
||||
{
|
||||
_state_strings[vpid] = StateStringInfo() ;
|
||||
it = _state_strings.find(vpid) ;
|
||||
it->second._own_is_new = true ;
|
||||
}
|
||||
if(it->second._own_is_new)
|
||||
{
|
||||
should_send_state_string = true ;
|
||||
it->second._own_is_new = false ;
|
||||
}
|
||||
}
|
||||
|
||||
if(should_send_state_string)
|
||||
{
|
||||
if(should_send_state_string)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "own status string is new for peer " << id << ": sending it." << std::endl ;
|
||||
std::cerr << "own status string is new for peer " << id << ": sending it." << std::endl ;
|
||||
#endif
|
||||
RsChatStatusItem *cs = makeOwnCustomStateStringItem() ;
|
||||
cs->PeerId(id) ;
|
||||
sendChatItem(cs) ;
|
||||
}
|
||||
RsChatStatusItem *cs = makeOwnCustomStateStringItem() ;
|
||||
cs->PeerId(vpid) ;
|
||||
sendChatItem(cs) ;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3ChatService::locked_checkAndRebuildPartialMessage(RsChatMsgItem *ci)
|
||||
|
@ -636,12 +664,12 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci)
|
|||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
// This crap is because chat lobby messages use a different method for chunking messages using an additional
|
||||
// subpacket ID, and a list of lobbies. We cannot just collapse the two because it would make the normal chat
|
||||
// (and chat lobbies) not backward compatible.
|
||||
// This crap is because chat lobby messages use a different method for chunking messages using an additional
|
||||
// subpacket ID, and a list of lobbies. We cannot just collapse the two because it would make the normal chat
|
||||
// (and chat lobbies) not backward compatible.
|
||||
|
||||
if(!DistributedChatService::locked_checkAndRebuildPartialLobbyMessage(dynamic_cast<RsChatLobbyMsgItem*>(ci)))
|
||||
return true ;
|
||||
if(!DistributedChatService::locked_checkAndRebuildPartialLobbyMessage(dynamic_cast<RsChatLobbyMsgItem*>(ci)))
|
||||
return true ;
|
||||
|
||||
if(!locked_checkAndRebuildPartialMessage(ci))
|
||||
return true ;
|
||||
|
@ -706,6 +734,7 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci)
|
|||
std::string message = ci->message;
|
||||
|
||||
if(!(ci->chatFlags & RS_CHAT_FLAG_LOBBY))
|
||||
{
|
||||
if(ci->chatFlags & RS_CHAT_FLAG_PRIVATE)
|
||||
RsServer::notify()->AddPopupMessage(popupChatFlag, ci->PeerId().toStdString(), name, message); /* notify private chat message */
|
||||
else
|
||||
|
@ -714,46 +743,24 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci)
|
|||
RsServer::notify()->AddPopupMessage(RS_POPUP_GROUPCHAT, ci->PeerId().toStdString(), "", message);
|
||||
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_CHAT_NEW, ci->PeerId().toStdString(), message, "");
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
ci->recvTime = now;
|
||||
|
||||
if (ci->chatFlags & RS_CHAT_FLAG_PRIVATE) {
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Adding msg " << std::hex << (void*)ci << std::dec << " to private chat incoming list from " << ci->PeerId() << "." << std::endl;
|
||||
#endif
|
||||
privateChanged = true;
|
||||
locked_storeIncomingMsg(ci); // don't delete the item !!
|
||||
} else {
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Adding msg " << std::hex << (void*)ci << std::dec << " to public chat incoming list." << std::endl;
|
||||
#endif
|
||||
publicChanged = true;
|
||||
publicList.push_back(ci); // don't delete the item !!
|
||||
|
||||
if (ci->PeerId() != mServiceCtrl->getOwnId()) {
|
||||
/* not from loop back */
|
||||
mHistoryMgr->addMessage(true, RsPeerId(), ci->PeerId(), ci);
|
||||
}
|
||||
}
|
||||
} /* UNLOCK */
|
||||
|
||||
if (publicChanged)
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_PUBLIC_CHAT, NOTIFY_TYPE_ADD);
|
||||
|
||||
if (privateChanged)
|
||||
{
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD);
|
||||
IndicateConfigChanged(); // only private chat messages are saved
|
||||
}
|
||||
|
||||
ci->recvTime = now;
|
||||
|
||||
ChatMessage cm;
|
||||
initChatMessage(ci, cm);
|
||||
cm.incoming = true;
|
||||
cm.online = true;
|
||||
RsServer::notify()->notifyChatMessage(cm);
|
||||
mHistoryMgr->addMessage(cm);
|
||||
return true ;
|
||||
}
|
||||
|
||||
void p3ChatService::locked_storeIncomingMsg(RsChatMsgItem *item)
|
||||
{
|
||||
#ifdef REMOVE
|
||||
privateIncomingList.push_back(item) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
|
||||
|
@ -762,6 +769,8 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
|
|||
std::cerr << "Received status string \"" << cs->status_string << "\"" << std::endl ;
|
||||
#endif
|
||||
|
||||
uint32_t status;
|
||||
|
||||
if(cs->flags & RS_CHAT_FLAG_REQUEST_CUSTOM_STATE) // no state here just a request.
|
||||
sendCustomState(cs->PeerId()) ;
|
||||
else if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE) // Check if new custom string is available at peer's.
|
||||
|
@ -776,198 +785,52 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
|
|||
#endif
|
||||
sendCustomStateRequest(cs->PeerId()) ;
|
||||
}
|
||||
else if(DistantChatService::getDistantChatStatus(RsGxsId(cs->PeerId()), status))
|
||||
{
|
||||
RsServer::notify()->notifyChatStatus(ChatId(RsGxsId(cs->PeerId())), cs->status_string) ;
|
||||
}
|
||||
else if(cs->flags & RS_CHAT_FLAG_PRIVATE)
|
||||
{
|
||||
RsServer::notify()->notifyChatStatus(cs->PeerId().toStdString(),cs->status_string,true) ;
|
||||
RsServer::notify()->notifyChatStatus(ChatId(cs->PeerId()),cs->status_string) ;
|
||||
}
|
||||
else if(cs->flags & RS_CHAT_FLAG_PUBLIC)
|
||||
RsServer::notify()->notifyChatStatus(cs->PeerId().toStdString(),cs->status_string,false) ;
|
||||
{
|
||||
ChatId id = ChatId::makeBroadcastId();
|
||||
id.broadcast_status_peer_id = cs->PeerId();
|
||||
RsServer::notify()->notifyChatStatus(id, cs->status_string) ;
|
||||
}
|
||||
|
||||
DistantChatService::handleRecvChatStatusItem(cs) ;
|
||||
}
|
||||
|
||||
|
||||
int p3ChatService::getPublicChatQueueCount()
|
||||
void p3ChatService::initChatMessage(RsChatMsgItem *c, ChatMessage &m)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
m.chat_id = ChatId(c->PeerId());
|
||||
m.chatflags = 0;
|
||||
m.sendTime = c->sendTime;
|
||||
m.recvTime = c->recvTime;
|
||||
m.msg = c->message;
|
||||
|
||||
return publicList.size();
|
||||
}
|
||||
RsChatLobbyMsgItem *lobbyItem = dynamic_cast<RsChatLobbyMsgItem*>(c) ;
|
||||
if(lobbyItem != NULL)
|
||||
{
|
||||
m.lobby_peer_nickname = lobbyItem->nick;
|
||||
m.chat_id = ChatId(lobbyItem->lobby_id);
|
||||
return;
|
||||
}
|
||||
|
||||
bool p3ChatService::getPublicChatQueue(std::list<ChatInfo> &chats)
|
||||
{
|
||||
bool changed = false;
|
||||
uint32_t status;
|
||||
if(DistantChatService::getDistantChatStatus(RsGxsId(c->PeerId()), status))
|
||||
m.chat_id = ChatId(RsGxsId(c->PeerId()));
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
// get the items from the public list.
|
||||
if (publicList.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<RsChatMsgItem *>::iterator it;
|
||||
while (publicList.size()) {
|
||||
RsChatMsgItem *c = publicList.front();
|
||||
publicList.pop_front();
|
||||
|
||||
ChatInfo ci;
|
||||
initRsChatInfo(c, ci);
|
||||
chats.push_back(ci);
|
||||
|
||||
changed = true;
|
||||
|
||||
delete c;
|
||||
}
|
||||
} /* UNLOCKED */
|
||||
|
||||
if (changed) {
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_PUBLIC_CHAT, NOTIFY_TYPE_DEL);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int p3ChatService::getPrivateChatQueueCount(bool incoming)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (incoming) {
|
||||
return privateIncomingList.size();
|
||||
}
|
||||
|
||||
return privateOutgoingList.size();
|
||||
}
|
||||
|
||||
bool p3ChatService::getPrivateChatQueueIds(bool incoming, std::list<RsPeerId> &ids)
|
||||
{
|
||||
ids.clear();
|
||||
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::list<RsChatMsgItem *> *list;
|
||||
|
||||
if (incoming) {
|
||||
list = &privateIncomingList;
|
||||
} else {
|
||||
list = &privateOutgoingList;
|
||||
}
|
||||
|
||||
// get the items from the private list.
|
||||
if (list->size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<RsChatMsgItem *>::iterator it;
|
||||
for (it = list->begin(); it != list->end(); ++it) {
|
||||
RsChatMsgItem *c = *it;
|
||||
|
||||
if (std::find(ids.begin(), ids.end(), c->PeerId()) == ids.end()) {
|
||||
ids.push_back(c->PeerId());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3ChatService::getPrivateChatQueue(bool incoming, const RsPeerId &id, std::list<ChatInfo> &chats)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::list<RsChatMsgItem *> *list;
|
||||
|
||||
if (incoming) {
|
||||
list = &privateIncomingList;
|
||||
} else {
|
||||
list = &privateOutgoingList;
|
||||
}
|
||||
|
||||
// get the items from the private list.
|
||||
if (list->size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<RsChatMsgItem *>::iterator it;
|
||||
for (it = list->begin(); it != list->end(); ++it) {
|
||||
RsChatMsgItem *c = *it;
|
||||
|
||||
if (c->PeerId() == id) {
|
||||
ChatInfo ci;
|
||||
initRsChatInfo(c, ci);
|
||||
chats.push_back(ci);
|
||||
}
|
||||
}
|
||||
|
||||
return (chats.size() > 0);
|
||||
}
|
||||
|
||||
bool p3ChatService::clearPrivateChatQueue(bool incoming, const RsPeerId &id)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::list<RsChatMsgItem *> *list;
|
||||
|
||||
if (incoming) {
|
||||
list = &privateIncomingList;
|
||||
} else {
|
||||
list = &privateOutgoingList;
|
||||
}
|
||||
|
||||
// get the items from the private list.
|
||||
if (list->size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<RsChatMsgItem *>::iterator it = list->begin();
|
||||
while (it != list->end()) {
|
||||
RsChatMsgItem *c = *it;
|
||||
|
||||
if (c->PeerId() == id) {
|
||||
if (incoming) {
|
||||
mHistoryMgr->addMessage(true, c->PeerId(), c->PeerId(), c);
|
||||
}
|
||||
|
||||
delete c;
|
||||
changed = true;
|
||||
|
||||
it = list->erase(it);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
} /* UNLOCKED */
|
||||
|
||||
if (changed) {
|
||||
RsServer::notify()->notifyListChange(incoming ? NOTIFY_LIST_PRIVATE_INCOMING_CHAT : NOTIFY_LIST_PRIVATE_OUTGOING_CHAT, NOTIFY_TYPE_DEL);
|
||||
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void p3ChatService::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i)
|
||||
{
|
||||
i.rsid = c->PeerId();
|
||||
i.chatflags = 0;
|
||||
i.sendTime = c->sendTime;
|
||||
i.recvTime = c->recvTime;
|
||||
i.msg = c->message;
|
||||
|
||||
RsChatLobbyMsgItem *lobbyItem = dynamic_cast<RsChatLobbyMsgItem*>(c) ;
|
||||
|
||||
if(lobbyItem != NULL)
|
||||
i.peer_nickname = lobbyItem->nick;
|
||||
|
||||
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
|
||||
i.chatflags |= RS_CHAT_PRIVATE;
|
||||
else
|
||||
i.chatflags |= RS_CHAT_PUBLIC;
|
||||
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
|
||||
m.chatflags |= RS_CHAT_PRIVATE;
|
||||
else
|
||||
{
|
||||
m.chat_id = ChatId::makeBroadcastId();
|
||||
m.broadcast_peer_id = c->PeerId();
|
||||
m.chatflags |= RS_CHAT_PUBLIC;
|
||||
}
|
||||
}
|
||||
|
||||
void p3ChatService::setOwnCustomStateString(const std::string& s)
|
||||
|
@ -1353,19 +1216,8 @@ bool p3ChatService::saveList(bool& cleanup, std::list<RsItem*>& list)
|
|||
|
||||
list.push_back(di) ;
|
||||
|
||||
/* save incoming private chat messages */
|
||||
|
||||
std::list<RsChatMsgItem *>::iterator it;
|
||||
for (it = privateIncomingList.begin(); it != privateIncomingList.end(); it++) {
|
||||
RsPrivateChatMsgConfigItem *ci = new RsPrivateChatMsgConfigItem;
|
||||
|
||||
ci->set(*it, (*it)->PeerId(), RS_CHATMSG_CONFIGFLAG_INCOMING);
|
||||
|
||||
list.push_back(ci);
|
||||
}
|
||||
|
||||
/* save outgoing private chat messages */
|
||||
|
||||
std::list<RsChatMsgItem *>::iterator it;
|
||||
for (it = privateOutgoingList.begin(); it != privateOutgoingList.end(); it++) {
|
||||
RsPrivateChatMsgConfigItem *ci = new RsPrivateChatMsgConfigItem;
|
||||
|
||||
|
@ -1418,7 +1270,7 @@ void p3ChatService::statusChange(const std::list<pqiServicePeer> &plist)
|
|||
RsChatMsgItem *c = *cit;
|
||||
|
||||
if (c->PeerId() == it->id) {
|
||||
mHistoryMgr->addMessage(false, c->PeerId(), ownId, c);
|
||||
//mHistoryMgr->addMessage(false, c->PeerId(), ownId, c);
|
||||
|
||||
to_send.push_back(c) ;
|
||||
|
||||
|
@ -1434,7 +1286,15 @@ void p3ChatService::statusChange(const std::list<pqiServicePeer> &plist)
|
|||
} /* UNLOCKED */
|
||||
|
||||
for(uint32_t i=0;i<to_send.size();++i)
|
||||
{
|
||||
ChatMessage message;
|
||||
initChatMessage(to_send[i], message);
|
||||
message.incoming = false;
|
||||
message.online = true;
|
||||
RsServer::notify()->notifyChatMessage(message);
|
||||
|
||||
checkSizeAndSendMessage(to_send[i]); // delete item
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_PRIVATE_OUTGOING_CHAT, NOTIFY_TYPE_DEL);
|
||||
|
@ -1445,18 +1305,18 @@ void p3ChatService::statusChange(const std::list<pqiServicePeer> &plist)
|
|||
else if (it->actions & RS_SERVICE_PEER_REMOVED)
|
||||
{
|
||||
/* now handle remove */
|
||||
clearPrivateChatQueue(true, it->id);
|
||||
clearPrivateChatQueue(false, it->id);
|
||||
mHistoryMgr->clear(it->id);
|
||||
mHistoryMgr->clear(ChatId(it->id));
|
||||
|
||||
std::list<RsChatMsgItem *>::iterator cit = privateOutgoingList.begin();
|
||||
while (cit != privateOutgoingList.end()) {
|
||||
RsChatMsgItem *c = *cit;
|
||||
if (c->PeerId() == it->id) {
|
||||
cit = privateOutgoingList.erase(cit);
|
||||
continue;
|
||||
}
|
||||
++cit;
|
||||
}
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -67,7 +67,6 @@ class p3ChatService: public p3Service, public DistantChatService, public Distrib
|
|||
* @see NotifyBase
|
||||
*/
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
/*************** pqiMonitor callback ***********************/
|
||||
virtual void statusChange(const std::list<pqiServicePeer> &plist);
|
||||
|
@ -75,9 +74,17 @@ class p3ChatService: public p3Service, public DistantChatService, public Distrib
|
|||
/*!
|
||||
* public chat sent to all peers
|
||||
*/
|
||||
int sendPublicChat(const std::string &msg);
|
||||
void sendPublicChat(const std::string &msg);
|
||||
|
||||
/********* RsMsgs ***********/
|
||||
/*!
|
||||
* Send a chat message.
|
||||
* @param destination where to send the chat message
|
||||
* @param msg the message
|
||||
* @see ChatId
|
||||
*/
|
||||
bool sendChat(ChatId destination, std::string msg);
|
||||
|
||||
/*!
|
||||
* chat is sent to specifc peer
|
||||
* @param id peer to send chat msg to
|
||||
|
@ -88,7 +95,7 @@ class p3ChatService: public p3Service, public DistantChatService, public Distrib
|
|||
* can be used to send 'immediate' status msgs, these status updates are meant for immediate use by peer (not saved by rs)
|
||||
* e.g currently used to update user when a peer 'is typing' during a chat
|
||||
*/
|
||||
void sendStatusString(const RsPeerId& peer_id,const std::string& status_str) ;
|
||||
void sendStatusString(const ChatId& peer_id,const std::string& status_str) ;
|
||||
|
||||
/*!
|
||||
* send to all peers online
|
||||
|
@ -130,33 +137,6 @@ class p3ChatService: public p3Service, public DistantChatService, public Distrib
|
|||
*/
|
||||
void getOwnAvatarJpegData(unsigned char *& data,int& size) ;
|
||||
|
||||
/*!
|
||||
* returns the count of messages in public queue
|
||||
* @param public or private queue
|
||||
*/
|
||||
int getPublicChatQueueCount();
|
||||
|
||||
/*!
|
||||
* This retrieves all public chat msg items
|
||||
*/
|
||||
bool getPublicChatQueue(std::list<ChatInfo> &chats);
|
||||
|
||||
/*!
|
||||
* returns the count of messages in private queue
|
||||
* @param public or private queue
|
||||
*/
|
||||
int getPrivateChatQueueCount(bool incoming);
|
||||
|
||||
/*!
|
||||
* @param id's of available private chat messages
|
||||
*/
|
||||
bool getPrivateChatQueueIds(bool incoming, std::list<RsPeerId> &ids);
|
||||
|
||||
/*!
|
||||
* This retrieves all private chat msg items for peer
|
||||
*/
|
||||
bool getPrivateChatQueue(bool incoming, const RsPeerId &id, std::list<ChatInfo> &chats);
|
||||
|
||||
/*!
|
||||
* Return the max message size for security forwarding
|
||||
* @param type RS_CHAT_TYPE_...
|
||||
|
@ -186,7 +166,8 @@ class p3ChatService: public p3Service, public DistantChatService, public Distrib
|
|||
virtual void saveDone();
|
||||
virtual bool loadList(std::list<RsItem*>& load) ;
|
||||
|
||||
bool isOnline(const RsPeerId& id) ;
|
||||
// accepts virtual peer id
|
||||
bool isOnline(const RsPeerId &pid) ;
|
||||
|
||||
/// This is to be used by subclasses/parents to call IndicateConfigChanged()
|
||||
virtual void triggerConfigSave() { IndicateConfigChanged() ; }
|
||||
|
@ -205,7 +186,7 @@ class p3ChatService: public p3Service, public DistantChatService, public Distrib
|
|||
|
||||
virtual void sendChatItem(RsChatItem *) ;
|
||||
|
||||
void initRsChatInfo(RsChatMsgItem *c, ChatInfo &i);
|
||||
void initChatMessage(RsChatMsgItem *c, ChatMessage& msg);
|
||||
|
||||
/// Send avatar info to peer in jpeg format.
|
||||
void sendAvatarJpegData(const RsPeerId& peer_id) ;
|
||||
|
@ -242,9 +223,7 @@ class p3ChatService: public p3Service, public DistantChatService, public Distrib
|
|||
p3LinkMgr *mLinkMgr;
|
||||
p3HistoryMgr *mHistoryMgr;
|
||||
|
||||
std::list<RsChatMsgItem *> publicList;
|
||||
std::list<RsChatMsgItem *> privateIncomingList;
|
||||
std::list<RsChatMsgItem *> privateOutgoingList;
|
||||
std::list<RsChatMsgItem *> privateOutgoingList; // messages waiting to be send when peer comes online
|
||||
|
||||
AvatarInfo *_own_avatar ;
|
||||
std::map<RsPeerId,AvatarInfo *> _avatars ;
|
||||
|
|
|
@ -68,8 +68,6 @@ class ftFileSearch;
|
|||
class ftDataMultiplex;
|
||||
class p3turtle;
|
||||
|
||||
class ftDwlQueue;
|
||||
|
||||
class p3PeerMgr;
|
||||
class p3ServiceControl;
|
||||
|
||||
|
@ -287,8 +285,6 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
|
|||
|
||||
ftFileSearch *mFtSearch;
|
||||
|
||||
ftDwlQueue *mFtDwlQueue;
|
||||
|
||||
RsMutex srvMutex;
|
||||
std::string mConfigPath;
|
||||
std::string mDownloadPath;
|
||||
|
|
|
@ -63,7 +63,8 @@ p3HistoryMgr::~p3HistoryMgr()
|
|||
|
||||
/***** p3HistoryMgr *****/
|
||||
|
||||
void p3HistoryMgr::addMessage(bool incoming, const RsPeerId &chatPeerId, const RsPeerId &peerId, const RsChatMsgItem *chatItem)
|
||||
//void p3HistoryMgr::addMessage(bool incoming, const RsPeerId &chatPeerId, const RsPeerId &peerId, const RsChatMsgItem *chatItem)
|
||||
void p3HistoryMgr::addMessage(const ChatMessage& cm)
|
||||
{
|
||||
uint32_t addMsgId = 0;
|
||||
|
||||
|
@ -78,38 +79,48 @@ void p3HistoryMgr::addMessage(bool incoming, const RsPeerId &chatPeerId, const R
|
|||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (mPublicEnable == false && chatPeerId.isNull()) {
|
||||
// public chat not enabled
|
||||
return;
|
||||
}
|
||||
|
||||
const RsChatLobbyMsgItem *cli = dynamic_cast<const RsChatLobbyMsgItem*>(chatItem);
|
||||
RsPeerId peerId; // id of sending peer
|
||||
RsPeerId chatPeerId; // id of chat endpoint
|
||||
std::string peerName; //name of sending peer
|
||||
|
||||
if (cli)
|
||||
{
|
||||
if (mLobbyEnable == false && !chatPeerId.isNull()) // lobby chat not enabled
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mPrivateEnable == false && !chatPeerId.isNull()) // private chat not enabled
|
||||
return;
|
||||
bool enabled = false;
|
||||
if (cm.chat_id.isBroadcast() && mPublicEnable == true) {
|
||||
peerName = rsPeers->getPeerName(cm.broadcast_peer_id);
|
||||
enabled = true;
|
||||
}
|
||||
if (cm.chat_id.isPeerId() && mPrivateEnable == true) {
|
||||
peerId = cm.incoming ? cm.chat_id.toPeerId() : rsPeers->getOwnId();
|
||||
peerName = rsPeers->getPeerName(peerId);
|
||||
enabled = true;
|
||||
}
|
||||
if (cm.chat_id.isLobbyId() && mLobbyEnable == true) {
|
||||
peerName = cm.lobby_peer_nickname;
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
// not handled: private distant chat
|
||||
|
||||
if(enabled == false)
|
||||
return;
|
||||
|
||||
if(!chatIdToVirtualPeerId(cm.chat_id, chatPeerId))
|
||||
return;
|
||||
|
||||
RsHistoryMsgItem* item = new RsHistoryMsgItem;
|
||||
item->chatPeerId = chatPeerId;
|
||||
item->incoming = incoming;
|
||||
item->incoming = cm.incoming;
|
||||
item->peerId = peerId;
|
||||
item->peerName = cli ? cli->nick : rsPeers->getPeerName(RsPeerId(item->peerId));
|
||||
item->sendTime = chatItem->sendTime;
|
||||
item->recvTime = chatItem->recvTime;
|
||||
item->peerName = peerName;
|
||||
item->sendTime = cm.sendTime;
|
||||
item->recvTime = cm.recvTime;
|
||||
|
||||
if (cli) {
|
||||
if (cm.chat_id.isLobbyId()) {
|
||||
// disable save to disc for chat lobbies until they are saved
|
||||
item->saveToDisc = false;
|
||||
}
|
||||
|
||||
item->message = chatItem->message ;
|
||||
item->message = cm.msg ;
|
||||
//librs::util::ConvertUtf16ToUtf8(chatItem->message, item->message);
|
||||
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(item->chatPeerId);
|
||||
|
@ -122,7 +133,7 @@ void p3HistoryMgr::addMessage(bool incoming, const RsPeerId &chatPeerId, const R
|
|||
uint32_t limit;
|
||||
if (chatPeerId.isNull())
|
||||
limit = mPublicSaveCount;
|
||||
else if (cli)
|
||||
else if (cm.chat_id.isLobbyId())
|
||||
limit = mLobbySaveCount;
|
||||
else
|
||||
limit = mPrivateSaveCount;
|
||||
|
@ -357,6 +368,35 @@ bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
|
|||
return true;
|
||||
}
|
||||
|
||||
// have to convert to virtual peer id, to be able to use existing serialiser and file format
|
||||
bool p3HistoryMgr::chatIdToVirtualPeerId(ChatId chat_id, RsPeerId &peer_id)
|
||||
{
|
||||
if (chat_id.isBroadcast()) {
|
||||
peer_id = RsPeerId();
|
||||
return true;
|
||||
}
|
||||
if (chat_id.isPeerId()) {
|
||||
peer_id = chat_id.toPeerId();
|
||||
return true;
|
||||
}
|
||||
if (chat_id.isLobbyId()) {
|
||||
if(sizeof(ChatLobbyId) > RsPeerId::SIZE_IN_BYTES){
|
||||
std::cerr << "p3HistoryMgr::chatIdToVirtualPeerId() ERROR: ChatLobbyId does not fit into virtual peer id. Please report this error." << std::endl;
|
||||
return false;
|
||||
}
|
||||
uint8_t bytes[RsPeerId::SIZE_IN_BYTES] ;
|
||||
memset(bytes,0,RsPeerId::SIZE_IN_BYTES) ;
|
||||
ChatLobbyId lobby_id = chat_id.toLobbyId();
|
||||
memcpy(bytes,&lobby_id,sizeof(ChatLobbyId));
|
||||
peer_id = RsPeerId(bytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
// not handled: private distant chat
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/***** p3History *****/
|
||||
|
||||
static void convertMsg(const RsHistoryMsgItem* item, HistoryMsg &msg)
|
||||
|
@ -371,24 +411,31 @@ static void convertMsg(const RsHistoryMsgItem* item, HistoryMsg &msg)
|
|||
msg.message = item->message;
|
||||
}
|
||||
|
||||
bool p3HistoryMgr::getMessages(const RsPeerId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount)
|
||||
bool p3HistoryMgr::getMessages(const ChatId &chatId, std::list<HistoryMsg> &msgs, uint32_t loadCount)
|
||||
{
|
||||
msgs.clear();
|
||||
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::cerr << "Getting history for peer " << chatPeerId << std::endl;
|
||||
RsPeerId chatPeerId;
|
||||
bool enabled = false;
|
||||
if (chatId.isBroadcast() && mPublicEnable == true) {
|
||||
enabled = true;
|
||||
}
|
||||
if (chatId.isPeerId() && mPrivateEnable == true) {
|
||||
enabled = true;
|
||||
}
|
||||
if (chatId.isLobbyId() && mLobbyEnable == true) {
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
if (mPublicEnable == false && chatPeerId.isNull()) { // chatPeerId.empty() means it's public chat
|
||||
// public chat not enabled
|
||||
return false;
|
||||
}
|
||||
if(enabled == false)
|
||||
return false;
|
||||
|
||||
if (mPrivateEnable == false && chatPeerId.isNull() == false) // private chat not enabled
|
||||
return false;
|
||||
if(!chatIdToVirtualPeerId(chatId, chatPeerId))
|
||||
return false;
|
||||
|
||||
if (mLobbyEnable == false && chatPeerId.isNull() == false) // private chat not enabled
|
||||
return false;
|
||||
std::cerr << "Getting history for virtual peer " << chatPeerId << std::endl;
|
||||
|
||||
uint32_t foundCount = 0;
|
||||
|
||||
|
@ -430,12 +477,16 @@ bool p3HistoryMgr::getMessage(uint32_t msgId, HistoryMsg &msg)
|
|||
return false;
|
||||
}
|
||||
|
||||
void p3HistoryMgr::clear(const RsPeerId &chatPeerId)
|
||||
void p3HistoryMgr::clear(const ChatId &chatId)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::cerr << "********** p3History::clear()called for peer id " << chatPeerId << std::endl;
|
||||
RsPeerId chatPeerId;
|
||||
if(!chatIdToVirtualPeerId(chatId, chatPeerId))
|
||||
return;
|
||||
|
||||
std::cerr << "********** p3History::clear()called for virtual peer id " << chatPeerId << std::endl;
|
||||
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
|
||||
if (mit == mMessages.end()) {
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
class RsChatMsgItem;
|
||||
class ChatMessage;
|
||||
|
||||
//! handles history
|
||||
/*!
|
||||
|
@ -48,13 +49,13 @@ public:
|
|||
|
||||
/******** p3HistoryMgr *********/
|
||||
|
||||
void addMessage(bool incoming, const RsPeerId &chatPeerId, const RsPeerId &peerId, const RsChatMsgItem *chatItem);
|
||||
void addMessage(const ChatMessage &cm);
|
||||
|
||||
/********* RsHistory ***********/
|
||||
|
||||
bool getMessages(const RsPeerId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
|
||||
bool getMessages(const ChatId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
|
||||
bool getMessage(uint32_t msgId, HistoryMsg &msg);
|
||||
void clear(const RsPeerId &chatPeerId);
|
||||
void clear(const ChatId &chatPeerId);
|
||||
void removeMessages(const std::list<uint32_t> &msgIds);
|
||||
|
||||
virtual bool getEnable(uint32_t chat_type);
|
||||
|
@ -72,6 +73,8 @@ public:
|
|||
virtual bool loadList(std::list<RsItem*>& load);
|
||||
|
||||
private:
|
||||
static bool chatIdToVirtualPeerId(ChatId chat_id, RsPeerId& peer_id);
|
||||
|
||||
uint32_t nextMsgId;
|
||||
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> > mMessages;
|
||||
|
||||
|
|
|
@ -223,8 +223,8 @@ void p3Notify::notifyListPreChange(int list, int type) { FOR_ALL_NOTIFY_CLIENTS
|
|||
void p3Notify::notifyListChange (int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListChange (list,type) ; }
|
||||
|
||||
void p3Notify::notifyErrorMsg (int list, int sev, std::string msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyErrorMsg(list,sev,msg) ; }
|
||||
void p3Notify::notifyChatStatus (const std::string& peer_id , const std::string& status_string ,bool is_private) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatStatus(peer_id,status_string,is_private) ; }
|
||||
void p3Notify::notifyChatShow (const std::string& peer_id) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatShow(peer_id) ; }
|
||||
void p3Notify::notifyChatMessage (const ChatMessage &msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatMessage(msg) ; }
|
||||
void p3Notify::notifyChatStatus (const ChatId& chat_id, const std::string& status_string) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatStatus(chat_id,status_string) ; }
|
||||
|
||||
void p3Notify::notifyChatLobbyTimeShift (int time_shift) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatLobbyTimeShift(time_shift) ; }
|
||||
void p3Notify::notifyCustomState (const std::string& peer_id , const std::string& status_string ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyCustomState (peer_id,status_string) ; }
|
||||
|
@ -238,10 +238,10 @@ void p3Notify::notifyPeerStatusChanged (const std::string& peer_id , uint
|
|||
|
||||
void p3Notify::notifyPeerStatusChangedSummary () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChangedSummary() ; }
|
||||
void p3Notify::notifyDiscInfoChanged () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDiscInfoChanged () ; }
|
||||
|
||||
#ifdef REMOVE
|
||||
void p3Notify::notifyForumMsgReadSatusChanged (const std::string& channelId, const std::string& msgId, uint32_t status) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyForumMsgReadSatusChanged (channelId,msgId,status) ; }
|
||||
void p3Notify::notifyChannelMsgReadSatusChanged (const std::string& channelId, const std::string& msgId, uint32_t status) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChannelMsgReadSatusChanged (channelId,msgId,status) ; }
|
||||
|
||||
#endif
|
||||
void p3Notify::notifyDownloadComplete (const std::string& fileHash ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadComplete (fileHash) ; }
|
||||
void p3Notify::notifyDownloadCompleteCount (uint32_t count ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadCompleteCount (count) ; }
|
||||
void p3Notify::notifyHistoryChanged (uint32_t msgId , int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHistoryChanged (msgId,type) ; }
|
||||
|
|
|
@ -98,8 +98,8 @@ class p3Notify: public RsNotify
|
|||
void notifyListPreChange (int /* list */, int /* type */) ;
|
||||
void notifyListChange (int /* list */, int /* type */) ;
|
||||
void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) ;
|
||||
void notifyChatStatus (const std::string& /* peer_id */, const std::string& /* status_string */ ,bool /* is_private */) ;
|
||||
void notifyChatShow (const std::string& /* peer_id */) ;
|
||||
void notifyChatMessage (const ChatMessage& /* msg */) ;
|
||||
void notifyChatStatus (const ChatId& /* chat_id */, const std::string& /* status_string */) ;
|
||||
void notifyChatLobbyEvent (uint64_t /* lobby id */, uint32_t /* event type */ ,const std::string& /* nickname */,const std::string& /* any string */) ;
|
||||
void notifyChatLobbyTimeShift (int /* time_shift*/) ;
|
||||
void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) ;
|
||||
|
@ -113,8 +113,10 @@ class p3Notify: public RsNotify
|
|||
|
||||
void notifyPeerStatusChangedSummary () ;
|
||||
void notifyDiscInfoChanged () ;
|
||||
#ifdef REMOVE
|
||||
void notifyForumMsgReadSatusChanged (const std::string& /* channelId */, const std::string& /* msgId */, uint32_t /* status */) ;
|
||||
void notifyChannelMsgReadSatusChanged (const std::string& /* channelId */, const std::string& /* msgId */, uint32_t /* status */) ;
|
||||
#endif
|
||||
bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */,int& signature_result ) ;
|
||||
void notifyDownloadComplete (const std::string& /* fileHash */) ;
|
||||
void notifyDownloadCompleteCount (uint32_t /* count */) ;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
|
||||
class RsHistory;
|
||||
class ChatId;
|
||||
|
||||
extern RsHistory *rsHistory;
|
||||
|
||||
|
@ -72,10 +73,10 @@ public:
|
|||
class RsHistory
|
||||
{
|
||||
public:
|
||||
virtual bool getMessages(const RsPeerId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount) = 0;
|
||||
virtual bool getMessages(const ChatId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount) = 0;
|
||||
virtual bool getMessage(uint32_t msgId, HistoryMsg &msg) = 0;
|
||||
virtual void removeMessages(const std::list<uint32_t> &msgIds) = 0;
|
||||
virtual void clear(const RsPeerId &chatPeerId) = 0;
|
||||
virtual void clear(const ChatId &chatPeerId) = 0;
|
||||
|
||||
virtual bool getEnable(uint32_t chat_type) = 0;
|
||||
virtual void setEnable(uint32_t chat_type, bool enable) = 0;
|
||||
|
|
|
@ -254,15 +254,64 @@ public:
|
|||
#define RS_DISTANT_CHAT_FLAG_SIGNED 0x0001
|
||||
#define RS_DISTANT_CHAT_FLAG_SIGNATURE_OK 0x0002
|
||||
|
||||
class ChatInfo
|
||||
// Identifier for an chat endpoint like
|
||||
// neighbour peer, distant peer, chatlobby, broadcast
|
||||
class ChatId
|
||||
{
|
||||
public:
|
||||
RsPeerId rsid;
|
||||
std::string peer_nickname;
|
||||
unsigned int chatflags;
|
||||
uint32_t sendTime;
|
||||
uint32_t recvTime;
|
||||
std::string msg;
|
||||
public:
|
||||
ChatId();
|
||||
explicit ChatId(RsPeerId id);
|
||||
explicit ChatId(RsGxsId id);
|
||||
explicit ChatId(ChatLobbyId id);
|
||||
explicit ChatId(std::string str);
|
||||
static ChatId makeBroadcastId();
|
||||
|
||||
std::string toStdString() const;
|
||||
bool operator<(const ChatId& other) const;
|
||||
bool isSameEndpoint(const ChatId& other) const;
|
||||
|
||||
bool isNotSet() const;
|
||||
bool isPeerId() const;
|
||||
bool isGxsId() const;
|
||||
bool isLobbyId() const;
|
||||
bool isBroadcast() const;
|
||||
|
||||
RsPeerId toPeerId() const;
|
||||
RsGxsId toGxsId() const;
|
||||
ChatLobbyId toLobbyId() const;
|
||||
|
||||
// for the very specific case of transfering a status string
|
||||
// from the chatservice to the gui,
|
||||
// this defines from which peer the status string came from
|
||||
RsPeerId broadcast_status_peer_id;
|
||||
private:
|
||||
enum Type { TYPE_NOT_SET,
|
||||
TYPE_PRIVATE, // private chat with directly connected friend, peer_id is valid
|
||||
TYPE_PRIVATE_DISTANT, // private chat with distant peer, gxs_id is valid
|
||||
TYPE_LOBBY, // chat lobby id, lobby_id is valid
|
||||
TYPE_BROADCAST // message to/from all connected peers
|
||||
};
|
||||
|
||||
Type type;
|
||||
RsPeerId peer_id;
|
||||
RsGxsId gxs_id;
|
||||
ChatLobbyId lobby_id;
|
||||
};
|
||||
|
||||
class ChatMessage
|
||||
{
|
||||
public:
|
||||
ChatId chat_id; // id of chat endpoint
|
||||
RsPeerId broadcast_peer_id; // only used for broadcast chat: source peer id
|
||||
std::string lobby_peer_nickname; // only used for lobbys: nickname of message author
|
||||
|
||||
unsigned int chatflags;
|
||||
uint32_t sendTime;
|
||||
uint32_t recvTime;
|
||||
std::string msg;
|
||||
bool incoming;
|
||||
bool online; // for outgoing messages: was this message send?
|
||||
//bool system_message;
|
||||
};
|
||||
|
||||
class ChatLobbyInvite
|
||||
|
@ -315,9 +364,6 @@ struct DistantChatInviteInfo
|
|||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const MessageInfo &info);
|
||||
std::ostream &operator<<(std::ostream &out, const ChatInfo &info);
|
||||
|
||||
bool operator==(const ChatInfo&, const ChatInfo&);
|
||||
|
||||
class RsMsgs;
|
||||
extern RsMsgs *rsMsgs;
|
||||
|
@ -381,18 +427,13 @@ virtual bool distantMessagingEnabled() = 0;
|
|||
/****************************************/
|
||||
/* Chat */
|
||||
/****************************************/
|
||||
virtual bool sendPublicChat(const std::string& msg) = 0;
|
||||
virtual bool sendPrivateChat(const RsPeerId& id, const std::string& msg) = 0;
|
||||
virtual int getPublicChatQueueCount() = 0;
|
||||
virtual bool getPublicChatQueue(std::list<ChatInfo> &chats) = 0;
|
||||
virtual int getPrivateChatQueueCount(bool incoming) = 0;
|
||||
virtual bool getPrivateChatQueueIds(bool incoming, std::list<RsPeerId> &ids) = 0;
|
||||
virtual bool getPrivateChatQueue(bool incoming, const RsPeerId& id, std::list<ChatInfo> &chats) = 0;
|
||||
virtual bool clearPrivateChatQueue(bool incoming, const RsPeerId& id) = 0;
|
||||
virtual uint32_t getMaxMessageSecuritySize(int type) = 0;
|
||||
// sendChat for broadcast, private, lobby and private distant chat
|
||||
// note: for lobby chat, you first have to subscribe to a lobby
|
||||
// for private distant chat, it is reqired to have an active distant chat session
|
||||
virtual bool sendChat(ChatId id, std::string msg) = 0;
|
||||
virtual uint32_t getMaxMessageSecuritySize(int type) = 0;
|
||||
|
||||
virtual void sendStatusString(const RsPeerId& id,const std::string& status_string) = 0 ;
|
||||
virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;
|
||||
virtual void sendStatusString(const ChatId& id,const std::string& status_string) = 0 ;
|
||||
|
||||
virtual void setCustomStateString(const std::string& status_string) = 0 ;
|
||||
virtual std::string getCustomStateString() = 0 ;
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
|
||||
#include "rsturtle.h"
|
||||
|
||||
class ChatId;
|
||||
class ChatMessage;
|
||||
|
||||
class RsNotify;
|
||||
extern RsNotify *rsNotify;
|
||||
|
||||
|
@ -198,8 +201,8 @@ class NotifyClient
|
|||
virtual void notifyListPreChange (int /* list */, int /* type */) {}
|
||||
virtual void notifyListChange (int /* list */, int /* type */) {}
|
||||
virtual void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) {}
|
||||
virtual void notifyChatStatus (const std::string& /* peer_id */, const std::string& /* status_string */ ,bool /* is_private */) {}
|
||||
virtual void notifyChatShow (const std::string& /* peer_id */) {}
|
||||
virtual void notifyChatMessage (const ChatMessage& /* msg */) {}
|
||||
virtual void notifyChatStatus (const ChatId& /* chat_id */, const std::string& /* status_string */) {}
|
||||
virtual void notifyChatLobbyEvent (uint64_t /* lobby id */, uint32_t /* event type */ ,const std::string& /* nickname */,const std::string& /* any string */) {}
|
||||
virtual void notifyChatLobbyTimeShift (int /* time_shift*/) {}
|
||||
virtual void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) {}
|
||||
|
@ -214,8 +217,10 @@ class NotifyClient
|
|||
/* one or more peers has changed the states */
|
||||
virtual void notifyPeerStatusChangedSummary () {}
|
||||
virtual void notifyDiscInfoChanged () {}
|
||||
#ifdef REMOVE
|
||||
virtual void notifyForumMsgReadSatusChanged (const std::string& /* channelId */, const std::string& /* msgId */, uint32_t /* status */) {}
|
||||
virtual void notifyChannelMsgReadSatusChanged (const std::string& /* channelId */, const std::string& /* msgId */, uint32_t /* status */) {}
|
||||
#endif
|
||||
virtual bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */,int& signature_result ) { signature_result = false ;return true; }
|
||||
virtual void notifyDownloadComplete (const std::string& /* fileHash */) {}
|
||||
virtual void notifyDownloadCompleteCount (uint32_t /* count */) {}
|
||||
|
|
|
@ -44,7 +44,7 @@ uint32_t p3History::getMaxStorageDuration()
|
|||
{
|
||||
return mHistoryMgr->getMaxStorageDuration() ;
|
||||
}
|
||||
bool p3History::getMessages(const RsPeerId &chatPeerId, std::list<HistoryMsg> &msgs, const uint32_t loadCount)
|
||||
bool p3History::getMessages(const ChatId &chatPeerId, std::list<HistoryMsg> &msgs, const uint32_t loadCount)
|
||||
{
|
||||
return mHistoryMgr->getMessages(chatPeerId, msgs, loadCount);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ void p3History::removeMessages(const std::list<uint32_t> &msgIds)
|
|||
mHistoryMgr->removeMessages(msgIds);
|
||||
}
|
||||
|
||||
void p3History::clear(const RsPeerId &chatPeerId)
|
||||
void p3History::clear(const ChatId &chatPeerId)
|
||||
{
|
||||
mHistoryMgr->clear(chatPeerId);
|
||||
}
|
||||
|
|
|
@ -41,10 +41,10 @@ public:
|
|||
p3History(p3HistoryMgr* historyMgr);
|
||||
virtual ~p3History();
|
||||
|
||||
virtual bool getMessages(const RsPeerId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
|
||||
virtual bool getMessages(const ChatId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
|
||||
virtual bool getMessage(uint32_t msgId, HistoryMsg &msg);
|
||||
virtual void removeMessages(const std::list<uint32_t> &msgIds);
|
||||
virtual void clear(const RsPeerId &chatPeerId);
|
||||
virtual void clear(const ChatId &chatPeerId);
|
||||
virtual bool getEnable(uint32_t chat_type);
|
||||
virtual void setEnable(uint32_t chat_type, bool enable);
|
||||
virtual uint32_t getSaveCount(uint32_t chat_type);
|
||||
|
|
|
@ -49,26 +49,223 @@ RsMsgs *rsMsgs = NULL;
|
|||
/****************************************/
|
||||
/****************************************/
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ChatInfo &info)
|
||||
ChatId::ChatId():
|
||||
type(TYPE_NOT_SET),
|
||||
lobby_id(0)
|
||||
{
|
||||
out << "ChatInfo: rsid: " << info.rsid << std::endl;
|
||||
out << "chatflags: " << info.chatflags << std::endl;
|
||||
out << "sendTime: " << info.sendTime << std::endl;
|
||||
out << "recvTime: " << info.recvTime << std::endl;
|
||||
std::string message;
|
||||
message.assign(info.msg.begin(), info.msg.end());
|
||||
out << "msg: " << message;
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
bool operator==(const ChatInfo& info1, const ChatInfo& info2)
|
||||
ChatId::ChatId(RsPeerId id):
|
||||
lobby_id(0)
|
||||
{
|
||||
return info1.rsid == info2.rsid &&
|
||||
info1.chatflags == info2.chatflags &&
|
||||
info1.sendTime == info2.sendTime &&
|
||||
info1.recvTime == info2.recvTime &&
|
||||
info1.msg == info2.msg;
|
||||
type = TYPE_PRIVATE;
|
||||
peer_id = id;
|
||||
}
|
||||
|
||||
ChatId::ChatId(RsGxsId id):
|
||||
lobby_id(0)
|
||||
{
|
||||
type = TYPE_PRIVATE_DISTANT;
|
||||
gxs_id = id;
|
||||
}
|
||||
|
||||
ChatId::ChatId(ChatLobbyId id):
|
||||
lobby_id(0)
|
||||
{
|
||||
type = TYPE_LOBBY;
|
||||
lobby_id = id;
|
||||
}
|
||||
|
||||
ChatId::ChatId(std::string str):
|
||||
lobby_id(0)
|
||||
{
|
||||
type = TYPE_NOT_SET;
|
||||
if(str.empty())
|
||||
return;
|
||||
if(str[0] == 'P')
|
||||
{
|
||||
type = TYPE_PRIVATE;
|
||||
peer_id = RsPeerId(str.substr(1));
|
||||
}
|
||||
else if(str[0] == 'D')
|
||||
{
|
||||
type = TYPE_PRIVATE_DISTANT;
|
||||
gxs_id == GXSId(str.substr(1));
|
||||
}
|
||||
else if(str[0] == 'L')
|
||||
{
|
||||
if(sizeof(ChatLobbyId) != 8)
|
||||
{
|
||||
std::cerr << "ChatId::ChatId(std::string) Error: sizeof(ChatLobbyId) != 8. please report this" << std::endl;
|
||||
return;
|
||||
}
|
||||
str = str.substr(1);
|
||||
if(str.size() != 16)
|
||||
return;
|
||||
ChatLobbyId id = 0;
|
||||
for(int i = 0; i<16; i++)
|
||||
{
|
||||
uint8_t c = str[i];
|
||||
if(c <= '9')
|
||||
c -= '9';
|
||||
else
|
||||
c -= 'A';
|
||||
id = id << 4;
|
||||
id |= c;
|
||||
}
|
||||
type = TYPE_LOBBY;
|
||||
lobby_id = id;
|
||||
}
|
||||
else if(str[0] == 'B')
|
||||
{
|
||||
type = TYPE_BROADCAST;
|
||||
}
|
||||
}
|
||||
|
||||
ChatId ChatId::makeBroadcastId()
|
||||
{
|
||||
ChatId id;
|
||||
id.type = TYPE_BROADCAST;
|
||||
return id;
|
||||
}
|
||||
|
||||
std::string ChatId::toStdString() const
|
||||
{
|
||||
std::string str;
|
||||
if(type == TYPE_PRIVATE)
|
||||
{
|
||||
str += "P";
|
||||
str += peer_id.toStdString();
|
||||
}
|
||||
else if(type == TYPE_PRIVATE_DISTANT)
|
||||
{
|
||||
str += "D";
|
||||
str += gxs_id.toStdString();
|
||||
}
|
||||
else if(type == TYPE_LOBBY)
|
||||
{
|
||||
if(sizeof(ChatLobbyId) != 8)
|
||||
{
|
||||
std::cerr << "ChatId::toStdString() Error: sizeof(ChatLobbyId) != 8. please report this" << std::endl;
|
||||
return "";
|
||||
}
|
||||
ChatLobbyId id = lobby_id;
|
||||
for(int i = 0; i<16; i++)
|
||||
{
|
||||
uint8_t c = id >>(64-4);
|
||||
if(c > 9)
|
||||
c += 'A';
|
||||
else
|
||||
c += '1';
|
||||
str += c;
|
||||
id = id << 4;
|
||||
}
|
||||
}
|
||||
else if(type == TYPE_BROADCAST)
|
||||
{
|
||||
str += "B";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
bool ChatId::operator <(const ChatId& other) const
|
||||
{
|
||||
if(type != other.type)
|
||||
return type < other.type;
|
||||
else
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case TYPE_NOT_SET:
|
||||
return false;
|
||||
case TYPE_PRIVATE:
|
||||
return peer_id < other.peer_id;
|
||||
case TYPE_PRIVATE_DISTANT:
|
||||
return gxs_id < other.gxs_id;
|
||||
case TYPE_LOBBY:
|
||||
return lobby_id < other.lobby_id;
|
||||
case TYPE_BROADCAST:
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ChatId::isSameEndpoint(const ChatId &other) const
|
||||
{
|
||||
if(type != other.type)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case TYPE_NOT_SET:
|
||||
return false;
|
||||
case TYPE_PRIVATE:
|
||||
return peer_id == other.peer_id;
|
||||
case TYPE_PRIVATE_DISTANT:
|
||||
return gxs_id == other.gxs_id;
|
||||
case TYPE_LOBBY:
|
||||
return lobby_id == other.lobby_id;
|
||||
case TYPE_BROADCAST:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ChatId::isNotSet() const
|
||||
{
|
||||
return type == TYPE_NOT_SET;
|
||||
}
|
||||
bool ChatId::isPeerId() const
|
||||
{
|
||||
return type == TYPE_PRIVATE;
|
||||
}
|
||||
bool ChatId::isGxsId() const
|
||||
{
|
||||
return type == TYPE_PRIVATE_DISTANT;
|
||||
}
|
||||
bool ChatId::isLobbyId() const
|
||||
{
|
||||
return type == TYPE_LOBBY;
|
||||
}
|
||||
bool ChatId::isBroadcast() const
|
||||
{
|
||||
return type == TYPE_BROADCAST;
|
||||
}
|
||||
RsPeerId ChatId::toPeerId() const
|
||||
{
|
||||
if(type == TYPE_PRIVATE)
|
||||
return peer_id;
|
||||
else
|
||||
{
|
||||
std::cerr << "ChatId Warning: conversation to RsPeerId requested, but type is different." << std::endl;
|
||||
return RsPeerId();
|
||||
}
|
||||
}
|
||||
RsGxsId ChatId::toGxsId() const
|
||||
{
|
||||
if(type == TYPE_PRIVATE_DISTANT)
|
||||
return gxs_id;
|
||||
else
|
||||
{
|
||||
std::cerr << "ChatId Warning: conversation to RsGxsId requested, but type is different." << std::endl;
|
||||
return RsGxsId();
|
||||
}
|
||||
}
|
||||
ChatLobbyId ChatId::toLobbyId() const
|
||||
{
|
||||
if(type == TYPE_LOBBY)
|
||||
return lobby_id;
|
||||
else
|
||||
{
|
||||
std::cerr << "ChatId Warning: conversation to ChatLobbyId requested, but type is different." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool p3Msgs::getMessageSummaries(std::list<MsgInfoSummary> &msgList)
|
||||
|
@ -200,56 +397,9 @@ bool p3Msgs::resetMessageStandardTagTypes(MsgTagType& tags)
|
|||
|
||||
/****************************************/
|
||||
/****************************************/
|
||||
bool p3Msgs::sendPublicChat(const std::string& msg)
|
||||
bool p3Msgs::sendChat(ChatId destination, std::string msg)
|
||||
{
|
||||
/* send a message to all for now */
|
||||
return mChatSrv -> sendPublicChat(msg);
|
||||
}
|
||||
|
||||
bool p3Msgs::sendPrivateChat(const RsPeerId& id, const std::string& msg)
|
||||
{
|
||||
/* send a message to peer */
|
||||
return mChatSrv -> sendPrivateChat(id, msg);
|
||||
}
|
||||
|
||||
void p3Msgs::sendGroupChatStatusString(const std::string& status_string)
|
||||
{
|
||||
mChatSrv->sendGroupChatStatusString(status_string);
|
||||
}
|
||||
|
||||
void p3Msgs::sendStatusString(const RsPeerId& peer_id, const std::string& status_string)
|
||||
{
|
||||
mChatSrv->sendStatusString(peer_id, status_string);
|
||||
}
|
||||
|
||||
int p3Msgs::getPublicChatQueueCount()
|
||||
{
|
||||
return mChatSrv->getPublicChatQueueCount();
|
||||
}
|
||||
|
||||
bool p3Msgs::getPublicChatQueue(std::list<ChatInfo> &chats)
|
||||
{
|
||||
return mChatSrv->getPublicChatQueue(chats);
|
||||
}
|
||||
|
||||
int p3Msgs::getPrivateChatQueueCount(bool incoming)
|
||||
{
|
||||
return mChatSrv->getPrivateChatQueueCount(incoming);
|
||||
}
|
||||
|
||||
bool p3Msgs::getPrivateChatQueueIds(bool incoming, std::list<RsPeerId> &ids)
|
||||
{
|
||||
return mChatSrv->getPrivateChatQueueIds(incoming, ids);
|
||||
}
|
||||
|
||||
bool p3Msgs::getPrivateChatQueue(bool incoming, const RsPeerId& id, std::list<ChatInfo> &chats)
|
||||
{
|
||||
return mChatSrv->getPrivateChatQueue(incoming, id, chats);
|
||||
}
|
||||
|
||||
bool p3Msgs::clearPrivateChatQueue(bool incoming, const RsPeerId& id)
|
||||
{
|
||||
return mChatSrv->clearPrivateChatQueue(incoming, id);
|
||||
return mChatSrv->sendChat(destination, msg);
|
||||
}
|
||||
|
||||
uint32_t p3Msgs::getMaxMessageSecuritySize(int type)
|
||||
|
@ -257,6 +407,11 @@ uint32_t p3Msgs::getMaxMessageSecuritySize(int type)
|
|||
return mChatSrv->getMaxMessageSecuritySize(type);
|
||||
}
|
||||
|
||||
void p3Msgs::sendStatusString(const ChatId& peer_id, const std::string& status_string)
|
||||
{
|
||||
mChatSrv->sendStatusString(peer_id, status_string);
|
||||
}
|
||||
|
||||
void p3Msgs::getOwnAvatarData(unsigned char *& data,int& size)
|
||||
{
|
||||
mChatSrv->getOwnAvatarJpegData(data,size) ;
|
||||
|
|
|
@ -116,47 +116,12 @@ class p3Msgs: public RsMsgs
|
|||
|
||||
|
||||
/*!
|
||||
* public chat sent to all peers
|
||||
* Send a chat message.
|
||||
* @param destination where to send the chat message
|
||||
* @param msg the message
|
||||
* @see ChatId
|
||||
*/
|
||||
virtual bool sendPublicChat(const std::string& msg);
|
||||
|
||||
/*!
|
||||
* chat is sent to specifc peer
|
||||
* @param id peer to send chat msg to
|
||||
*/
|
||||
virtual bool sendPrivateChat(const RsPeerId& id, const std::string& msg);
|
||||
|
||||
/*!
|
||||
* returns the count of messages in public or private queue
|
||||
* @param public or private queue
|
||||
*/
|
||||
virtual int getPublicChatQueueCount();
|
||||
|
||||
/*!
|
||||
* @param chats ref to list of received public chats is stored here
|
||||
*/
|
||||
virtual bool getPublicChatQueue(std::list<ChatInfo> &chats);
|
||||
|
||||
/*!
|
||||
* returns the count of messages in private queue
|
||||
* @param public or private queue
|
||||
*/
|
||||
virtual int getPrivateChatQueueCount(bool incoming);
|
||||
|
||||
/*!
|
||||
* @param id's of available private chat messages
|
||||
*/
|
||||
virtual bool getPrivateChatQueueIds(bool incoming, std::list<RsPeerId> &ids);
|
||||
|
||||
/*!
|
||||
* @param chats ref to list of received private chats is stored here
|
||||
*/
|
||||
virtual bool getPrivateChatQueue(bool incoming, const RsPeerId& id, std::list<ChatInfo> &chats);
|
||||
|
||||
/*!
|
||||
* @param clear private chat queue
|
||||
*/
|
||||
virtual bool clearPrivateChatQueue(bool incoming, const RsPeerId& id);
|
||||
virtual bool sendChat(ChatId destination, std::string msg) ;
|
||||
|
||||
/*!
|
||||
* Return the max message size for security forwarding
|
||||
|
@ -165,16 +130,10 @@ class p3Msgs: public RsMsgs
|
|||
|
||||
/*!
|
||||
* sends immediate status string to a specific peer, e.g. in a private chat
|
||||
* @param peer_id peer to send status string to
|
||||
* @param chat_id chat id to send status string to
|
||||
* @param status_string immediate status to send
|
||||
*/
|
||||
virtual void sendStatusString(const RsPeerId& peer_id, const std::string& status_string) ;
|
||||
|
||||
/*!
|
||||
* sends immediate status to all peers
|
||||
* @param status_string immediate status to send
|
||||
*/
|
||||
virtual void sendGroupChatStatusString(const std::string& status_string) ;
|
||||
virtual void sendStatusString(const ChatId& chat_id, const std::string& status_string) ;
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue