/** * @brief Fetches chat messages counts for each day from the database. * @param friendPk Friend public key to fetch. * @param from Start of period to fetch. * @param to End of period to fetch. * @return List of structs containing days offset and message count for that day. */ QList<History::DateMessages> History::getChatHistoryCounts(const ToxPk& friendPk, const QDate& from, const QDate& to) { if (!isValid()) { return {}; } QDateTime fromTime(from); QDateTime toTime(to); QList<DateMessages> counts; auto rowCallback = [&counts](const QVector<QVariant>& row) { DateMessages app; app.count = row[0].toUInt(); app.offsetDays = row[1].toUInt(); counts.append(app); }; QString queryText = QString("SELECT COUNT(history.id), ((timestamp / 1000 / 60 / 60 / 24) - %4 ) AS day " "FROM history " "JOIN peers chat ON chat_id = chat.id " "WHERE timestamp BETWEEN %1 AND %2 AND chat.public_key='%3'" "GROUP BY day;") .arg(fromTime.toMSecsSinceEpoch()) .arg(toTime.toMSecsSinceEpoch()) .arg(friendPk.toString()) .arg(QDateTime::fromMSecsSinceEpoch(0).daysTo(fromTime)); db->execNow({queryText, rowCallback}); return counts; }
// --------------------------------------------------------------------------- // TPresCondValidity::IsTimeValidL() // --------------------------------------------------------------------------- // EXPORT_C TBool TPresCondValidity::IsTimeValidL(const TDesC& aRuleID, const TTimePeriod aTime) { OPENG_DP(D_OPENG_LIT( "TPresCondValidity::IsTimeValid()" ) ); OPENG_DP(D_OPENG_LIT( " aRuleID = %S"),&aRuleID); OPENG_DP(D_OPENG_LIT( " from:")); LogDateTime(aTime.from); OPENG_DP(D_OPENG_LIT( " until:")); LogDateTime(aTime.until); CXdmDocumentNode* validityNode = GetValidityNodeL(aRuleID, EFalse); if (validityNode==NULL) return ETrue; // because all times are valid if no validity node TBool result(EFalse); RArray<TTimePeriod> validTimes; GetValidityL(aRuleID, validTimes); TTime givenfromTime(aTime.from); TTime givenuntilTime(aTime.until); TInt validTimeCounts = validTimes.Count(); for(TInt i=0; i<validTimeCounts; i++) { TTime fromTime((validTimes[i]).from); TTime untilTime((validTimes[i]).until); if( (givenfromTime>=fromTime) && (givenuntilTime<=untilTime) ) { result = ETrue; break; } } validTimes.Close(); OPENG_DP(D_OPENG_LIT( " result = %d"),result); return result; }
// --------------------------------------------------------------------------- // TPresCondValidity::GetValidity() // --------------------------------------------------------------------------- // EXPORT_C TInt TPresCondValidity::GetValidityL(const TDesC& aRuleID, RArray<TTimePeriod>& aValidTimes) { OPENG_DP(D_OPENG_LIT( "TPresCondValidity::GetValidity()" ) ); OPENG_DP(D_OPENG_LIT( " aRuleID = %S"),&aRuleID); CXdmDocumentNode* validityNode = GetValidityNodeL(aRuleID, EFalse); if(validityNode==NULL) return KErrNotFound; TInt nodeCount = validityNode->NodeCount(); OPENG_DP(D_OPENG_LIT( " validityNode->NodeCount() = %d"),nodeCount); if(!nodeCount) return KErrNotFound; RPointerArray<CXdmDocumentNode> fromNodes; RPointerArray<CXdmDocumentNode> untilNodes; HBufC* fromPtr(NULL); HBufC* untilPtr(NULL); TTime fromTime(0); TTime untilTime(0); TTimePeriod myTimePeriod; // Get all the <from> nodes validityNode->Find(KXdmFrom, fromNodes); validityNode->Find(KXdmUntil, untilNodes); if((fromNodes.Count()) != (untilNodes.Count())) { fromNodes.Close(); untilNodes.Close(); return KErrGeneral; } nodeCount = fromNodes.Count(); OPENG_DP(D_OPENG_LIT( " nodesCount = %d" ),nodeCount); for(TInt i=0; i<nodeCount; i++) { aValidTimes.Append(myTimePeriod); // processing from (fromNodes[i])->SetLeafNode(ETrue); fromPtr = CnvUtfConverter::ConvertToUnicodeFromUtf8L((fromNodes[i])->LeafNodeContent()); CleanupStack::PushL(fromPtr); OPENG_DP(D_OPENG_LIT( " from string at i(%d): %S" ),i,&(*fromPtr)); ParseFromXMLTimeString(fromPtr->Des(), fromTime); CleanupStack::PopAndDestroy(fromPtr); ConvertToLocal(fromTime); ((aValidTimes[i]).from).Set(fromTime.DateTime().Year(),fromTime.DateTime().Month(), fromTime.DateTime().Day(),fromTime.DateTime().Hour(),fromTime.DateTime().Minute(), fromTime.DateTime().Second(), fromTime.DateTime().MicroSecond()); OPENG_DP(D_OPENG_LIT( " from at i = %d" ),i); LogDateTime((aValidTimes[i]).from); // processing until (untilNodes[i])->SetLeafNode(ETrue); untilPtr = CnvUtfConverter::ConvertToUnicodeFromUtf8L((untilNodes[i])->LeafNodeContent()); CleanupStack::PushL(untilPtr); OPENG_DP(D_OPENG_LIT( " until string at i(%d): %S" ),i,&(*untilPtr)); ParseFromXMLTimeString(untilPtr->Des(), untilTime); CleanupStack::PopAndDestroy(untilPtr); ConvertToLocal(untilTime); (aValidTimes[i]).until.Set(untilTime.DateTime().Year(),untilTime.DateTime().Month(), untilTime.DateTime().Day(),untilTime.DateTime().Hour(),untilTime.DateTime().Minute(), untilTime.DateTime().Second(),untilTime.DateTime().MicroSecond()); OPENG_DP(D_OPENG_LIT( " until at i = %d" ),i); LogDateTime((aValidTimes[i]).until); } fromNodes.Close(); untilNodes.Close(); return KErrNone; }