2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2015-10-03 13:16:42 +00:00
|
|
|
Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
#include "abstractbox.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
enum MembersFilter {
|
|
|
|
MembersFilterRecent,
|
|
|
|
MembersFilterAdmins,
|
|
|
|
};
|
|
|
|
typedef QMap<UserData*, bool> MembersAlreadyIn;
|
|
|
|
|
|
|
|
class ConfirmBox;
|
|
|
|
class ContactsInner : public TWidget, public RPCSender {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
struct ContactData;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
public:
|
|
|
|
|
2015-09-16 13:04:08 +00:00
|
|
|
ContactsInner(CreatingGroupType creating = CreatingGroupNone);
|
2015-09-23 17:43:08 +00:00
|
|
|
ContactsInner(ChannelData *channel, MembersFilter channelFilter = MembersFilterRecent, const MembersAlreadyIn &already = MembersAlreadyIn());
|
2015-04-02 10:33:19 +00:00
|
|
|
ContactsInner(ChatData *chat);
|
2015-06-15 17:19:24 +00:00
|
|
|
ContactsInner(UserData *bot);
|
2015-04-02 10:33:19 +00:00
|
|
|
void init();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
void enterEvent(QEvent *e);
|
|
|
|
void leaveEvent(QEvent *e);
|
|
|
|
void mouseMoveEvent(QMouseEvent *e);
|
|
|
|
void mousePressEvent(QMouseEvent *e);
|
2014-11-25 12:15:29 +00:00
|
|
|
void resizeEvent(QResizeEvent *e);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
void paintDialog(Painter &p, PeerData *peer, ContactData *data, bool sel);
|
2014-05-30 08:53:19 +00:00
|
|
|
void updateFilter(QString filter = QString());
|
|
|
|
|
|
|
|
void selectSkip(int32 dir);
|
|
|
|
void selectSkipPage(int32 h, int32 dir);
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
QVector<UserData*> selected();
|
|
|
|
QVector<MTPInputUser> selectedInputs();
|
|
|
|
PeerData *selectedUser();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void loadProfilePhotos(int32 yFrom);
|
2015-04-02 10:33:19 +00:00
|
|
|
void chooseParticipant();
|
|
|
|
void changeCheckState(DialogRow *row);
|
2015-08-07 12:11:50 +00:00
|
|
|
void changeCheckState(ContactData *data, PeerData *peer);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2015-09-06 10:17:09 +00:00
|
|
|
void peopleReceived(const QString &query, const QVector<MTPPeer> &people);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
void refresh();
|
|
|
|
|
|
|
|
ChatData *chat() const;
|
2015-09-16 13:04:08 +00:00
|
|
|
ChannelData *channel() const;
|
2015-09-23 17:43:08 +00:00
|
|
|
MembersFilter channelFilter() const;
|
2015-06-15 17:19:24 +00:00
|
|
|
UserData *bot() const;
|
2015-09-16 13:04:08 +00:00
|
|
|
CreatingGroupType creating() const;
|
|
|
|
|
|
|
|
int32 selectedCount() const;
|
2015-09-23 17:43:08 +00:00
|
|
|
bool hasAlreadyMembersInChannel() const {
|
|
|
|
return !_already.isEmpty();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
~ContactsInner();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
void mustScrollTo(int ymin, int ymax);
|
2015-04-02 10:33:19 +00:00
|
|
|
void selectAllQuery();
|
|
|
|
void searchByUsername();
|
2015-09-16 13:04:08 +00:00
|
|
|
void chosenChanged();
|
2015-09-23 17:43:08 +00:00
|
|
|
void adminAdded();
|
2015-10-11 08:37:24 +00:00
|
|
|
void addRequested();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
void onDialogRowReplaced(DialogRow *oldRow, DialogRow *newRow);
|
|
|
|
|
|
|
|
void updateSel();
|
|
|
|
void peerUpdated(PeerData *peer);
|
2015-06-15 17:19:24 +00:00
|
|
|
void onPeerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
|
|
|
|
|
|
|
|
void onAddBot();
|
2015-09-23 17:43:08 +00:00
|
|
|
void onAddAdmin();
|
|
|
|
void onNoAddAdminBox(QObject *obj);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2015-10-01 14:05:05 +00:00
|
|
|
void updateSelectedRow();
|
2015-09-23 17:43:08 +00:00
|
|
|
void addAdminDone(const MTPBool &result, mtpRequestId req);
|
|
|
|
bool addAdminFail(const RPCError &error, mtpRequestId req);
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
int32 _rowHeight, _newItemHeight;
|
|
|
|
bool _newItemSel;
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
ChatData *_chat;
|
2015-09-16 13:04:08 +00:00
|
|
|
ChannelData *_channel;
|
2015-09-23 17:43:08 +00:00
|
|
|
MembersFilter _channelFilter;
|
2015-06-15 17:19:24 +00:00
|
|
|
UserData *_bot;
|
2015-09-16 13:04:08 +00:00
|
|
|
CreatingGroupType _creating;
|
2015-09-23 17:43:08 +00:00
|
|
|
MembersAlreadyIn _already;
|
2015-06-15 17:19:24 +00:00
|
|
|
|
|
|
|
ChatData *_addToChat;
|
2015-09-23 17:43:08 +00:00
|
|
|
UserData *_addAdmin;
|
|
|
|
mtpRequestId _addAdminRequestId;
|
|
|
|
ConfirmBox *_addAdminBox;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 _time;
|
|
|
|
|
|
|
|
DialogsIndexed *_contacts;
|
|
|
|
DialogRow *_sel;
|
|
|
|
QString _filter;
|
|
|
|
typedef QVector<DialogRow*> FilteredDialogs;
|
|
|
|
FilteredDialogs _filtered;
|
|
|
|
int32 _filteredSel;
|
|
|
|
bool _mouseSel;
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
int32 _selCount;
|
|
|
|
|
|
|
|
struct ContactData {
|
2014-05-30 08:53:19 +00:00
|
|
|
Text name;
|
|
|
|
QString online;
|
2015-04-02 10:33:19 +00:00
|
|
|
bool inchat;
|
|
|
|
bool check;
|
|
|
|
};
|
2015-06-15 17:19:24 +00:00
|
|
|
typedef QMap<PeerData*, ContactData*> ContactsData;
|
2014-05-30 08:53:19 +00:00
|
|
|
ContactsData _contactsData;
|
2015-08-07 12:11:50 +00:00
|
|
|
typedef QMap<PeerData*, bool> CheckedContacts;
|
|
|
|
CheckedContacts _checkedContacts;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
ContactData *contactData(DialogRow *row);
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
bool _searching;
|
|
|
|
QString _lastQuery;
|
2015-09-06 10:17:09 +00:00
|
|
|
typedef QVector<PeerData*> ByUsernameRows;
|
2015-04-02 10:33:19 +00:00
|
|
|
typedef QVector<ContactData*> ByUsernameDatas;
|
|
|
|
ByUsernameRows _byUsername, _byUsernameFiltered;
|
|
|
|
ByUsernameDatas d_byUsername, d_byUsernameFiltered; // filtered is partly subset of d_byUsername, partly subset of _byUsernameDatas
|
|
|
|
ByUsernameDatas _byUsernameDatas;
|
|
|
|
int32 _byUsernameSel;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
QPoint _lastMousePos;
|
2014-11-25 12:15:29 +00:00
|
|
|
LinkButton _addContactLnk;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
class ContactsBox : public ItemListBox, public RPCSender {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2015-09-16 13:04:08 +00:00
|
|
|
ContactsBox();
|
|
|
|
ContactsBox(const QString &name, const QImage &photo); // group creation
|
|
|
|
ContactsBox(ChannelData *channel); // channel setup
|
2015-09-23 17:43:08 +00:00
|
|
|
ContactsBox(ChannelData *channel, MembersFilter filter, const MembersAlreadyIn &already);
|
2015-04-02 10:33:19 +00:00
|
|
|
ContactsBox(ChatData *chat);
|
2015-06-15 17:19:24 +00:00
|
|
|
ContactsBox(UserData *bot);
|
2014-05-30 08:53:19 +00:00
|
|
|
void keyPressEvent(QKeyEvent *e);
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
void resizeEvent(QResizeEvent *e);
|
|
|
|
|
2015-09-16 13:04:08 +00:00
|
|
|
void closePressed();
|
|
|
|
|
|
|
|
void setInnerFocus() {
|
|
|
|
_filter.setFocus();
|
|
|
|
}
|
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void adminAdded();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
public slots:
|
|
|
|
|
|
|
|
void onFilterUpdate();
|
2015-10-11 08:37:24 +00:00
|
|
|
void onFilterCancel();
|
|
|
|
void onChosenChanged();
|
2014-05-30 08:53:19 +00:00
|
|
|
void onScroll();
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
void onInvite();
|
2015-09-16 13:04:08 +00:00
|
|
|
void onCreate();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
bool onSearchByUsername(bool searchCache = false);
|
|
|
|
void onNeedSearchByUsername();
|
|
|
|
|
|
|
|
protected:
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void hideAll();
|
|
|
|
void showAll();
|
2015-04-02 10:33:19 +00:00
|
|
|
void showDone();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
void init();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
ContactsInner _inner;
|
2015-10-11 08:37:24 +00:00
|
|
|
InputField _filter;
|
|
|
|
IconedButton _filterCancel;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
BoxButton _next, _cancel;
|
2015-09-23 17:43:08 +00:00
|
|
|
MembersFilter _membersFilter;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
ScrollableBoxShadow _topShadow, *_bottomShadow;
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void peopleReceived(const MTPcontacts_Found &result, mtpRequestId req);
|
|
|
|
bool peopleFailed(const RPCError &error, mtpRequestId req);
|
|
|
|
|
|
|
|
QTimer _searchTimer;
|
|
|
|
QString _peopleQuery;
|
|
|
|
bool _peopleFull;
|
|
|
|
mtpRequestId _peopleRequest;
|
|
|
|
|
|
|
|
typedef QMap<QString, MTPcontacts_Found> PeopleCache;
|
|
|
|
PeopleCache _peopleCache;
|
|
|
|
|
|
|
|
typedef QMap<mtpRequestId, QString> PeopleQueries;
|
|
|
|
PeopleQueries _peopleQueries;
|
2015-09-16 13:04:08 +00:00
|
|
|
|
|
|
|
// group creation
|
|
|
|
int32 _creationRequestId;
|
|
|
|
QString _creationName;
|
|
|
|
QImage _creationPhoto;
|
|
|
|
|
|
|
|
void creationDone(const MTPUpdates &updates);
|
|
|
|
bool creationFail(const RPCError &e);
|
2015-04-02 10:33:19 +00:00
|
|
|
};
|
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
class MembersInner : public TWidget, public RPCSender {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
struct MemberData;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
MembersInner(ChannelData *channel, MembersFilter filter);
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
void enterEvent(QEvent *e);
|
|
|
|
void leaveEvent(QEvent *e);
|
|
|
|
void mouseMoveEvent(QMouseEvent *e);
|
|
|
|
void mousePressEvent(QMouseEvent *e);
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e);
|
|
|
|
|
|
|
|
void paintDialog(Painter &p, PeerData *peer, MemberData *data, bool sel, bool kickSel, bool kickDown);
|
|
|
|
|
|
|
|
void selectSkip(int32 dir);
|
|
|
|
void selectSkipPage(int32 h, int32 dir);
|
|
|
|
|
|
|
|
void loadProfilePhotos(int32 yFrom);
|
|
|
|
void chooseParticipant();
|
|
|
|
|
|
|
|
void refresh();
|
|
|
|
|
|
|
|
ChannelData *channel() const;
|
|
|
|
MembersFilter filter() const;
|
|
|
|
|
|
|
|
bool isLoaded() const {
|
|
|
|
return !_loading;
|
|
|
|
}
|
2015-10-03 10:09:09 +00:00
|
|
|
void clearSel();
|
2015-09-23 17:43:08 +00:00
|
|
|
|
|
|
|
QMap<UserData*, bool> already() const;
|
|
|
|
|
|
|
|
~MembersInner();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
void mustScrollTo(int ymin, int ymax);
|
2015-10-11 08:37:24 +00:00
|
|
|
void addRequested();
|
2015-09-23 17:43:08 +00:00
|
|
|
void loaded();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
2015-09-25 07:47:32 +00:00
|
|
|
void load();
|
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
void updateSel();
|
|
|
|
void peerUpdated(PeerData *peer);
|
|
|
|
void onPeerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
|
|
|
|
void onKickConfirm();
|
|
|
|
void onKickBoxDestroyed(QObject *obj);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2015-10-01 14:05:05 +00:00
|
|
|
void updateSelectedRow();
|
2015-09-23 17:43:08 +00:00
|
|
|
MemberData *data(int32 index);
|
|
|
|
|
|
|
|
void membersReceived(const MTPchannels_ChannelParticipants &result, mtpRequestId req);
|
|
|
|
bool membersFailed(const RPCError &error, mtpRequestId req);
|
|
|
|
|
|
|
|
void kickDone(const MTPUpdates &result, mtpRequestId req);
|
|
|
|
void kickAdminDone(const MTPBool &result, mtpRequestId req);
|
|
|
|
bool kickFail(const RPCError &error, mtpRequestId req);
|
|
|
|
void removeKicked();
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
int32 _rowHeight, _newItemHeight;
|
|
|
|
bool _newItemSel;
|
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
ChannelData *_channel;
|
|
|
|
MembersFilter _filter;
|
|
|
|
|
|
|
|
QString _kickText;
|
|
|
|
int32 _time, _kickWidth;
|
|
|
|
|
|
|
|
int32 _sel, _kickSel, _kickDown;
|
|
|
|
bool _mouseSel;
|
|
|
|
|
|
|
|
UserData *_kickConfirm;
|
|
|
|
mtpRequestId _kickRequestId;
|
|
|
|
|
|
|
|
ConfirmBox *_kickBox;
|
|
|
|
|
|
|
|
enum MemberRole {
|
|
|
|
MemberRoleNone,
|
|
|
|
MemberRoleSelf,
|
|
|
|
MemberRoleCreator,
|
|
|
|
MemberRoleEditor,
|
|
|
|
MemberRoleModerator,
|
|
|
|
MemberRoleKicked
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MemberData {
|
|
|
|
Text name;
|
|
|
|
QString online;
|
|
|
|
bool canKick;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool _loading;
|
|
|
|
mtpRequestId _loadingRequestId;
|
|
|
|
typedef QVector<UserData*> MemberRows;
|
|
|
|
typedef QVector<QDateTime> MemberDates;
|
|
|
|
typedef QVector<MemberRole> MemberRoles;
|
|
|
|
typedef QVector<MemberData*> MemberDatas;
|
|
|
|
MemberRows _rows;
|
|
|
|
MemberDates _dates;
|
|
|
|
MemberRoles _roles;
|
|
|
|
MemberDatas _datas;
|
|
|
|
|
|
|
|
QPoint _lastMousePos;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class MembersBox : public ItemListBox {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
MembersBox(ChannelData *channel, MembersFilter filter);
|
|
|
|
void keyPressEvent(QKeyEvent *e);
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
void resizeEvent(QResizeEvent *e);
|
|
|
|
|
|
|
|
void setInnerFocus() {
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
void onScroll();
|
|
|
|
|
|
|
|
void onAdd();
|
|
|
|
void onAdminAdded();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void showDone();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
MembersInner _inner;
|
|
|
|
|
|
|
|
ContactsBox *_addBox;
|
2015-09-25 07:47:32 +00:00
|
|
|
|
|
|
|
SingleTimer _loadTimer;
|
2015-09-23 17:43:08 +00:00
|
|
|
};
|