Commit 660a1af7 authored by ufownl's avatar ufownl

Correct the mistake of group chat example

parent f1b66b58
...@@ -32,8 +32,6 @@ istream& operator>>(istream& is, line& l) { ...@@ -32,8 +32,6 @@ istream& operator>>(istream& is, line& l) {
return is; return is;
} }
namespace { string s_last_line; }
void client(event_based_actor* self, const string& name) { void client(event_based_actor* self, const string& name) {
self->become ( self->become (
[=](broadcast_atom, const string& message) { [=](broadcast_atom, const string& message) {
...@@ -44,7 +42,7 @@ void client(event_based_actor* self, const string& name) { ...@@ -44,7 +42,7 @@ void client(event_based_actor* self, const string& name) {
[=](join_atom, const group& what) { [=](join_atom, const group& what) {
for (auto g : self->joined_groups()) { for (auto g : self->joined_groups()) {
cout << "*** leave " << to_string(g) << endl; cout << "*** leave " << to_string(g) << endl;
self->send(self, g, name + " has left the chatroom"); self->send(g, name + " has left the chatroom");
self->leave(g); self->leave(g);
} }
cout << "*** join " << to_string(what) << endl; cout << "*** join " << to_string(what) << endl;
...@@ -53,7 +51,9 @@ void client(event_based_actor* self, const string& name) { ...@@ -53,7 +51,9 @@ void client(event_based_actor* self, const string& name) {
}, },
[=](const string& txt) { [=](const string& txt) {
// don't print own messages // don't print own messages
if (self->current_sender() != self) cout << txt << endl; if (self->current_sender() != self) {
cout << txt << endl;
}
}, },
[=](const group_down_msg& g) { [=](const group_down_msg& g) {
cout << "*** chatroom offline: " << to_string(g.source) << endl; cout << "*** chatroom offline: " << to_string(g.source) << endl;
...@@ -148,8 +148,8 @@ int main(int argc, char** argv) { ...@@ -148,8 +148,8 @@ int main(int argc, char** argv) {
" /help print this text\n" << flush; " /help print this text\n" << flush;
}, },
others >> [&] { others >> [&] {
if (!s_last_line.empty()) { if (!i->str.empty()) {
anon_send(client_actor, broadcast_atom::value, s_last_line); anon_send(client_actor, broadcast_atom::value, i->str);
} }
} }
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment