summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/groupwise/libgroupwise/tasks/joinchattask.cpp
blob: 35fab51691f42beb4e7ab6d05921bfdf76921ee5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
    Kopete Groupwise Protocol
    joinchattask.cpp - Join a Chat on the server, after having been invited.

    Copyright (c) 2005      SUSE Linux Products GmbH	 	 http://www.suse.com
    
    Based on Iris, Copyright (C) 2003  Justin Karneges

    Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
 
    *************************************************************************
    *                                                                       *
    * This library is free software; you can redistribute it and/or         *
    * modify it under the terms of the GNU Lesser General Public            *
    * License as published by the Free Software Foundation; either          *
    * version 2 of the License, or (at your option) any later version.      *
    *                                                                       *
    *************************************************************************
*/

#include "gwerror.h"
#include "client.h"
#include "response.h"
#include "userdetailsmanager.h"

#include "joinchattask.h"

JoinChatTask::JoinChatTask(Task* tqparent): RequestTask(tqparent)
{
}

JoinChatTask::~JoinChatTask()
{
}

void JoinChatTask::join( const TQString & displayName )
{
	m_displayName = displayName;
	Field::FieldList lst, tmp;
	tmp.append( new Field::SingleField( NM_A_SZ_OBJECT_ID, 0, NMFIELD_TYPE_UTF8, displayName ) );
	lst.append( new Field::MultiField( NM_A_FA_CONVERSATION, NMFIELD_METHOD_VALID, 0, NMFIELD_TYPE_ARRAY, tmp ) );
	createTransfer( "joinchat", lst );
}

bool JoinChatTask::take( Transfer * transfer )
{
	if ( forMe( transfer ) )
	{
		client()->debug( "JoinChatTask::take()" );
		Response * response = dynamic_cast<Response *>( transfer );
		Field::FieldList responseFields = response->fields();
		// if the request was successful
		if ( response->resultCode() == GroupWise::None )
		{
			// extract the list of participants and store them
			Field::MultiField * participants = responseFields.findMultiField( NM_A_FA_CONTACT_LIST );
			if ( participants )
			{
				Field::SingleField * contact = 0;
				Field::FieldList contactList = participants->fields();
				const Field::FieldListIterator end = contactList.end();
				for ( Field::FieldListIterator it = contactList.tqfind( NM_A_SZ_DN );
								  it != end;
								  it = contactList.tqfind( ++it, NM_A_SZ_DN ) )
				{
					contact = static_cast<Field::SingleField *>( *it );
					if ( contact )
					{
						// HACK: lowercased DN 
						TQString dn = contact->value().toString().lower();
						m_participants.append( dn );
						// need to ask for details for these contacts
					}
				}
			}
			else 
				setError( GroupWise::Protocol );
			
			// now, extract the list of pending invites and store them
			Field::MultiField * invitees = responseFields.findMultiField( NM_A_FA_RESULTS );
			if ( invitees )
			{
				Field::SingleField * contact = 0;
				Field::FieldList contactList = invitees->fields();
				const Field::FieldListIterator end = contactList.end();
				for ( Field::FieldListIterator it = contactList.tqfind( NM_A_SZ_DN );
								  it != end;
								  it = contactList.tqfind( ++it, NM_A_SZ_DN ) )
				{
					contact = static_cast<Field::SingleField *>( *it );
					if ( contact )
					{
						// HACK: lowercased DN 
						TQString dn = contact->value().toString().lower();
						m_invitees.append( dn );
						// need to ask for details for these contacts
						if ( !client()->userDetailsManager()->known( dn )  )
							; // don't request details for chatrooms, there could be too many
					}
				}
			}
			else 
				setError( GroupWise::Protocol );

			client()->debug( "JoinChatTask::finished()" );
			finished();	
		}
		else
			setError( response->resultCode() );
		return true;
	}
	else
		return false;
}

TQStringList JoinChatTask::participants() const
{
	return m_participants;
}

TQStringList JoinChatTask::invitees() const
{
	return m_invitees;
}

TQString JoinChatTask::displayName() const
{
	return m_displayName;
}

#include "joinchattask.moc"