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
1=== added directory '.bzr-builddeb'
2=== added file '.bzr-builddeb/default.conf'
3--- .bzr-builddeb/default.conf 1970-01-01 00:00:00 +0000
4+++ .bzr-builddeb/default.conf 2017-03-22 14:38:33 +0000
5@@ -0,0 +1,2 @@
6+[BUILDDEB]
7+split = True
8
9=== added file 'COPYING'
10--- COPYING 1970-01-01 00:00:00 +0000
11+++ COPYING 2017-03-22 14:38:33 +0000
12@@ -0,0 +1,165 @@
13+ GNU LESSER GENERAL PUBLIC LICENSE
14+ Version 3, 29 June 2007
15+
16+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
17+ Everyone is permitted to copy and distribute verbatim copies
18+ of this license document, but changing it is not allowed.
19+
20+
21+ This version of the GNU Lesser General Public License incorporates
22+the terms and conditions of version 3 of the GNU General Public
23+License, supplemented by the additional permissions listed below.
24+
25+ 0. Additional Definitions.
26+
27+ As used herein, "this License" refers to version 3 of the GNU Lesser
28+General Public License, and the "GNU GPL" refers to version 3 of the GNU
29+General Public License.
30+
31+ "The Library" refers to a covered work governed by this License,
32+other than an Application or a Combined Work as defined below.
33+
34+ An "Application" is any work that makes use of an interface provided
35+by the Library, but which is not otherwise based on the Library.
36+Defining a subclass of a class defined by the Library is deemed a mode
37+of using an interface provided by the Library.
38+
39+ A "Combined Work" is a work produced by combining or linking an
40+Application with the Library. The particular version of the Library
41+with which the Combined Work was made is also called the "Linked
42+Version".
43+
44+ The "Minimal Corresponding Source" for a Combined Work means the
45+Corresponding Source for the Combined Work, excluding any source code
46+for portions of the Combined Work that, considered in isolation, are
47+based on the Application, and not on the Linked Version.
48+
49+ The "Corresponding Application Code" for a Combined Work means the
50+object code and/or source code for the Application, including any data
51+and utility programs needed for reproducing the Combined Work from the
52+Application, but excluding the System Libraries of the Combined Work.
53+
54+ 1. Exception to Section 3 of the GNU GPL.
55+
56+ You may convey a covered work under sections 3 and 4 of this License
57+without being bound by section 3 of the GNU GPL.
58+
59+ 2. Conveying Modified Versions.
60+
61+ If you modify a copy of the Library, and, in your modifications, a
62+facility refers to a function or data to be supplied by an Application
63+that uses the facility (other than as an argument passed when the
64+facility is invoked), then you may convey a copy of the modified
65+version:
66+
67+ a) under this License, provided that you make a good faith effort to
68+ ensure that, in the event an Application does not supply the
69+ function or data, the facility still operates, and performs
70+ whatever part of its purpose remains meaningful, or
71+
72+ b) under the GNU GPL, with none of the additional permissions of
73+ this License applicable to that copy.
74+
75+ 3. Object Code Incorporating Material from Library Header Files.
76+
77+ The object code form of an Application may incorporate material from
78+a header file that is part of the Library. You may convey such object
79+code under terms of your choice, provided that, if the incorporated
80+material is not limited to numerical parameters, data structure
81+layouts and accessors, or small macros, inline functions and templates
82+(ten or fewer lines in length), you do both of the following:
83+
84+ a) Give prominent notice with each copy of the object code that the
85+ Library is used in it and that the Library and its use are
86+ covered by this License.
87+
88+ b) Accompany the object code with a copy of the GNU GPL and this license
89+ document.
90+
91+ 4. Combined Works.
92+
93+ You may convey a Combined Work under terms of your choice that,
94+taken together, effectively do not restrict modification of the
95+portions of the Library contained in the Combined Work and reverse
96+engineering for debugging such modifications, if you also do each of
97+the following:
98+
99+ a) Give prominent notice with each copy of the Combined Work that
100+ the Library is used in it and that the Library and its use are
101+ covered by this License.
102+
103+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
104+ document.
105+
106+ c) For a Combined Work that displays copyright notices during
107+ execution, include the copyright notice for the Library among
108+ these notices, as well as a reference directing the user to the
109+ copies of the GNU GPL and this license document.
110+
111+ d) Do one of the following:
112+
113+ 0) Convey the Minimal Corresponding Source under the terms of this
114+ License, and the Corresponding Application Code in a form
115+ suitable for, and under terms that permit, the user to
116+ recombine or relink the Application with a modified version of
117+ the Linked Version to produce a modified Combined Work, in the
118+ manner specified by section 6 of the GNU GPL for conveying
119+ Corresponding Source.
120+
121+ 1) Use a suitable shared library mechanism for linking with the
122+ Library. A suitable mechanism is one that (a) uses at run time
123+ a copy of the Library already present on the user's computer
124+ system, and (b) will operate properly with a modified version
125+ of the Library that is interface-compatible with the Linked
126+ Version.
127+
128+ e) Provide Installation Information, but only if you would otherwise
129+ be required to provide such information under section 6 of the
130+ GNU GPL, and only to the extent that such information is
131+ necessary to install and execute a modified version of the
132+ Combined Work produced by recombining or relinking the
133+ Application with a modified version of the Linked Version. (If
134+ you use option 4d0, the Installation Information must accompany
135+ the Minimal Corresponding Source and Corresponding Application
136+ Code. If you use option 4d1, you must provide the Installation
137+ Information in the manner specified by section 6 of the GNU GPL
138+ for conveying Corresponding Source.)
139+
140+ 5. Combined Libraries.
141+
142+ You may place library facilities that are a work based on the
143+Library side by side in a single library together with other library
144+facilities that are not Applications and are not covered by this
145+License, and convey such a combined library under terms of your
146+choice, if you do both of the following:
147+
148+ a) Accompany the combined library with a copy of the same work based
149+ on the Library, uncombined with any other library facilities,
150+ conveyed under the terms of this License.
151+
152+ b) Give prominent notice with the combined library that part of it
153+ is a work based on the Library, and explaining where to find the
154+ accompanying uncombined form of the same work.
155+
156+ 6. Revised Versions of the GNU Lesser General Public License.
157+
158+ The Free Software Foundation may publish revised and/or new versions
159+of the GNU Lesser General Public License from time to time. Such new
160+versions will be similar in spirit to the present version, but may
161+differ in detail to address new problems or concerns.
162+
163+ Each version is given a distinguishing version number. If the
164+Library as you received it specifies that a certain numbered version
165+of the GNU Lesser General Public License "or any later version"
166+applies to it, you have the option of following the terms and
167+conditions either of that published version or of any later version
168+published by the Free Software Foundation. If the Library as you
169+received it does not specify a version number of the GNU Lesser
170+General Public License, you may choose any version of the GNU Lesser
171+General Public License ever published by the Free Software Foundation.
172+
173+ If the Library as you received it specifies that a proxy can decide
174+whether future versions of the GNU Lesser General Public License shall
175+apply, that proxy's public statement of acceptance of any version is
176+permanent authorization for you to choose that version for the
177+Library.
178
179=== modified file 'data/irc.protocol.in'
180--- data/irc.protocol.in 2016-12-16 18:58:01 +0000
181+++ data/irc.protocol.in 2017-03-22 14:38:33 +0000
182@@ -9,3 +9,8 @@
183 ShowOnSelector=1
184 ShowOnlineStatus=0
185 JoinExistingChannels=1
186+ReturnToSend=1
187+EnableAttachments=0
188+EnableRejoin=1
189+EnableTabCompletion=1
190+LeaveRoomsOnClose=1
191
192=== modified file 'data/irc.service.in'
193--- data/irc.service.in 2016-12-16 18:58:01 +0000
194+++ data/irc.service.in 2017-03-22 14:38:33 +0000
195@@ -1,3 +1,3 @@
196 [D-BUS Service]
197 Name=org.freedesktop.Telepathy.ConnectionManager.@CM@
198-Exec=@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@.so
199+Exec=@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
200
201=== modified file 'debian/changelog'
202--- debian/changelog 2016-12-16 18:58:01 +0000
203+++ debian/changelog 2017-03-22 14:38:33 +0000
204@@ -1,4 +1,4 @@
205-mfw-plugin-irc (0.1) xenial; urgency=medium
206+mfw-plugin-irc (0.1-0ubuntu1) xenial; urgency=medium
207
208 * Initial release
209
210
211=== modified file 'debian/control'
212--- debian/control 2016-12-16 18:58:01 +0000
213+++ debian/control 2017-03-22 14:38:33 +0000
214@@ -1,11 +1,8 @@
215 Source: mfw-plugin-irc
216 Priority: optional
217 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
218-Build-Depends: astyle:native,
219- clang-format-3.5:native,
220- cmake,
221+Build-Depends: cmake,
222 debhelper (>= 9),
223- dos2unix:native,
224 doxygen,
225 gcovr,
226 google-mock,
227@@ -14,16 +11,16 @@
228 libboost-filesystem-dev,
229 libboost-program-options-dev,
230 libboost-system-dev,
231+ libcppnetlib-dev,
232 libdbus-cpp-dev,
233 libgoogle-glog-dev,
234- libircclient-dev
235+ libircclient-dev,
236 libmessaging-framework-dev,
237 libprocess-cpp-dev,
238- libtelepathy-qt5-dev,
239+ libtelepathy-qt5-dev,
240 pkg-config,
241- qtbase5-dev,
242- libcppnetlib-dev,
243-Standards-Version: 3.9.5
244+ qtbase5-dev
245+Standards-Version: 3.9.7
246 Section: libs
247 Homepage: https://launchpad.net/mfw-plugin-irc
248 Vcs-Bzr: https://code.launchpad.net/
249
250=== removed directory 'debian/source'
251=== removed file 'debian/source/format'
252--- debian/source/format 2016-12-16 18:58:01 +0000
253+++ debian/source/format 1970-01-01 00:00:00 +0000
254@@ -1,1 +0,0 @@
255-3.0 (native)
256
257=== modified file 'include/irc/connection.h'
258--- include/irc/connection.h 2016-12-16 18:58:01 +0000
259+++ include/irc/connection.h 2017-03-22 14:38:33 +0000
260@@ -95,6 +95,7 @@
261
262 std::string server_id;
263 std::string nickname;
264+ int nick_collision;
265
266 private:
267
268
269=== modified file 'include/irc/group_chat.h'
270--- include/irc/group_chat.h 2016-12-16 18:58:01 +0000
271+++ include/irc/group_chat.h 2017-03-22 14:38:33 +0000
272@@ -39,6 +39,10 @@
273 void mark_message_as_delivered(const std::string& message_token);
274 std::string id();
275
276+ void set_active(bool active);
277+ bool active();
278+
279+
280 private:
281 /// @brief Creates a new instance translating the given recipient to a user.
282 GroupChat(const std::shared_ptr<messaging::Group> &group,
283@@ -46,6 +50,7 @@
284
285 irc_session_t *irc_session;
286 std::string channel_id;
287+ bool is_active;
288
289 };
290
291
292=== modified file 'include/irc/group_manager.h'
293--- include/irc/group_manager.h 2016-12-16 18:58:01 +0000
294+++ include/irc/group_manager.h 2017-03-22 14:38:33 +0000
295@@ -38,6 +38,7 @@
296 std::string group_id() override;
297 std::string group_title() override;
298 std::string group_subject() override;
299+ bool persistent() override;
300 std::shared_ptr<messaging::Member> group_creator() override;
301 std::set<std::string> group_admins() override;
302 messaging::Members members() override;
303@@ -72,8 +73,6 @@
304 irc_session_t *irc_session;
305 std::string creator;
306
307- /// @brief this valImClientImplue is created when chat is created and sent in any method call into the chat
308-
309 };
310
311 }
312
313=== modified file 'include/irc/messenger.h'
314--- include/irc/messenger.h 2016-12-16 18:58:01 +0000
315+++ include/irc/messenger.h 2017-03-22 14:38:33 +0000
316@@ -14,6 +14,7 @@
317 class Message;
318 class File;
319 class Connector;
320+class Connection;
321 class GroupManager;
322
323 class IRC_PUBLIC Messenger
324@@ -25,7 +26,7 @@
325 DEFINE_PTRS(Messenger);
326 /// @endcond
327
328- static std::shared_ptr<Messenger> create(const std::shared_ptr<Messenger::Observer>& messenger_observer, irc_session_t *irc_session);
329+ 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);
330
331 std::shared_ptr<messaging::Chat> create_chat_with(const messaging::Recipient::shared_ptr& recipient, const std::shared_ptr<messaging::Chat::Observer>& observer) override;
332
333@@ -34,9 +35,11 @@
334 std::shared_ptr<GroupManager> get_group_manager(const std::string &group_chat_id);
335 void handle_join_new_channel(const std::string &channel);
336 void handle_join_new_channel(const std::string &channel, const std::string &the_creator);
337+ void remove_chat(const std::string &chat_id);
338
339+ std::shared_ptr<irc::Connection> connection;
340 private:
341- Messenger(const std::shared_ptr<messaging::Messenger::Observer>& observer, irc_session_t *irc_session);
342+ Messenger(const std::shared_ptr<messaging::Messenger::Observer>& observer, const std::shared_ptr<irc::Connection> &connection, irc_session_t *irc_session);
343
344 /// @brief identity provider to correlate msg_id with imdn unique identifier. First will be
345 /// used internally for chat messages and the other used as message external unique id
346
347=== modified file 'src/CMakeLists.txt'
348--- src/CMakeLists.txt 2016-12-16 18:58:01 +0000
349+++ src/CMakeLists.txt 2017-03-22 14:38:33 +0000
350@@ -34,4 +34,4 @@
351
352 install(
353 TARGETS ${PLUGIN_NAME}
354- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
355+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/messaging-framework)
356
357=== modified file 'src/irc/connection.cpp'
358--- src/irc/connection.cpp 2016-12-16 18:58:01 +0000
359+++ src/irc/connection.cpp 2017-03-22 14:38:33 +0000
360@@ -151,6 +151,15 @@
361 std::string irc_channel(params[1]);
362 ctx->channel_members_changed(irc_channel, channel_users[irc_channel]);
363 channel_users.erase(irc_channel);
364+ } else if (event == LIBIRC_RFC_ERR_NICKNAMEINUSE) {
365+ if (ctx->nick_collision++ < 3) {
366+ std::string irc_nick(params[1]);
367+ irc_nick += "_";
368+ irc_cmd_nick(session, irc_nick.c_str());
369+ } else {
370+ LOG(INFO) << "Could not connect. Nickname already in use";
371+ ctx->disconnect(messaging::Connection::StatusChangedReason::name_in_use);
372+ }
373 }
374 }
375
376@@ -213,6 +222,7 @@
377 , port(6667)
378 , use_ssl(false)
379 , verify_ssl_cert(true)
380+ , nick_collision(0)
381 {
382 messaging::Parameter server_param{"server", "s", messaging::Parameter::Flags::required|messaging::Parameter::Flags::required_for_registration};
383 messaging::Parameter port_param{"port", "q", messaging::Parameter::Flags::none};
384@@ -253,6 +263,9 @@
385 {
386 throw std::runtime_error{"nickname could not be found"};
387 }
388+ if (username.empty()) {
389+ username = nickname;
390+ }
391 }
392 else
393 {
394@@ -269,6 +282,10 @@
395 fullname = fullname_param.extract_from(dict).as_string();
396 }
397
398+ if (fullname.empty()) {
399+ fullname = nickname;
400+ }
401+
402 if (use_ssl_param.can_extract_from(dict))
403 {
404 use_ssl = use_ssl_param.extract_from(dict).as_bool();
405@@ -361,7 +378,7 @@
406 irc_set_ctx(irc_session, ctx);
407
408 // initiate other components
409- messenger_ = Messenger::create(messenger_observer_, irc_session);
410+ messenger_ = Messenger::create(messenger_observer_, shared_from_this(), irc_session);
411 group_starter_ = irc::GroupStarter::create(messenger_, irc_session);
412
413 // Initiate the IRC server connection
414@@ -405,6 +422,7 @@
415 switch (new_status)
416 {
417 case Status::connected:
418+ nick_collision = 0;
419 break;
420 case Status::connecting:
421 break;
422@@ -459,9 +477,14 @@
423
424 messaging::Members members;
425 for (auto user: users) {
426- members.push_back(std::make_shared<messaging::Member>(user, messaging::PendingStatus::None, messaging::Role::Member));
427+ if (user != self_identifier()) {
428+ members.push_back(std::make_shared<messaging::Member>(user, messaging::PendingStatus::None, messaging::Role::Member));
429+ continue;
430+ }
431 }
432 group_manager->handle_members_changed(members);
433+ members.push_back(std::make_shared<messaging::Member>(self_identifier(), messaging::PendingStatus::None, messaging::Role::Member));
434+ group_manager->handle_members_changed(members);
435 }
436
437 void irc::Connection::channel_member_joined(const std::string &channel, const std::string &nick)
438@@ -474,18 +497,18 @@
439 return;
440 }
441 }
442- group_manager->handle_member_joined(std::make_shared<messaging::Member>(nick, messaging::PendingStatus::None, messaging::Role::Member));
443+ messaging::PendingStatus pending_status = messaging::PendingStatus::None;
444+ if (nick == self_identifier()) {
445+ pending_status = messaging::PendingStatus::Remote;
446+ }
447+ group_manager->handle_member_joined(std::make_shared<messaging::Member>(nick, pending_status, messaging::Role::Member));
448 }
449
450 void irc::Connection::channel_member_left(const std::string &channel, const std::string &nick)
451 {
452 std::shared_ptr<irc::GroupManager> group_manager = messenger_->get_group_manager(channel);
453 if (!group_manager) {
454- messenger_->handle_join_new_channel(channel, self_identifier());
455- group_manager = messenger_->get_group_manager(channel);
456- if (!group_manager) {
457- return;
458- }
459+ return;
460 }
461
462 group_manager->handle_member_left(std::make_shared<messaging::Member>(nick, messaging::PendingStatus::None, messaging::Role::Member));
463
464=== modified file 'src/irc/group_chat.cpp'
465--- src/irc/group_chat.cpp 2016-12-16 18:58:01 +0000
466+++ src/irc/group_chat.cpp 2017-03-22 14:38:33 +0000
467@@ -30,11 +30,14 @@
468 , irc_session(session)
469 , channel_id(group->id())
470 {
471- irc_cmd_join(session, channel_id.c_str(), "");
472+ set_active(!irc_cmd_join(irc_session, channel_id.c_str(), ""));
473 }
474
475 std::string irc::GroupChat::send_message(const messaging::Message& message)
476 {
477+ if (!is_active) {
478+ set_active(!irc_cmd_join(irc_session, channel_id.c_str(), ""));
479+ }
480 boost::uuids::uuid uuid = boost::uuids::random_generator()();
481 messaging::DeliveryStatus status = messaging::DeliveryStatus::permanently_failed;
482 std::string id(boost::lexical_cast<std::string>(uuid));
483@@ -72,3 +75,8 @@
484 {
485 return channel_id;
486 }
487+
488+void irc::GroupChat::set_active(bool active)
489+{
490+ is_active = active;
491+}
492
493=== modified file 'src/irc/group_manager.cpp'
494--- src/irc/group_manager.cpp 2016-12-16 18:58:01 +0000
495+++ src/irc/group_manager.cpp 2017-03-22 14:38:33 +0000
496@@ -2,6 +2,7 @@
497
498 #include <irc/messenger.h>
499 #include <irc/group_chat.h>
500+#include <irc/connection.h>
501
502
503 #include <memory>
504@@ -93,44 +94,92 @@
505
506 void irc::GroupManager::add_members(const messaging::Members &members)
507 {
508-
509 }
510
511 void irc::GroupManager::remove_members(const messaging::Members &members)
512 {
513+ for (auto member : members) {
514+ if (member->id() == messenger_.lock()->connection->self_identifier()) {
515+ leave_group();
516+ }
517+ }
518 }
519
520 void irc::GroupManager::leave_group()
521 {
522 irc_cmd_part(irc_session, group_id().c_str());
523+ std::string self_identifier = messenger_.lock()->connection->self_identifier();
524+
525+ // first move self contact to pending list
526+ auto it = std::find_if(participants.begin(), participants.end(), [self_identifier](const std::shared_ptr<messaging::Member>& m) {
527+ return m->id() == self_identifier;
528+ });
529+ if (it != participants.end()) {
530+ participants.erase(it);
531+ participants.push_back(std::make_shared<messaging::Member>(self_identifier, messaging::PendingStatus::Remote, messaging::Role::Member));
532+ }
533+ announce_members_updated(participants);
534+
535+ participants.clear();
536+ announce_members_updated(participants);
537+
538+ announce_group_cancelled(messaging::CancelGroupReason::Leave, "");
539+ chat_.lock()->set_active(false);
540+ messenger_.lock()->remove_chat(group_id());
541 }
542
543 void irc::GroupManager::dissolve_group()
544 {
545-
546+ // not supported on irc
547 }
548
549 void irc::GroupManager::handle_members_changed(messaging::Members new_participants)
550 {
551- for (auto participant : new_participants) {
552- participants.push_back(participant);
553+ for (auto new_participant : new_participants) {
554+ auto it = std::find_if(participants.begin(), participants.end(), [new_participant](const std::shared_ptr<messaging::Member>& m) {
555+ return m->id() == new_participant->id();
556+ });
557+ if (it != participants.end()) {
558+ participants.erase(it);
559+ }
560+ participants.push_back(new_participant);
561 }
562 announce_members_updated(participants);
563 }
564
565 void irc::GroupManager::handle_member_joined(const std::shared_ptr<messaging::Member> &member)
566 {
567+ auto it = std::find_if(participants.begin(), participants.end(), [member](const std::shared_ptr<messaging::Member>& m) {
568+ return m->id() == member->id();
569+ });
570+
571+ if (it != participants.end()) {
572+ return;
573+ }
574+
575 participants.push_back(member);
576 announce_members_updated(participants);
577 }
578
579 void irc::GroupManager::handle_member_left(const std::shared_ptr<messaging::Member> &member)
580 {
581+ if (member->id() == messenger_.lock()->connection->self_identifier()) {
582+ leave_group();
583+ return;
584+ }
585+
586 auto it = std::find_if(participants.begin(), participants.end(), [member](const std::shared_ptr<messaging::Member>& m) {
587 return m->id() == member->id();
588 });
589+
590 if (it != participants.end()) {
591 participants.erase(it);
592 announce_members_updated(participants);
593 }
594 }
595+
596+bool irc::GroupManager::persistent()
597+{
598+ return false;
599+}
600+
601
602=== modified file 'src/irc/messenger.cpp'
603--- src/irc/messenger.cpp 2016-12-16 18:58:01 +0000
604+++ src/irc/messenger.cpp 2017-03-22 14:38:33 +0000
605@@ -2,6 +2,12 @@
606 #include <irc/group_chat.h>
607 #include <irc/contact_chat.h>
608 #include <irc/group_manager.h>
609+#include <irc/connection.h>
610+
611+#include <boost/lexical_cast.hpp>
612+#include <boost/uuid/uuid.hpp>
613+#include <boost/uuid/uuid_generators.hpp>
614+#include <boost/uuid/uuid_io.hpp>
615
616 #include <messaging/group.h>
617 #include <messaging/user.h>
618@@ -13,15 +19,16 @@
619
620 using namespace std;
621
622-irc::Messenger::Messenger(const std::shared_ptr<messaging::Messenger::Observer>& observer, irc_session_t *session)
623+irc::Messenger::Messenger(const std::shared_ptr<messaging::Messenger::Observer>& observer, const std::shared_ptr<irc::Connection> &_connection, irc_session_t *session)
624 : messaging::Messenger{observer}
625+ , connection(_connection)
626 , irc_session(session)
627 {
628 }
629
630-std::shared_ptr<irc::Messenger> irc::Messenger::create(const std::shared_ptr<messaging::Messenger::Observer>& observer, irc_session_t *session)
631+std::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)
632 {
633- std::shared_ptr<Messenger> messenger(new Messenger{observer, session});
634+ std::shared_ptr<Messenger> messenger(new Messenger{observer, connection, session});
635 return messenger;
636 }
637
638@@ -48,6 +55,7 @@
639 auto chat = get_chat(channel);
640 if (!chat) {
641 messaging::Members initial_invitees;
642+ initial_invitees.push_back(std::make_shared<messaging::Member>(connection->self_identifier(), messaging::PendingStatus::Remote));
643 std::string initial_title;
644 announce_new_group_invitation_received(std::make_shared<messaging::Group>(channel, initial_invitees, initial_title, std::make_shared<messaging::Member>(the_creator)));
645 }
646@@ -58,6 +66,9 @@
647 messaging::Message api_message;
648 api_message.sender = sender;
649 api_message.message = message;
650+ boost::uuids::uuid uuid = boost::uuids::random_generator()();
651+ api_message.id = boost::lexical_cast<std::string>(uuid);
652+
653 auto chat = get_chat(sender);
654 if (chat) {
655 dynamic_pointer_cast<irc::ContactChat>(chat)->handle_incoming_message(api_message);
656@@ -71,6 +82,9 @@
657 messaging::Message api_message;
658 api_message.sender = sender;
659 api_message.message = message;
660+ boost::uuids::uuid uuid = boost::uuids::random_generator()();
661+ api_message.id = boost::lexical_cast<std::string>(uuid);
662+
663 auto chat = get_chat(channel);
664 if (chat) {
665 dynamic_pointer_cast<irc::GroupChat>(chat)->handle_incoming_message(api_message);
666@@ -101,3 +115,8 @@
667
668 return std::dynamic_pointer_cast<irc::GroupManager>(group_manager);
669 }
670+
671+void irc::Messenger::remove_chat(const std::string &chat_id)
672+{
673+ chats().erase(chat_id);
674+}

Subscribers

People subscribed via source and target branches

to all changes: