Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
add handling groupId in private conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
wsekta committed Jan 14, 2024
1 parent 5ffb4e3 commit eb81436
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ vcpkg_installed
lib
CMakeLists.txt.user
coverage.txt
**/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ void PrivateMessagesController::rejectFriendInvitation(const QString& requestId)
session->sendMessage(common::messages::MessageId::RejectFriendInvitations, data);
}

void PrivateMessagesController::setCurrentFriend(const QString& friendId, const QString& friendName)
void PrivateMessagesController::setCurrentFriend(const QString& friendId, const QString& friendName,
const QString& groupId)
{
LOG_S(INFO) << fmt::format("Set current friend to {} with id {}", friendName.toStdString(), friendId.toStdString());

Expand All @@ -121,10 +122,12 @@ void PrivateMessagesController::setCurrentFriend(const QString& friendId, const

currentFriendId = friendId.toStdString();
currentFriendName = friendName.toStdString();
currentFriendGroupId = groupId.toStdString();

emit setCurrentFriendName(friendName);

session->sendMessage(common::messages::MessageId::GetPrivateMessages, {{"friendId", currentFriendId}});
session->sendMessage(common::messages::MessageId::GetPrivateMessages,
{{"groupId", currentFriendGroupId}, {"limit", 50}, {"offset", 0}});
}

void PrivateMessagesController::removeFromFriends()
Expand Down Expand Up @@ -158,14 +161,16 @@ void PrivateMessagesController::handleGetUserFriendsResponse(const common::messa
{
for (const auto& userFriend : responseJson.at("data"))
{
if (userFriend.contains("id") and userFriend.contains("name") and userFriend.contains("isActive"))
if (userFriend.contains("id") and userFriend.contains("name") and userFriend.contains("isActive") and
userFriend.contains("groupId"))
{
LOG_S(INFO) << fmt::format("Adding friend {} with id {} to list",
userFriend.at("name").get<std::string>(),
userFriend.at("id").get<std::string>());

emit addFriend(QString::fromStdString(userFriend.at("name").get<std::string>()),
QString::fromStdString(userFriend.at("id").get<std::string>()),
QString::fromStdString(userFriend.at("groupId").get<std::string>()),
userFriend.at("isActive").get<bool>());
}
else
Expand Down Expand Up @@ -259,7 +264,7 @@ void PrivateMessagesController::sendPrivateMessage(const QString& messageText)
currentFriendName, currentFriendId);

nlohmann::json data{
{"receiverId", currentFriendId},
{"groupId", currentFriendGroupId},
{"message", messageText.toStdString()},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class PrivateMessagesController : public QObject
Q_INVOKABLE void goToSendFriendInvitation();
Q_INVOKABLE void acceptFriendInvitation(const QString& requestId);
Q_INVOKABLE void rejectFriendInvitation(const QString& requestId);
Q_INVOKABLE void setCurrentFriend(const QString& friendId, const QString& friendName);
Q_INVOKABLE void setCurrentFriend(const QString& friendId, const QString& friendName, const QString& groupId);
Q_INVOKABLE void removeFromFriends();

signals:
void addFriend(const QString& friendName, const QString& friendId, bool isActive);
void addFriend(const QString& friendName, const QString& friendId, const QString& groupId, bool isActive);
void addFriendInvitation(const QString& friendName, const QString& requestId);
void clearFriendList();
void clearFriendInvitationList();
Expand Down Expand Up @@ -60,6 +60,7 @@ public slots:
std::shared_ptr<storage::ConversationStorage> conversationStorage;
std::string currentFriendId;
std::string currentFriendName;
std::string currentFriendGroupId;

inline static const QString name{"privateMessagesController"};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Rectangle {
}
}
Connections {
function onAddFriend(friendName: string, friendId: string, isActive: bool) {
friendsColumn.addFriend(friendName, friendId, isActive);
function onAddFriend(friendName: string, friendId: string, groupId: string, isActive: bool) {
friendsColumn.addFriend(friendName, friendId, groupId, isActive);
}

function onAddFriendInvitation(friendName: string, requestId: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Rectangle {
property var friendInvitations: []
property var friends: []

function addFriend(friendName: string, friendId: string, isActive: bool) {
friends.push([friendName, friendId, isActive]);
function addFriend(friendName: string, friendId: string, groupId: string, isActive: bool) {
friends.push([friendName, friendId, groupId, isActive]);
friendsView.model = friends;
friendsView.height = 36 * friends.length;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ Rectangle {
width: parent.width - firendActive.width - 5

onClicked: {
privateMessagesController.setCurrentFriend(modelData[1], modelData[0]);
privateMessagesController.setCurrentFriend(modelData[1], modelData[0], modelData[2]);
}
}
ActivityIndicator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ common::messages::Message GetUserFriendsMessageHandler::handleMessage(const comm
const auto userFriend =
friendship.getUser()->getId() == userId ? *friendship.getUserFriend() : *friendship.getUser();

nlohmann::json friendJson{
{"id", userFriend.getId()}, {"name", userFriend.getNickname()}, {"isActive", userFriend.isActive()}};
nlohmann::json friendJson{{"id", userFriend.getId()},
{"groupId", friendship.getGroup()->getId()},
{"name", userFriend.getNickname()},
{"isActive", userFriend.isActive()}};

friendsJsonArray.push_back(friendJson);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@ TEST_F(GetUserFriendsMessageHandlerTest, handleValidGetUserFriendsMessageWithFew

auto responseMessage = getUserFriendsMessageHandler.handleMessage(message);

auto expectedResponsePayloadJson = nlohmann::json{
{"data", nlohmann::json::array({
{{"id", friend1->getId()}, {"name", friend1->getNickname()}, {"isActive", friend1->isActive()}},
{{"id", friend2->getId()}, {"name", friend2->getNickname()}, {"isActive", friend2->isActive()}},
})}};
auto expectedResponsePayloadJson = nlohmann::json{{"data", nlohmann::json::array({
{{"id", friend1->getId()},
{"name", friend1->getNickname()},
{"isActive", friend1->isActive()},
{"groupId", group1->getId()}},
{{"id", friend2->getId()},
{"name", friend2->getNickname()},
{"isActive", friend2->isActive()},
{"groupId", group2->getId()}},
})}};

auto expectedMessageResponse = common::messages::Message{common::messages::MessageId::GetUserFriendsResponse,
common::bytes::Bytes{expectedResponsePayloadJson.dump()}};
Expand Down

0 comments on commit eb81436

Please sign in to comment.