コード例 #1
0
ファイル: dropbox_utils.cpp プロジェクト: wyrover/miranda-ng
void CDropbox::SendToContact(MCONTACT hContact, const TCHAR *data)
{
	if (hContact == GetDefaultContact()) {
		char *message = mir_utf8encodeT(data);
		AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF, (DWORD)mir_strlen(message), (PBYTE)message);
		return;
	}

	const char *szProto = GetContactProto(hContact);
	if (db_get_b(hContact, szProto, "ChatRoom", 0) == TRUE) {
		ptrT tszChatRoom(db_get_tsa(hContact, szProto, "ChatRoomID"));
		GCDEST gcd = { szProto, tszChatRoom, GC_EVENT_SENDMESSAGE };
		GCEVENT gce = { sizeof(gce), &gcd };
		gce.bIsMe = TRUE;
		gce.dwFlags = GCEF_ADDTOLOG;
		gce.ptszText = mir_tstrdup(data);
		gce.time = time(NULL);
		CallServiceSync(MS_GC_EVENT, WINDOW_VISIBLE, (LPARAM)&gce);
		mir_free((void*)gce.ptszText);
		return;
	}

	char *message = mir_utf8encodeT(data);
	if (CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)message) != ACKRESULT_FAILED)
		AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF | DBEF_SENT, (DWORD)mir_strlen(message), (PBYTE)message);
}
コード例 #2
0
ファイル: m_message.cpp プロジェクト: Seldom/miranda-ng
static int lua_Send(lua_State *L)
{
	MCONTACT hContact = luaL_checkinteger(L, 1);
	const char *message = luaL_checkstring(L, 2);

	INT_PTR res = 1;

	const char *szProto = GetContactProto(hContact);
	if (db_get_b(hContact, szProto, "ChatRoom", 0) == TRUE)
	{
		ptrT tszChatRoom(db_get_tsa(hContact, szProto, "ChatRoomID"));
		GCDEST gcd = { szProto, tszChatRoom, GC_EVENT_SENDMESSAGE };
		GCEVENT gce = { sizeof(gce), &gcd };
		gce.bIsMe = TRUE;
		gce.dwFlags = GCEF_ADDTOLOG;
		gce.ptszText = mir_utf8decodeT(message);
		gce.time = time(NULL);

		res = ::CallServiceSync(MS_GC_EVENT, WINDOW_VISIBLE, (LPARAM)&gce);
		lua_pushinteger(L, res);

		mir_free((void*)gce.ptszText);
	}
	else if ((res = ::CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)message)) != ACKRESULT_FAILED)
	{
		DBEVENTINFO dbei;
		dbei.cbSize = sizeof(dbei);
		dbei.szModule = MODULE;
		dbei.timestamp = time(NULL);
		dbei.eventType = EVENTTYPE_MESSAGE;
		dbei.cbBlob = mir_strlen(message);
		dbei.pBlob = (PBYTE)mir_strdup(message);
		dbei.flags = DBEF_UTF | DBEF_SENT;
		::db_event_add(hContact, &dbei);

		lua_pushinteger(L, res);
		return 1;
	}

	lua_pushinteger(L, res);

	return 1;
}