Advertisement
neochapay

Untitled

Nov 24th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. /* Copyright (C) 2018-2021 Chupligin Sergey <neochapay@gmail.com>
  2. * Copyright (C) 2012 John Brooks <john.brooks@dereferenced.net>
  3. * Copyright (C) 2011 Robin Burchell <robin+nemo@viroteck.net>
  4. *
  5. * You may use this file under the terms of the BSD license as follows:
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Nemo Mobile nor the names of its contributors
  17. * may be used to endorse or promote products derived from this
  18. * software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32.  
  33. import QtQuick 2.6
  34.  
  35. import QtQuick.Controls 1.0
  36. import QtQuick.Controls.Nemo 1.0
  37. import QtQuick.Controls.Styles.Nemo 1.0
  38.  
  39. import org.nemomobile.messages.internal 1.0
  40. import org.nemomobile.qmlcontacts 1.0
  41. import org.nemomobile.commhistory 1.0
  42. import org.nemomobile.voicecall 1.0
  43.  
  44.  
  45. import "../components"
  46.  
  47. /* ConversationPage has two states, depending on if it has an active
  48. * conversation or not. This is determined by whether the channel property
  49. * is set. If unset, this is the new conversation page, and some elements
  50. * are different. */
  51. Page {
  52. id: conversationPage
  53.  
  54. property QtObject channel: null
  55. property QtObject group
  56. property QtObject person: group ? peopleModel.personById(group.contactId) : null
  57. property string remoteUid: ""
  58.  
  59. headerTools: HeaderToolsLayout {
  60. id: hTools
  61. title: person ? person.displayLabel : (group ? group.remoteUids[0] : remoteUid)
  62. showBackButton: true;
  63.  
  64. tools: [
  65. ToolButton {
  66. id: callButton
  67. iconSource: "image://theme/phone"
  68. visible: group != null
  69. onClicked: {
  70. callManager.dial(callManager.defaultProviderId, group.remoteUids[0])
  71. }
  72. }
  73. ]
  74. }
  75.  
  76. Component.onCompleted: {
  77. group.markAsRead()
  78. }
  79.  
  80. VoiceCallManager {
  81. id:callManager
  82. }
  83.  
  84. TextField {
  85. id: targetEditor
  86. visible: !channel
  87. width: parent.width-Theme.itemSpacingLarge*2
  88. height: Theme.itemHeightExtraLarge-Theme.itemSpacingLarge*2
  89.  
  90. anchors{
  91. top: parent.top
  92. topMargin: Theme.itemSpacingLarge
  93. left: parent.left
  94. leftMargin: Theme.itemSpacingLarge
  95. }
  96.  
  97. inputMethodHints: Qt.ImhNoAutoUppercase
  98. placeholderText: qsTr("Phone number")
  99.  
  100. }
  101.  
  102. CommConversationModel {
  103. id: conversationModel
  104. useBackgroundThread: true
  105. groupId: group ? group.id : -1
  106. }
  107.  
  108. MessagesView {
  109. id: messagesView
  110. anchors {
  111. top: targetEditor.visible ? targetEditor.bottom : parent.top
  112. bottom: textArea.top
  113. left: parent.left;
  114. right: parent.right
  115. topMargin: 10;
  116. bottomMargin: 10
  117. leftMargin: 5;
  118. rightMargin: 5
  119. }
  120.  
  121. model: conversationModel
  122. }
  123.  
  124. ChatTextInput {
  125. id: textArea
  126. anchors.bottom: parent.bottom
  127. width: parent.width
  128.  
  129. onSendMessage: {
  130. if (text.length < 1 && (!channel && targetEditor.length < 1)) {
  131. return
  132. }
  133.  
  134. if(!channel) {
  135. channel = channelManager.getConversation(accountsModel.get(0, TelepathyAccountsModel.AccountUidRole),targetEditor.text)
  136. hTools.title = targetEditor.text
  137. }
  138.  
  139. groupManager.createOutgoingMessageEvent(group.groupId, channel.localUid, group.remoteUids[0], text, function(eventId) {
  140. console.log("groupId" + group.groupId)
  141. console.log("channel.localUid" + channel.localUid)
  142. console.log("group.remoteUids[0]" + group.remoteUids[0])
  143. console.log("eventId" + eventId)
  144. channel.sendMessage(text, eventId)
  145. })
  146. clear()
  147. }
  148. }
  149.  
  150. states: [
  151. State {
  152. name: "new"
  153. when: channel == null
  154.  
  155. PropertyChanges {
  156. target: targetEditor
  157. visible: true
  158. }
  159.  
  160. AnchorChanges {
  161. target: messagesView
  162. anchors.top: targetEditor.bottom
  163. }
  164. }
  165. ]
  166.  
  167. onChannelChanged: {
  168. if (channel != null) {
  169. channel.ensureChannel()
  170. _updateGroup()
  171. }
  172. }
  173.  
  174. Connections {
  175. target: groupManager
  176.  
  177. function onGroupAdded(){ _updateGroup() }
  178. function onGroupUpdated() { _updateGroup() }
  179. }
  180.  
  181. Connections {
  182. target: Qt.application
  183. onActiveChanged: markAsRead()
  184. }
  185.  
  186. function _updateGroup() {
  187. if (group === null)
  188. group = groupManager.findGroup(channel.localUid, channel.remoteUid)
  189. }
  190.  
  191. function markAsRead() {
  192. if (!Qt.application.active) {
  193. return
  194. }
  195.  
  196. if (group && group.unreadMessages > 0) {
  197. group.markAsRead()
  198. }
  199. }
  200. }
  201.  
  202.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement