-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
66 lines (57 loc) · 1.93 KB
/
test.cpp
1
2
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include "Users.h"
#include "include/libmatrix-client/MatrixSession.h"
#include "include/libmatrix-client/Messages.h"
#include "MessageUtils.h"
using LibMatrix::MatrixSession;
int main(int argc, const char **argv) {
MatrixSession client{argv[1]};
try {
auto future = client.login(argv[2], argv[3]);
if(future.valid()) {
std::cout << "Moving along!" << std::endl;
future.get();
}
}catch(std::runtime_error e) {
std::cout << "Could not login :(" << std::endl;
std::cout << e.what() << std::endl;
return 1;
}
std::cout << "Logged in :)" << std::endl;
auto rooms = client.syncState().get();
for(auto i = rooms.begin(); i != rooms.end(); ++i) {
std::cout << i->first << "\n";
//Print users
auto users = client.getRoomMembers(i->first).get();
for(LibMatrix::User i : users) {
std::cout << "\t" << i.id << std::endl;
std::cout << "\t\t" << i.displayName << std::endl;
std::cout << "\t\t" << i.avatarURL << std::endl;
}
std::cout << "\t" << i->second->name << "\n";
for(LibMatrix::Message msg : i->second->messages) {
std::cout << "\t" << "\t" << msg.id << "\n";
std::cout << "\t" << "\t" << msg.content << "\n";
std::cout << "\t" << "\t" << msg.sender << "\n";
}
}
while(true) {
auto patch = client.syncState().get();
for(auto i = patch.begin(); i != patch.end(); ++i) {
std::cout << i->first << "\n";
std::cout << "\t" << i->second->name << "\n";
for(LibMatrix::Message msg : i->second->messages) {
std::cout << "\t" << "\t" << msg.id << "\n";
std::cout << "\t" << "\t" << msg.content << "\n";
std::cout << "\t" << "\t" << msg.sender << "\n";
client.updateReadReceipt(i->second->id, *(i->second->messages.rbegin()) ).get();
}
}
}
/* LibMatrix::MessageBatchMap result = client.syncState().get();
for(auto it = result.begin(); it != result.end(); ++it) {
std::cout << *(it->second) << std::endl;
}*/
// client.sendMessage(argv[4], argv[5]).get();
return 0;
}