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; }
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; }