void FacebookChatService::removeOldUndeliveredMessages() { auto now = QDateTime::currentDateTime(); auto it = m_undeliveredMessages.begin(); auto removedMessages = std::vector<Message>{}; while (it != m_undeliveredMessages.end()) if (it->second.sendDate().addSecs(60) < now) { removedMessages.push_back(it->second); it = m_undeliveredMessages.erase(it); } else ++it; for (auto const &message : removedMessages) { message.setStatus(MessageStatusWontDeliver); emit sentMessageStatusChanged(message); } }
MorseTextChannel::MorseTextChannel(CTelegramCore *core, Tp::BaseChannel *baseChannel, uint selfHandle, const QString &selfID) : Tp::BaseChannelTextType(baseChannel), m_targetHandle(baseChannel->targetHandle()), m_selfHandle(selfHandle), m_targetID(baseChannel->targetID()), m_selfID(selfID), m_localTypingTimer(0) { m_core = core; QStringList supportedContentTypes = QStringList() << QLatin1String("text/plain"); Tp::UIntList messageTypes = Tp::UIntList() << Tp::ChannelTextMessageTypeNormal << Tp::ChannelTextMessageTypeDeliveryReport; uint messagePartSupportFlags = 0; uint deliveryReportingSupport = Tp::DeliveryReportingSupportFlagReceiveSuccesses|Tp::DeliveryReportingSupportFlagReceiveRead; setMessageAcknowledgedCallback(Tp::memFun(this, &MorseTextChannel::messageAcknowledgedCallback)); m_messagesIface = Tp::BaseChannelMessagesInterface::create(this, supportedContentTypes, messageTypes, messagePartSupportFlags, deliveryReportingSupport); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(m_messagesIface)); m_messagesIface->setSendMessageCallback(Tp::memFun(this, &MorseTextChannel::sendMessageCallback)); m_chatStateIface = Tp::BaseChannelChatStateInterface::create(); m_chatStateIface->setSetChatStateCallback(Tp::memFun(this, &MorseTextChannel::setChatState)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(m_chatStateIface)); #if TP_QT_VERSION >= TP_QT_VERSION_CHECK(0, 9, 7) if (baseChannel->targetHandleType() == Tp::HandleTypeRoom) { Tp::ChannelGroupFlags groupFlags = Tp::ChannelGroupFlagProperties; // Permissions: groupFlags |= Tp::ChannelGroupFlagCanAdd; m_groupIface = Tp::BaseChannelGroupInterface::create(); //Tp::ChannelGroupFlagChannelSpecificHandles m_groupIface->setGroupFlags(groupFlags); m_groupIface->setSelfHandle(m_selfHandle); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(m_groupIface)); TelegramNamespace::GroupChat info; quint32 chatId = CTelegramCore::identifierToChatId(m_targetID); m_core->getChatInfo(&info, chatId); QDateTime creationTimestamp; if (info.date) { creationTimestamp.setTime_t(info.date); } m_roomIface = Tp::BaseChannelRoomInterface::create(/* roomName */ m_targetID, /* server */ QString(), /* creator */ QString(), /* creatorHandle */ 0, creationTimestamp); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(m_roomIface)); m_roomConfigIface = Tp::BaseChannelRoomConfigInterface::create(); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(m_roomConfigIface)); } #endif connect(m_core.data(), SIGNAL(contactTypingStatusChanged(QString,bool)), SLOT(whenContactChatStateComposingChanged(QString,bool))); connect(m_core.data(), SIGNAL(sentMessageStatusChanged(QString,quint64,TelegramNamespace::MessageDeliveryStatus)), SLOT(sentMessageDeliveryStatusChanged(QString,quint64,TelegramNamespace::MessageDeliveryStatus))); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_contactsModel(new CContactsModel(this)), m_messagingModel(new CMessagingModel(this)), m_chatContactsModel(new CContactsModel(this)), m_chatMessagingModel(new CMessagingModel(this)), m_chatInfoModel(new CChatInfoModel(this)), m_activeChatId(0), m_chatCreationMode(false), m_core(new CTelegramCore(this)), m_registered(false), m_appState(AppStateNone) { ui->setupUi(this); ui->contactListTable->setModel(m_contactsModel); ui->messagingView->setModel(m_messagingModel); ui->groupChatContacts->setModel(m_chatContactsModel); ui->groupChatChatsList->setModel(m_chatInfoModel); ui->groupChatMessagingView->setModel(m_chatMessagingModel); QCompleter *comp = new QCompleter(m_contactsModel, this); ui->messagingContactPhone->setCompleter(comp); ui->groupChatContactPhone->setCompleter(comp); connect(ui->secretOpenFile, SIGNAL(clicked()), SLOT(loadSecretFromBrowsedFile())); // Telepathy Morse app info CAppInformation appInfo; appInfo.setAppId(14617); appInfo.setAppHash(QLatin1String("e17ac360fd072f83d5d08db45ce9a121")); appInfo.setAppVersion(QLatin1String("0.1")); appInfo.setDeviceInfo(QLatin1String("pc")); appInfo.setOsInfo(QLatin1String("GNU/Linux")); appInfo.setLanguageCode(QLatin1String("en")); m_core->setAppInformation(&appInfo); m_core->setAutoReconnection(true); connect(m_core, SIGNAL(connectionStateChanged(TelegramNamespace::ConnectionState)), SLOT(whenConnectionStateChanged(TelegramNamespace::ConnectionState))); connect(m_core, SIGNAL(phoneStatusReceived(QString,bool,bool)), SLOT(whenPhoneStatusReceived(QString,bool,bool))); connect(m_core, SIGNAL(phoneCodeRequired()), SLOT(whenPhoneCodeRequested())); connect(m_core, SIGNAL(authSignErrorReceived(TelegramNamespace::AuthSignError,QString)), SLOT(whenAuthSignErrorReceived(TelegramNamespace::AuthSignError,QString))); connect(m_core, SIGNAL(contactListChanged()), SLOT(whenContactListChanged())); connect(m_core, SIGNAL(contactProfileChanged(QString)), SLOT(whenContactProfileChanged(QString))); connect(m_core, SIGNAL(avatarReceived(QString,QByteArray,QString,QString)), SLOT(whenAvatarReceived(QString,QByteArray,QString))); connect(m_core, SIGNAL(messageMediaDataReceived(QString,quint32,QByteArray,QString,TelegramNamespace::MessageType,quint32,quint32)), SLOT(whenMessageMediaDataReceived(QString,quint32,QByteArray,QString,TelegramNamespace::MessageType,quint32,quint32))); connect(m_core, SIGNAL(messageReceived(TelegramNamespace::Message)), SLOT(whenMessageReceived(TelegramNamespace::Message))); connect(m_core, SIGNAL(contactChatTypingStatusChanged(quint32,QString,bool)), SLOT(whenContactChatTypingStatusChanged(quint32,QString,bool))); connect(m_core, SIGNAL(contactTypingStatusChanged(QString,bool)), SLOT(whenContactTypingStatusChanged(QString,bool))); connect(m_core, SIGNAL(contactStatusChanged(QString,TelegramNamespace::ContactStatus)), SLOT(whenContactStatusChanged(QString))); connect(m_core, SIGNAL(sentMessageStatusChanged(QString,quint64,TelegramNamespace::MessageDeliveryStatus)), m_messagingModel, SLOT(setMessageDeliveryStatus(QString,quint64,TelegramNamespace::MessageDeliveryStatus))); connect(m_core, SIGNAL(uploadingStatusUpdated(quint32,quint32,quint32)), SLOT(whenUploadingStatusUpdated(quint32,quint32,quint32))); connect(m_core, SIGNAL(chatAdded(quint32)), SLOT(whenChatAdded(quint32))); connect(m_core, SIGNAL(chatChanged(quint32)), SLOT(whenChatChanged(quint32))); ui->groupChatContacts->hideColumn(CContactsModel::Blocked); ui->mainSplitter->setSizes(QList<int>() << 0 << 100); ui->groupChatSplitter->setSizes(QList<int>() << 550 << 450 << 300); ui->groupChatChatsList->setColumnWidth(CChatInfoModel::Id, 30); ui->blockContact->hide(); ui->unblockContact->hide(); ui->groupChatLeaveChat->hide(); QFile helpFile(QLatin1String(":/USAGE")); helpFile.open(QIODevice::ReadOnly); ui->helpView->setPlainText(helpFile.readAll()); setAppState(AppStateNone); updateGroupChatAddContactButtonText(); connect(ui->groupChatContactPhone, SIGNAL(textChanged(QString)), SLOT(updateGroupChatAddContactButtonText())); #if QT_VERSION > QT_VERSION_CHECK(5, 0, 0) connect(ui->messagingView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(whenCustomMenuRequested(QPoint))); #endif ui->groupChatAddContactForwardMessages->hide(); ui->messagingAttachButton->hide(); }