示例#1
0
void CMsnProto::MSN_GCAddMessage(TCHAR *mChatID, MCONTACT hContact, char *email, time_t ts, bool sentMsg, char *msgBody)
{
	GCDEST gcd = { m_szModuleName, mChatID, GC_EVENT_MESSAGE };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.ptszUID = mir_a2t(email);
	gce.ptszNick = GetContactNameT(hContact);
	gce.time = ts;
	gce.bIsMe = sentMsg;

	TCHAR* p = mir_utf8decodeT(msgBody);
	gce.ptszText = EscapeChatTags(p);
	mir_free(p);

	CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
	mir_free((void*)gce.ptszUID);
	mir_free((void*)gce.ptszText);
}
void JabberGroupchatProcessMessage( XmlNode *node, void *userdata )
{
	ThreadData* info;
	XmlNode *n, *xNode;
	TCHAR* from, *type, *p, *nick, *msgText;
	JABBER_LIST_ITEM *item;

	if ( !node->name || strcmp( node->name, "message" )) return;
	if (( info=( ThreadData* ) userdata ) == NULL ) return;
	if (( from = JabberXmlGetAttrValue( node, "from" )) == NULL ) return;
	if (( item = JabberListGetItemPtr( LIST_CHATROOM, from )) == NULL ) return;

	if (( type = JabberXmlGetAttrValue( node, "type" )) == NULL ) return;
	if ( !lstrcmp( type, _T("error")))
		return;

	GCDEST gcd = { jabberProtoName, NULL, 0 };
	gcd.ptszID = item->jid;

	if (( n = JabberXmlGetChild( node, "subject" )) != NULL ) {
		if ( n->text == NULL || n->text[0] == '\0' )
			return;

		msgText = n->text;

		gcd.iType = GC_EVENT_TOPIC;

		if ( from != NULL ) {
			nick = _tcschr( from, '/' );
			if ( nick == NULL || nick[1] == '\0' )
				nick = NULL;
			else
				nick++;
		}
		else nick = NULL;
	}
	else {
		if (( n = JabberXmlGetChild( node, "body" )) == NULL ) return;
		if ( n->text == NULL )
			return;

		nick = _tcschr( from, '/' );
		if ( nick == NULL || nick[1] == '\0' )
			return;
		nick++;

		msgText = n->text;

		if ( _tcsncmp( msgText, _T("/me "), 4 ) == 0 && _tcslen( msgText ) > 4 ) {
			msgText += 4;
			gcd.iType = GC_EVENT_ACTION;
		}
		else gcd.iType = GC_EVENT_MESSAGE;
	}

	JabberGcLogCreate( item );

	time_t msgTime = 0;
	BOOL delivered = FALSE;
	for ( int i = 1; ( xNode=JabberXmlGetNthChild( node, "x", i )) != NULL; i++ )
		if (( p=JabberXmlGetAttrValue( xNode, "xmlns" )) != NULL )
			if ( !_tcscmp( p, _T("jabber:x:delay")) && msgTime==0 )
				if (( p=JabberXmlGetAttrValue( xNode, "stamp" )) != NULL )
					msgTime = JabberIsoToUnixTime( p );

	time_t now = time( NULL );
	if ( msgTime == 0 || msgTime > now )
		msgTime = now;

	GCEVENT gce = {0};
	gce.cbSize = sizeof(GCEVENT);
	gce.pDest = &gcd;
	gce.ptszUID = nick;
	gce.ptszNick = nick;
	gce.time = msgTime;
	gce.ptszText = EscapeChatTags( msgText );
	gce.bIsMe = lstrcmp( nick, item->nick ) == 0;
	gce.dwFlags = GC_TCHAR | GCEF_ADDTOLOG;
	JCallService(MS_GC_EVENT, NULL, (LPARAM)&gce);

	item->bChatActive = 2;

	if ( gcd.iType == GC_EVENT_TOPIC ) {
		gce.dwFlags &= ~GCEF_ADDTOLOG;
		gcd.iType = GC_EVENT_SETSBTEXT;
		JCallService(MS_GC_EVENT, NULL, (LPARAM)&gce);
	}

	mir_free( (void*)gce.pszText ); // Since we processed msgText and created a new string
}