Merge lp:~phablet-team/mfw-plugin-irc/dummy-branch into lp:mfw-plugin-irc

Proposed by Tiago Salem Herrmann
Status: Approved
Approved by: Gustavo Pichorim Boiko
Approved revision: 21
Proposed branch: lp:~phablet-team/mfw-plugin-irc/dummy-branch
Merge into: lp:mfw-plugin-irc
Diff against target: 674 lines (+308/-33)
16 files modified
.bzr-builddeb/default.conf (+2/-0)
COPYING (+165/-0)
data/irc.protocol.in (+5/-0)
data/irc.service.in (+1/-1)
debian/changelog (+1/-1)
debian/control (+6/-9)
debian/source/format (+0/-1)
include/irc/connection.h (+1/-0)
include/irc/group_chat.h (+5/-0)
include/irc/group_manager.h (+1/-2)
include/irc/messenger.h (+5/-2)
src/CMakeLists.txt (+1/-1)
src/irc/connection.cpp (+31/-8)
src/irc/group_chat.cpp (+9/-1)
src/irc/group_manager.cpp (+53/-4)
src/irc/messenger.cpp (+22/-3)
To merge this branch: bzr merge lp:~phablet-team/mfw-plugin-irc/dummy-branch
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
Review via email: mp+313489@code.launchpad.net

Commit message

Finish the basic implementation of an IRC plugin.

Description of the change

Finish the basic implementation of an IRC plugin.

To post a comment you must log in.
2. By Tiago Salem Herrmann

fix control file

3. By Tiago Salem Herrmann

remove some build deps not needed by this package

4. By Tiago Salem Herrmann

enable return to send on messaging-app

5. By Tiago Salem Herrmann

Enable Attachments

6. By Tiago Salem Herrmann

Add EnableRejoin property

7. By Tiago Salem Herrmann

Fix leaving and rejoing channels

8. By Tiago Salem Herrmann

add property EnableTabCompletion

9. By Tiago Salem Herrmann

try different nicknames on collision

10. By Tiago Salem Herrmann

Add property: LeaveRoomsOnClose

11. By Tiago Salem Herrmann

Set self contact as remote

12. By Tiago Salem Herrmann

Force self contact to be always the last

13. By Tiago Salem Herrmann

If we just joined the channel, put our state as RemotePending

14. By Gustavo Pichorim Boiko

Keep the self contact as pending while reporting users.

15. By Tiago Salem Herrmann

Emit a separate signal to move self contact to the final members list

16. By Tiago Salem Herrmann

add random ids to messages

17. By Tiago Salem Herrmann

add fallback values

18. By Tiago Salem Herrmann

move self contact to pending list before removing other members

19. By Tiago Salem Herrmann

Add persistent property

20. By Ken VanDine

packaging cleanup

21. By Tiago Salem Herrmann

Move plugins to a separate directory

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good!

review: Approve

Unmerged revisions

21. By Tiago Salem Herrmann

Move plugins to a separate directory

20. By Ken VanDine

packaging cleanup

19. By Tiago Salem Herrmann

Add persistent property

18. By Tiago Salem Herrmann

move self contact to pending list before removing other members

17. By Tiago Salem Herrmann

add fallback values

16. By Tiago Salem Herrmann

add random ids to messages

15. By Tiago Salem Herrmann

Emit a separate signal to move self contact to the final members list

14. By Gustavo Pichorim Boiko

Keep the self contact as pending while reporting users.

13. By Tiago Salem Herrmann

If we just joined the channel, put our state as RemotePending

12. By Tiago Salem Herrmann

Force self contact to be always the last

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory '.bzr-builddeb'
=== added file '.bzr-builddeb/default.conf'
--- .bzr-builddeb/default.conf 1970-01-01 00:00:00 +0000
+++ .bzr-builddeb/default.conf 2017-03-22 14:38:33 +0000
@@ -0,0 +1,2 @@
1[BUILDDEB]
2split = True
03
=== added file 'COPYING'
--- COPYING 1970-01-01 00:00:00 +0000
+++ COPYING 2017-03-22 14:38:33 +0000
@@ -0,0 +1,165 @@
1 GNU LESSER GENERAL PUBLIC LICENSE
2 Version 3, 29 June 2007
3
4 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5 Everyone is permitted to copy and distribute verbatim copies
6 of this license document, but changing it is not allowed.
7
8
9 This version of the GNU Lesser General Public License incorporates
10the terms and conditions of version 3 of the GNU General Public
11License, supplemented by the additional permissions listed below.
12
13 0. Additional Definitions.
14
15 As used herein, "this License" refers to version 3 of the GNU Lesser
16General Public License, and the "GNU GPL" refers to version 3 of the GNU
17General Public License.
18
19 "The Library" refers to a covered work governed by this License,
20other than an Application or a Combined Work as defined below.
21
22 An "Application" is any work that makes use of an interface provided
23by the Library, but which is not otherwise based on the Library.
24Defining a subclass of a class defined by the Library is deemed a mode
25of using an interface provided by the Library.
26
27 A "Combined Work" is a work produced by combining or linking an
28Application with the Library. The particular version of the Library
29with which the Combined Work was made is also called the "Linked
30Version".
31
32 The "Minimal Corresponding Source" for a Combined Work means the
33Corresponding Source for the Combined Work, excluding any source code
34for portions of the Combined Work that, considered in isolation, are
35based on the Application, and not on the Linked Version.
36
37 The "Corresponding Application Code" for a Combined Work means the
38object code and/or source code for the Application, including any data
39and utility programs needed for reproducing the Combined Work from the
40Application, but excluding the System Libraries of the Combined Work.
41
42 1. Exception to Section 3 of the GNU GPL.
43
44 You may convey a covered work under sections 3 and 4 of this License
45without being bound by section 3 of the GNU GPL.
46
47 2. Conveying Modified Versions.
48
49 If you modify a copy of the Library, and, in your modifications, a
50facility refers to a function or data to be supplied by an Application
51that uses the facility (other than as an argument passed when the
52facility is invoked), then you may convey a copy of the modified
53version:
54
55 a) under this License, provided that you make a good faith effort to
56 ensure that, in the event an Application does not supply the
57 function or data, the facility still operates, and performs
58 whatever part of its purpose remains meaningful, or
59
60 b) under the GNU GPL, with none of the additional permissions of
61 this License applicable to that copy.
62
63 3. Object Code Incorporating Material from Library Header Files.
64
65 The object code form of an Application may incorporate material from
66a header file that is part of the Library. You may convey such object
67code under terms of your choice, provided that, if the incorporated
68material is not limited to numerical parameters, data structure
69layouts and accessors, or small macros, inline functions and templates
70(ten or fewer lines in length), you do both of the following:
71
72 a) Give prominent notice with each copy of the object code that the
73 Library is used in it and that the Library and its use are
74 covered by this License.
75
76 b) Accompany the object code with a copy of the GNU GPL and this license
77 document.
78
79 4. Combined Works.
80
81 You may convey a Combined Work under terms of your choice that,
82taken together, effectively do not restrict modification of the
83portions of the Library contained in the Combined Work and reverse
84engineering for debugging such modifications, if you also do each of
85the following:
86
87 a) Give prominent notice with each copy of the Combined Work that
88 the Library is used in it and that the Library and its use are
89 covered by this License.
90
91 b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 document.
93
94 c) For a Combined Work that displays copyright notices during
95 execution, include the copyright notice for the Library among
96 these notices, as well as a reference directing the user to the
97 copies of the GNU GPL and this license document.
98
99 d) Do one of the following:
100
101 0) Convey the Minimal Corresponding Source under the terms of this
102 License, and the Corresponding Application Code in a form
103 suitable for, and under terms that permit, the user to
104 recombine or relink the Application with a modified version of
105 the Linked Version to produce a modified Combined Work, in the
106 manner specified by section 6 of the GNU GPL for conveying
107 Corresponding Source.
108
109 1) Use a suitable shared library mechanism for linking with the
110 Library. A suitable mechanism is one that (a) uses at run time
111 a copy of the Library already present on the user's computer
112 system, and (b) will operate properly with a modified version
113 of the Library that is interface-compatible with the Linked
114 Version.
115
116 e) Provide Installation Information, but only if you would otherwise
117 be required to provide such information under section 6 of the
118 GNU GPL, and only to the extent that such information is
119 necessary to install and execute a modified version of the
120 Combined Work produced by recombining or relinking the
121 Application with a modified version of the Linked Version. (If
122 you use option 4d0, the Installation Information must accompany
123 the Minimal Corresponding Source and Corresponding Application
124 Code. If you use option 4d1, you must provide the Installation
125 Information in the manner specified by section 6 of the GNU GPL
126 for conveying Corresponding Source.)
127
128 5. Combined Libraries.
129
130 You may place library facilities that are a work based on the
131Library side by side in a single library together with other library
132facilities that are not Applications and are not covered by this
133License, and convey such a combined library under terms of your
134choice, if you do both of the following:
135
136 a) Accompany the combined library with a copy of the same work based
137 on the Library, uncombined with any other library facilities,
138 conveyed under the terms of this License.
139
140 b) Give prominent notice with the combined library that part of it
141 is a work based on the Library, and explaining where to find the
142 accompanying uncombined form of the same work.
143
144 6. Revised Versions of the GNU Lesser General Public License.
145
146 The Free Software Foundation may publish revised and/or new versions
147of the GNU Lesser General Public License from time to time. Such new
148versions will be similar in spirit to the present version, but may
149differ in detail to address new problems or concerns.
150
151 Each version is given a distinguishing version number. If the
152Library as you received it specifies that a certain numbered version
153of the GNU Lesser General Public License "or any later version"
154applies to it, you have the option of following the terms and
155conditions either of that published version or of any later version
156published by the Free Software Foundation. If the Library as you
157received it does not specify a version number of the GNU Lesser
158General Public License, you may choose any version of the GNU Lesser
159General Public License ever published by the Free Software Foundation.
160
161 If the Library as you received it specifies that a proxy can decide
162whether future versions of the GNU Lesser General Public License shall
163apply, that proxy's public statement of acceptance of any version is
164permanent authorization for you to choose that version for the
165Library.
0166
=== modified file 'data/irc.protocol.in'
--- data/irc.protocol.in 2016-12-16 18:58:01 +0000
+++ data/irc.protocol.in 2017-03-22 14:38:33 +0000
@@ -9,3 +9,8 @@
9ShowOnSelector=19ShowOnSelector=1
10ShowOnlineStatus=010ShowOnlineStatus=0
11JoinExistingChannels=111JoinExistingChannels=1
12ReturnToSend=1
13EnableAttachments=0
14EnableRejoin=1
15EnableTabCompletion=1
16LeaveRoomsOnClose=1
1217
=== modified file 'data/irc.service.in'
--- data/irc.service.in 2016-12-16 18:58:01 +0000
+++ data/irc.service.in 2017-03-22 14:38:33 +0000
@@ -1,3 +1,3 @@
1[D-BUS Service]1[D-BUS Service]
2Name=org.freedesktop.Telepathy.ConnectionManager.@CM@2Name=org.freedesktop.Telepathy.ConnectionManager.@CM@
3Exec=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/messaging-framework-runner --connection-manager-name @CM@ --protocol-name @PROTOCOL@ --connector messaging::PluginConnector --PluginConnector::path=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/libmfw-plugin-@CM@.so3Exec=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/messaging-framework-runner --connection-manager-name @CM@ --protocol-name @PROTOCOL@ --connector messaging::PluginConnector --PluginConnector::path=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/messaging-framework/libmfw-plugin-@CM@.so
44
=== modified file 'debian/changelog'
--- debian/changelog 2016-12-16 18:58:01 +0000
+++ debian/changelog 2017-03-22 14:38:33 +0000
@@ -1,4 +1,4 @@
1mfw-plugin-irc (0.1) xenial; urgency=medium1mfw-plugin-irc (0.1-0ubuntu1) xenial; urgency=medium
22
3 * Initial release3 * Initial release
44
55
=== modified file 'debian/control'
--- debian/control 2016-12-16 18:58:01 +0000
+++ debian/control 2017-03-22 14:38:33 +0000
@@ -1,11 +1,8 @@
1Source: mfw-plugin-irc1Source: mfw-plugin-irc
2Priority: optional2Priority: optional
3Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>3Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
4Build-Depends: astyle:native,4Build-Depends: cmake,
5 clang-format-3.5:native,
6 cmake,
7 debhelper (>= 9),5 debhelper (>= 9),
8 dos2unix:native,
9 doxygen,6 doxygen,
10 gcovr,7 gcovr,
11 google-mock,8 google-mock,
@@ -14,16 +11,16 @@
14 libboost-filesystem-dev,11 libboost-filesystem-dev,
15 libboost-program-options-dev,12 libboost-program-options-dev,
16 libboost-system-dev,13 libboost-system-dev,
14 libcppnetlib-dev,
17 libdbus-cpp-dev,15 libdbus-cpp-dev,
18 libgoogle-glog-dev,16 libgoogle-glog-dev,
19 libircclient-dev17 libircclient-dev,
20 libmessaging-framework-dev,18 libmessaging-framework-dev,
21 libprocess-cpp-dev,19 libprocess-cpp-dev,
22 libtelepathy-qt5-dev,20 libtelepathy-qt5-dev,
23 pkg-config,21 pkg-config,
24 qtbase5-dev,22 qtbase5-dev
25 libcppnetlib-dev,23Standards-Version: 3.9.7
26Standards-Version: 3.9.5
27Section: libs24Section: libs
28Homepage: https://launchpad.net/mfw-plugin-irc25Homepage: https://launchpad.net/mfw-plugin-irc
29Vcs-Bzr: https://code.launchpad.net/26Vcs-Bzr: https://code.launchpad.net/
3027
=== removed directory 'debian/source'
=== removed file 'debian/source/format'
--- debian/source/format 2016-12-16 18:58:01 +0000
+++ debian/source/format 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
13.0 (native)
20
=== modified file 'include/irc/connection.h'
--- include/irc/connection.h 2016-12-16 18:58:01 +0000
+++ include/irc/connection.h 2017-03-22 14:38:33 +0000
@@ -95,6 +95,7 @@
9595
96 std::string server_id;96 std::string server_id;
97 std::string nickname;97 std::string nickname;
98 int nick_collision;
9899
99private:100private:
100101
101102
=== modified file 'include/irc/group_chat.h'
--- include/irc/group_chat.h 2016-12-16 18:58:01 +0000
+++ include/irc/group_chat.h 2017-03-22 14:38:33 +0000
@@ -39,6 +39,10 @@
39 void mark_message_as_delivered(const std::string& message_token);39 void mark_message_as_delivered(const std::string& message_token);
40 std::string id();40 std::string id();
4141
42 void set_active(bool active);
43 bool active();
44
45
42private:46private:
43 /// @brief Creates a new instance translating the given recipient to a user.47 /// @brief Creates a new instance translating the given recipient to a user.
44 GroupChat(const std::shared_ptr<messaging::Group> &group,48 GroupChat(const std::shared_ptr<messaging::Group> &group,
@@ -46,6 +50,7 @@
4650
47 irc_session_t *irc_session;51 irc_session_t *irc_session;
48 std::string channel_id;52 std::string channel_id;
53 bool is_active;
4954
50};55};
5156
5257
=== modified file 'include/irc/group_manager.h'
--- include/irc/group_manager.h 2016-12-16 18:58:01 +0000
+++ include/irc/group_manager.h 2017-03-22 14:38:33 +0000
@@ -38,6 +38,7 @@
38 std::string group_id() override;38 std::string group_id() override;
39 std::string group_title() override;39 std::string group_title() override;
40 std::string group_subject() override;40 std::string group_subject() override;
41 bool persistent() override;
41 std::shared_ptr<messaging::Member> group_creator() override;42 std::shared_ptr<messaging::Member> group_creator() override;
42 std::set<std::string> group_admins() override;43 std::set<std::string> group_admins() override;
43 messaging::Members members() override;44 messaging::Members members() override;
@@ -72,8 +73,6 @@
72 irc_session_t *irc_session;73 irc_session_t *irc_session;
73 std::string creator;74 std::string creator;
7475
75 /// @brief this valImClientImplue is created when chat is created and sent in any method call into the chat
76
77};76};
7877
79}78}
8079
=== modified file 'include/irc/messenger.h'
--- include/irc/messenger.h 2016-12-16 18:58:01 +0000
+++ include/irc/messenger.h 2017-03-22 14:38:33 +0000
@@ -14,6 +14,7 @@
14class Message;14class Message;
15class File;15class File;
16class Connector;16class Connector;
17class Connection;
17class GroupManager;18class GroupManager;
1819
19class IRC_PUBLIC Messenger20class IRC_PUBLIC Messenger
@@ -25,7 +26,7 @@
25 DEFINE_PTRS(Messenger);26 DEFINE_PTRS(Messenger);
26 /// @endcond27 /// @endcond
2728
28 static std::shared_ptr<Messenger> create(const std::shared_ptr<Messenger::Observer>& messenger_observer, irc_session_t *irc_session);29 static std::shared_ptr<Messenger> create(const std::shared_ptr<Messenger::Observer>& messenger_observer, const std::shared_ptr<irc::Connection> &connection, irc_session_t *irc_session);
2930
30 std::shared_ptr<messaging::Chat> create_chat_with(const messaging::Recipient::shared_ptr& recipient, const std::shared_ptr<messaging::Chat::Observer>& observer) override;31 std::shared_ptr<messaging::Chat> create_chat_with(const messaging::Recipient::shared_ptr& recipient, const std::shared_ptr<messaging::Chat::Observer>& observer) override;
3132
@@ -34,9 +35,11 @@
34 std::shared_ptr<GroupManager> get_group_manager(const std::string &group_chat_id);35 std::shared_ptr<GroupManager> get_group_manager(const std::string &group_chat_id);
35 void handle_join_new_channel(const std::string &channel);36 void handle_join_new_channel(const std::string &channel);
36 void handle_join_new_channel(const std::string &channel, const std::string &the_creator);37 void handle_join_new_channel(const std::string &channel, const std::string &the_creator);
38 void remove_chat(const std::string &chat_id);
3739
40 std::shared_ptr<irc::Connection> connection;
38private:41private:
39 Messenger(const std::shared_ptr<messaging::Messenger::Observer>& observer, irc_session_t *irc_session);42 Messenger(const std::shared_ptr<messaging::Messenger::Observer>& observer, const std::shared_ptr<irc::Connection> &connection, irc_session_t *irc_session);
4043
41 /// @brief identity provider to correlate msg_id with imdn unique identifier. First will be44 /// @brief identity provider to correlate msg_id with imdn unique identifier. First will be
42 /// used internally for chat messages and the other used as message external unique id45 /// used internally for chat messages and the other used as message external unique id
4346
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2016-12-16 18:58:01 +0000
+++ src/CMakeLists.txt 2017-03-22 14:38:33 +0000
@@ -34,4 +34,4 @@
3434
35install(35install(
36 TARGETS ${PLUGIN_NAME}36 TARGETS ${PLUGIN_NAME}
37 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})37 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/messaging-framework)
3838
=== modified file 'src/irc/connection.cpp'
--- src/irc/connection.cpp 2016-12-16 18:58:01 +0000
+++ src/irc/connection.cpp 2017-03-22 14:38:33 +0000
@@ -151,6 +151,15 @@
151 std::string irc_channel(params[1]);151 std::string irc_channel(params[1]);
152 ctx->channel_members_changed(irc_channel, channel_users[irc_channel]);152 ctx->channel_members_changed(irc_channel, channel_users[irc_channel]);
153 channel_users.erase(irc_channel);153 channel_users.erase(irc_channel);
154 } else if (event == LIBIRC_RFC_ERR_NICKNAMEINUSE) {
155 if (ctx->nick_collision++ < 3) {
156 std::string irc_nick(params[1]);
157 irc_nick += "_";
158 irc_cmd_nick(session, irc_nick.c_str());
159 } else {
160 LOG(INFO) << "Could not connect. Nickname already in use";
161 ctx->disconnect(messaging::Connection::StatusChangedReason::name_in_use);
162 }
154 }163 }
155}164}
156165
@@ -213,6 +222,7 @@
213 , port(6667)222 , port(6667)
214 , use_ssl(false)223 , use_ssl(false)
215 , verify_ssl_cert(true)224 , verify_ssl_cert(true)
225 , nick_collision(0)
216{226{
217 messaging::Parameter server_param{"server", "s", messaging::Parameter::Flags::required|messaging::Parameter::Flags::required_for_registration};227 messaging::Parameter server_param{"server", "s", messaging::Parameter::Flags::required|messaging::Parameter::Flags::required_for_registration};
218 messaging::Parameter port_param{"port", "q", messaging::Parameter::Flags::none};228 messaging::Parameter port_param{"port", "q", messaging::Parameter::Flags::none};
@@ -253,6 +263,9 @@
253 {263 {
254 throw std::runtime_error{"nickname could not be found"};264 throw std::runtime_error{"nickname could not be found"};
255 }265 }
266 if (username.empty()) {
267 username = nickname;
268 }
256 }269 }
257 else270 else
258 {271 {
@@ -269,6 +282,10 @@
269 fullname = fullname_param.extract_from(dict).as_string();282 fullname = fullname_param.extract_from(dict).as_string();
270 }283 }
271284
285 if (fullname.empty()) {
286 fullname = nickname;
287 }
288
272 if (use_ssl_param.can_extract_from(dict))289 if (use_ssl_param.can_extract_from(dict))
273 {290 {
274 use_ssl = use_ssl_param.extract_from(dict).as_bool();291 use_ssl = use_ssl_param.extract_from(dict).as_bool();
@@ -361,7 +378,7 @@
361 irc_set_ctx(irc_session, ctx);378 irc_set_ctx(irc_session, ctx);
362379
363 // initiate other components380 // initiate other components
364 messenger_ = Messenger::create(messenger_observer_, irc_session);381 messenger_ = Messenger::create(messenger_observer_, shared_from_this(), irc_session);
365 group_starter_ = irc::GroupStarter::create(messenger_, irc_session);382 group_starter_ = irc::GroupStarter::create(messenger_, irc_session);
366383
367 // Initiate the IRC server connection384 // Initiate the IRC server connection
@@ -405,6 +422,7 @@
405 switch (new_status)422 switch (new_status)
406 {423 {
407 case Status::connected:424 case Status::connected:
425 nick_collision = 0;
408 break;426 break;
409 case Status::connecting:427 case Status::connecting:
410 break;428 break;
@@ -459,9 +477,14 @@
459477
460 messaging::Members members;478 messaging::Members members;
461 for (auto user: users) {479 for (auto user: users) {
462 members.push_back(std::make_shared<messaging::Member>(user, messaging::PendingStatus::None, messaging::Role::Member));480 if (user != self_identifier()) {
481 members.push_back(std::make_shared<messaging::Member>(user, messaging::PendingStatus::None, messaging::Role::Member));
482 continue;
483 }
463 }484 }
464 group_manager->handle_members_changed(members);485 group_manager->handle_members_changed(members);
486 members.push_back(std::make_shared<messaging::Member>(self_identifier(), messaging::PendingStatus::None, messaging::Role::Member));
487 group_manager->handle_members_changed(members);
465}488}
466489
467void irc::Connection::channel_member_joined(const std::string &channel, const std::string &nick)490void irc::Connection::channel_member_joined(const std::string &channel, const std::string &nick)
@@ -474,18 +497,18 @@
474 return;497 return;
475 }498 }
476 }499 }
477 group_manager->handle_member_joined(std::make_shared<messaging::Member>(nick, messaging::PendingStatus::None, messaging::Role::Member));500 messaging::PendingStatus pending_status = messaging::PendingStatus::None;
501 if (nick == self_identifier()) {
502 pending_status = messaging::PendingStatus::Remote;
503 }
504 group_manager->handle_member_joined(std::make_shared<messaging::Member>(nick, pending_status, messaging::Role::Member));
478}505}
479506
480void irc::Connection::channel_member_left(const std::string &channel, const std::string &nick)507void irc::Connection::channel_member_left(const std::string &channel, const std::string &nick)
481{508{
482 std::shared_ptr<irc::GroupManager> group_manager = messenger_->get_group_manager(channel);509 std::shared_ptr<irc::GroupManager> group_manager = messenger_->get_group_manager(channel);
483 if (!group_manager) {510 if (!group_manager) {
484 messenger_->handle_join_new_channel(channel, self_identifier());511 return;
485 group_manager = messenger_->get_group_manager(channel);
486 if (!group_manager) {
487 return;
488 }
489 }512 }
490513
491 group_manager->handle_member_left(std::make_shared<messaging::Member>(nick, messaging::PendingStatus::None, messaging::Role::Member));514 group_manager->handle_member_left(std::make_shared<messaging::Member>(nick, messaging::PendingStatus::None, messaging::Role::Member));
492515
=== modified file 'src/irc/group_chat.cpp'
--- src/irc/group_chat.cpp 2016-12-16 18:58:01 +0000
+++ src/irc/group_chat.cpp 2017-03-22 14:38:33 +0000
@@ -30,11 +30,14 @@
30 , irc_session(session)30 , irc_session(session)
31 , channel_id(group->id())31 , channel_id(group->id())
32{32{
33 irc_cmd_join(session, channel_id.c_str(), "");33 set_active(!irc_cmd_join(irc_session, channel_id.c_str(), ""));
34}34}
3535
36std::string irc::GroupChat::send_message(const messaging::Message& message)36std::string irc::GroupChat::send_message(const messaging::Message& message)
37{37{
38 if (!is_active) {
39 set_active(!irc_cmd_join(irc_session, channel_id.c_str(), ""));
40 }
38 boost::uuids::uuid uuid = boost::uuids::random_generator()();41 boost::uuids::uuid uuid = boost::uuids::random_generator()();
39 messaging::DeliveryStatus status = messaging::DeliveryStatus::permanently_failed;42 messaging::DeliveryStatus status = messaging::DeliveryStatus::permanently_failed;
40 std::string id(boost::lexical_cast<std::string>(uuid));43 std::string id(boost::lexical_cast<std::string>(uuid));
@@ -72,3 +75,8 @@
72{75{
73 return channel_id;76 return channel_id;
74}77}
78
79void irc::GroupChat::set_active(bool active)
80{
81 is_active = active;
82}
7583
=== modified file 'src/irc/group_manager.cpp'
--- src/irc/group_manager.cpp 2016-12-16 18:58:01 +0000
+++ src/irc/group_manager.cpp 2017-03-22 14:38:33 +0000
@@ -2,6 +2,7 @@
22
3#include <irc/messenger.h>3#include <irc/messenger.h>
4#include <irc/group_chat.h>4#include <irc/group_chat.h>
5#include <irc/connection.h>
56
67
7#include <memory>8#include <memory>
@@ -93,44 +94,92 @@
9394
94void irc::GroupManager::add_members(const messaging::Members &members)95void irc::GroupManager::add_members(const messaging::Members &members)
95{96{
96
97}97}
9898
99void irc::GroupManager::remove_members(const messaging::Members &members)99void irc::GroupManager::remove_members(const messaging::Members &members)
100{100{
101 for (auto member : members) {
102 if (member->id() == messenger_.lock()->connection->self_identifier()) {
103 leave_group();
104 }
105 }
101}106}
102107
103void irc::GroupManager::leave_group()108void irc::GroupManager::leave_group()
104{109{
105 irc_cmd_part(irc_session, group_id().c_str());110 irc_cmd_part(irc_session, group_id().c_str());
111 std::string self_identifier = messenger_.lock()->connection->self_identifier();
112
113 // first move self contact to pending list
114 auto it = std::find_if(participants.begin(), participants.end(), [self_identifier](const std::shared_ptr<messaging::Member>& m) {
115 return m->id() == self_identifier;
116 });
117 if (it != participants.end()) {
118 participants.erase(it);
119 participants.push_back(std::make_shared<messaging::Member>(self_identifier, messaging::PendingStatus::Remote, messaging::Role::Member));
120 }
121 announce_members_updated(participants);
122
123 participants.clear();
124 announce_members_updated(participants);
125
126 announce_group_cancelled(messaging::CancelGroupReason::Leave, "");
127 chat_.lock()->set_active(false);
128 messenger_.lock()->remove_chat(group_id());
106}129}
107130
108void irc::GroupManager::dissolve_group()131void irc::GroupManager::dissolve_group()
109{132{
110133 // not supported on irc
111}134}
112135
113void irc::GroupManager::handle_members_changed(messaging::Members new_participants)136void irc::GroupManager::handle_members_changed(messaging::Members new_participants)
114{137{
115 for (auto participant : new_participants) {138 for (auto new_participant : new_participants) {
116 participants.push_back(participant);139 auto it = std::find_if(participants.begin(), participants.end(), [new_participant](const std::shared_ptr<messaging::Member>& m) {
140 return m->id() == new_participant->id();
141 });
142 if (it != participants.end()) {
143 participants.erase(it);
144 }
145 participants.push_back(new_participant);
117 }146 }
118 announce_members_updated(participants);147 announce_members_updated(participants);
119}148}
120149
121void irc::GroupManager::handle_member_joined(const std::shared_ptr<messaging::Member> &member)150void irc::GroupManager::handle_member_joined(const std::shared_ptr<messaging::Member> &member)
122{151{
152 auto it = std::find_if(participants.begin(), participants.end(), [member](const std::shared_ptr<messaging::Member>& m) {
153 return m->id() == member->id();
154 });
155
156 if (it != participants.end()) {
157 return;
158 }
159
123 participants.push_back(member);160 participants.push_back(member);
124 announce_members_updated(participants);161 announce_members_updated(participants);
125}162}
126163
127void irc::GroupManager::handle_member_left(const std::shared_ptr<messaging::Member> &member)164void irc::GroupManager::handle_member_left(const std::shared_ptr<messaging::Member> &member)
128{165{
166 if (member->id() == messenger_.lock()->connection->self_identifier()) {
167 leave_group();
168 return;
169 }
170
129 auto it = std::find_if(participants.begin(), participants.end(), [member](const std::shared_ptr<messaging::Member>& m) {171 auto it = std::find_if(participants.begin(), participants.end(), [member](const std::shared_ptr<messaging::Member>& m) {
130 return m->id() == member->id();172 return m->id() == member->id();
131 });173 });
174
132 if (it != participants.end()) {175 if (it != participants.end()) {
133 participants.erase(it);176 participants.erase(it);
134 announce_members_updated(participants);177 announce_members_updated(participants);
135 }178 }
136}179}
180
181bool irc::GroupManager::persistent()
182{
183 return false;
184}
185
137186
=== modified file 'src/irc/messenger.cpp'
--- src/irc/messenger.cpp 2016-12-16 18:58:01 +0000
+++ src/irc/messenger.cpp 2017-03-22 14:38:33 +0000
@@ -2,6 +2,12 @@
2#include <irc/group_chat.h>2#include <irc/group_chat.h>
3#include <irc/contact_chat.h>3#include <irc/contact_chat.h>
4#include <irc/group_manager.h>4#include <irc/group_manager.h>
5#include <irc/connection.h>
6
7#include <boost/lexical_cast.hpp>
8#include <boost/uuid/uuid.hpp>
9#include <boost/uuid/uuid_generators.hpp>
10#include <boost/uuid/uuid_io.hpp>
511
6#include <messaging/group.h>12#include <messaging/group.h>
7#include <messaging/user.h>13#include <messaging/user.h>
@@ -13,15 +19,16 @@
1319
14using namespace std;20using namespace std;
1521
16irc::Messenger::Messenger(const std::shared_ptr<messaging::Messenger::Observer>& observer, irc_session_t *session)22irc::Messenger::Messenger(const std::shared_ptr<messaging::Messenger::Observer>& observer, const std::shared_ptr<irc::Connection> &_connection, irc_session_t *session)
17 : messaging::Messenger{observer}23 : messaging::Messenger{observer}
24 , connection(_connection)
18 , irc_session(session)25 , irc_session(session)
19{26{
20}27}
2128
22std::shared_ptr<irc::Messenger> irc::Messenger::create(const std::shared_ptr<messaging::Messenger::Observer>& observer, irc_session_t *session)29std::shared_ptr<irc::Messenger> irc::Messenger::create(const std::shared_ptr<messaging::Messenger::Observer>& observer, const std::shared_ptr<irc::Connection> &connection, irc_session_t *session)
23{30{
24 std::shared_ptr<Messenger> messenger(new Messenger{observer, session});31 std::shared_ptr<Messenger> messenger(new Messenger{observer, connection, session});
25 return messenger;32 return messenger;
26}33}
2734
@@ -48,6 +55,7 @@
48 auto chat = get_chat(channel);55 auto chat = get_chat(channel);
49 if (!chat) {56 if (!chat) {
50 messaging::Members initial_invitees;57 messaging::Members initial_invitees;
58 initial_invitees.push_back(std::make_shared<messaging::Member>(connection->self_identifier(), messaging::PendingStatus::Remote));
51 std::string initial_title;59 std::string initial_title;
52 announce_new_group_invitation_received(std::make_shared<messaging::Group>(channel, initial_invitees, initial_title, std::make_shared<messaging::Member>(the_creator)));60 announce_new_group_invitation_received(std::make_shared<messaging::Group>(channel, initial_invitees, initial_title, std::make_shared<messaging::Member>(the_creator)));
53 }61 }
@@ -58,6 +66,9 @@
58 messaging::Message api_message;66 messaging::Message api_message;
59 api_message.sender = sender;67 api_message.sender = sender;
60 api_message.message = message;68 api_message.message = message;
69 boost::uuids::uuid uuid = boost::uuids::random_generator()();
70 api_message.id = boost::lexical_cast<std::string>(uuid);
71
61 auto chat = get_chat(sender);72 auto chat = get_chat(sender);
62 if (chat) {73 if (chat) {
63 dynamic_pointer_cast<irc::ContactChat>(chat)->handle_incoming_message(api_message);74 dynamic_pointer_cast<irc::ContactChat>(chat)->handle_incoming_message(api_message);
@@ -71,6 +82,9 @@
71 messaging::Message api_message;82 messaging::Message api_message;
72 api_message.sender = sender;83 api_message.sender = sender;
73 api_message.message = message;84 api_message.message = message;
85 boost::uuids::uuid uuid = boost::uuids::random_generator()();
86 api_message.id = boost::lexical_cast<std::string>(uuid);
87
74 auto chat = get_chat(channel);88 auto chat = get_chat(channel);
75 if (chat) {89 if (chat) {
76 dynamic_pointer_cast<irc::GroupChat>(chat)->handle_incoming_message(api_message);90 dynamic_pointer_cast<irc::GroupChat>(chat)->handle_incoming_message(api_message);
@@ -101,3 +115,8 @@
101115
102 return std::dynamic_pointer_cast<irc::GroupManager>(group_manager);116 return std::dynamic_pointer_cast<irc::GroupManager>(group_manager);
103}117}
118
119void irc::Messenger::remove_chat(const std::string &chat_id)
120{
121 chats().erase(chat_id);
122}

Subscribers

People subscribed via source and target branches

to all changes: