Merge lp:~libqtelegram-team/telegram-app/dev-remove-only-some-members into lp:telegram-app/dev

Proposed by Michał Karnicki
Status: Merged
Approved by: Roberto Mier Escandon
Approved revision: 136
Merged at revision: 135
Proposed branch: lp:~libqtelegram-team/telegram-app/dev-remove-only-some-members
Merge into: lp:telegram-app/dev
Diff against target: 249 lines (+104/-29)
6 files modified
lib/core/eventtimer.cpp (+0/-1)
qmlplugin/data.cpp (+1/-1)
qmlplugin/models/groupmembersmodel.cpp (+67/-19)
qmlplugin/models/groupmembersmodel.h (+28/-2)
qmlplugin/models/groupmodel.cpp (+5/-2)
qmlplugin/models/groupmodel.h (+3/-4)
To merge this branch: bzr merge lp:~libqtelegram-team/telegram-app/dev-remove-only-some-members
Reviewer Review Type Date Requested Status
Michał Karnicki (community) Approve
Roberto Mier Escandon (community) Needs Fixing
Review via email: mp+244590@code.launchpad.net

Description of the change

Test with UI proposed here:
https://code.launchpad.net/~libqtelegram-team/libqtelegram/app-dev-remove-only-some-members/+merge/244589

Added isRemovable role in group members profile.

To post a comment you must log in.
Revision history for this message
Roberto Mier Escandon (rmescandon) wrote :

inline

review: Needs Fixing
135. By Michał Karnicki

Review fixes.

Revision history for this message
Roberto Mier Escandon (rmescandon) wrote :

Test1:
- Create a group with 3 people (including the user of our app) from another account (our user is not admin or inviter)
Expected:
- I cannot kick anybody but myself
Result:
- I cannot even leave the chat. I'm catched in the chat forever!!! ;)
----------------------------------------------------------------------
Test2:
- Pressing on participant picture into group chat profile
Expected:
- Shown that user profile
Result:
- Opened dialog 1-1 with that user

review: Needs Fixing
136. By Roberto Mier Escandon

modified groupsmembers model to include app user in the authorized users to be removed from a chat

Revision history for this message
Roberto Mier Escandon (rmescandon) wrote :

Fixed the Test1 issue.
Included copyright headers in groupmembersmodel files

Revision history for this message
Michał Karnicki (karni) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/core/eventtimer.cpp'
2--- lib/core/eventtimer.cpp 2014-12-09 18:32:04 +0000
3+++ lib/core/eventtimer.cpp 2014-12-12 15:35:59 +0000
4@@ -15,7 +15,6 @@
5 */
6
7 #include "eventtimer.h"
8-#include <QDebug> //remove when not needed
9
10 EventTimer::EventTimer(qint64 msgId, qint32 timeout, QObject *parent) :
11 QTimer(parent), mMsgId(msgId) {
12
13=== modified file 'qmlplugin/data.cpp'
14--- qmlplugin/data.cpp 2014-12-12 08:44:51 +0000
15+++ qmlplugin/data.cpp 2014-12-12 15:35:59 +0000
16@@ -3920,7 +3920,7 @@
17 query.bindValue(":isAdmin", chatParticipants.adminId() == member.userId());
18 query.bindValue(":version", chatParticipants.version());
19 if (!query.exec()) {
20- throw "Error updating chat participants (on removal)";
21+ throw "Error updating chat participants (on insert)";
22 }
23 }
24 }
25
26=== modified file 'qmlplugin/models/groupmembersmodel.cpp'
27--- qmlplugin/models/groupmembersmodel.cpp 2014-11-14 12:47:25 +0000
28+++ qmlplugin/models/groupmembersmodel.cpp 2014-12-12 15:35:59 +0000
29@@ -1,33 +1,68 @@
30+/*
31+ * Copyright 2014 Canonical Ltd.
32+ *
33+ * This program is free software; you can redistribute it and/or modify
34+ * it under the terms of the GNU General Public License as published by
35+ * the Free Software Foundation; version 3.
36+ *
37+ * This program is distributed in the hope that it will be useful,
38+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
39+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40+ * GNU General Public License for more details.
41+ *
42+ * You should have received a copy of the GNU General Public License
43+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
44+ */
45+
46 #include "models/groupmembersmodel.h"
47 #include "types/tluser.h"
48 #include "types/tlinputpeer.h"
49-#include <QDebug>
50+
51 GroupMembersModel::GroupMembersModel(QObject *parent) :
52- Model(parent) {
53-}
54-
55-QHash<int, QByteArray> GroupMembersModel::roleNames() const {
56- QHash<int, QByteArray> roles;
57- roles[IdRole] = "id";
58- roles[NameRole] = "name";
59- roles[PhotoRole] = "photo";
60- roles[LastSeenOnlineRole] = "lastSeenOnline";
61- roles[OnlineRole] = "online";
62- roles[IsAdminRole] = "isAdmin";
63- roles[PeerTypeRole] = "peerType";
64- return roles;
65-}
66-
67-void GroupMembersModel::setup(qint32 chatId) {
68+ Model(parent), mTelegramClient(NULL), mChatId(0) {
69+}
70+
71+GroupMembersModel::~GroupMembersModel() {
72+ mTelegramClient = NULL;
73+}
74+
75+void GroupMembersModel::setup(TelegramClient *telegramClient, qint32 chatId) {
76+ Q_ASSERT(telegramClient != NULL);
77+
78+ if (mTelegramClient == NULL) {
79+ mTelegramClient = telegramClient;
80+ connect(mTelegramClient, SIGNAL(chatUpdated(qint32)),
81+ this, SLOT(refresh(qint32)));
82+ }
83+ mChatId = chatId;
84+ refresh(mChatId);
85+}
86+
87+void GroupMembersModel::refresh(qint32 chatId) {
88+ if (mChatId != chatId || mTelegramClient == NULL) return;
89+ /*
90+ * Member is removalbe from chat if one of the conditions is met:
91+ * - we are the chat admin
92+ * - we have invited that member
93+ */
94 mQueryString = QString("SELECT id, "
95 " (firstName || \" \" || lastName) AS name, "
96 " (SELECT localPath FROM fileLocations WHERE rowid=thumbnail) AS photo, "
97 " lastSeenOnline, online, isAdmin, "
98+ /* admin */ " (SELECT CASE WHEN EXISTS"
99+ " (SELECT isAdmin FROM participants "
100+ " WHERE participants.chatId = %1 "
101+ " AND participants.userId = %2 "
102+ " AND participants.isAdmin = 1) "
103+ /* or inviter */ " THEN 1 ELSE 0 END) OR inviterId = %2 "
104+ /* or me */ " OR userId = %2 AS isRemovable, "
105 " (SELECT type FROM users WHERE users.id=participants.userId) AS peerType "
106 "FROM users, participants "
107 "WHERE participants.chatId = %1 AND users.id=participants.userId "
108- "ORDER BY online DESC, lastSeenOnline DESC").arg(chatId);
109- refresh();
110+ "ORDER BY online DESC, lastSeenOnline DESC")
111+ .arg(chatId)
112+ .arg(mTelegramClient->ourId());
113+ Model::refresh();
114 }
115
116 qint32 GroupMembersModel::getInputPeerType(qint32 peerType) {
117@@ -48,3 +83,16 @@
118 }
119 return InputPeer::typeInputPeerEmpty;
120 }
121+
122+QHash<int, QByteArray> GroupMembersModel::roleNames() const {
123+ QHash<int, QByteArray> roles;
124+ roles[IdRole] = "id";
125+ roles[NameRole] = "name";
126+ roles[PhotoRole] = "photo";
127+ roles[LastSeenOnlineRole] = "lastSeenOnline";
128+ roles[OnlineRole] = "online";
129+ roles[IsAdminRole] = "isAdmin";
130+ roles[IsRemovableRole] = "isRemovable";
131+ roles[PeerTypeRole] = "peerType";
132+ return roles;
133+}
134
135=== modified file 'qmlplugin/models/groupmembersmodel.h'
136--- qmlplugin/models/groupmembersmodel.h 2014-11-14 12:47:25 +0000
137+++ qmlplugin/models/groupmembersmodel.h 2014-12-12 15:35:59 +0000
138@@ -1,8 +1,26 @@
139+/*
140+ * Copyright 2014 Canonical Ltd.
141+ *
142+ * This program is free software; you can redistribute it and/or modify
143+ * it under the terms of the GNU General Public License as published by
144+ * the Free Software Foundation; version 3.
145+ *
146+ * This program is distributed in the hope that it will be useful,
147+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
148+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
149+ * GNU General Public License for more details.
150+ *
151+ * You should have received a copy of the GNU General Public License
152+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
153+ */
154+
155 #ifndef GROUP_MEMBERS_MODEL_H
156 #define GROUP_MEMBERS_MODEL_H
157
158+#include <QLoggingCategory>
159+
160 #include "model.h"
161-#include <QLoggingCategory>
162+#include "telegramclient.h"
163
164 class GroupMembersModel : public Model
165 {
166@@ -17,15 +35,23 @@
167 LastSeenOnlineRole,
168 OnlineRole,
169 IsAdminRole,
170+ IsRemovableRole,
171 PeerTypeRole
172 };
173
174 explicit GroupMembersModel(QObject *parent = 0);
175+ ~GroupMembersModel();
176
177- Q_INVOKABLE void setup(qint32 chatId);
178+ Q_INVOKABLE void setup(TelegramClient *telegramClient, qint32 chatId);
179 Q_INVOKABLE qint32 getInputPeerType(qint32 userType);
180
181+public Q_SLOTS:
182+ void refresh(qint32 chatId);
183+
184 private:
185+ TelegramClient *mTelegramClient;
186+ qint32 mChatId;
187+
188 QHash<qint32, QByteArray> roleNames() const;
189 };
190
191
192=== modified file 'qmlplugin/models/groupmodel.cpp'
193--- qmlplugin/models/groupmodel.cpp 2014-12-12 09:32:27 +0000
194+++ qmlplugin/models/groupmodel.cpp 2014-12-12 15:35:59 +0000
195@@ -24,7 +24,7 @@
196 mTelegramClient = 0;
197 }
198
199-void GroupModel::setTelegramClient(TelegramClient *telegramClient) {
200+void GroupModel::setup(TelegramClient *telegramClient, qint32 chatId) {
201 Q_ASSERT(telegramClient != NULL);
202
203 if (mTelegramClient == NULL) {
204@@ -39,6 +39,10 @@
205 connect(mTelegramClient, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)),
206 this, SLOT(chatsMuted(NotifyPeer::NotifyPeerType,bool)));
207 }
208+
209+ if (mTelegramClient != NULL) {
210+ setChatId(chatId);
211+ }
212 }
213
214 qint32 GroupModel::getChatId() const {
215@@ -106,7 +110,6 @@
216 setMuted(false);
217 }
218
219-// Currently used by GroupMembersModel to requery.
220 void GroupModel::refreshGroupDetails(qint32 chatId) {
221 if (mChatId != chatId) return;
222 qCDebug(TG_PLUGIN_LOGIC) << "Refreshing group chat profile model for chat:" << chatId;
223
224=== modified file 'qmlplugin/models/groupmodel.h'
225--- qmlplugin/models/groupmodel.h 2014-12-04 17:03:45 +0000
226+++ qmlplugin/models/groupmodel.h 2014-12-12 15:35:59 +0000
227@@ -19,7 +19,6 @@
228
229 #include <QObject>
230 #include <QString>
231-#include <QSqlQueryModel>
232
233 #include "telegramclient.h"
234 #include "dbmanager.h"
235@@ -38,11 +37,11 @@
236 explicit GroupModel(QObject *parent = 0);
237 ~GroupModel();
238
239- Q_INVOKABLE void setTelegramClient(TelegramClient *telegramClient);
240+ Q_INVOKABLE void setup(TelegramClient *telegramClient, qint32 chatId);
241 void resetGroupDetails();
242
243- Q_INVOKABLE qint32 getChatId() const;
244- Q_INVOKABLE void setChatId(const qint32 chatId);
245+ void setChatId(qint32 chatId);
246+ qint32 getChatId() const;
247 QString getTitle() const;
248 QString getPhoto() const;
249 qint32 getCount() const;

Subscribers

People subscribed via source and target branches

to all changes: