2020-10-19 13:20:02 +03:00
/ *
2020-10-19 20:34:47 +03:00
Copyright ( C ) 2020 Sebastian J . Wolf and other contributors
2020-10-19 13:20:02 +03:00
This file is part of Fernschreiber .
Fernschreiber is free software: you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
Fernschreiber is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with Fernschreiber . If not , see < http: //www.gnu.org/licenses/>.
* /
import QtQuick 2.6
import Sailfish . Silica 1.0
import QtQml . Models 2.3
import "../"
import "../../pages"
import "../../js/twemoji.js" as Emoji
import "../../js/functions.js" as Functions
ChatInformationTabItemBase {
id: tabBase
2020-11-28 21:11:51 +03:00
loadingText: ( isPrivateChat || isSecretChat ) ? qsTr ( "Loading common chats…" , "chats you have in common with a user" ) : qsTr ( "Loading group members…" )
loading: ( chatInformationPage . isSuperGroup || chatInformationPage . isPrivateChat || chatInformationPage . isSecretChat ) && ! chatInformationPage . isChannel
2020-10-19 13:20:02 +03:00
loadingVisible: loading && membersView . count === 0
2020-11-06 01:23:37 +03:00
property var chatPartnerCommonGroupsIds: ( [ ] ) ;
2020-10-19 13:20:02 +03:00
SilicaListView {
id: membersView
2020-11-28 21:11:51 +03:00
model: ( chatInformationPage . isPrivateChat || chatInformationPage . isSecretChat ) ? ( chatPartnerCommonGroupsIds . length > 0 ? delegateModel : null ) : pageContent . membersList
2020-10-19 13:20:02 +03:00
clip: true
height: tabBase . height
width: tabBase . width
opacity: tabBase . loading ? ( count > 0 ? 0.5 : 0.0 ) : 1.0
2020-11-17 12:09:06 +03:00
Behavior on opacity { FadeAnimation { } }
2020-10-19 13:20:02 +03:00
function handleScrollIntoView ( force ) {
if ( ! tabBase . loading && ! dragging && ! quickScrollAnimating ) {
if ( ! atYBeginning ) {
2020-11-16 23:38:55 +03:00
pageContent . scrollDown ( )
2020-10-19 13:20:02 +03:00
} else {
2020-11-16 23:38:55 +03:00
pageContent . scrollUp ( force ) ;
2020-10-19 13:20:02 +03:00
}
}
}
onDraggingChanged: {
handleScrollIntoView ( )
}
onAtYBeginningChanged: {
handleScrollIntoView ( )
}
onAtYEndChanged: {
2020-11-18 12:34:46 +03:00
if ( tabBase . active && ! tabBase . loading && chatInformationPage . isSuperGroup && ! chatInformationPage . isChannel && ( chatInformationPage . groupInformation . member_count > membersView . count ) && membersView . atYEnd ) {
2020-10-19 13:20:02 +03:00
tabBase . loading = true ;
fetchMoreMembersTimer . start ( )
}
}
onQuickScrollAnimatingChanged: {
handleScrollIntoView ( true )
}
2020-10-19 22:06:28 +03:00
ViewPlaceholder {
2020-11-03 00:51:12 +03:00
y: Theme . paddingLarge
2020-10-19 22:06:28 +03:00
enabled: membersView . count === 0
2020-11-28 21:11:51 +03:00
text: ( chatInformationPage . isPrivateChat || chatInformationPage . isSecretChat ) ? qsTr ( "You don't have any groups in common with this user." ) : ( chatInformationPage . isChannel ? qsTr ( "Channel members are anonymous." ) : qsTr ( "This group is empty." ) )
2020-10-19 22:06:28 +03:00
}
2020-10-19 13:20:02 +03:00
delegate: PhotoTextsListItem {
pictureThumbnail {
2021-01-17 22:37:47 +03:00
photoData: user . profile_photo ? user.profile_photo.small : null
2020-10-19 13:20:02 +03:00
}
width: parent . width
2020-11-16 23:38:55 +03:00
// chat title
2020-11-22 01:56:03 +03:00
primaryText.text: Emoji . emojify ( Functions . getUserName ( user ) , primaryText . font . pixelSize )
2020-10-19 13:20:02 +03:00
// last user
2023-11-18 16:45:22 +03:00
prologSecondaryText.text: "@" + ( user . username ? user.username : member_id . user_id ) + ( member_id . user_id === chatInformationPage . myUserId ? " " + qsTr ( "You" ) : "" )
2020-10-19 13:20:02 +03:00
secondaryText {
horizontalAlignment: Text . AlignRight
property string statusText: Functions . getChatMemberStatusText ( model . status [ "@type" ] )
2020-11-22 01:56:03 +03:00
property string customText: model . status . custom_title ? Emoji . emojify ( model . status . custom_title , secondaryText . font . pixelSize ) : ""
2020-10-19 13:20:02 +03:00
text: ( statusText !== "" && customText !== "" ) ? statusText + ", " + customText : statusText + customText
}
tertiaryText {
maximumLineCount: 1
2020-11-22 01:56:03 +03:00
text: user . type [ "@type" ] === "userTypeBot" ? ( Emoji . emojify ( "🤖 " + bot_info . description , tertiaryText . font . pixelSize ) ) : Functions . getChatPartnerStatusText ( user . status [ "@type" ] , user . status . was_online ) ;
2020-10-19 13:20:02 +03:00
}
onClicked: {
2021-12-07 22:36:48 +03:00
tdLibWrapper . createPrivateChat ( member_id . user_id , "openDirectly" ) ;
2020-10-19 13:20:02 +03:00
}
}
footer: Component {
Item {
2020-11-16 23:38:55 +03:00
property bool active: tabBase . active && chatInformationPage . isSuperGroup && ( chatInformationPage . groupInformation . member_count > membersView . count )
2020-10-19 13:20:02 +03:00
width: tabBase . width
height: active ? Theme.itemSizeLarge : Theme . paddingMedium
BusyIndicator {
id: loadMoreIndicator
anchors.centerIn: parent
size: BusyIndicatorSize . Small
2020-11-03 00:51:12 +03:00
running: tabBase . loading
2020-10-19 13:20:02 +03:00
}
}
}
VerticalScrollDecorator { }
}
DelegateModel {
id: delegateModel
model: chatListModel
groups: [
DelegateModelGroup {
name: "filterGroup" ; includeByDefault: true
}
]
filterOnGroup: "filterGroup"
function hasMatch ( searchInArray ) {
for ( var i = 0 ; i < searchInArray . length ; i ++ ) {
if ( searchInArray [ i ] . toLowerCase ( ) . indexOf ( chatInformationPage . searchString ) > - 1 ) {
return true ;
}
}
return false ;
}
function applyFilter ( ) {
var numberOfEntries = chatListModel . rowCount ( ) ;
var hasFilterString = ! ! chatInformationPage . searchString && chatInformationPage . searchString !== ""
for ( var i = 0 ; i < numberOfEntries ; i ++ ) {
var metadata = chatListModel . get ( i ) ;
if ( tabBase . chatPartnerCommonGroupsIds . indexOf ( metadata . chat_id ) > - 1 ) {
items . addGroups ( i , 1 , "filterGroup" ) ;
} else {
items . removeGroups ( i , 1 , "filterGroup" ) ;
}
}
}
delegate: ChatListViewItem {
ownUserId: chatInformationPage . myUserId
unreadCount: unread_count
onClicked: {
pageStack . pop ( pageStack . find ( function ( page ) { return ( page . _depth === 0 ) } ) , PageStackAction . Immediate ) ;
pageStack . push ( Qt . resolvedUrl ( "../../pages/ChatPage.qml" ) , { "chatInformation" : display } ) ;
}
}
}
Timer {
id: fetchMoreMembersTimer
interval: 600
property int fetchLimit: 50
onTriggered: {
2021-01-14 02:33:46 +03:00
if ( chatInformationPage . isSuperGroup && ( ! chatInformationPage . isChannel || chatInformationPage . canGetMembers ) && ( chatInformationPage . groupInformation . member_count > membersView . count ) ) {
2020-10-19 13:20:02 +03:00
tabBase . loading = true
2020-11-16 23:38:55 +03:00
tdLibWrapper . getSupergroupMembers ( chatInformationPage . chatPartnerGroupId , fetchLimit , pageContent . membersList . count ) ;
2020-10-19 13:20:02 +03:00
fetchLimit = 200
interval = 400
}
}
}
Connections {
target: tdLibWrapper
onChatMembersReceived: {
2020-11-16 23:38:55 +03:00
if ( chatInformationPage . isSuperGroup && chatInformationPage . chatPartnerGroupId === extra ) {
if ( members && members . length > 0 && chatInformationPage . groupInformation . member_count > membersView . count ) {
2020-10-19 13:20:02 +03:00
for ( var memberIndex in members ) {
var memberData = members [ memberIndex ] ;
2021-12-07 01:51:54 +03:00
var userInfo = tdLibWrapper . getUserInformation ( memberData . member_id . user_id ) || { user: { } , bot_info: { } } ;
2023-11-18 16:45:22 +03:00
if ( ! userInfo . username && userInfo . usernames && userInfo . usernames . active_usernames ) {
userInfo . username = userInfo . usernames . active_usernames [ 0 ]
}
2020-10-19 13:20:02 +03:00
memberData . user = userInfo ;
memberData . bot_info = memberData . bot_info || { } ;
2020-11-16 23:38:55 +03:00
pageContent . membersList . append ( memberData ) ;
2020-10-19 13:20:02 +03:00
}
2020-11-16 23:38:55 +03:00
chatInformationPage . groupInformation . member_count = totalMembers
2020-10-19 13:20:02 +03:00
updateGroupStatusText ( ) ;
2020-11-16 23:38:55 +03:00
// if(pageContent.membersList.count < totalMembers) {
2020-10-19 13:20:02 +03:00
// fetchMoreMembersTimer.start()
2020-11-16 23:38:55 +03:00
// }
2020-10-19 13:20:02 +03:00
}
// if we set it directly, the views start scrolling
loadedTimer . start ( ) ;
}
}
onChatsReceived: { // common chats with user
2020-11-28 21:11:51 +03:00
if ( ( isPrivateChat || isSecretChat ) && chats [ "@extra" ] === chatInformationPage . chatPartnerGroupId ) {
2020-10-19 13:20:02 +03:00
tabBase . chatPartnerCommonGroupsIds = chats . chat_ids ;
delegateModel . applyFilter ( ) ;
// if we set it directly, the views start scrolling
loadedTimer . start ( ) ;
}
}
}
Timer {
id: loadedTimer
interval: 50
onTriggered: {
tabBase . loading = false
}
}
Component.onCompleted: {
2020-11-28 21:11:51 +03:00
if ( chatInformationPage . isPrivateChat || chatInformationPage . isSecretChat ) {
2020-10-19 13:20:02 +03:00
tdLibWrapper . getGroupsInCommon ( chatInformationPage . chatPartnerGroupId , 200 , 0 ) ; // we only use the first 200
2020-11-16 23:38:55 +03:00
} else if ( chatInformationPage . isSuperGroup ) {
2020-10-19 13:20:02 +03:00
fetchMoreMembersTimer . start ( ) ;
}
}
}