Changeset 412:3d6ce860cd96

Show
Ignore:
Timestamp:
06/20/2010 04:52:48 PM (20 months ago)
Author:
Sidgyck <sidgyck@…>
Branch:
default
Children:
413:02aa4da1feb1, 417:b139596e0b24
Message:

[FIX]: "!muc invite" code cleanup

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/plugins/muc/mucplugin.cpp

    r411 r412  
    25712571{ 
    25722572        Conference* conf = getConf(s); 
    2573         if(!conf) { 
     2573        if(!conf) 
    25742574                return "You are not in conference!"; 
    2575         } 
    2576         QStringList nicks = n.split(' '); 
     2575 
    25772576        QStringList jids; 
    25782577        Nick *nick = 0; 
    2579         for( int ndx = 0; ndx < nicks.size(); ndx++ ) { 
    2580                 if(isBareJidValid(nicks.at(ndx))) { 
    2581                         jids.append(nicks.at(ndx)); 
     2578 
     2579        if (isBareJidValid(n)) 
     2580        { 
     2581                jids.append(n); 
     2582        } 
     2583        else 
     2584        { 
     2585                nick = conf->nicks()->byName(n); 
     2586                if (nick) { 
     2587                        jids.append(nick->jid()->jid()); 
    25822588                } else { 
    2583                         nick = conf->nicks()->byName(nicks.at(ndx)); 
    2584                         if(nick) { 
    2585                                 jids.append(nick->jid()->jid()); 
    2586                         } 
    2587                         else 
    2588                         { 
    2589                                 jids = Nick::nickToJids(conf, nicks.at(ndx), true); 
    2590                         } 
    2591                 } 
    2592         } 
    2593         if( reason.length() > 255 ) 
    2594                         reason.left(252).append("..."); 
     2589                        jids = Nick::nickToJids(conf, n, true); 
     2590                } 
     2591        } 
     2592        if (reason.length() > 255) 
     2593                reason.left(252).append("..."); 
     2594 
    25952595        gloox::Stanza* st = invite(conf, jids, reason); 
    2596  
    2597         if( !st ) { /// TODO: Multi-invites. 
    2598                 QString str = "Can't resolve: \"%1\"'s JID"; 
    2599                 str = (nicks.count() > 1) ? str + "s.": str + "."; 
    2600                 return str.arg(nicks.join("\n")); 
    2601         } 
     2596        if (!st) 
     2597                return QString("Can't resolve: \"%1\"'s JID").arg(n); 
    26022598 
    26032599        bot()->client()->send(st); 
    2604  
    26052600        return "Invitation sent."; 
    26062601} 
     
    26092604MucPlugin::invite(Conference *conf, const QStringList& jids, const QString& reason, const QString& pass) 
    26102605{ 
    2611         if(!conf) return 0; 
     2606        if (!conf) return 0; 
     2607 
    26122608        bool validJID = false; 
    26132609        gloox::Tag *m = new gloox::Tag( "message" ); 
     
    26162612        x->addAttribute( "xmlns", "http://jabber.org/protocol/muc#user" ); 
    26172613 
    2618         for( int ndx = 0; ndx < jids.size(); ndx++ ) { 
    2619                 if(isBareJidValid(jids.at(ndx))) { 
     2614        for (int ndx = 0; ndx < jids.size(); ndx++) 
     2615        { 
     2616                if (isBareJidValid(jids.at(ndx))) 
     2617                { 
    26202618                        validJID = true; 
    26212619                        gloox::Tag *i = new gloox::Tag( x, "invite" ); 
    26222620                        i->addAttribute( "to", jids.at(ndx).toStdString() ); 
    26232621                        qDebug() << "JID: " << jids.at(ndx); 
    2624                         if(!reason.isEmpty()) 
    2625                                 new gloox::Tag( i, "reason", 
    2626                                         reason.toStdString() ); 
    2627                 } 
    2628         } 
    2629         if( !validJID ) { 
    2630                 return 0; 
    2631         } 
    2632         if(!pass.isEmpty()) { 
     2622                        if (!reason.isEmpty()) 
     2623                                new gloox::Tag( i, "reason", reason.toStdString() ); 
     2624                } 
     2625        } 
     2626        if (!validJID)  return 0; 
     2627 
     2628        if (!pass.isEmpty()) 
    26332629                new gloox::Tag( x, "password", pass.toStdString() ); 
    2634         } 
     2630 
    26352631        return (new gloox::Stanza(m)); 
    26362632}