Changeset 412:3d6ce860cd96
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r411
|
r412
|
|
| 2571 | 2571 | { |
| 2572 | 2572 | Conference* conf = getConf(s); |
| 2573 | | if(!conf) { |
| | 2573 | if(!conf) |
| 2574 | 2574 | return "You are not in conference!"; |
| 2575 | | } |
| 2576 | | QStringList nicks = n.split(' '); |
| | 2575 | |
| 2577 | 2576 | QStringList jids; |
| 2578 | 2577 | 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()); |
| 2582 | 2588 | } 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 | |
| 2595 | 2595 | 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); |
| 2602 | 2598 | |
| 2603 | 2599 | bot()->client()->send(st); |
| 2604 | | |
| 2605 | 2600 | return "Invitation sent."; |
| 2606 | 2601 | } |
| … |
… |
|
| 2609 | 2604 | MucPlugin::invite(Conference *conf, const QStringList& jids, const QString& reason, const QString& pass) |
| 2610 | 2605 | { |
| 2611 | | if(!conf) return 0; |
| | 2606 | if (!conf) return 0; |
| | 2607 | |
| 2612 | 2608 | bool validJID = false; |
| 2613 | 2609 | gloox::Tag *m = new gloox::Tag( "message" ); |
| … |
… |
|
| 2616 | 2612 | x->addAttribute( "xmlns", "http://jabber.org/protocol/muc#user" ); |
| 2617 | 2613 | |
| 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 | { |
| 2620 | 2618 | validJID = true; |
| 2621 | 2619 | gloox::Tag *i = new gloox::Tag( x, "invite" ); |
| 2622 | 2620 | i->addAttribute( "to", jids.at(ndx).toStdString() ); |
| 2623 | 2621 | 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()) |
| 2633 | 2629 | new gloox::Tag( x, "password", pass.toStdString() ); |
| 2634 | | } |
| | 2630 | |
| 2635 | 2631 | return (new gloox::Stanza(m)); |
| 2636 | 2632 | } |