20 #ifndef __OPERATOR_CLIENT_HH_ 21 #define __OPERATOR_CLIENT_HH_ 47 Room(
Client &c,
const std::string &_id, Event::RoomMembership::membership_t _membership)
48 : client(c), id(_id), membership(_membership) {}
50 const std::string &getID()
const {
return id; }
51 Event::RoomMembership::membership_t getMembership()
const {
return membership; }
58 Event::RoomMembership::membership_t membership;
59 std::map<std::string, nlohmann::json> state;
60 std::map<std::string, std::list<callback_t<Room &, const Event::Event &> > > listeners;
62 friend class ::Operator::Client::Client;
109 auto room_it = rooms.find(room_id);
110 if (room_it != rooms.end())
112 return room_it->second;
116 rooms.emplace(room_id,
Room(*
this, room_id, Event::RoomMembership::NONE));
119 const Room &
getRoom(
const std::string &room_id)
const throw (std::out_of_range) {
120 return rooms.at(room_id);
123 Room &operator[](
const std::string &room_id) {
126 const Room &operator[](
const std::string &room_id)
const throw (std::out_of_range) {
160 void triggerError(
const std::string &event_type, std::shared_ptr<Error::Error> error,
const std::string &room_id =
"");
161 std::map<std::string, Room> rooms;
163 void _setRoomMembership(
Room &room, Event::RoomMembership::membership_t membership) {
164 room.membership = membership;
167 std::map<std::string, std::list<callback_t<Room &, const Event::Event &> > > listeners;
176 client.sendMessage(message, noop_callback<const std::string &>);
182 #endif // __OPERATOR_CLIENT_HH_ general "message" events (a.k.a. timeline events)
Definition: event.hh:115
Client & operator<<(Client &client, const Event::MessageEvent &message)
send a message event.
Definition: client.hh:175
virtual void loginWith3PID(const std::string &medium, const std::string &address, const std::string &password, const callback_t< const std::string &, const std::string &> &=noop_callback< const std::string &, const std::string &>)=0
log in using third party ID and pasword.
virtual void sendMessage(const Event::MessageEvent &message, const callback_t< const std::string &> &callback=noop_callback< const std::string &>)=0
send a message event.
Matrix client interface for high-level API.This interface is implemented by the high-level API classe...
Definition: client.hh:41
virtual void startClient()=0
start listening for new events.
Room & getRoom(const std::string &room_id)
return the room with the given ID.
Definition: client.hh:108
virtual void stopClient()=0
stop listening for new events.
void on(const callback_t< Room &, const Event::Event &> &callback)
register an event handler.
Definition: client.hh:155
virtual void logout(const callback_t<> &=noop_callback<>)=0
log out.
void trigger(const Event::Event &event)
call event handlers for the given event.
Definition: client.cc:39
virtual void login(const std::string &username, const std::string &password, const callback_t< const std::string &, const std::string &> &=noop_callback< const std::string &, const std::string &>)=0
log in using username and password
virtual bool isLoggedIn() const =0
determine if the client is currently logged in.
typename std::function< void(std::shared_ptr< Error::Error > err, T...)> callback_t
general type for callbacks
Definition: structs.hh:43
base event class.
Definition: event.hh:35