Changeset 13980 for trunk/FACT++


Ignore:
Timestamp:
05/30/12 12:45:38 (12 years ago)
Author:
tbretz
Message:
Ensure that no message is processed twice; also add processing of massages if the chat window is open (do we want that? but what if somebody unintentionally opens it?) and show only the status not everybody who is subscribed.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/skypeclient.cc

    r13966 r13980  
    3232
    3333    bool fAllowRaw;
     34
     35    uint64_t fLastReadMessage;
    3436
    3537    string Contact(const string &id) const
     
    424426        if (vec[0]=="CHATMESSAGE")
    425427        {
    426             if (vec[2]=="STATUS" && vec[3]=="RECEIVED")
    427             {
     428            if (vec[2]=="STATUS" && (vec[3]=="RECEIVED"|| vec[3]=="READ"))
     429            {
     430                const uint64_t last = stoll(vec[1]);
     431
     432                // Check if message has already been processed: Sometimes
     433                // some messages are received twice as READ/READ
     434                if (last<=fLastReadMessage)
     435                    return;
     436                fLastReadMessage = last;
     437
    428438                string rc;
    429439
     
    436446                const size_t p = rc.find(" BODY ");
    437447                if (p==string::npos)
     448                {
     449                    cout<< "BODY TAG NOT FOUND|" << rc << "|" << endl;
    438450                    return;
    439 
    440                 rc = rc.substr(rc.find(" BODY ")+6);
     451                }
     452
     453                rc = Tools::Trim(rc.substr(rc.find(" BODY ")+6));
    441454
    442455                if (rc=="start")
     
    467480                }
    468481
    469                 if (rc=="list")
     482                if (rc=="status")
    470483                {
    471                     ostringstream out;
    472                     out << "*\n\nCurrently subscribed:\n";
    473 
    474                     int cnt = 0;
    475484                    for (auto it=fContacts.begin(); it!=fContacts.end(); it++)
    476485                    {
    477                         const string user = Contact(*it);
    478                         if (user.empty())
    479                             continue;
    480 
    481                         out << "   *   " << user << '\n';
    482                         cnt ++;
     486                        if (*it==vec[1])
     487                        {
     488                            SendSkypeMessage(id, "You are subscribed.");
     489                            return;
     490                        }
    483491                    }
    484 
    485                     if (cnt==0)
    486                         out << " <no subscriptions>";
    487                     else
    488                         out << cnt << " user(s) subscribed.";
    489 
    490                     SendSkypeMessage(id, out.str());
     492                    SendSkypeMessage(id, "You are not subscribed.");
    491493                    return;
    492494                }
    493495
    494                 SendSkypeMessage(id, "*\n\nSyntax Error:\nPlease use either 'start' or 'stop'");
     496                SendSkypeMessage(id, "SYNTAX ERROR\n\nAvailable commands:\nPlease use either 'start', 'stop' or 'status'");
    495497
    496498            }
     
    502504            if (vec[2]=="ACTIVITY_TIMESTAMP")
    503505            {
     506                //SendDBusMessage("CHAT CREATE "+Contact(vec[1]));
    504507                //Info(vec[2]);
     508                // ALTER CHAT DISBAND
    505509            }
    506510            if (vec[2]=="MYROLE")
     
    541545    }
    542546
     547    int HandleDisconnect()
     548    {
     549        return kStateDisconnected;
     550    }
     551
    543552    int HandleConnect()
    544553    {
     
    619628public:
    620629    SkypeClient(ostream &lout) : StateMachineDim(lout, "SKYPE"),
    621         fLastConnect(Time()-boost::posix_time::minutes(5)), fLoop(0)
     630        fLastConnect(Time()-boost::posix_time::minutes(5)), fLoop(0),
     631        fLastReadMessage(0)
    622632    {
    623633        AddStateName(kStateDisconnected, "Disonnected", "");
     
    638648        AddEvent("CONNECT", kStateDisconnected)
    639649            (bind(&SkypeClient::HandleConnect, this))
     650            ("");
     651
     652        AddEvent("DISCONNECT", kStateConnected)
     653            (bind(&SkypeClient::HandleDisconnect, this))
    640654            ("");
    641655
Note: See TracChangeset for help on using the changeset viewer.