void PurpleChatMngr::UpdateBuddyTyping(PurpleConversation *conv, PurpleTypingState state) { IMChat::TypingState mState; mConvInfo_t *mConv = (mConvInfo_t *)conv->ui_data; PurpleIMChat *mIMChat = FindIMChatByPurpleConv(conv); if (!mIMChat) return; switch (state) { case PURPLE_TYPING: mState = IMChat::TypingStateTyping; break; case PURPLE_TYPED: mState = IMChat::TypingStateStopTyping; break; default: mState = IMChat::TypingStateNotTyping; break; } // Get contact id. If it's a jabber contact, remove its ressource. const char* name = purple_conversation_get_name(conv); PurpleAccount* gAccount = purple_conversation_get_account(conv); const char* gPrclId = purple_account_get_protocol_id(gAccount); std::string contactId = cleanContactId(name, PurpleIMPrcl::GetEnumIMProtocol(gPrclId)); // mIMChat->typingStateChangedEvent(*mIMChat, *((IMChatSession *)(mConv->conv_session)), contactId, mState); mIMChat->typingStateChangedEvent(*mIMChat, *(mConv->conv_session), contactId, mState); //VOXOX - JRT - 2009.07.09 }
//----------------------------------------------------------------------------- //VOXOX CHANGE CJC SEND MESSAGE AUTOMATICALLY WHEN OPENING AN ACCOUNT bool PurpleIMChat::createSessionAndSendMessageCbk(void * dataIn) { #if (defined OS_WINDOWS) Mutex::ScopedLock lock(PurpleIMChat::_mutex); #endif PurpleIMChatCallbackData* cbData = (PurpleIMChatCallbackData*) dataIn; PurpleIMChat* imChat = cbData->getPurpleIMChat(); IMContactSet* imContactSet = cbData->getIMContactSet(); PurpleAccount* gAccount = getPurpleAccount( imChat->getIMAccount() ); // const char * message = (const char *)((misc_t *)data)->data_ptr2; // std::string realMessage = message; //VOXOX CHANGE CJC TO BE ABLE TO SEND THIS VALUES TO PURPLECHATMNGR AND SEND MESSAGE AUTOMATICALLY IMContactSet::const_iterator it; if (imContactSet->empty()) { LOG_FATAL("imContactSet is empty"); } else if (imContactSet->size() == 1) { it = imContactSet->begin(); std::string contactId = (*it).getContactId(); PurpleConversation *gConv = NULL; if ((gConv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, contactId.c_str(), gAccount))) { mConvInfo_t *mConv = (mConvInfo_t *)gConv->ui_data; imChat->newIMChatAndSendMessageSessionCreatedEvent(*imChat, *(mConv->conv_session), cbData->getMessage(), false); //VOXOX - JRT - 2009.07.09 timeoutRemove( cbData ); delete cbData; return FALSE; } purple_conversation_new(PURPLE_CONV_TYPE_IM, gAccount, contactId.c_str()); } timeoutRemove( cbData ); delete cbData; return TRUE; }
bool PurpleIMChat::addContactCbk(void * dataIn) { Mutex::ScopedLock lock(PurpleIMChat::_mutex); PurpleIMChatCallbackData* cbData = (PurpleIMChatCallbackData*) dataIn; PurpleIMChat* imChat = cbData->getPurpleIMChat(); IMChatSession* chatSession = cbData->getIMChatSession(); PurpleAccount* gAccount = getPurpleAccount( imChat->getIMAccount() ); // const char * contactId = (const char *)((misc_t *)data)->data_ptr2; mConvInfo_t *mConv = FindChatStructById(chatSession->getId()); int BuddyNbr = chatSession->getIMContactSet().size(); PurpleConversation *gConv = NULL; if (mConv) gConv = mConv->purple_conv_session; //VOXOX - JRT - 2009.07.09 else LOG_FATAL("ConvInfo not created !!!"); if (purple_conversation_get_type(gConv) == PURPLE_CONV_TYPE_IM) { GList *mlist = NULL; IMContactSet& chatContact = const_cast<IMContactSet&>(chatSession->getIMContactSet()); IMContactSet::const_iterator it = chatContact.begin(); const std::string & firstContactId = it->getContactId(); PurpleConnection *gGC; gConv = mConv->purple_conv_session; //VOXOX - JRT - 2009.07.09 gGC = purple_conversation_get_gc(gConv); mlist = g_list_append(mlist, const_cast<char*>(cbData->getContactId().c_str()) ); mlist = g_list_append(mlist, (char *) firstContactId.c_str()); createPurpleChat(gGC, chatSession->getId(), mlist, *imChat, gAccount); //VOXOX - JRT - 2009.07.10 } else if (purple_conversation_get_type(gConv) == PURPLE_CONV_TYPE_CHAT) { serv_chat_invite(purple_conversation_get_gc(gConv), purple_conv_chat_get_id(PURPLE_CONV_CHAT(gConv)), NULL, cbData->getContactId().c_str() ); } timeoutRemove( cbData ); delete cbData; return TRUE; }
void PurpleChatMngr::ChatAddUsersCbk(PurpleConversation *conv, GList *users, gboolean new_arrivals) { GList *l; PurpleAccount *gAccount = purple_conversation_get_account(conv); const char *gPrclId = purple_account_get_protocol_id(gAccount); IMAccount *account = _accountMngr->FindIMAccount(purple_account_get_username(gAccount), PurpleIMPrcl::GetEnumIMProtocol(gPrclId)); mConvInfo_t *mConv = NULL; IMChatSession *chatSession = NULL; PurpleIMChat *mChat = FindIMChat(*account); if (!mChat) LOG_FATAL("Can't find IMChat !"); mConv = (mConvInfo_t *) conv->ui_data; chatSession = mConv->conv_session; //VOXOX - JRT - 2009.07.09 for (l = users; l != NULL; l = l->next) { PurpleConvChatBuddy *gCCBuddy = (PurpleConvChatBuddy *) l->data; if (gCCBuddy && strcmp(purple_account_get_username(gAccount), (char *) gCCBuddy->name)) { std::string buddy((char *) gCCBuddy->name); IMContact imContact(*account, buddy); if (chatSession->getIMContactSet().find(imContact) != chatSession->getIMContactSet().end()) { LOG_DEBUG("IMContact for " + imContact.getContactId() + " already in IMContactSet"); } else { ((IMContactSet &) chatSession->getIMContactSet()).insert(imContact); if (chatSession->getIMContactSet().size() == 1) { //Create session when first contact is added. mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession); } LOG_DEBUG("IMContact " + imContact.getContactId() + " added to IMContactSet"); } mChat->contactAddedEvent(*mChat, *chatSession, imContact); } } }
//----------------------------------------------------------------------------- //VOXOX - CJC - 2009.05.07 Add session form AskImVoxOxCom bool PurpleIMChat::createChatToEmailSessionCbk(void * dataIn) { #if (defined OS_WINDOWS) Mutex::ScopedLock lock(PurpleIMChat::_mutex); #endif PurpleIMChatCallbackData* cbData = (PurpleIMChatCallbackData*) dataIn; PurpleIMChat* imChat = cbData->getPurpleIMChat(); IMContactSet* imContactSet = cbData->getIMContactSet(); PurpleAccount* gAccount = getPurpleAccount( imChat->getIMAccount() ); IMContactSet::const_iterator askImContact; if (imContactSet->empty()) { LOG_FATAL("imContactSet is empty"); } else if (imContactSet->size() == 1) { askImContact = imContactSet->begin(); std::string askId = (*askImContact).getContactId(); PurpleConversation *gConv = NULL; if ((gConv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, askId.c_str(), gAccount))) { mConvInfo_t *mConv = (mConvInfo_t *)gConv->ui_data; imChat->newIMChatToEmailSessionCreatedEvent(*imChat, *(mConv->conv_session)); //VOXOX - JRT - 2009.07.09 timeoutRemove( cbData ); delete cbData; return FALSE; } purple_conversation_new(PURPLE_CONV_TYPE_IM, gAccount, askId.c_str()); } timeoutRemove( cbData ); delete cbData; return TRUE; }
int PurpleChatMngr::HandleChatInvite( PurpleAccount *gAccount, const char *who, const char* name, const char *message, void *data ) { int result = 0; const char* gPrclId = purple_account_get_protocol_id(gAccount); IMAccount* account = _accountMngr->FindIMAccount(purple_account_get_username(gAccount), PurpleIMPrcl::GetEnumIMProtocol(gPrclId)); PurpleIMChat* pImChat = FindIMChat(*account); if ( pImChat ) { GroupChatInfo gcInfo( true, who, name, message ); gcInfo.setAccountId( account->getKey() ); pImChat->getGroupChatInfo() = gcInfo; //VOXOX - JRT - 2009.10.06 pImChat->incomingGroupChatInviteEvent(*pImChat, gcInfo ); //VOXOX - JRT - 2009.10.06 result = (gcInfo.acceptedInvite() ? 1 : -1 ); } return result; }
void PurpleChatMngr::WriteConvCbk(PurpleConversation *conv, const char *name, const char *alias, const char *message, PurpleMessageFlags flags, time_t mtime) { if ((flags & PURPLE_MESSAGE_RECV)) { mConvInfo_t *mConv = (mConvInfo_t *)conv->ui_data; PurpleIMChat *mIMChat = FindIMChatByPurpleConv(conv); // Prevent from double message during a chat session if (strcmp(purple_account_get_username(conv->account), name) == 0) return; // Check if it's a jabber contact, and remove his resource PurpleAccount *gAccount = purple_conversation_get_account(conv); const char *gPrclId = purple_account_get_protocol_id(gAccount); std::string contactId = cleanContactId(name, PurpleIMPrcl::GetEnumIMProtocol(gPrclId)); mIMChat->messageReceivedEvent(*mIMChat, *(mConv->conv_session), contactId, std::string(message)); //VOXOX - JRT - 2009.07.09 } }
void PurpleChatMngr::ChatRemoveUsersCbk(PurpleConversation *conv, GList *users) { GList *l; PurpleAccount *gAccount = purple_conversation_get_account(conv); const char *gPrclId = purple_account_get_protocol_id(gAccount); IMAccount *account = _accountMngr->FindIMAccount(purple_account_get_username(gAccount), PurpleIMPrcl::GetEnumIMProtocol(gPrclId)); mConvInfo_t *mConv = NULL; IMChatSession *chatSession = NULL; PurpleIMChat *mChat = FindIMChat(*account); if (!mChat) LOG_FATAL("Can't find IMChat !"); mConv = (mConvInfo_t *) conv->ui_data; chatSession = mConv->conv_session; //VOXOX - JRT - 2009.07.09 for (l = users; l != NULL; l = l->next) { if (strcmp(purple_account_get_username(gAccount), (char *) l->data)) { std::string buddy((char *) l->data); IMContact imContact(*account, buddy); IMContact* imContact2 = chatSession->getIMContactSet().findBy( account->getKey(), buddy ); // if (chatSession->getIMContactSet().find(imContact) == chatSession->getIMContactSet().end()) if ( imContact2 == NULL ) { LOG_ERROR("IMContact for " + imContact.getContactId() + " not in IMContactSet"); } else { LOG_DEBUG("IMContact " + imContact.getContactId() + " removed from IMContactSet"); mChat->contactRemovedEvent(*mChat, *chatSession, buddy); } } } }
//----------------------------------------------------------------------------- //VOXOX CHANGE CJC ADD SKYPE CALL SUPPORT //TODO: THIS SHOULD NOT BE HERE bool PurpleIMChat::callSkypeContactCbk(void * dataIn) { Mutex::ScopedLock lock(PurpleIMChat::_mutex); PurpleIMChatCallbackData* cbData = (PurpleIMChatCallbackData*) dataIn; PurpleIMChat* imChat = cbData->getPurpleIMChat(); IMContactSet* imContactSet = cbData->getIMContactSet(); PurpleAccount* gAccount = getPurpleAccount( imChat->getIMAccount() ); PurplePluginProtocolInfo* prpl_info = NULL; PurpleConnection* gc = purple_account_get_connection(gAccount); PurplePlugin* prpl = NULL; IMContactSet::const_iterator it; if (imContactSet->size() == 1) { it = imContactSet->begin(); std::string contactId = (*it).getContactId(); if (gc != NULL) prpl = purple_connection_get_prpl(gc); if (prpl != NULL) prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); if (prpl_info != NULL && prpl_info->set_info != NULL) prpl_info->set_info(NULL,contactId.c_str()); } timeoutRemove( cbData ); delete cbData; return TRUE; }
bool PurpleIMChat::createSessionCbk(void * dataIn) { Mutex::ScopedLock lock(PurpleIMChat::_mutex); PurpleIMChatCallbackData* cbData = (PurpleIMChatCallbackData*) dataIn; PurpleIMChat* imChat = cbData->getPurpleIMChat(); IMContactSet* imContactSet = cbData->getIMContactSet(); // PurpleAccount* gAccount = purple_accounts_find(imChat->getIMAccount().getLogin().c_str(), // PurpleIMPrcl::GetPrclId(imChat->getIMAccount().getProtocol())); PurpleAccount* gAccount = getPurpleAccount( imChat->getIMAccount() ); IMContactSet::const_iterator it; if (imContactSet->empty()) { LOG_FATAL("imContactSet is empty"); } else { switch( imChat->getIMChatType() ) { case IMChat::Chat: { it = imContactSet->begin(); std::string contactId = (*it).getContactId(); PurpleConversation *gConv = NULL; gConv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, contactId.c_str(), gAccount); //If converation already exists, we still do the CreatedEvent so UI responds properly, // then we remove the task from queue. if ( gConv ) { mConvInfo_t *mConv = (mConvInfo_t *)gConv->ui_data; imChat->newIMChatSessionCreatedEvent(*imChat, *(mConv->conv_session)); //VOXOX - JRT - 2009.07.09 timeoutRemove( cbData ); delete cbData; return FALSE; } purple_conversation_new(PURPLE_CONV_TYPE_IM, gAccount, contactId.c_str()); break; } case IMChat::ChatGroup: { //Capture invitees. They will be handled later. PurpleConnection *gGC = purple_account_get_connection(gAccount); GList *mlist = NULL; for (it = imContactSet->begin(); it != imContactSet->end(); it++) { mlist = g_list_append(mlist, strdup(it->getContactId().c_str()) ); } //Does this group chat already exist? std::string chatRoomName = imChat->getGroupChatInfo().getAlias(); //VOXOX - JRT - 2009.06.18 - TODO: use getChatRoom() PurpleConversation *gConv = NULL; gConv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, chatRoomName.c_str(), gAccount); //If converation already exists, we still do the CreatedEvent so UI responds properly, // then we remove the task from queue. if ( gConv ) { mConvInfo_t *mConv = (mConvInfo_t *)gConv->ui_data; imChat->newIMChatSessionCreatedEvent(*imChat, *(mConv->conv_session)); //VOXOX - JRT - 2009.07.09 timeoutRemove( cbData ); delete cbData; return FALSE; } //Create new chat. // purple_conversation_new(PURPLE_CONV_TYPE_CHAT, gAccount, contactId.c_str()); createPurpleChat(gGC, 0, mlist, *imChat, gAccount ); //VOXOX - JRT - 2009.07.10 break; } default: LOG_FATAL("IMChat:IMChatType is improper: ", imChat->getIMChatType()); } } timeoutRemove( cbData ); delete cbData; return TRUE; }
void PurpleIMChat::createPurpleChat(PurpleConnection *gGC, int id, GList *users, PurpleIMChat & imChat, PurpleAccount* gAccount) //VOXOX - JRT - 2009.07.10 { char chatName[256]; mConvInfo_t *mConv = FindChatStructById(id); PurpleConversation *gConv = NULL; EnumIMProtocol::IMProtocol protocol = PurpleIMPrcl::GetEnumIMProtocol(gGC->account->protocol_id); if (mConv == NULL) { //Create IMChatSession and copy some values from IMChat. mConv = CreateChatSession(true, imChat); mConv->conv_session->setIMChatType( imChat.getIMChatType() ); // mConv->conv_session->getGroupChatInfo() = imChat.getGroupChatInfo(); } //VOXOX - JRT - 2009.06.15 - purple_conversation_get_name() uses this to id (numeric)! // Since id is ChatSession Address (0x), if you change this, then some 'find's will fail. // You will need your own data members to track alias, etc. // NOTE: This may be JABBER ONLY. // snprintf(chatName, sizeof(chatName), "Chat%d", mConv->conv_id); strcpy( chatName, imChat.getGroupChatInfo().getAlias().c_str() ); if (protocol == EnumIMProtocol::IMProtocolMSN) { //VOXOX - JRT - 2009.06.18 - TODO: check on use of 'chatname'; move to switch in following else-clause. gConv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, chatName, gGC->account); if (!gConv) LOG_FATAL("Chat doesn't exist !!"); mConv->purple_conv_session = gConv; // gConv->ui_data = mConv; } else { GHashTable *components; components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); char *room = NULL; char *server = NULL; g_hash_table_replace(components, g_strdup("room"), g_strdup(chatName)); switch( protocol ) { case EnumIMProtocol::IMProtocolYahoo: g_hash_table_replace(components, g_strdup("topic"), g_strdup("Join my conference...")); g_hash_table_replace(components, g_strdup("type"), g_strdup("Conference")); break; case EnumIMProtocol::IMProtocolAIM: case EnumIMProtocol::IMProtocolICQ: //Defaults for: // "room" - empty or passed in value (NULL below) // "exchange" - "4" components = serv_chat_info_defaults( gGC, NULL ); g_hash_table_replace(components, g_strdup("exchange"), g_strdup("16")); //VOXOX - JRT - 2009.06.14 - why do we use "16"? g_hash_table_replace(components, g_strdup("room"), g_strdup(chatName)); room = (char*)g_hash_table_lookup(components, "room"); // server = (char*)g_hash_table_lookup(components, "server"); //TODO: break; case EnumIMProtocol::IMProtocolJabber: std::string userChatRoomName = (imChat.getGroupChatInfo().getAlias().empty() ? chatName : imChat.getGroupChatInfo().getAlias()); //This will return defaults for: // "server" - conference.im.voxox.com // "room" - user-defined, or parsed from room@server/handle // "handle" - user id without domain. "*****@*****.**" -> "user" components = serv_chat_info_defaults( gGC, NULL ); //VOXOX - JRT - 2009.06.14 - Get defaults, like server (conference.im.voxox.com) g_hash_table_replace(components, g_strdup("room"), g_strdup(chatName)); room = (char*)g_hash_table_lookup(components, "room"); server = (char*)g_hash_table_lookup(components, "server"); break; } std::string fullRoomName = room; if ( server != NULL ) //VOXOX - JRT - 2009.10.12 - AIM gives NULL server. { fullRoomName += "@"; fullRoomName += server; } mConv->conv_session->getGroupChatInfo().setChatRoom( fullRoomName ); mConv->pending_invites = users; // purple_conversation_new(PURPLE_CONV_TYPE_CHAT, gAccount, fullRoomName.c_str()); //JRT-XXX serv_join_chat(gGC, components); g_hash_table_destroy(components); } }
void PurpleChatMngr::CreateConversationCbk(PurpleConversation *conv, bool userCreated) { PurpleAccount* gAccount = purple_conversation_get_account(conv); PurpleConversationType chatType = purple_conversation_get_type(conv); const char* gPrclId = purple_account_get_protocol_id(gAccount); IMAccount* account = _accountMngr->FindIMAccount(purple_account_get_username(gAccount), PurpleIMPrcl::GetEnumIMProtocol(gPrclId)); //VOXOX - JRT - 2009.07.20 - We seem to get a lot of crashes through here, via skype_find_chat. I suspect account is not being found. if ( account == NULL ) { std::string username = purple_account_get_username(gAccount); LOG_ERROR(" account == NULL for " + username + "\n"); } PurpleIMChat* mChat = FindIMChat(*account); mConvInfo_t* mConv = NULL; if (chatType == PURPLE_CONV_TYPE_IM) { IMChatSession *chatSession = NULL; // Check if it's a jabber contact, remove the resource std::string contactId = cleanContactId(std::string(purple_conversation_get_name(conv)), PurpleIMPrcl::GetEnumIMProtocol(gPrclId)); IMContact imContact(*account, contactId); mConv = mChat->CreateChatSession(userCreated, *mChat); mConv->purple_conv_session = conv; conv->ui_data = mConv; // chatSession = (IMChatSession *) mConv->conv_session; chatSession = mConv->conv_session; //VOXOX - JRT - 2009.07.09 - changed def from void* to IMChatSession* ((IMContactSet &) chatSession->getIMContactSet()).insert(imContact); //VOXOX CHANGE CJC - validate if message don't have to be sent automatically if(userCreated) { if(mChat->getAutoMessage() != "") { mChat->newIMChatAndSendMessageSessionCreatedEvent(*mChat, *((IMChatSession *)(mConv->conv_session)),mChat->getAutoMessage(),true); } else { switch( mChat->getIMChatType() ) { case IMChat::ChatToEmail: mChat->newIMChatToEmailSessionCreatedEvent(*mChat, *(mConv->conv_session)); //VOXOX - JRT - 2009.07.09 mChat->contactAddedEvent(*mChat, *chatSession, imContact); break; case IMChat::ChatToSMS: mChat->newIMChatToSMSSessionCreatedEvent(*mChat, *(mConv->conv_session)); //VOXOX - JRT - 2009.07.09 mChat->contactAddedEvent(*mChat, *chatSession, imContact); break; case IMChat::Chat: case IMChat::ChatGroup: //VOXOX - JRT - 2009.06.15 - we don't really expect this type. mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession); mChat->contactAddedEvent(*mChat, *chatSession, imContact); break; default: assert(false); //New IMChatType? } } } else { mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession); mChat->contactAddedEvent(*mChat, *chatSession, imContact); } } else if (chatType == PURPLE_CONV_TYPE_CHAT) { // int id = GetPurpleConversationId(purple_conversation_get_name(conv)); //VOXOX - JRT - 2009.06.16 - This does not work because it relies on CR name having ID as part of name. // int id = mChat->getGroupChatInfo().getId(); // if ((mConv = mChat->FindChatStructById(id)) == NULL) if ((mConv = mChat->FindChatStructByName( conv->name )) == NULL) { mConv = mChat->CreateChatSession(userCreated, *mChat); IMChatSession* chatSession = mConv->conv_session; //VOXOX - JRT - 2009.07.09 if ( chatSession ) { chatSession->setIMChatType( IMChat::ChatGroup ); // GroupChatInfo& gcInfo = chatSession->getIMChat().getGroupChatInfo(); GroupChatInfo& gcInfo = chatSession->getGroupChatInfo(); gcInfo.setId ( mConv->conv_id ); gcInfo.setChatRoom( conv->name ); } } if (mConv->purple_conv_session) purple_conversation_destroy(mConv->purple_conv_session); //VOXOX - JRT - 2009.07.09 mConv->purple_conv_session = conv; conv->ui_data = mConv; } }