servatrice/cockatrice/src/userlist.h
ebbit1q 1e995cd97c
add option to delete a user's messages (#4362)
* add option to delete a user's messages

add optional parameter remove_messages to the ban and warn commands
add event for clients to redact messages
implement server side command and message handling
implement server history removal
todo: client side implementation

add option to remove messages to moderator action dialogs

add storage of message beginnings to chatview

add redactMessage command
handle Event_RemoveMessages on rooms

this approach is favored over parsing the chatroom after the fact but
will use additional memory to store the block indexes

this also leaves a problem in that user messages from the chat backlog
are not removed in the same way because they don't have a user
associated with them

add workaround for old qt versions

add action for users to remove messages from users in chats

add chat history to userMessagePositions with regex

proper const usage for userName

allow removing the messages of unregistered users

add menus to usernames in chat history

this allows you to remove user messages on chat history as well
this also allows moderators to take actions on users in chat history

Apply suggestions from code review

* readd missing call to handler
2021-09-14 16:05:20 -04:00

142 lines
3.6 KiB
C++

#ifndef USERLIST_H
#define USERLIST_H
#include "pb/moderator_commands.pb.h"
#include "user_level.h"
#include <QComboBox>
#include <QDialog>
#include <QGroupBox>
#include <QStyledItemDelegate>
#include <QTreeWidgetItem>
class QTreeWidget;
class ServerInfo_User;
class AbstractClient;
class TabSupervisor;
class QLabel;
class QCheckBox;
class QSpinBox;
class QRadioButton;
class QPlainTextEdit;
class Response;
class CommandContainer;
class UserContextMenu;
class BanDialog : public QDialog
{
Q_OBJECT
private:
QLabel *daysLabel, *hoursLabel, *minutesLabel;
QCheckBox *nameBanCheckBox, *ipBanCheckBox, *idBanCheckBox, *deleteMessages;
QLineEdit *nameBanEdit, *ipBanEdit, *idBanEdit;
QSpinBox *daysEdit, *hoursEdit, *minutesEdit;
QRadioButton *permanentRadio, *temporaryRadio;
QPlainTextEdit *reasonEdit, *visibleReasonEdit;
private slots:
void okClicked();
void enableTemporaryEdits(bool enabled);
public:
BanDialog(const ServerInfo_User &info, QWidget *parent = nullptr);
QString getBanName() const;
QString getBanIP() const;
QString getBanId() const;
int getMinutes() const;
QString getReason() const;
QString getVisibleReason() const;
int getDeleteMessages() const;
};
class WarningDialog : public QDialog
{
Q_OBJECT
private:
QLabel *descriptionLabel;
QLineEdit *nameWarning;
QComboBox *warningOption;
QLineEdit *warnClientID;
QCheckBox *deleteMessages;
private slots:
void okClicked();
public:
WarningDialog(const QString userName, const QString clientID, QWidget *parent = nullptr);
QString getName() const;
QString getWarnID() const;
QString getReason() const;
int getDeleteMessages() const;
void addWarningOption(const QString warning);
};
class UserListItemDelegate : public QStyledItemDelegate
{
public:
UserListItemDelegate(QObject *const parent);
bool
editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
};
class UserListTWI : public QTreeWidgetItem
{
private:
ServerInfo_User userInfo;
public:
UserListTWI(const ServerInfo_User &_userInfo);
const ServerInfo_User &getUserInfo() const
{
return userInfo;
}
void setUserInfo(const ServerInfo_User &_userInfo);
void setOnline(bool online);
bool operator<(const QTreeWidgetItem &other) const;
};
class UserList : public QGroupBox
{
Q_OBJECT
public:
enum UserListType
{
AllUsersList,
RoomList,
BuddyList,
IgnoreList
};
private:
QMap<QString, UserListTWI *> users;
TabSupervisor *tabSupervisor;
AbstractClient *client;
UserListType type;
QTreeWidget *userTree;
UserListItemDelegate *itemDelegate;
UserContextMenu *userContextMenu;
int onlineCount;
QString titleStr;
void updateCount();
private slots:
void userClicked(QTreeWidgetItem *item, int column);
signals:
void openMessageDialog(const QString &userName, bool focus);
void addBuddy(const QString &userName);
void removeBuddy(const QString &userName);
void addIgnore(const QString &userName);
void removeIgnore(const QString &userName);
public:
UserList(TabSupervisor *_tabSupervisor, AbstractClient *_client, UserListType _type, QWidget *parent = nullptr);
void retranslateUi();
void processUserInfo(const ServerInfo_User &user, bool online);
bool deleteUser(const QString &userName);
void setUserOnline(const QString &userName, bool online);
const QMap<QString, UserListTWI *> &getUsers() const
{
return users;
}
void showContextMenu(const QPoint &pos, const QModelIndex &index);
void sortItems();
};
#endif