Joining/leaving chats seems to work...

This commit is contained in:
Sebastian Wolf 2020-11-07 20:29:44 +01:00
parent ccf15121e0
commit 9bb24b4862
17 changed files with 311 additions and 49 deletions

View file

@ -184,17 +184,23 @@ Page {
PullDownMenu { PullDownMenu {
MenuItem { MenuItem {
visible: (isBasicGroup || isSuperGroup) && userIsMember visible: (chatPage.isSuperGroup || chatPage.isBasicGroup) && groupInformation && groupInformation.status["@type"] !== "chatMemberStatusBanned"
text: qsTr("Leave Group") text: userIsMember ? qsTr("Leave Chat") : qsTr("Join Chat")
onClicked: { onClicked: {
// ensure it's done even if the page is closed: // ensure it's done even if the page is closed:
var remorse = Remorse.popupAction(appWindow, qsTr("Leaving chat"), (function(chatid) { if (userIsMember) {
return function() { var remorse = Remorse.popupAction(appWindow, qsTr("Leaving chat"), (function(chatid) {
tdLibWrapper.leaveChat(chatid); return function() {
// this does not care about the response (ideally type "ok" without further reference) for now tdLibWrapper.leaveChat(chatid);
pageStack.pop(pageStack.find( function(page){ return(page._depth === 0)} )); // this does not care about the response (ideally type "ok" without further reference) for now
}; pageStack.pop(pageStack.find( function(page){ return(page._depth === 0)} ));
}(chatInformation.id.toString()))) };
}(chatInformation.id)))
} else {
tdLibWrapper.joinChat(chatInformation.id);
}
} }
} }
MenuItem { MenuItem {

View file

@ -42,6 +42,13 @@ Page {
property var chatGroupInformation; property var chatGroupInformation;
property int chatOnlineMemberCount: 0; property int chatOnlineMemberCount: 0;
property var emojiProposals; property var emojiProposals;
property bool userIsMember: (isPrivateChat && chatInformation["@type"]) || // should be optimized
(isBasicGroup || isSuperGroup) && (
(chatGroupInformation.status["@type"] === "chatMemberStatusMember")
|| (chatGroupInformation.status["@type"] === "chatMemberStatusAdministrator")
|| (chatGroupInformation.status["@type"] === "chatMemberStatusRestricted" && chatGroupInformation.status.is_member)
|| (chatGroupInformation.status["@type"] === "chatMemberStatusCreator" && chatGroupInformation.status.is_member)
)
function updateChatPartnerStatusText() { function updateChatPartnerStatusText() {
var statusText = Functions.getChatPartnerStatusText(chatPartnerInformation.status['@type'], chatPartnerInformation.status.was_online); var statusText = Functions.getChatPartnerStatusText(chatPartnerInformation.status['@type'], chatPartnerInformation.status.was_online);
@ -60,6 +67,7 @@ Page {
chatStatusText.text = qsTr("%1 members").arg(Functions.getShortenedCount(chatGroupInformation.member_count)); chatStatusText.text = qsTr("%1 members").arg(Functions.getShortenedCount(chatGroupInformation.member_count));
} }
} }
joinLeaveChatMenuItem.text = chatPage.userIsMember ? qsTr("Leave Chat") : qsTr("Join Chat");
} }
function initializePage() { function initializePage() {
@ -310,6 +318,13 @@ Page {
} }
} }
Connections {
target: chatListModel
onChatJoined: {
chatPageNotification.show(qsTr("You joined the chat %1").arg(chatTitle));
}
}
Timer { Timer {
id: lostFocusTimer id: lostFocusTimer
interval: 200 interval: 200
@ -369,8 +384,28 @@ Page {
PullDownMenu { PullDownMenu {
visible: chatInformation.id !== chatPage.myUserId && !stickerPickerLoader.active visible: chatInformation.id !== chatPage.myUserId && !stickerPickerLoader.active
MenuItem {
id: joinLeaveChatMenuItem
visible: (chatPage.isSuperGroup || chatPage.isBasicGroup) && chatGroupInformation && chatGroupInformation.status["@type"] !== "chatMemberStatusBanned"
onClicked: {
if (chatPage.userIsMember) {
var remorse = Remorse.popupAction(appWindow, qsTr("Leaving chat"), (function(chatid) {
return function() {
tdLibWrapper.leaveChat(chatid);
// this does not care about the response (ideally type "ok" without further reference) for now
pageStack.pop(pageStack.find( function(page){ return(page._depth === 0)} ));
};
}(chatInformation.id)))
} else {
tdLibWrapper.joinChat(chatInformation.id);
}
}
text: chatPage.userIsMember ? qsTr("Leave Chat") : qsTr("Join Chat")
}
MenuItem { MenuItem {
id: muteChatMenuItem id: muteChatMenuItem
visible: chatPage.userIsMember
onClicked: { onClicked: {
var newNotificationSettings = chatInformation.notification_settings; var newNotificationSettings = chatInformation.notification_settings;
if (newNotificationSettings.mute_for > 0) { if (newNotificationSettings.mute_for > 0) {
@ -384,6 +419,10 @@ Page {
} }
} }
AppNotification {
id: chatPageNotification
}
BackgroundItem { BackgroundItem {
id: headerMouseArea id: headerMouseArea
height: headerRow.height height: headerRow.height

View file

@ -179,6 +179,10 @@ Page {
} }
} }
AppNotification {
id: overviewPageNotification
}
Column { Column {
id: column id: column
width: parent.width width: parent.width

View file

@ -405,10 +405,12 @@ void ChatListModel::addVisibleChat(ChatData *chat)
chatIndexMap.insert(chatList.at(i)->chatId, i); chatIndexMap.insert(chatList.at(i)->chatId, i);
} }
endInsertRows(); endInsertRows();
emit chatJoined(chat->chatId, chat->chatData.value("title").toString());
} }
void ChatListModel::updateChatVisibility(const TDLibWrapper::Group *group) void ChatListModel::updateChatVisibility(const TDLibWrapper::Group *group)
{ {
LOG("Updating chat visibility" << group->groupId);
// See if any group has been removed from from view // See if any group has been removed from from view
for (int i = 0; i < chatList.size(); i++) { for (int i = 0; i < chatList.size(); i++) {
ChatData *chat = chatList.at(i); ChatData *chat = chatList.at(i);

View file

@ -56,6 +56,7 @@ private slots:
signals: signals:
void showAllChatsChanged(); void showAllChatsChanged();
void chatChanged(const qlonglong &changedChatId); void chatChanged(const qlonglong &changedChatId);
void chatJoined(const qlonglong &chatId, const QString &chatTitle);
private: private:
class ChatData; class ChatData;

View file

@ -237,6 +237,15 @@ void TDLibWrapper::closeChat(const QString &chatId)
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }
void TDLibWrapper::joinChat(const QString &chatId)
{
LOG("Joining chat " << chatId);
QVariantMap requestObject;
requestObject.insert(_TYPE, "joinChat");
requestObject.insert("chat_id", chatId);
this->sendRequest(requestObject);
}
void TDLibWrapper::leaveChat(const QString &chatId) void TDLibWrapper::leaveChat(const QString &chatId)
{ {
LOG("Leaving chat " << chatId); LOG("Leaving chat " << chatId);

View file

@ -115,6 +115,7 @@ public:
Q_INVOKABLE void downloadFile(const QString &fileId); Q_INVOKABLE void downloadFile(const QString &fileId);
Q_INVOKABLE void openChat(const QString &chatId); Q_INVOKABLE void openChat(const QString &chatId);
Q_INVOKABLE void closeChat(const QString &chatId); Q_INVOKABLE void closeChat(const QString &chatId);
Q_INVOKABLE void joinChat(const QString &chatId);
Q_INVOKABLE void leaveChat(const QString &chatId); Q_INVOKABLE void leaveChat(const QString &chatId);
Q_INVOKABLE void getChatHistory(const QString &chatId, const qlonglong &fromMessageId = 0, int offset = 0, int limit = 50, bool onlyLocal = false); Q_INVOKABLE void getChatHistory(const QString &chatId, const qlonglong &fromMessageId = 0, int offset = 0, int limit = 50, bool onlyLocal = false);
Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId, bool force); Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId, bool force);

View file

@ -117,10 +117,6 @@
<source>%1 members</source> <source>%1 members</source>
<translation>%1 Mitglieder</translation> <translation>%1 Mitglieder</translation>
</message> </message>
<message>
<source>Leave Group</source>
<translation>Gruppe verlassen</translation>
</message>
<message> <message>
<source>Leaving chat</source> <source>Leaving chat</source>
<translation>Verlasse Gruppe</translation> <translation>Verlasse Gruppe</translation>
@ -153,6 +149,14 @@
<source>Enter 1-128 characters</source> <source>Enter 1-128 characters</source>
<translation>Geben Sie 1-128 Zeichen ein</translation> <translation>Geben Sie 1-128 Zeichen ein</translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation>Chat verlassen</translation>
</message>
<message>
<source>Join Chat</source>
<translation>Chat beitreten</translation>
</message>
</context> </context>
<context> <context>
<name>ChatInformationTabItemMembersGroups</name> <name>ChatInformationTabItemMembersGroups</name>
@ -285,6 +289,22 @@
<source>This chat is empty.</source> <source>This chat is empty.</source>
<translation>Dieser Chat ist leer.</translation> <translation>Dieser Chat ist leer.</translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation>Chat verlassen</translation>
</message>
<message>
<source>Join Chat</source>
<translation>Chat beitreten</translation>
</message>
<message>
<source>Leaving chat</source>
<translation>Verlasse Chat</translation>
</message>
<message>
<source>You joined the chat %1</source>
<translation>Sie sind dem Chat %1 beigetreten.</translation>
</message>
</context> </context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>

View file

@ -117,10 +117,6 @@
<source>%1 members</source> <source>%1 members</source>
<translation>%1 miembros</translation> <translation>%1 miembros</translation>
</message> </message>
<message>
<source>Leave Group</source>
<translation>Salir del grupo</translation>
</message>
<message> <message>
<source>Leaving chat</source> <source>Leaving chat</source>
<translation>Saliendo de la charla</translation> <translation>Saliendo de la charla</translation>
@ -153,6 +149,14 @@
<source>Enter 1-128 characters</source> <source>Enter 1-128 characters</source>
<translation>Introducir 1-128 caracteres</translation> <translation>Introducir 1-128 caracteres</translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ChatInformationTabItemMembersGroups</name> <name>ChatInformationTabItemMembersGroups</name>
@ -285,6 +289,22 @@
<source>This chat is empty.</source> <source>This chat is empty.</source>
<translation>Esta charla está vacía.</translation> <translation>Esta charla está vacía.</translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Leaving chat</source>
<translation type="unfinished">Saliendo de la charla</translation>
</message>
<message>
<source>You joined the chat %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>

View file

@ -117,10 +117,6 @@
<source>%1 members</source> <source>%1 members</source>
<translation>%1 jäsentä</translation> <translation>%1 jäsentä</translation>
</message> </message>
<message>
<source>Leave Group</source>
<translation>Poistu ryhmästä</translation>
</message>
<message> <message>
<source>Leaving chat</source> <source>Leaving chat</source>
<translation>Poistutaan keskustelusta</translation> <translation>Poistutaan keskustelusta</translation>
@ -153,6 +149,14 @@
<source>Enter 1-128 characters</source> <source>Enter 1-128 characters</source>
<translation>Syötä 1-128 merkkiä</translation> <translation>Syötä 1-128 merkkiä</translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ChatInformationTabItemMembersGroups</name> <name>ChatInformationTabItemMembersGroups</name>
@ -285,6 +289,22 @@
<source>This chat is empty.</source> <source>This chat is empty.</source>
<translation>Tämä keskustelu on tyhjä.</translation> <translation>Tämä keskustelu on tyhjä.</translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Leaving chat</source>
<translation type="unfinished">Poistutaan keskustelusta</translation>
</message>
<message>
<source>You joined the chat %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>

View file

@ -117,10 +117,6 @@
<source>%1 members</source> <source>%1 members</source>
<translation type="unfinished">%1 tag</translation> <translation type="unfinished">%1 tag</translation>
</message> </message>
<message>
<source>Leave Group</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Leaving chat</source> <source>Leaving chat</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -153,6 +149,14 @@
<source>Enter 1-128 characters</source> <source>Enter 1-128 characters</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ChatInformationTabItemMembersGroups</name> <name>ChatInformationTabItemMembersGroups</name>
@ -285,6 +289,22 @@
<source>This chat is empty.</source> <source>This chat is empty.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Leaving chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You joined the chat %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>

View file

@ -89,10 +89,6 @@
</context> </context>
<context> <context>
<name>ChatInformationPage</name> <name>ChatInformationPage</name>
<message>
<source>Leave Group</source>
<translation>Lascia gruppo</translation>
</message>
<message> <message>
<source>Leaving chat</source> <source>Leaving chat</source>
<translation>Lascia chat</translation> <translation>Lascia chat</translation>
@ -153,6 +149,14 @@
<source>Enter 1-128 characters</source> <source>Enter 1-128 characters</source>
<translation>Inserisci da 1 a 128 caratteri</translation> <translation>Inserisci da 1 a 128 caratteri</translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ChatInformationTabItemMembersGroups</name> <name>ChatInformationTabItemMembersGroups</name>
@ -285,6 +289,22 @@
<source>Uploading...</source> <source>Uploading...</source>
<translation>Carica...</translation> <translation>Carica...</translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Leaving chat</source>
<translation type="unfinished">Lascia chat</translation>
</message>
<message>
<source>You joined the chat %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>

View file

@ -117,10 +117,6 @@
<source>%1 members</source> <source>%1 members</source>
<translation type="unfinished">%1 czlonków</translation> <translation type="unfinished">%1 czlonków</translation>
</message> </message>
<message>
<source>Leave Group</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Leaving chat</source> <source>Leaving chat</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -153,6 +149,14 @@
<source>Enter 1-128 characters</source> <source>Enter 1-128 characters</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ChatInformationTabItemMembersGroups</name> <name>ChatInformationTabItemMembersGroups</name>
@ -285,6 +289,22 @@
<source>This chat is empty.</source> <source>This chat is empty.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Leaving chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You joined the chat %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>

View file

@ -117,10 +117,6 @@
<source>%1 members</source> <source>%1 members</source>
<translation type="unfinished">%1 участников</translation> <translation type="unfinished">%1 участников</translation>
</message> </message>
<message>
<source>Leave Group</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Leaving chat</source> <source>Leaving chat</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -153,6 +149,14 @@
<source>Enter 1-128 characters</source> <source>Enter 1-128 characters</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ChatInformationTabItemMembersGroups</name> <name>ChatInformationTabItemMembersGroups</name>
@ -285,6 +289,22 @@
<source>This chat is empty.</source> <source>This chat is empty.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Leaving chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You joined the chat %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>

View file

@ -117,10 +117,6 @@
<source>%1 members</source> <source>%1 members</source>
<translation>%1 medlemmar</translation> <translation>%1 medlemmar</translation>
</message> </message>
<message>
<source>Leave Group</source>
<translation>Lämna gruppen</translation>
</message>
<message> <message>
<source>Leaving chat</source> <source>Leaving chat</source>
<translation>Lämnar chatten</translation> <translation>Lämnar chatten</translation>
@ -153,6 +149,14 @@
<source>Enter 1-128 characters</source> <source>Enter 1-128 characters</source>
<translation>Ange 1-128 tecken</translation> <translation>Ange 1-128 tecken</translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ChatInformationTabItemMembersGroups</name> <name>ChatInformationTabItemMembersGroups</name>
@ -285,6 +289,22 @@
<source>This chat is empty.</source> <source>This chat is empty.</source>
<translation>Denna chatt är tom.</translation> <translation>Denna chatt är tom.</translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Leaving chat</source>
<translation type="unfinished">Lämnar chatten</translation>
</message>
<message>
<source>You joined the chat %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>

View file

@ -117,10 +117,6 @@
<source>%1 members</source> <source>%1 members</source>
<translation type="unfinished">%1 </translation> <translation type="unfinished">%1 </translation>
</message> </message>
<message>
<source>Leave Group</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Leaving chat</source> <source>Leaving chat</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -153,6 +149,14 @@
<source>Enter 1-128 characters</source> <source>Enter 1-128 characters</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ChatInformationTabItemMembersGroups</name> <name>ChatInformationTabItemMembersGroups</name>
@ -285,6 +289,22 @@
<source>This chat is empty.</source> <source>This chat is empty.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Leaving chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You joined the chat %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>

View file

@ -117,10 +117,6 @@
<source>%1 members</source> <source>%1 members</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Group</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Leaving chat</source> <source>Leaving chat</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -153,6 +149,14 @@
<source>Enter 1-128 characters</source> <source>Enter 1-128 characters</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ChatInformationTabItemMembersGroups</name> <name>ChatInformationTabItemMembersGroups</name>
@ -285,6 +289,22 @@
<source>This chat is empty.</source> <source>This chat is empty.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Leave Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Join Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Leaving chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You joined the chat %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>