mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge branch 'pr774'
This commit is contained in:
commit
014b39e7d0
|
@ -19,15 +19,22 @@
|
||||||
#include "widget/friendwidget.h"
|
#include "widget/friendwidget.h"
|
||||||
#include "widget/form/chatform.h"
|
#include "widget/form/chatform.h"
|
||||||
#include "widget/widget.h"
|
#include "widget/widget.h"
|
||||||
|
#include "src/core.h"
|
||||||
|
#include "src/misc/settings.h"
|
||||||
|
|
||||||
Friend::Friend(int FriendId, QString UserId)
|
Friend::Friend(int FriendId, const ToxID &UserId)
|
||||||
: friendId(FriendId)
|
: friendId(FriendId)
|
||||||
{
|
{
|
||||||
hasNewEvents = 0;
|
hasNewEvents = 0;
|
||||||
friendStatus = Status::Offline;
|
friendStatus = Status::Offline;
|
||||||
userID = ToxID::fromString(UserId);
|
userID = UserId;
|
||||||
userName = UserId;
|
userName = Core::getInstance()->getPeerName(UserId);
|
||||||
widget = new FriendWidget(friendId, UserId);
|
if (userName.size() == 0)
|
||||||
|
userName = UserId.publicKey;
|
||||||
|
|
||||||
|
userAlias = Settings::getInstance().getFriendAlias(UserId);
|
||||||
|
|
||||||
|
widget = new FriendWidget(friendId, getDisplayedName());
|
||||||
chatForm = new ChatForm(this);
|
chatForm = new ChatForm(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class ChatForm;
|
||||||
struct Friend
|
struct Friend
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Friend(int FriendId, QString UserId);
|
Friend(int FriendId, const ToxID &UserId);
|
||||||
~Friend();
|
~Friend();
|
||||||
|
|
||||||
void setName(QString name);
|
void setName(QString name);
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
QHash<int, Friend*> FriendList::friendList;
|
QHash<int, Friend*> FriendList::friendList;
|
||||||
QHash<QString, int> FriendList::tox2id;
|
QHash<QString, int> FriendList::tox2id;
|
||||||
|
|
||||||
Friend* FriendList::addFriend(int friendId, const QString& userId)
|
Friend* FriendList::addFriend(int friendId, const ToxID& userId)
|
||||||
{
|
{
|
||||||
auto friendChecker = friendList.find(friendId);
|
auto friendChecker = friendList.find(friendId);
|
||||||
if (friendChecker != friendList.end())
|
if (friendChecker != friendList.end())
|
||||||
|
@ -32,7 +32,7 @@ Friend* FriendList::addFriend(int friendId, const QString& userId)
|
||||||
|
|
||||||
Friend* newfriend = new Friend(friendId, userId);
|
Friend* newfriend = new Friend(friendId, userId);
|
||||||
friendList[friendId] = newfriend;
|
friendList[friendId] = newfriend;
|
||||||
tox2id[userId] = friendId;
|
tox2id[userId.publicKey] = friendId;
|
||||||
|
|
||||||
return newfriend;
|
return newfriend;
|
||||||
}
|
}
|
||||||
|
@ -63,15 +63,15 @@ void FriendList::clear()
|
||||||
delete friendptr;
|
delete friendptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Friend* FriendList::findFriend(QString userId)
|
Friend* FriendList::findFriend(const ToxID& userId)
|
||||||
{
|
{
|
||||||
auto id = tox2id.find(userId);
|
auto id = tox2id.find(userId.publicKey);
|
||||||
if (id != tox2id.end())
|
if (id != tox2id.end())
|
||||||
{
|
{
|
||||||
Friend *f = findFriend(*id);
|
Friend *f = findFriend(*id);
|
||||||
if (!f)
|
if (!f)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (f->getToxID() == ToxID::fromString(userId))
|
if (f->getToxID() == userId)
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,15 @@ template <class T> class QList;
|
||||||
template <class A, class B> class QHash;
|
template <class A, class B> class QHash;
|
||||||
struct Friend;
|
struct Friend;
|
||||||
class QString;
|
class QString;
|
||||||
|
struct ToxID;
|
||||||
|
|
||||||
class FriendList
|
class FriendList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FriendList();
|
FriendList();
|
||||||
static Friend* addFriend(int friendId, const QString& userId);
|
static Friend* addFriend(int friendId, const ToxID &userId);
|
||||||
static Friend* findFriend(int friendId);
|
static Friend* findFriend(int friendId);
|
||||||
static Friend* findFriend(QString userId);
|
static Friend* findFriend(const ToxID &userId);
|
||||||
static QList<Friend*> getAllFriends();
|
static QList<Friend*> getAllFriends();
|
||||||
static void removeFriend(int friendId, bool fake = false);
|
static void removeFriend(int friendId, bool fake = false);
|
||||||
static void clear();
|
static void clear();
|
||||||
|
|
|
@ -78,9 +78,6 @@ ChatForm::ChatForm(Friend* chatFriend)
|
||||||
connect(this, SIGNAL(chatAreaCleared()), this, SLOT(clearReciepts()));
|
connect(this, SIGNAL(chatAreaCleared()), this, SLOT(clearReciepts()));
|
||||||
|
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
|
||||||
if (Settings::getInstance().getEnableLogging())
|
|
||||||
loadHistory(QDateTime::currentDateTime().addDays(-7), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatForm::~ChatForm()
|
ChatForm::~ChatForm()
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
ChatForm(Friend* chatFriend);
|
ChatForm(Friend* chatFriend);
|
||||||
~ChatForm();
|
~ChatForm();
|
||||||
void setStatusMessage(QString newMessage);
|
void setStatusMessage(QString newMessage);
|
||||||
|
void loadHistory(QDateTime since, bool processUndelivered = false);
|
||||||
|
|
||||||
void dischargeReceipt(int receipt);
|
void dischargeReceipt(int receipt);
|
||||||
|
|
||||||
|
@ -85,7 +86,6 @@ private slots:
|
||||||
void updateTime();
|
void updateTime();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void loadHistory(QDateTime since, bool processUndelivered = false);
|
|
||||||
// drag & drop
|
// drag & drop
|
||||||
void dragEnterEvent(QDragEnterEvent* ev);
|
void dragEnterEvent(QDragEnterEvent* ev);
|
||||||
void dropEvent(QDropEvent* ev);
|
void dropEvent(QDropEvent* ev);
|
||||||
|
|
|
@ -364,7 +364,7 @@ MessageActionPtr GenericChatForm::genMessageActionAction(const ToxID& author, QS
|
||||||
if (isMe)
|
if (isMe)
|
||||||
authorStr = core->getUsername();
|
authorStr = core->getUsername();
|
||||||
else {
|
else {
|
||||||
Friend *f = FriendList::findFriend(author.publicKey);
|
Friend *f = FriendList::findFriend(author);
|
||||||
if (f)
|
if (f)
|
||||||
authorStr = f->getDisplayedName();
|
authorStr = f->getDisplayedName();
|
||||||
else
|
else
|
||||||
|
|
|
@ -611,12 +611,13 @@ void Widget::setStatusMessage(const QString &statusMessage)
|
||||||
void Widget::addFriend(int friendId, const QString &userId)
|
void Widget::addFriend(int friendId, const QString &userId)
|
||||||
{
|
{
|
||||||
//qDebug() << "Widget: Adding friend with id" << userId;
|
//qDebug() << "Widget: Adding friend with id" << userId;
|
||||||
Friend* newfriend = FriendList::addFriend(friendId, userId);
|
ToxID userToxId = ToxID::fromString(userId);
|
||||||
|
Friend* newfriend = FriendList::addFriend(friendId, userToxId);
|
||||||
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline);
|
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline);
|
||||||
layout->addWidget(newfriend->getFriendWidget());
|
layout->addWidget(newfriend->getFriendWidget());
|
||||||
|
|
||||||
QString alias = Settings::getInstance().getFriendAlias(ToxID::fromString(userId));
|
if (Settings::getInstance().getEnableLogging())
|
||||||
newfriend->setAlias(alias);
|
newfriend->getChatForm()->loadHistory(QDateTime::currentDateTime().addDays(-7), true);
|
||||||
|
|
||||||
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
||||||
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user