Example #1
0
	void ChannelHandler::SetChannelUser (const QString& nick,
			const QString& user, const QString& host)
	{
		QString nickName = nick;
		bool hasRole = false;
		QChar roleSign;

		if (CM_->GetISupport ().contains ("PREFIX"))
		{
			const QStringList& prefixList = CM_->GetISupport () ["PREFIX"].split (')');
			int id = prefixList.value (1).indexOf (nick [0]);
			if (id != -1)
			{
				hasRole = true;
				nickName = nickName.mid (1);
				roleSign = prefixList.at (0) [id + 1];
			}
		}

		CM_->ClosePrivateChat (nickName);

		const auto existed = Nick2Entry_.contains (nickName);

		ChannelParticipantEntry_ptr entry (GetParticipantEntry (nickName, false));
		entry->SetUserName (user);
		entry->SetHostName (host);

		ChannelRole role;
		if (hasRole)
			switch (roleSign.toAscii ())
			{
				case 'v':
					role = ChannelRole::Voiced;
					break;
				case 'h':
					role = ChannelRole::HalfOperator;
					break;
				case 'o':
					role = ChannelRole::Operator;
					break;
				case 'a':
					role = ChannelRole::Admin;
					break;
				case 'q':
					role = ChannelRole::Owner;
					break;
				default:
					role = ChannelRole::Participant;
 			}
		else
			role = ChannelRole::Participant;

		entry->SetRole (role);
		entry->SetStatus (EntryStatus (SOnline, QString ()));

		if (!existed)
			CM_->GetAccount ()->handleGotRosterItems ({ entry.get () });

		MakeJoinMessage (nickName);
	}
Example #2
0
	void RoomHandler::handleParticipantAdded (const QString& jid)
	{
		const QXmppPresence& pres = Room_->participantPresence (jid);

		QString nick;
		ClientConnection::Split (jid, 0, &nick);

		if (PendingNickChanges_.remove (nick))
			return;

		RoomParticipantEntry_ptr entry = GetParticipantEntry (nick);
		entry->SetAffiliation (pres.mucItem ().affiliation ());
		entry->SetRole (pres.mucItem ().role ());

		entry->SetPhotoHash (pres.photoHash ());
		entry->HandlePresence (pres, "");

		MakeJoinMessage (pres, nick);
	}
Example #3
0
	void RoomHandler::HandlePresence (const QXmppPresence& pres, const QString& nick)
	{
		if (pres.type () == QXmppPresence::Unavailable &&
				PendingNickChanges_.remove (nick))
			return;
		const bool existed = Nick2Entry_.contains (nick);
		RoomParticipantEntry_ptr entry = GetParticipantEntry (nick);

		if (pres.type () == QXmppPresence::Unavailable)
		{
			MakeLeaveMessage (pres, nick);

			Account_->handleEntryRemoved (entry.get ());
			Nick2Entry_.remove (nick);
			return;
		}

		entry->SetClientInfo ("", pres);

		const QXmppPresence::Status& xmppSt = pres.status ();
		EntryStatus status (static_cast<State> (xmppSt.type ()),
				xmppSt.statusText ());
		const bool statusChanged = (status != entry->GetStatus (QString ()));
		if (statusChanged)
			entry->SetStatus (status, QString ());

		if (!PendingNickChanges_.remove (nick))
		{
			if (!existed)
			{	
				Account_->GetClientConnection ()->
					FetchVCard (RoomJID_ + "/" + nick);
				MakeJoinMessage (pres, nick);
				entry->SetAffiliation (MUCManager_->getAffiliation (RoomJID_, nick));
				entry->SetRole (MUCManager_->getRole (RoomJID_, nick));
			}
			else if (statusChanged)
				MakeStatusChangedMessage (pres, nick);
		}
	}