bool DeclarativeGroupManager::setEventStatus(int eventId, int status) { SingleEventModel model; if (!model.getEventById(eventId)) { qWarning() << Q_FUNC_INFO << "No event with id" << eventId; return false; } Event ev = model.event(model.index(0, 0)); if (ev.status() == status) return true; ev.setStatus(static_cast<Event::EventStatus>(status)); return model.modifyEvent(ev); }
void MmsHandler::messageReceiveStateChanged(const QString &recId, int state) { Event event; SingleEventModel model; if (model.getEventById(recId.toInt())) event = model.event(model.index(0, 0)); if (!event.isValid()) { qWarning() << "Ignoring MMS message receive state for unknown event" << recId; m_activeEvents.removeOne(recId.toInt()); return; } Event::EventStatus newStatus = event.status(); switch (state) { case Deferred: newStatus = Event::WaitingStatus; break; case Receiving: case Decoding: newStatus = Event::DownloadingStatus; break; case NoSpace: case RecvError: // Avoid overwriting the status for cancelled receive calls if (event.status() == Event::ManualNotificationStatus) return; newStatus = Event::TemporarilyFailedStatus; break; case Garbage: newStatus = Event::PermanentlyFailedStatus; break; } if (newStatus != event.status()) { event.setStatus(newStatus); if (!model.modifyEvent(event)) qWarning() << "Failed updating MMS event status for" << recId; if (newStatus != Event::WaitingStatus && newStatus != Event::DownloadingStatus) { m_activeEvents.removeOne(event.id()); NotificationManager::instance()->showNotification(event, event.remoteUid(), Group::ChatTypeP2P); } } }
void SingleEventModelTest::updateStatus() { SingleEventModel model; watcher.setModel(&model); SingleEventModel observer; ModelWatcher watcherObserver; watcherObserver.setModel(&observer); Event event; event.setType(Event::SMSEvent); event.setDirection(Event::Outbound); event.setLocalUid("/org/freedesktop/Telepathy/Account/gabble/jabber/dut_40localhost0"); event.setGroupId(group1.id()); event.setFreeText("freeText"); event.setStartTime(QDateTime::currentDateTime()); event.setEndTime(QDateTime::currentDateTime()); event.setRemoteUid("123456"); event.setMessageToken("messageTokenB"); QVERIFY(model.addEvent(event)); watcher.waitForSignals(); QVERIFY(event.id() != -1); CommHistory::Event::PropertySet props = CommHistory::Event::PropertySet() << CommHistory::Event::Id << CommHistory::Event::Direction << CommHistory::Event::Status << CommHistory::Event::GroupId << CommHistory::Event::MessageToken << CommHistory::Event::ReportDelivery << CommHistory::Event::MmsId; model.setPropertyMask(props); QVERIFY(model.getEventByUri(event.url())); QVERIFY(watcher.waitForModelReady()); QCOMPARE(model.rowCount(), 1); Event modelEvent = model.event(model.index(0, 0)); QVERIFY(modelEvent.validProperties().contains(CommHistory::Event::Status)); QVERIFY(modelEvent.validProperties().contains(CommHistory::Event::MessageToken)); QVERIFY(!modelEvent.validProperties().contains(CommHistory::Event::FreeText)); QVERIFY(!modelEvent.validProperties().contains(CommHistory::Event::ContactId)); QCOMPARE(event.status(), modelEvent.status()); QCOMPARE(event.messageToken(), modelEvent.messageToken()); // init observer model with the same event and all properties QVERIFY(observer.getEventByUri(event.url())); QVERIFY(watcherObserver.waitForModelReady()); QCOMPARE(observer.rowCount(), 1); Event observedEvent = observer.event(observer.index(0, 0)); QVERIFY(compareEvents(event, observedEvent)); // modify event with new status only modelEvent.setStatus(Event::SentStatus); QVERIFY(model.modifyEvent(modelEvent)); watcher.waitForSignals(); QCOMPARE(watcher.updatedCount(), 1); QCOMPARE(watcher.committedCount(), 1); //check observer model QTest::qWait(100); observedEvent = observer.event(observer.index(0, 0)); QCOMPARE(observedEvent.freeText(), event.freeText()); QCOMPARE(observedEvent.status(), Event::SentStatus); }
void MmsHandler::messageReceived(const QString &recId, const QString &mmsId, const QString &from, const QStringList &to, const QStringList &cc, const QString &subj, uint date, int priority, const QString &cls, bool readReport, MmsPartList parts) { Event event; SingleEventModel model; if (model.getEventById(recId.toInt())) event = model.event(model.index(0, 0)); m_activeEvents.removeOne(recId.toInt()); if (!event.isValid()) { // Create new event event.setType(Event::MMSEvent); event.setEndTime(QDateTime::currentDateTime()); event.setDirection(Event::Inbound); event.setLocalUid(RING_ACCOUNT_PATH); event.setRemoteUid(from); if (!setGroupForEvent(event)) { qCritical() << "Failed to handle group for MMS received event; message dropped:" << event.toString(); return; } } // Update event properties event.setSubject(subj); event.setStartTime(QDateTime::fromTime_t(date)); event.setMmsId(mmsId); event.setToList(to); event.setCcList(cc); event.setReportRead(readReport); event.setStatus(Event::ReceivedStatus); Q_UNUSED(priority); Q_UNUSED(cls); // Remove MMS notification properties event.setExtraProperty("mms-notification-imsi", QVariant()); event.setExtraProperty("mms-expiry", QVariant()); event.setExtraProperty("mms-push-data", QVariant()); // Change UID/group if necessary if (event.remoteUid() != from) { int oldGroup = event.groupId(); event.setRemoteUid(from); if (!setGroupForEvent(event)) qCritical() << "Failed handling group for MMS received event"; if (oldGroup != event.groupId()) { int newGroup = event.groupId(); event.setGroupId(oldGroup); if (!model.moveEvent(event, newGroup)) qCritical() << "Failed moving MMS received event from group" << oldGroup << "to" << newGroup << event.toString(); event.setGroupId(newGroup); } } // If there wasn't a matching notification, save first to get the event ID before message parts if (event.id() < 0 && !model.addEvent(event)) { qCritical() << "Failed adding MMS received event; message dropped: " << event.toString(); return; } QList<MessagePart> eventParts; QString freeText; bool ok = copyMmsPartFiles(parts, event.id(), eventParts, freeText); if (ok) { event.setMessageParts(eventParts); event.setFreeText(freeText); if (!model.modifyEvent(event)) { qCritical() << "Failed updating MMS received event:" << event.toString(); ok = false; } } if (!ok) { // Clean up copied MMS parts, and try to set TemporarilyFailed on the event foreach (const MessagePart &part, eventParts) QFile::remove(part.path()); // Re-query event to avoid wiping out notification data if (model.getEventById(event.id())) { event = model.event(model.index(0, 0)); if (event.isValid()) { event.setStatus(Event::TemporarilyFailedStatus); model.modifyEvent(event); NotificationManager::instance()->showNotification(event, from, Group::ChatTypeP2P); } } return; }