Remove nick colors
This commit is contained in:
parent
18625d9d27
commit
43b1bdfe63
8 changed files with 727 additions and 763 deletions
|
|
@ -32,65 +32,65 @@
|
|||
#include "Text.h"
|
||||
|
||||
namespace events = matrix::events;
|
||||
namespace msgs = matrix::events::messages;
|
||||
namespace msgs = matrix::events::messages;
|
||||
|
||||
class TimelineItem : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
TimelineItem(const events::MessageEvent<msgs::Notice> &e,
|
||||
bool with_sender,
|
||||
const QString &color,
|
||||
QWidget *parent = 0);
|
||||
TimelineItem(const events::MessageEvent<msgs::Text> &e,
|
||||
bool with_sender,
|
||||
const QString &color,
|
||||
QWidget *parent = 0);
|
||||
TimelineItem(const events::MessageEvent<msgs::Notice> &e,
|
||||
bool with_sender,
|
||||
QWidget *parent = 0);
|
||||
TimelineItem(const events::MessageEvent<msgs::Text> &e,
|
||||
bool with_sender,
|
||||
QWidget *parent = 0);
|
||||
|
||||
// For local messages.
|
||||
TimelineItem(const QString &userid, const QString &color, QString body, QWidget *parent = 0);
|
||||
TimelineItem(QString body, QWidget *parent = 0);
|
||||
// For local messages.
|
||||
TimelineItem(const QString &userid, QString body, QWidget *parent = 0);
|
||||
TimelineItem(QString body, QWidget *parent = 0);
|
||||
|
||||
TimelineItem(ImageItem *img, const events::MessageEvent<msgs::Image> &e, const QString &color, QWidget *parent);
|
||||
TimelineItem(ImageItem *img, const events::MessageEvent<msgs::Image> &e, QWidget *parent);
|
||||
TimelineItem(ImageItem *img,
|
||||
const events::MessageEvent<msgs::Image> &e,
|
||||
bool with_sender,
|
||||
QWidget *parent);
|
||||
|
||||
void setUserAvatar(const QImage &pixmap);
|
||||
inline DescInfo descriptionMessage() const;
|
||||
void setUserAvatar(const QImage &pixmap);
|
||||
inline DescInfo descriptionMessage() const;
|
||||
|
||||
~TimelineItem();
|
||||
~TimelineItem();
|
||||
|
||||
private:
|
||||
void init();
|
||||
void init();
|
||||
|
||||
void generateBody(const QString &body);
|
||||
void generateBody(const QString &userid, const QString &color, const QString &body);
|
||||
void generateTimestamp(const QDateTime &time);
|
||||
QString descriptiveTime(const QDateTime &then);
|
||||
void generateBody(const QString &body);
|
||||
void generateBody(const QString &userid, const QString &body);
|
||||
void generateTimestamp(const QDateTime &time);
|
||||
QString descriptiveTime(const QDateTime &then);
|
||||
|
||||
void setupAvatarLayout(const QString &userName);
|
||||
void setupSimpleLayout();
|
||||
void setupAvatarLayout(const QString &userName);
|
||||
void setupSimpleLayout();
|
||||
|
||||
QString replaceEmoji(const QString &body);
|
||||
QString replaceEmoji(const QString &body);
|
||||
|
||||
DescInfo descriptionMsg_;
|
||||
DescInfo descriptionMsg_;
|
||||
|
||||
QHBoxLayout *topLayout_;
|
||||
QVBoxLayout *sideLayout_; // Avatar or Timestamp
|
||||
QVBoxLayout *mainLayout_; // Header & Message body
|
||||
QHBoxLayout *topLayout_;
|
||||
QVBoxLayout *sideLayout_; // Avatar or Timestamp
|
||||
QVBoxLayout *mainLayout_; // Header & Message body
|
||||
|
||||
QHBoxLayout *headerLayout_; // Username (&) Timestamp
|
||||
QHBoxLayout *headerLayout_; // Username (&) Timestamp
|
||||
|
||||
Avatar *userAvatar_;
|
||||
Avatar *userAvatar_;
|
||||
|
||||
QFont font_;
|
||||
QFont font_;
|
||||
|
||||
QLabel *timestamp_;
|
||||
QLabel *userName_;
|
||||
QLabel *body_;
|
||||
QLabel *timestamp_;
|
||||
QLabel *userName_;
|
||||
QLabel *body_;
|
||||
};
|
||||
|
||||
inline DescInfo
|
||||
TimelineItem::descriptionMessage() const
|
||||
{
|
||||
return descriptionMsg_;
|
||||
return descriptionMsg_;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,122 +32,121 @@
|
|||
#include "RoomInfoListItem.h"
|
||||
#include "Text.h"
|
||||
|
||||
namespace msgs = matrix::events::messages;
|
||||
namespace msgs = matrix::events::messages;
|
||||
namespace events = matrix::events;
|
||||
|
||||
// Contains info about a message shown in the history view
|
||||
// but not yet confirmed by the homeserver through sync.
|
||||
struct PendingMessage {
|
||||
int txn_id;
|
||||
QString body;
|
||||
QString event_id;
|
||||
TimelineItem *widget;
|
||||
int txn_id;
|
||||
QString body;
|
||||
QString event_id;
|
||||
TimelineItem *widget;
|
||||
|
||||
PendingMessage(int txn_id, QString body, QString event_id, TimelineItem *widget)
|
||||
: txn_id(txn_id)
|
||||
, body(body)
|
||||
, event_id(event_id)
|
||||
, widget(widget)
|
||||
{
|
||||
}
|
||||
PendingMessage(int txn_id, QString body, QString event_id, TimelineItem *widget)
|
||||
: txn_id(txn_id)
|
||||
, body(body)
|
||||
, event_id(event_id)
|
||||
, widget(widget)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// In which place new TimelineItems should be inserted.
|
||||
enum class TimelineDirection {
|
||||
Top,
|
||||
Bottom,
|
||||
Top,
|
||||
Bottom,
|
||||
};
|
||||
|
||||
class TimelineView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TimelineView(const Timeline &timeline,
|
||||
QSharedPointer<MatrixClient> client,
|
||||
const QString &room_id,
|
||||
QWidget *parent = 0);
|
||||
TimelineView(QSharedPointer<MatrixClient> client, const QString &room_id, QWidget *parent = 0);
|
||||
TimelineView(const Timeline &timeline,
|
||||
QSharedPointer<MatrixClient> client,
|
||||
const QString &room_id,
|
||||
QWidget *parent = 0);
|
||||
TimelineView(QSharedPointer<MatrixClient> client,
|
||||
const QString &room_id,
|
||||
QWidget *parent = 0);
|
||||
|
||||
TimelineItem *createTimelineItem(const events::MessageEvent<msgs::Image> &e,
|
||||
const QString &color,
|
||||
bool with_sender);
|
||||
TimelineItem *createTimelineItem(const events::MessageEvent<msgs::Notice> &e,
|
||||
const QString &color,
|
||||
bool with_sender);
|
||||
TimelineItem *createTimelineItem(const events::MessageEvent<msgs::Text> &e,
|
||||
const QString &color,
|
||||
bool with_sender);
|
||||
TimelineItem *createTimelineItem(const events::MessageEvent<msgs::Image> &e,
|
||||
bool with_sender);
|
||||
TimelineItem *createTimelineItem(const events::MessageEvent<msgs::Notice> &e,
|
||||
bool with_sender);
|
||||
TimelineItem *createTimelineItem(const events::MessageEvent<msgs::Text> &e,
|
||||
bool with_sender);
|
||||
|
||||
// Add new events at the end of the timeline.
|
||||
int addEvents(const Timeline &timeline);
|
||||
void addUserTextMessage(const QString &msg, int txn_id);
|
||||
void updatePendingMessage(int txn_id, QString event_id);
|
||||
void scrollDown();
|
||||
// Add new events at the end of the timeline.
|
||||
int addEvents(const Timeline &timeline);
|
||||
void addUserTextMessage(const QString &msg, int txn_id);
|
||||
void updatePendingMessage(int txn_id, QString event_id);
|
||||
void scrollDown();
|
||||
|
||||
public slots:
|
||||
void sliderRangeChanged(int min, int max);
|
||||
void sliderMoved(int position);
|
||||
void fetchHistory();
|
||||
void sliderRangeChanged(int min, int max);
|
||||
void sliderMoved(int position);
|
||||
void fetchHistory();
|
||||
|
||||
// Add old events at the top of the timeline.
|
||||
void addBackwardsEvents(const QString &room_id, const RoomMessages &msgs);
|
||||
// Add old events at the top of the timeline.
|
||||
void addBackwardsEvents(const QString &room_id, const RoomMessages &msgs);
|
||||
|
||||
signals:
|
||||
void updateLastTimelineMessage(const QString &user, const DescInfo &info);
|
||||
void updateLastTimelineMessage(const QString &user, const DescInfo &info);
|
||||
|
||||
private:
|
||||
void init();
|
||||
void removePendingMessage(const events::MessageEvent<msgs::Text> &e);
|
||||
void addTimelineItem(TimelineItem *item, TimelineDirection direction);
|
||||
void updateLastSender(const QString &user_id, TimelineDirection direction);
|
||||
void notifyForLastEvent();
|
||||
void init();
|
||||
void removePendingMessage(const events::MessageEvent<msgs::Text> &e);
|
||||
void addTimelineItem(TimelineItem *item, TimelineDirection direction);
|
||||
void updateLastSender(const QString &user_id, TimelineDirection direction);
|
||||
void notifyForLastEvent();
|
||||
|
||||
// Used to determine whether or not we should prefix a message with the sender's name.
|
||||
bool isSenderRendered(const QString &user_id, TimelineDirection direction);
|
||||
bool isPendingMessage(const events::MessageEvent<msgs::Text> &e, const QString &userid);
|
||||
inline bool isDuplicate(const QString &event_id);
|
||||
// Used to determine whether or not we should prefix a message with the sender's name.
|
||||
bool isSenderRendered(const QString &user_id, TimelineDirection direction);
|
||||
bool isPendingMessage(const events::MessageEvent<msgs::Text> &e, const QString &userid);
|
||||
inline bool isDuplicate(const QString &event_id);
|
||||
|
||||
// Return nullptr if the event couldn't be parsed.
|
||||
TimelineItem *parseMessageEvent(const QJsonObject &event, TimelineDirection direction);
|
||||
// Return nullptr if the event couldn't be parsed.
|
||||
TimelineItem *parseMessageEvent(const QJsonObject &event, TimelineDirection direction);
|
||||
|
||||
QVBoxLayout *top_layout_;
|
||||
QVBoxLayout *scroll_layout_;
|
||||
QVBoxLayout *top_layout_;
|
||||
QVBoxLayout *scroll_layout_;
|
||||
|
||||
QScrollArea *scroll_area_;
|
||||
ScrollBar *scrollbar_;
|
||||
QWidget *scroll_widget_;
|
||||
QScrollArea *scroll_area_;
|
||||
ScrollBar *scrollbar_;
|
||||
QWidget *scroll_widget_;
|
||||
|
||||
QString lastSender_;
|
||||
QString firstSender_;
|
||||
QString room_id_;
|
||||
QString prev_batch_token_;
|
||||
QString local_user_;
|
||||
QString lastSender_;
|
||||
QString firstSender_;
|
||||
QString room_id_;
|
||||
QString prev_batch_token_;
|
||||
QString local_user_;
|
||||
|
||||
bool isPaginationInProgress_ = false;
|
||||
bool isInitialized = false;
|
||||
bool isTimelineFinished = false;
|
||||
bool isInitialSync = true;
|
||||
bool isPaginationScrollPending_ = false;
|
||||
bool isPaginationInProgress_ = false;
|
||||
bool isInitialized = false;
|
||||
bool isTimelineFinished = false;
|
||||
bool isInitialSync = true;
|
||||
bool isPaginationScrollPending_ = false;
|
||||
|
||||
const int SCROLL_BAR_GAP = 400;
|
||||
const int SCROLL_BAR_GAP = 400;
|
||||
|
||||
QTimer *paginationTimer_;
|
||||
QTimer *paginationTimer_;
|
||||
|
||||
int scroll_height_ = 0;
|
||||
int previous_max_height_ = 0;
|
||||
int scroll_height_ = 0;
|
||||
int previous_max_height_ = 0;
|
||||
|
||||
int oldPosition_;
|
||||
int oldHeight_;
|
||||
int oldPosition_;
|
||||
int oldHeight_;
|
||||
|
||||
// The events currently rendered. Used for duplicate detection.
|
||||
QMap<QString, bool> eventIds_;
|
||||
QList<PendingMessage> pending_msgs_;
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
// The events currently rendered. Used for duplicate detection.
|
||||
QMap<QString, bool> eventIds_;
|
||||
QList<PendingMessage> pending_msgs_;
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
||||
inline bool
|
||||
TimelineView::isDuplicate(const QString &event_id)
|
||||
{
|
||||
return eventIds_.contains(event_id);
|
||||
return eventIds_.contains(event_id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,39 +29,37 @@
|
|||
|
||||
class TimelineViewManager : public QStackedWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TimelineViewManager(QSharedPointer<MatrixClient> client, QWidget *parent);
|
||||
~TimelineViewManager();
|
||||
TimelineViewManager(QSharedPointer<MatrixClient> client, QWidget *parent);
|
||||
~TimelineViewManager();
|
||||
|
||||
// Initialize with timeline events.
|
||||
void initialize(const Rooms &rooms);
|
||||
// Empty initialization.
|
||||
void initialize(const QList<QString> &rooms);
|
||||
void sync(const Rooms &rooms);
|
||||
void clearAll();
|
||||
// Initialize with timeline events.
|
||||
void initialize(const Rooms &rooms);
|
||||
// Empty initialization.
|
||||
void initialize(const QList<QString> &rooms);
|
||||
void sync(const Rooms &rooms);
|
||||
void clearAll();
|
||||
|
||||
static QString chooseRandomColor();
|
||||
static QString getUserColor(const QString &userid);
|
||||
static QString displayName(const QString &userid);
|
||||
static QString chooseRandomColor();
|
||||
static QString displayName(const QString &userid);
|
||||
|
||||
static QMap<QString, QString> NICK_COLORS;
|
||||
static QMap<QString, QString> DISPLAY_NAMES;
|
||||
static QMap<QString, QString> DISPLAY_NAMES;
|
||||
|
||||
signals:
|
||||
void unreadMessages(QString roomid, int count);
|
||||
void updateRoomsLastMessage(const QString &user, const DescInfo &info);
|
||||
void unreadMessages(QString roomid, int count);
|
||||
void updateRoomsLastMessage(const QString &user, const DescInfo &info);
|
||||
|
||||
public slots:
|
||||
void setHistoryView(const QString &room_id);
|
||||
void sendTextMessage(const QString &msg);
|
||||
void setHistoryView(const QString &room_id);
|
||||
void sendTextMessage(const QString &msg);
|
||||
|
||||
private slots:
|
||||
void messageSent(const QString &eventid, const QString &roomid, int txnid);
|
||||
void messageSent(const QString &eventid, const QString &roomid, int txnid);
|
||||
|
||||
private:
|
||||
QString active_room_;
|
||||
QMap<QString, QSharedPointer<TimelineView>> views_;
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
QString active_room_;
|
||||
QMap<QString, QSharedPointer<TimelineView>> views_;
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue