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 {
MenuItem {
visible: (isBasicGroup || isSuperGroup) && userIsMember
text: qsTr("Leave Group")
visible: (chatPage.isSuperGroup || chatPage.isBasicGroup) && groupInformation && groupInformation.status["@type"] !== "chatMemberStatusBanned"
text: userIsMember ? qsTr("Leave Chat") : qsTr("Join Chat")
onClicked: {
// ensure it's done even if the page is closed:
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.toString())))
if (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);
}
}
}
MenuItem {

View file

@ -42,6 +42,13 @@ Page {
property var chatGroupInformation;
property int chatOnlineMemberCount: 0;
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() {
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));
}
}
joinLeaveChatMenuItem.text = chatPage.userIsMember ? qsTr("Leave Chat") : qsTr("Join Chat");
}
function initializePage() {
@ -310,6 +318,13 @@ Page {
}
}
Connections {
target: chatListModel
onChatJoined: {
chatPageNotification.show(qsTr("You joined the chat %1").arg(chatTitle));
}
}
Timer {
id: lostFocusTimer
interval: 200
@ -369,8 +384,28 @@ Page {
PullDownMenu {
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 {
id: muteChatMenuItem
visible: chatPage.userIsMember
onClicked: {
var newNotificationSettings = chatInformation.notification_settings;
if (newNotificationSettings.mute_for > 0) {
@ -384,6 +419,10 @@ Page {
}
}
AppNotification {
id: chatPageNotification
}
BackgroundItem {
id: headerMouseArea
height: headerRow.height

View file

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

View file

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

View file

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

View file

@ -237,6 +237,15 @@ void TDLibWrapper::closeChat(const QString &chatId)
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)
{
LOG("Leaving chat " << chatId);

View file

@ -115,6 +115,7 @@ public:
Q_INVOKABLE void downloadFile(const QString &fileId);
Q_INVOKABLE void openChat(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 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);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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