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/form/chatform.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)
|
||||
{
|
||||
hasNewEvents = 0;
|
||||
friendStatus = Status::Offline;
|
||||
userID = ToxID::fromString(UserId);
|
||||
userName = UserId;
|
||||
widget = new FriendWidget(friendId, UserId);
|
||||
userID = UserId;
|
||||
userName = Core::getInstance()->getPeerName(UserId);
|
||||
if (userName.size() == 0)
|
||||
userName = UserId.publicKey;
|
||||
|
||||
userAlias = Settings::getInstance().getFriendAlias(UserId);
|
||||
|
||||
widget = new FriendWidget(friendId, getDisplayedName());
|
||||
chatForm = new ChatForm(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class ChatForm;
|
|||
struct Friend
|
||||
{
|
||||
public:
|
||||
Friend(int FriendId, QString UserId);
|
||||
Friend(int FriendId, const ToxID &UserId);
|
||||
~Friend();
|
||||
|
||||
void setName(QString name);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
QHash<int, Friend*> FriendList::friendList;
|
||||
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);
|
||||
if (friendChecker != friendList.end())
|
||||
|
@ -32,7 +32,7 @@ Friend* FriendList::addFriend(int friendId, const QString& userId)
|
|||
|
||||
Friend* newfriend = new Friend(friendId, userId);
|
||||
friendList[friendId] = newfriend;
|
||||
tox2id[userId] = friendId;
|
||||
tox2id[userId.publicKey] = friendId;
|
||||
|
||||
return newfriend;
|
||||
}
|
||||
|
@ -63,15 +63,15 @@ void FriendList::clear()
|
|||
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())
|
||||
{
|
||||
Friend *f = findFriend(*id);
|
||||
if (!f)
|
||||
return nullptr;
|
||||
if (f->getToxID() == ToxID::fromString(userId))
|
||||
if (f->getToxID() == userId)
|
||||
return f;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,14 +21,15 @@ template <class T> class QList;
|
|||
template <class A, class B> class QHash;
|
||||
struct Friend;
|
||||
class QString;
|
||||
struct ToxID;
|
||||
|
||||
class FriendList
|
||||
{
|
||||
public:
|
||||
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(QString userId);
|
||||
static Friend* findFriend(const ToxID &userId);
|
||||
static QList<Friend*> getAllFriends();
|
||||
static void removeFriend(int friendId, bool fake = false);
|
||||
static void clear();
|
||||
|
|
|
@ -78,9 +78,6 @@ ChatForm::ChatForm(Friend* chatFriend)
|
|||
connect(this, SIGNAL(chatAreaCleared()), this, SLOT(clearReciepts()));
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
if (Settings::getInstance().getEnableLogging())
|
||||
loadHistory(QDateTime::currentDateTime().addDays(-7), true);
|
||||
}
|
||||
|
||||
ChatForm::~ChatForm()
|
||||
|
|
|
@ -36,6 +36,7 @@ public:
|
|||
ChatForm(Friend* chatFriend);
|
||||
~ChatForm();
|
||||
void setStatusMessage(QString newMessage);
|
||||
void loadHistory(QDateTime since, bool processUndelivered = false);
|
||||
|
||||
void dischargeReceipt(int receipt);
|
||||
|
||||
|
@ -85,7 +86,6 @@ private slots:
|
|||
void updateTime();
|
||||
|
||||
protected:
|
||||
void loadHistory(QDateTime since, bool processUndelivered = false);
|
||||
// drag & drop
|
||||
void dragEnterEvent(QDragEnterEvent* ev);
|
||||
void dropEvent(QDropEvent* ev);
|
||||
|
|
|
@ -364,7 +364,7 @@ MessageActionPtr GenericChatForm::genMessageActionAction(const ToxID& author, QS
|
|||
if (isMe)
|
||||
authorStr = core->getUsername();
|
||||
else {
|
||||
Friend *f = FriendList::findFriend(author.publicKey);
|
||||
Friend *f = FriendList::findFriend(author);
|
||||
if (f)
|
||||
authorStr = f->getDisplayedName();
|
||||
else
|
||||
|
|
|
@ -611,12 +611,13 @@ void Widget::setStatusMessage(const QString &statusMessage)
|
|||
void Widget::addFriend(int friendId, const QString &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);
|
||||
layout->addWidget(newfriend->getFriendWidget());
|
||||
|
||||
QString alias = Settings::getInstance().getFriendAlias(ToxID::fromString(userId));
|
||||
newfriend->setAlias(alias);
|
||||
if (Settings::getInstance().getEnableLogging())
|
||||
newfriend->getChatForm()->loadHistory(QDateTime::currentDateTime().addDays(-7), true);
|
||||
|
||||
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
||||
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
||||
|
|
Loading…
Reference in New Issue
Block a user