interaction.h 3.69 KB
Newer Older
Nicolas Jager's avatar
Nicolas Jager committed
1
/****************************************************************************
Guillaume Roguez's avatar
Guillaume Roguez committed
2
 *   Copyright (C) 2017-2018 Savoir-faire Linux                                  *
Nicolas Jager's avatar
Nicolas Jager committed
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
 *   Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com>             *
 *   Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>           *
 *                                                                          *
 *   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.1 of the License, or (at your option) any later version.     *
 *                                                                          *
 *   This library is distributed in the hope that it will be useful,        *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
 *   Lesser General Public License for more details.                        *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
#pragma once

// Std
#include <ctime>
#include <string>

namespace lrc
{

namespace api
{

namespace interaction
{

enum class Type {
    INVALID,
    TEXT,
    CALL,
    CONTACT
};

41
static inline const std::string
Nicolas Jager's avatar
Nicolas Jager committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
to_string(const Type& type)
{
    switch(type) {
    case Type::TEXT:
        return "TEXT";
    case Type::CALL:
        return "CALL";
    case Type::CONTACT:
        return "CONTACT";
    case Type::INVALID:
    default:
        return "INVALID";
    }
}

57
static inline Type
Nicolas Jager's avatar
Nicolas Jager committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
to_type(const std::string& type)
{
    if (type == "TEXT")
        return interaction::Type::TEXT;
    else if (type == "CALL")
        return interaction::Type::CALL;
    else if (type == "CONTACT")
        return interaction::Type::CONTACT;
    else
        return interaction::Type::INVALID;
}


enum class Status {
    INVALID,
73
    UNKNOWN,
Nicolas Jager's avatar
Nicolas Jager committed
74 75 76 77 78 79 80
    SENDING,
    FAILED,
    SUCCEED,
    READ,
    UNREAD
};

81
static inline const std::string
Nicolas Jager's avatar
Nicolas Jager committed
82 83 84
to_string(const Status& status)
{
    switch(status) {
85 86
    case Status::UNKNOWN:
        return "UNKNOWN";
Nicolas Jager's avatar
Nicolas Jager committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    case Status::SENDING:
        return "SENDING";
    case Status::FAILED:
        return "FAILED";
    case Status::SUCCEED:
        return "SUCCEED";
    case Status::READ:
        return "READ";
    case Status::UNREAD:
        return "UNREAD";
    case Status::INVALID:
    default:
        return "INVALID";
    }
}

103
static inline Status
Nicolas Jager's avatar
Nicolas Jager committed
104 105
to_status(const std::string& status)
{
106 107 108
    if (status == "UNKNOWN")
        return interaction::Status::UNKNOWN;
    else if (status == "SENDING")
Nicolas Jager's avatar
Nicolas Jager committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
        return interaction::Status::SENDING;
    else if (status == "FAILED")
        return interaction::Status::FAILED;
    else if (status == "SUCCEED")
        return interaction::Status::SUCCEED;
    else if (status == "READ")
        return interaction::Status::READ;
    else if (status == "UNREAD")
        return interaction::Status::UNREAD;
    else
        return interaction::Status::INVALID;

}

struct Info
{
    std::string authorUri;
    std::string body;
    std::time_t timestamp = 0;
    Type type = Type::INVALID;
    Status status = Status::INVALID;
};

132
static inline bool isOutgoing(const Info& interaction) {
Nicolas Jager's avatar
Nicolas Jager committed
133 134 135 136 137 138 139
    return interaction.status != lrc::api::interaction::Status::READ
    && interaction.status != lrc::api::interaction::Status::UNREAD;
}

} // namespace interaction
} // namespace api
} // namespace lrc