void MeanwhileSession::handleImConvOpened(struct mwConversation *conv) { HERE; struct ConversationData *convdata = (struct ConversationData *)mwConversation_getClientData(conv); if (convdata == 0L) { /* a new conversation */ convdata = createConversationData(conv, conversationContact(conv)); if (convdata == 0L) { mwDebug() << "No memory for conversation data!" << endl; return; } } else if (convdata->queue && !convdata->queue->isEmpty()) { /* send any messages that were waiting for the conversation to open */ QList<Kopete::Message>::iterator it; for (it = convdata->queue->begin(); it != convdata->queue->end(); ++it) { mwConversation_send(conv, mwImSend_PLAIN, (*it).plainBody().toAscii()); convdata->chat->appendMessage(*it); convdata->chat->messageSucceeded(); } convdata->queue->clear(); delete convdata->queue; convdata->queue = 0L; } resolveContactNickname(convdata->contact); }
HANDLE SendMessageToUserW(HANDLE hContact, wchar_t *msg) { mwIdBlock idb; mwAwareIdBlock id_block; char text[MAX_MESSAGE_SIZE]; WideCharToMultiByte(CP_UTF8, 0, msg, -1, text, MAX_MESSAGE_SIZE * sizeof(char), 0, 0); if(GetAwareIdFromContact(hContact, &id_block)) { idb.user = id_block.user; idb.community = id_block.community; mwConversation *conv = mwServiceIm_getConversation(service_im, &idb); if(conv) { if(!mwConversation_isOpen(conv)) { EnterCriticalSection(&q_cs); contact_message_queue[hContact].push(text); LeaveCriticalSection(&q_cs); mwConversation_open(conv); } else mwConversation_send(conv, mwImSend_PLAIN, (gconstpointer)text); free(id_block.user); return (HANDLE)conv; } free(id_block.user); } return 0; }
void mwIm_conversation_opened(mwConversation *conv) { mwIdBlock *idb = mwConversation_getTarget(conv); HANDLE hContact = FindContactByUserId(idb->user); if(!hContact) { mwSametimeList *user_list = mwSametimeList_new(); mwSametimeGroup *stgroup = mwSametimeGroup_new(user_list, mwSametimeGroup_NORMAL, Translate("None")); mwSametimeUser *stuser = mwSametimeUser_new(stgroup, mwSametimeUser_NORMAL, idb); AddContact(stuser, (options.add_contacts ? false : true)); GetMoreDetails(idb->user); } ContactMessageQueue::iterator i; EnterCriticalSection(&q_cs); if((i = contact_message_queue.find(hContact)) != contact_message_queue.end()) { while(i->second.size()) { mwConversation_send(conv, mwImSend_PLAIN, (gconstpointer)i->second.front().c_str()); i->second.pop(); } contact_message_queue.erase(i); } LeaveCriticalSection(&q_cs); // gives linker error 'unresolved external symbol' :( So instead we will either add ciphers to the session or not (see session.cpp) //mwConversation_setEncrypted(conv, options.encrypt_session); }
void MeanwhileSession::sendTyping(MeanwhileContact *contact, bool isTyping) { HERE; struct mwIdBlock target = { strdup(contact->meanwhileId().toAscii()), 0L }; struct mwConversation *conv; conv = mwServiceIm_getConversation(imService, &target); free(target.user); if (conv == 0L) return; if (mwConversation_isOpen(conv)) mwConversation_send(conv, mwImSend_TYPING, (void *)isTyping); }
int MeanwhileSession::sendMessage(Kopete::Message &message) { HERE; MeanwhileContact *contact = static_cast<MeanwhileContact *>(message.to().first()); if (!contact) { mwDebug() << "No target for message!" <<endl; return 0; } struct mwIdBlock target = { strdup(contact->meanwhileId().toAscii()), 0L }; struct mwConversation *conv; conv = mwServiceIm_getConversation(imService, &target); free(target.user); if (conv == 0L) { mwDebug() << "No target for conversation with '" << contact->meanwhileId() << "'" << endl; return 0; } struct ConversationData *convdata = (struct ConversationData *) mwConversation_getClientData(conv); if (convdata == 0L) { convdata = createConversationData(conv, contact, true); if (convdata == 0L) { mwDebug() << "No memory for conversation data!" << endl; return 0; } } /* if there's other messages in the queue, or the conversation isn't open, * then append to the queue instead of sending right away */ if ((convdata->queue && !convdata->queue->isEmpty()) || !mwConversation_isOpen(conv)) { convdata->queue->append(message); mwConversation_open(conv); } else if (!mwConversation_send(conv, mwImSend_PLAIN, message.plainBody().toAscii())) { convdata->chat->appendMessage(message); convdata->chat->messageSucceeded(); } return 1; }
void SendTyping(HANDLE hContact, bool typing) { mwIdBlock idb; mwAwareIdBlock id_block; if(GetAwareIdFromContact(hContact, &id_block)) { idb.user = id_block.user; idb.community = id_block.community; mwConversation *conv = mwServiceIm_getConversation(service_im, &idb); if(conv) { if(mwConversation_isOpen(conv)) mwConversation_send(conv, mwImSend_TYPING, (gconstpointer)GUINT_TO_POINTER(typing ? 1 : 0)); } free(id_block.user); } }