//	Return true if the poll was successfully started.
bool
CEventBallotPoll::FStartPoll()
	{
	m_tsStopped = d_ts_zNA;		// Clear this variable in case it is a resume of a poll
	m_uFlagsBallot &= ~FB_kfStopAcceptingVotes;
	if (m_tsStarted == d_ts_zNA)
		{
		Assert(m_pEventBallotSent == NULL);
		ITreeItemChatLogEvents * pGroup = PGetGroupTarget_YZ();
		if (pGroup == NULL)
			return false;
		m_tsStarted = Timestamp_GetCurrentDateTime();

		// To send a poll, we need to clone the template and add it to the Chat Log of the group (or contact)
		m_pEventBallotSent = new CEventBallotSent(IN &m_tsStarted);		// Create a ballot with the same Event ID
		m_pEventBallotSent->Event_InitFromDataOfEvent(this);
		m_pEventBallotSent->m_uFlagsBallot |= FB_kfFromBallotmaster;
		pGroup->Vault_AddEventToChatLogAndSendToContacts(PA_CHILD m_pEventBallotSent);
		if (m_cSecondsPollLength > 0)
			{
			TimerQueue_CallbackAdd(m_cSecondsPollLength, TimerQueueCallback_PollStop, this);
			//TimerQueue_DisplayToMessageLog();
			}
		}
	return true;
	}
//	CServiceBallotmaster::IXmlExchange::XmlExchange()
void
CServiceBallotmaster::XmlExchange(INOUT CXmlExchanger * pXmlExchanger)
	{
	IService::XmlExchange(pXmlExchanger);
	m_oVaultBallots.XmlExchange("Ballots", INOUT pXmlExchanger);
	if (pXmlExchanger->m_fSerializing)
		return;
	// Initialize the timers for polls to automatically stop
	TIMESTAMP tsNow = Timestamp_GetCurrentDateTime();
	IEvent ** ppEventStop;
	IEvent ** ppEvent = m_oVaultBallots.m_arraypaEvents.PrgpGetEventsStop(OUT &ppEventStop);
	while (ppEvent != ppEventStop)
		{
		CEventBallotPoll * pEventBallotPoll = (CEventBallotPoll *)*ppEvent++;
		Assert(pEventBallotPoll->EGetEventClass() == CEventBallotPoll::c_eEventClass);
		if (pEventBallotPoll->m_tsStarted != d_ts_zNA && pEventBallotPoll->m_tsStopped == d_ts_zNA && pEventBallotPoll->m_cSecondsPollLength > 0)
			{
			TIMESTAMP tsStop = pEventBallotPoll->m_tsStarted + pEventBallotPoll->m_cSecondsPollLength * (TIMESTAMP_DELTA)d_ts_cSeconds;
			TIMESTAMP_DELTA dtsStopping = tsStop - tsNow;	// If this value is negative, it means the poll 'stopped' while SocietyPro was not running.
			if (dtsStopping < 10 * d_ts_cMinutes)
				dtsStopping = 10 * d_ts_cMinutes;	// Make the poll has a minimum of 10 minutes to run so it may collect all pending votes before closing
			MessageLog_AppendTextFormatSev(eSeverityNoise, "Poll ID $t which started on {tL} lasting $I seconds will automatically stop at {tL} in $I seconds ($T).\n", pEventBallotPoll->m_tsEventID, pEventBallotPoll->m_tsStarted, pEventBallotPoll->m_cSecondsPollLength, tsStop, (int)(dtsStopping / d_ts_cSeconds), dtsStopping);
			TimerQueue_CallbackAdd(dtsStopping / d_ts_cSeconds, TimerQueueCallback_PollStop, pEventBallotPoll);
			}
		} // while
	TimerQueue_DisplayToMessageLog();
	} // XmlExchange()
Пример #3
0
TContact *
TAccountXmpp::TreeItemAccount_PContactAllocateNewToNavigationTree_NZ(PSZUC pszContactJID, PSZUC pszContactNameDisplay)
	{
	Assert(pszContactJID != NULL);
	Endorse(pszContactNameDisplay == NULL);	// Automatically generate a display name
	Assert(Contact_PFindByJID(pszContactJID, eFindContact_zDefault) == NULL && "The JID is already present!");
	Assert(!m_strJID.FCompareStringsJIDs(pszContactJID) && "The contact JID is the same as the JID of the XMPP account!");
	Assert(m_paTreeItemW_YZ != NULL && "No Tree Item to attach to");	// This line of code has to be revised
	TContact * pContact = new TContact(this);
	pContact->m_strRessource = pContact->m_strJidBare.AppendTextUntilCharacterPszr(pszContactJID, '/');
	pContact->m_strNameDisplayTyped = pszContactNameDisplay;
	pContact->TreeItemContact_GenerateDisplayNameFromJid();
	m_arraypaContacts.Add(PA_CHILD pContact);
	#ifdef WANT_TREE_NODE_NEW_CONTACT
	pContact->TreeItemW_DisplayWithinNavigationTreeBefore(m_pTreeItemContactNew);
	#else
	pContact->TreeItemW_DisplayWithinNavigationTree(this);
	#endif
	pContact->TreeItemContact_UpdateIcon();
	pContact->TreeItemW_EnsureVisible();	// Make sure the new contact is visible in the Navigation Tree
	pContact->m_tsCreated = Timestamp_GetCurrentDateTime();
	if (m_paSocket != NULL)
		Contact_RosterSubscribe(pContact);
	Configuration_Save();		// Save the configuration after adding a new contact (just in case the application crashes)
	TWallet::S_ContactAdded(pContact);	// Notify the wallet(s) there is a new contact
	return pContact;
	}
Пример #4
0
void
CArrayPtrErrors::AddError_UI(const CBin * pbinError)
	{
	int cbError = pbinError->CbGetData();
	SErrorLogEntry * paError = (SErrorLogEntry *)new CHU[sizeof(SErrorLogEntryHeaderOnly) + cbError];
	memcpy(OUT paError->szmError, IN pbinError->PvGetData(), cbError);
	paError->tsError = Timestamp_GetCurrentDateTime();
	if (Add(PA_CHILD paError) > 100)
		delete (SErrorLogEntry *)RemoveElementFirstPv();	// Make sure we keep only the last 100 errors
	g_oErrorLog.AppendTextError(IN paError);
	}
void
CEventBallotPoll::StopPoll()
	{
	Assert(EGetEventClass() == c_eEventClass);
	MessageLog_AppendTextFormatSev(eSeverityNoise, "Stopping Poll ID $t\n", m_tsEventID);
	m_uFlagsBallot |= FB_kfStopAcceptingVotes;
	if (PGetEventBallotSend_YZ() != NULL)
		m_pEventBallotSent->m_uFlagsBallot |= FB_kfStopAcceptingVotes;
	if (m_tsStarted != d_ts_zNA && m_tsStopped == d_ts_zNA)
		{
		// Stop the poll if it was started and not already stopped
		m_tsStopped = Timestamp_GetCurrentDateTime();
		// Notify each Ballotmaster about the poll stopped
		OJapiAppBallotmaster * pBallotmaster = OJapiAppBallotmaster::s_plistBallotmasters;
		while (pBallotmaster != NULL)
			{
			pBallotmaster->OnEventPollStopped(this);
			pBallotmaster = pBallotmaster->m_pNext;
			}
		}
	}
Пример #6
0
//	For debugging
void
CListTasksSendReceive::DisplayTasksToMessageLog()
	{
	int cTasks = 0;
	TIMESTAMP tsNow = Timestamp_GetCurrentDateTime();
	CTaskSendReceive * pTask = m_plistTasks;
	while (pTask != NULL)
		{
		TIMESTAMP_DELTA dts = tsNow - pTask->m_tsTaskID;
		const int cbXmlData = pTask->m_binXmlData.CbGetData();
		if (pTask->FIsTaskSend())
			MessageLog_AppendTextFormatCo(d_coPurple, "\t [$T] Sending Task ID $t: $I bytes\n", dts, pTask->m_tsTaskID, cbXmlData);
		else
			MessageLog_AppendTextFormatCo(d_coPurple, "\t [$T] Downloading Task ID $t: cbTotalToDownload = $I, cbDownloadedSoFar = $I\n", dts, pTask->m_tsTaskID, pTask->m_cbTotal, cbXmlData);
		if (cbXmlData > 0) // && cbXmlData < 200)
			MessageLog_AppendTextFormatCo(d_coGray, "\t\t {Bm}\n", &pTask->m_binXmlData);
		pTask = pTask->m_pNext;
		cTasks++;
		} // while
	if (cTasks >= 3)
		MessageLog_AppendTextFormatCo(COX_MakeBold(d_coPurple), "\t\t Total of $i tasks\n", cTasks);
	}
Пример #7
0
void
CTaskSendReceive::InitTaskSend()
	{
	m_tsTaskID = Timestamp_GetCurrentDateTime();
	m_cbTotal = c_cbTotal_TaskSendAndRetry;		// By default a task will be retried to be sent
	}
Пример #8
0
void
TContact::Vault_XmppAllocateEventMessageReceivedAndDisplayToChatLog(const CXmlNode * pXmlNodeMessageStanza, PSZUC pszuMessageBody, HChatLog * pwChatLog)
	{
	Assert(pXmlNodeMessageStanza != NULL);
	Assert(pszuMessageBody != NULL);
	Assert(pwChatLog != NULL);
	// First thing is to determine if the message is a duplicate/update of another message
	TIMESTAMP tsMessageWritten = pXmlNodeMessageStanza->LFindAttributeValueIdTimestamp_ZZR();	// Get the timestamp of when the message was written
	if (tsMessageWritten > 0)
		{
		CEventMessageTextReceived * pEvent = Vault_PGet_NZ()->m_arraypaEvents.PFindEventMessageReceivedByTimestamp(tsMessageWritten);
		if (pEvent != NULL)
			{
			if (pEvent->m_strMessageText.FCompareStringsExactCase(pszuMessageBody))
				{
				// The event contains the exact same text as before, so assume it is a duplicate
				MessageLog_AppendTextFormatSev(eSeverityComment, "Ignoring duplicate message ID '$t': $s\n", tsMessageWritten, pszuMessageBody);
				return;
				}
			// The message is not a duplicate, so update it in the GUI only if NOT older than 10 minutes, otherwise display it as a new message
			TIMESTAMP_DELTA dtsDelaySinceMessageWasWritten = Timestamp_GetCurrentDateTime() - pEvent->m_tsEventID;
			Assert(dtsDelaySinceMessageWasWritten > 0);
			if (dtsDelaySinceMessageWasWritten < d_ts_cMinutes * 10)
				{
				MessageLog_AppendTextFormatSev(eSeverityComment, "Updating message ID '$t' which was written $L seconds ago.\n", pEvent->m_tsEventID, dtsDelaySinceMessageWasWritten / d_ts_cSeconds);
				pEvent->MessageUpdated(pszuMessageBody, INOUT pwChatLog);
				return;
				}
			MessageLog_AppendTextFormatSev(eSeverityWarning, "Ignoring the update of message ID '$t' because its timestamp is too old (the message was written $L minutes ago).\n", pEvent->m_tsEventID, dtsDelaySinceMessageWasWritten / d_ts_cMinutes);
			} // if (event)
		}
	CEventMessageTextReceived * pEvent = new CEventMessageTextReceived(NULL);
	if (tsMessageWritten != d_ts_zNULL)
		pEvent->m_tsOther = tsMessageWritten;
	else
		pEvent->m_tsOther = pEvent->m_tsEventID;	// Use the same timestamp
	pEvent->m_strMessageText = pszuMessageBody;
	const CXmlNode * pXmlNodeHtml = pXmlNodeMessageStanza->PFindElement("html");
	if (pXmlNodeHtml != NULL)
		{
		const CXmlNode * pXmlNodeBody = pXmlNodeHtml->PFindElement(c_sza_body);
		if (pXmlNodeBody != NULL)
			{
			// At the moment, the only element we are supporting is <p>, however if we discover other HTML formats, we will suppor them
			CXmlNode * pXmlNodeP = pXmlNodeBody->PFindElement("p");
			if (pXmlNodeP != NULL)
				{
				// At this point the HTML message has been parsed into XML nodes, so we have to serialize the nodes to get an HTML string.
				pXmlNodeP->m_pszuTagName = (PSZU)c_szuEmpty;	// Remove the name so the <p> </p> will not be serialized
				pEvent->m_strMessageText.Empty();
				pXmlNodeP->SerializeToBinUtf8(OUT &pEvent->m_strMessageText, CXmlNode::STBF_kfCRLF);
				pEvent->m_strMessageText.BinAppendNullTerminatorSz();
				pEvent->m_uFlagsMessage |= CEventMessageTextReceived::FM_kfMessageHtml;
				MessageLog_AppendTextFormatCo(d_coGray, "Html Message: $S\n", &pEvent->m_strMessageText);
				}
			}
		}
	//Vault_AddEventToChatLogAndSendToContacts(PA_CHILD pEvent);
	//pEvent->EventAddToVault(PA_PARENT Vault_PGet_NZ());
	Vault_PGet_NZ()->EventAdd(PA_CHILD pEvent);
	#ifdef COMPILE_WITH_CHATLOG_HTML
	pwChatLog->ChatLog_EventAppend(IN pEvent);
	#else
	pwChatLog->ChatLog_EventDisplay(IN pEvent);
	#endif
	} // Event_AllocateEventMessageReceivedAndDisplayToChatLog()