Пример #1
0
/*
 * Unformat the from address - removes blanks and converts to lower case
 *
 *  see IMAddressFormatter.unformat() - palm.com.messaging.data
 */
MojErr IMMessage::unformatFromAddress(const MojString formattedScreenName, MojString& unformattedName) {

	if(!formattedScreenName.empty()) {
		MojVector<MojString> stringTokens;
		MojErr err = formattedScreenName.split(' ', stringTokens);
		MojErrCheck(err);

		MojVector<MojString>::ConstIterator itr = stringTokens.begin();
		while (itr != stringTokens.end()) {
			err = unformattedName.append(*itr);
			MojErrCheck(err);
			itr++;
		}
		err = unformattedName.toLower();
		MojErrCheck(err);
	}
	return MojErrNone;
}
Пример #2
0
MojErr MojDb::dumpObj(MojFile& file, MojObject obj, MojSize& bytesWrittenOut, MojUInt32 maxBytes)
{
	// remove the rev key before dumping the object
	bool found = false;
	MojErr err = obj.del(RevKey, found);
	MojErrCheck(err);

	MojString str;
	err = obj.toJson(str);
	MojErrCheck(err);
	err = str.append(_T("\n"));
	MojErrCheck(err);
	MojSize len = str.length() * sizeof(MojChar);
	// if writing this object will put us over the max length, throw an error
	if (maxBytes && bytesWrittenOut + len > maxBytes) {
		MojErrThrow(MojErrDbBackupFull);
	}
	err = file.writeString(str, bytesWrittenOut);
	MojErrCheck(err);

	return MojErrNone;
}
/**
 * Callback from the save buddy in buddyStatus DB call.
 *
 * Now save in contacts db
 */
MojErr SendOneCommandHandler::addBuddyResult(MojObject& result, MojErr saveErr)
{
	MojLogTrace(IMServiceApp::s_log);

	if (saveErr) {
		MojString error;
		MojErrToString(saveErr, error);
		MojLogError(IMServiceApp::s_log, _T("addBuddyResult failed. error %d - %s"), saveErr, error.data());
	}
	else {
		IMServiceHandler::logMojObjectJsonString(_T("addBuddyResult success: %s"), result);
	}

	// now add to contacts DB
	// create the DB object
	//{
	//    accountId:<>,
	//    displayName:<>,
	//    photos:[{localFilepath:<>}],
	//    ims:[{value:<>, type:<>}]
	// }
	MojObject contact;
	contact.putString("_kind", IM_CONTACT_KIND);
	contact.put("accountId", m_accountId);
	contact.put("remoteId", m_buddyName); // using username as remote ID since we don't have anything else and this should be unique

	// "ims" array
	MojObject newImsArray, newImObj;
	newImObj.put("value", m_buddyName);
	newImObj.put("type", m_serviceName);
	// Note we need this twice since some services look for "serviceName" and some look for "type"... Maybe we can evenutally standardize...
	newImObj.put("serviceName", m_serviceName);
	newImsArray.push(newImObj);
	contact.put("ims", newImsArray);

	// need to add email address too for contacts linker
	//    email:[{value:<>}]
	MojString emailAddr;
	bool validEmail = true;
	emailAddr.assign(m_buddyName.data());
	// for AIM, need to add back the "@aol.com" to the email
	if (MojInvalidIndex == m_buddyName.find('@')) {
		if (0 == m_serviceName.compare(SERVICENAME_AIM))
			emailAddr.append("@aol.com");
		else
			validEmail = false;
	}

	if (validEmail) {
		MojObject newEmailArray, newEmailObj;
		newEmailObj.put("value", emailAddr);
		newEmailArray.push(newEmailObj);
		contact.put("emails", newEmailArray);
	}

	// log it
	MojString json;
	contact.toJson(json);
	MojLogInfo(IMServiceApp::s_log, _T("saving contact to db: %s"), json.data());

	// save it
	// the save generates a call to the save result handler
	MojErr err = m_dbClient.put(this->m_addContactSlot, contact);
	if (err) {
		MojString error;
		MojErrToString(err, error);
		MojLogError(IMServiceApp::s_log, _T("addBuddyResult: dbClient.put() failed: error %d - %s"), err, error.data());
		// tell the outgoing Command handler we are done
		m_outgoingIMHandler->messageFinished();
	}

	return MojErrNone;
}