#include "context.h" #include #include #include Context::Context(QObject *parent) : QObject(parent) { } Context::Context(QObject *parent, dc_context_t *context) : QObject(parent) , m_context(context) { } Context::~Context() { dc_context_unref(m_context); } void Context::configure() { dc_configure(m_context); } bool Context::isConfigured() const { return dc_is_configured(m_context); } void Context::startIo() { dc_start_io(m_context); } void Context::stopIo() { dc_stop_io(m_context); } void Context::maybeNetwork() { dc_maybe_network(m_context); } QString Context::getInfo() { char *info = dc_get_info(m_context); QString result{info}; dc_str_unref(info); return result; } DcChatlist * Context::getChatlist(int flags, QString query) { QByteArray utf8Query = query.toUtf8(); dc_chatlist_t *chatlist = dc_get_chatlist( m_context, flags, query.isEmpty() ? nullptr : utf8Query.constData(), 0 ); return new DcChatlist{chatlist}; } uint32_t Context::createChatByContactId(uint32_t contactId) { return dc_create_chat_by_contact_id(m_context, contactId); } void Context::setChatVisibility(uint32_t chatId, int visibility) { dc_set_chat_visibility(m_context, chatId, visibility); } void Context::deleteChat(uint32_t chatId) { dc_delete_chat(m_context, chatId); } void Context::blockChat(uint32_t chatId) { dc_block_chat(m_context, chatId); } void Context::acceptChat(uint32_t chatId) { dc_accept_chat(m_context, chatId); } void Context::blockContact(uint32_t contactId, uint32_t blockMode) { dc_block_contact(m_context, contactId, blockMode); } QVariantMap Context::getBlockedContacts() { QVariantMap blockList; uint32_t CID; char *addr; dc_contact_t *contact; dc_array_t *blockedContacts = dc_get_blocked_contacts(m_context); size_t max = dc_array_get_cnt(blockedContacts); for (size_t i = 0; i < max; i++) { CID = dc_array_get_id(blockedContacts, i); contact = dc_get_contact(m_context, CID); addr = dc_contact_get_addr(contact); blockList.insert(addr, CID); dc_contact_unref(contact); dc_str_unref(addr); } dc_array_unref(blockedContacts); return blockList; } QString Context::getChatEncrinfo(uint32_t chatId) { char *encrinfo = dc_get_chat_encrinfo(m_context, chatId); QString result{encrinfo}; dc_str_unref(encrinfo); return result; } uint32_t Context::getChatEphemeralTimer(uint32_t chatId) { return dc_get_chat_ephemeral_timer(m_context, chatId); } DcChat * Context::getChat(uint32_t chatId) { dc_chat_t *chat = dc_get_chat(m_context, chatId); return new DcChat{chat}; } QVariantList Context::getMsgIdList(uint32_t chatId) { QVariantList result; dc_array_t *msgIdArray = dc_get_chat_msgs(m_context, chatId, 0, 0); for (size_t i = 0; i < dc_array_get_cnt(msgIdArray); i++) { result << dc_array_get_id(msgIdArray, i); } dc_array_unref(msgIdArray); return result; } QVariantList Context::getContacts(uint32_t flags, QString query) { QVariantList result; QByteArray utf8Query = query.toUtf8(); dc_array_t *contactsArray = dc_get_contacts(m_context, flags, utf8Query.constData()); for (size_t i = 0; i < dc_array_get_cnt(contactsArray); i++) { result << dc_array_get_id(contactsArray, i); } dc_array_unref(contactsArray); return result; } int Context::getFreshMsgCnt(uint32_t chatId) { return dc_get_fresh_msg_cnt(m_context, chatId); } void Context::marknoticedChat(uint32_t chatId) { return dc_marknoticed_chat(m_context, chatId); } void Context::markseenMsgs(QVector msg_ids) { dc_markseen_msgs(m_context, msg_ids.constData(), msg_ids.count()); } DcMessage * Context::getMessage(uint32_t msgId) { dc_msg_t *message = dc_get_msg(m_context, msgId); return new DcMessage{message}; } DcContact * Context::getContact(uint32_t contactId) { dc_contact_t *contact = dc_get_contact(m_context, contactId); return new DcContact{contact}; } uint32_t Context::createContact(QString name, QString addr) { QByteArray utf8name = name.toUtf8(); QByteArray utf8addr = addr.toUtf8(); return dc_create_contact(m_context, utf8name.constData(), utf8addr.constData()); } QString Context::getBlobdir() { char *blobdir = dc_get_blobdir(m_context); QString result{blobdir}; dc_str_unref(blobdir); return result; } bool Context::setConfig(QString key, QString value) { QByteArray utf8Key = key.toUtf8(); QByteArray utf8Value = value.toUtf8(); return dc_set_config(m_context, utf8Key.constData(), utf8Value.constData()); } QString Context::getConfig(QString key) { QByteArray utf8Key = key.toUtf8(); char *value = dc_get_config(m_context, utf8Key.constData()); QString result{value}; dc_str_unref(value); return result; } QString Context::getMessageInfo(uint32_t msgId) { char *info = dc_get_msg_info(m_context, msgId); QString result{info}; dc_str_unref(info); return result; } QString Context::getMessageHtml(uint32_t msgId) { char *html = dc_get_msg_html(m_context, msgId); QString result{html}; dc_str_unref(html); return result; } uint32_t Context::sendTextMessage(uint32_t chatId, QString textToSend) { QByteArray utf8Text = textToSend.toUtf8(); return dc_send_text_msg(m_context, chatId, utf8Text.constData()); } void Context::setDraft(uint32_t chatId, DcMessage *message) { dc_set_draft(m_context, chatId, message ? message->m_message : nullptr); } DcMessage * Context::getDraft(uint32_t chatId) { dc_msg_t *draft = dc_get_draft(m_context, chatId); if (draft) { return new DcMessage{draft}; } else { return NULL; } } bool Context::setChatMuteDuration(uint32_t chatId, int64_t duration) { return dc_set_chat_mute_duration(m_context, chatId, duration); } DcMessage * Context::newMessage(int viewtype) { dc_msg_t *message = dc_msg_new(m_context, viewtype); return new DcMessage{message}; } uint32_t Context::sendMessage(uint32_t chatId, DcMessage *message) { return dc_send_msg(m_context, chatId, message->m_message); } uint32_t Context::sendVChatInv(uint32_t chatId) { return dc_send_videochat_invitation(m_context, chatId); } void Context::importBackup(QString tarfile) { QByteArray utf8Text = tarfile.toUtf8(); return dc_imex(m_context, DC_IMEX_IMPORT_BACKUP, utf8Text.constData(), NULL); }