2020-10-31 22:49:03 +03:00
import QtQuick 2.6
2020-10-19 13:20:02 +03:00
import Sailfish . Silica 1.0
2020-11-25 02:23:38 +03:00
import WerkWolf . Fernschreiber 1.0
2020-10-19 13:20:02 +03:00
import "../js/twemoji.js" as Emoji
import "../js/functions.js" as Functions
PhotoTextsListItem {
id: listItem
pictureThumbnail {
2020-11-15 01:50:12 +03:00
photoData: photo_small || ( { } )
2021-01-10 05:25:02 +03:00
highlighted: listItem . highlighted && ! listItem . menuOpen
2020-10-19 13:20:02 +03:00
}
property int ownUserId
2020-12-31 02:59:05 +03:00
property bool showDraft: ! ! draft_message_text && draft_message_date > last_message_date
property string previewText: showDraft ? draft_message_text : last_message_text
2020-10-19 13:20:02 +03:00
// chat title
2021-01-10 00:25:58 +03:00
primaryText.text: title ? Emoji . emojify ( title , Theme . fontSizeMedium ) : qsTr ( "Unknown" )
2020-10-19 13:20:02 +03:00
// last user
2021-01-19 02:02:37 +03:00
prologSecondaryText.text: showDraft ? "<i>" + qsTr ( "Draft" ) + "</i>" : ( is_channel ? "" : ( last_message_sender_id ? ( last_message_sender_id !== ownUserId ? Emoji . emojify ( Functions . getUserName ( tdLibWrapper . getUserInformation ( last_message_sender_id ) ) , Theme . fontSizeExtraSmall ) : qsTr ( "You" ) ) : "" ) )
2020-10-19 13:20:02 +03:00
// last message
2020-12-31 02:59:05 +03:00
secondaryText.text: previewText ? Emoji . emojify ( Functions . enhanceHtmlEntities ( previewText ) , Theme . fontSizeExtraSmall ) : "<i>" + qsTr ( "No message in this chat." ) + "</i>"
2020-10-19 13:20:02 +03:00
// message date
2020-12-31 02:59:05 +03:00
tertiaryText.text: showDraft ? Functions . getDateTimeElapsed ( draft_message_date ) : ( last_message_date ? ( last_message_date . length === 0 ? "" : Functions . getDateTimeElapsed ( last_message_date ) + Emoji . emojify ( last_message_status , tertiaryText . font . pixelSize ) ) : "" )
2020-10-19 13:20:02 +03:00
unreadCount: unread_count
2022-06-06 16:55:21 +03:00
unreadReactionCount: unread_reaction_count
unreadMentionCount: unread_mention_count
2020-11-25 02:23:38 +03:00
isSecret: ( chat_type === TelegramAPI . ChatTypeSecret )
2020-12-31 02:19:36 +03:00
isMarkedAsUnread: is_marked_as_unread
2021-01-06 12:42:12 +03:00
isPinned: is_pinned
2021-01-10 00:25:58 +03:00
isMuted: display . notification_settings . mute_for > 0
2020-10-19 13:20:02 +03:00
openMenuOnPressAndHold: true //chat_id != overviewPage.ownUserId
2020-10-19 16:30:03 +03:00
2020-12-26 01:09:23 +03:00
onPressAndHold: {
contextMenuLoader . active = true ;
}
Loader {
id: contextMenuLoader
active: false
asynchronous: true
onStatusChanged: {
if ( status === Loader . Ready ) {
listItem . menu = item ;
listItem . openMenu ( ) ;
2020-10-19 13:20:02 +03:00
}
}
2020-12-26 01:09:23 +03:00
sourceComponent: Component {
ContextMenu {
MenuItem {
2022-06-06 16:55:21 +03:00
visible: unread_count > 0 || unread_reaction_count > 0 || unread_mention_count > 0
2020-12-26 01:09:23 +03:00
onClicked: {
tdLibWrapper . viewMessage ( chat_id , display . last_message . id , true ) ;
2022-05-24 22:19:15 +03:00
tdLibWrapper . readAllChatMentions ( chat_id ) ;
tdLibWrapper . readAllChatReactions ( chat_id ) ;
2020-12-31 02:19:36 +03:00
tdLibWrapper . toggleChatIsMarkedAsUnread ( chat_id , false ) ;
2020-12-26 01:09:23 +03:00
}
text: qsTr ( "Mark all messages as read" )
}
2020-10-19 13:20:02 +03:00
2020-12-31 02:19:36 +03:00
MenuItem {
2022-06-06 16:55:21 +03:00
visible: unread_count === 0 && unread_reaction_count === 0 && unread_mention_count === 0
2020-12-31 02:19:36 +03:00
onClicked: {
2021-01-08 00:47:42 +03:00
tdLibWrapper . toggleChatIsMarkedAsUnread ( chat_id , ! is_marked_as_unread ) ;
2020-12-31 02:19:36 +03:00
}
2021-01-08 00:47:42 +03:00
text: is_marked_as_unread ? qsTr ( "Mark chat as read" ) : qsTr ( "Mark chat as unread" )
2020-12-31 02:19:36 +03:00
}
MenuItem {
onClicked: {
2021-01-08 00:47:42 +03:00
tdLibWrapper . toggleChatIsPinned ( chat_id , ! is_pinned ) ;
2020-12-31 02:19:36 +03:00
}
2021-01-08 00:47:42 +03:00
text: is_pinned ? qsTr ( "Unpin chat" ) : qsTr ( "Pin chat" )
2020-12-31 02:19:36 +03:00
}
2020-12-26 01:09:23 +03:00
MenuItem {
visible: chat_id != listItem . ownUserId
onClicked: {
var newNotificationSettings = display . notification_settings ;
if ( newNotificationSettings . mute_for > 0 ) {
newNotificationSettings . mute_for = 0 ;
} else {
newNotificationSettings . mute_for = 6666666 ;
}
newNotificationSettings . use_default_mute_for = false ;
tdLibWrapper . setChatNotificationSettings ( chat_id , newNotificationSettings ) ;
}
2021-01-08 00:47:42 +03:00
text: display . notification_settings . mute_for > 0 ? qsTr ( "Unmute chat" ) : qsTr ( "Mute chat" )
2020-10-19 13:20:02 +03:00
}
2020-12-26 01:09:23 +03:00
MenuItem {
onClicked: {
if ( pageStack . depth > 2 ) {
pageStack . pop ( pageStack . find ( function ( page ) { return ( page . _depth === 0 ) } ) , PageStackAction . Immediate ) ;
}
pageStack . push ( Qt . resolvedUrl ( "../pages/ChatInformationPage.qml" ) , { "chatInformation" : display } ) ;
}
text: model . display . type [ '@type' ] === "chatTypePrivate" ? qsTr ( "User Info" ) : qsTr ( "Group Info" )
}
2020-10-19 13:20:02 +03:00
}
}
}
}