PageRenderTime 58ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/qml/pages/TestMessageList.qml

https://gitlab.com/blacksailer/sailfish-vk
QML | 154 lines | 121 code | 23 blank | 10 comment | 12 complexity | 78c752b84d442b48e640566f6ccdcbef MD5 | raw file
  1. import QtQuick 2.0
  2. import Sailfish.Silica 1.0
  3. import QtMultimedia 5.0
  4. import VKModels 1.0
  5. import ".."
  6. import "../items"
  7. import "../../MessageSendNetwork.js" as Net
  8. import QtDocGallery 5.0
  9. import org.nemomobile.thumbnailer 1.0
  10. Page{
  11. id:attachDrawer
  12. signal addAttach(var src,var type);
  13. signal addPhotoId(var json,var indx);
  14. property string attachId:"";
  15. property string attachPreview;
  16. property string headertitle;
  17. property int chat_id;
  18. property bool isMulti:false
  19. property string sobesed_photo;
  20. ListModel{
  21. id:testMessagesModel
  22. ListElement{
  23. first_name:"Ivan"
  24. last_name:"Ivanov"
  25. user_photo:"https://images.duckduckgo.com/iu/?u=http%3A%2F%2Fmedia01.money4invest.com%2F2010%2F01%2Ffaceyourmanga-female-avatar.jpg&f=1"
  26. date:19000000
  27. read_state:1
  28. out:1
  29. title:" ... "
  30. body:"Ipsum Lorem dolorum"
  31. // roles[PHOTOATTACHMENTS] = "gridAttachments";
  32. // roles[AUDIOATTACHMENTS] = "listAttachments";
  33. // roles[DOCATTACHMENTS] = "docAttachments";
  34. // roles[VIDEOATTACHMENTS] = "videoAttachments";
  35. // roles[GIFATTACHMENTS] = "gifAttachments";
  36. // roles[CHAT_ID]="chat_id";
  37. // roles[PHOTO_50]="photo_50";
  38. // roles[PHOTO_100]="photo_100";
  39. // roles[PHOTO_200]="photo_200";
  40. }
  41. }
  42. WritingItem{
  43. id:writer
  44. typeWriter:"message"
  45. bottomArea.visible:true
  46. PageHeader{
  47. id:name_info
  48. title:headertitle
  49. anchors {
  50. leftMargin: 10
  51. }
  52. }
  53. SilicaListView {
  54. id: listView
  55. model: historyModel
  56. verticalLayoutDirection: ListView.BottomToTop
  57. focus:!writer.textArea.focus
  58. PullDownMenu {
  59. id:pulley
  60. MenuItem {
  61. text: qsTr("добавить прошлые записи")
  62. onClicked:
  63. {
  64. vkapi.messages_getHistory(chat_id,listView.count,20,-1)
  65. }
  66. }
  67. }
  68. width: parent.width
  69. height: parent.height-writer.sendAreaHeight-name_info.height
  70. spacing: 30
  71. anchors {
  72. top:name_info.bottom
  73. bottom: writer.bottomArea.top
  74. }
  75. clip:true
  76. delegate:MessageItem{
  77. isOut:out
  78. author: isMulti?first_name+ " "+last_name:""
  79. fwdMsg: historyModel.getFwdMessage(id)
  80. attachWallpost: historyModel.getFwdPost(id)
  81. }
  82. }
  83. actionButton.onClicked: {
  84. var Attachments = c_Model.getAllSendUrls()
  85. console.log(Attachments)
  86. // vkapi.messages_send(chat_id,text,Attachments)
  87. c_Model.clear();
  88. text=""
  89. highlighted=!highlighted
  90. writer.author=writer.authorsText=""
  91. writer.reply_id=-1
  92. }
  93. }
  94. onAddPhotoId:
  95. {
  96. var obj = JSON.parse(json)
  97. c_attachmentsModelToSend.setPhotoAttachmentId(obj.response[0].id,indx)
  98. }
  99. onStatusChanged: {
  100. if(status == PageStatus.Active)
  101. historyModel.isActive = true;
  102. else if(status == PageStatus.Activating)
  103. historyModel.isActive = true;
  104. historyModel.isActive = false;
  105. }
  106. Component.onCompleted: {
  107. historyModel.clear_Messages();
  108. globalSettings.companionId=chat_id;
  109. vkapi.messages_getHistory(chat_id,0,20,-1);
  110. console.log(attachId,attachPreview)
  111. if(attachId.length>0)
  112. {
  113. console.log(attachId,attachPreview)
  114. if(attachId.substring(0,4)=="wall")
  115. writer.c_Model.addAttachment(attachId,4) //Add Wall
  116. else if(attachId.substring(0,5)=="photo")
  117. writer.c_Model.addAttachment(attachId,0,attachPreview) //Add Photo
  118. else if(attachId.substring(0,3)=="doc")
  119. {
  120. if(attachPreview.length>0)
  121. writer.c_Model.addAttachment(attachId,0,attachPreview)
  122. else
  123. writer.c_Model.addAttachment(attachId,3)
  124. }
  125. }
  126. }
  127. Component.onDestruction:
  128. {
  129. globalSettings.companionId=0;
  130. }
  131. }