55
56
property var pendingEventsToMarkAsRead: []
56
57
property bool reloadFilters: false
57
58
// to be used by tests as variant does not work with autopilot
59
property bool userTyping: false
60
property QtObject chatEntry: !account ? null : chatManager.chatEntryForParticipants(account.accountId, participants, true)
58
61
property string firstParticipantId: participantIds.length > 0 ? participantIds[0] : ""
59
62
property variant firstParticipant: participants.length > 0 ? participants[0] : null
60
63
property var threads: []
64
property var accountsModel: getAccountsModel()
65
function getAccountsModel() {
67
// on new chat dialogs display all possible accounts
68
if (accountId == "" && participants.length === 0) {
69
for (var i in telepathyHelper.activeAccounts) {
70
accounts.push(telepathyHelper.activeAccounts[i])
72
// suru divider must be empty if there is only one sim card
73
if (accounts.length == 1 && accounts[0].type == AccountEntry.PhoneAccount) {
79
var tmpAccount = telepathyHelper.accountForId(messages.accountId)
80
// on generic accounts we don't give the option to switch to another account
81
if (tmpAccount && tmpAccount.type == AccountEntry.GenericAccount) {
85
// if we get here, this is a regular sms conversation. just
86
// add the available phone accounts next
87
for (var i in telepathyHelper.activeAccounts) {
88
var account = telepathyHelper.activeAccounts[i]
89
if (account.type == AccountEntry.PhoneAccount) {
90
accounts.push(account)
97
function getSectionsModel() {
99
// suru divider must be empty if there is only one sim card
100
if (messages.accountsModel.length == 1 &&
101
messages.accountsModel[0].type == AccountEntry.PhoneAccount) {
105
for (var i in messages.accountsModel) {
106
accountNames.push(messages.accountsModel[i].displayName)
108
return accountNames.length > 0 ? accountNames : []
111
function getSelectedIndex() {
112
if (accountId == "" && participants.length === 0) {
113
// if this is a new message, just pre select the the
114
// default phone account for messages if available
115
if (multiplePhoneAccounts && telepathyHelper.defaultMessagingAccount) {
116
for (var i in messages.accountsModel) {
117
if (telepathyHelper.defaultMessagingAccount == messages.accountsModel[i]) {
122
// otherwise pre-select the first available phone account if any
123
for (var i in messages.accountsModel) {
124
if (messages.accountsModel[i].type == AccountEntry.PhoneAccount) {
128
// otherwise select none
132
// if we get here, just pre-select the account that is set in messages.account
133
return accountIndex(messages.account)
136
function accountIndex(account) {
138
for (var i in messages.accountsModel) {
139
if (messages.accountsModel[i] == account) {
147
function getCurrentAccount() {
148
if (messages.accountId !== "") {
149
var tmpAccount = telepathyHelper.accountForId(messages.accountId)
150
// if the selected account is a phone account, check if there is a default
151
// phone account for messages
152
if (tmpAccount && tmpAccount.type == AccountEntry.PhoneAccount) {
153
if (telepathyHelper.defaultMessagingAccount) {
154
for (var i in messages.accountsModel) {
155
if (messages.accountsModel[i] == telepathyHelper.defaultMessagingAccount) {
156
return telepathyHelper.defaultMessagingAccount
160
for (var i in messages.accountsModel) {
161
if (messages.accountsModel[i].type == AccountEntry.PhoneAccount) {
162
return messages.accountsModel[i]
166
for (var i in messages.accountsModel) {
167
if (tmpAccount.accountId == messages.accountId) {
173
return mainView.account
177
function isPhoneAccount() {
178
var tmpAccount = telepathyHelper.accountForId(accountId)
179
return (!tmpAccount || tmpAccount.type == AccountEntry.PhoneAccount || tmpAccount.type == AccountEntry.MultimediaAccount)
183
target: telepathyHelper
185
// force reevaluation
186
messages.account = Qt.binding(getCurrentAccount)
187
messages.phoneAccount = Qt.binding(isPhoneAccount)
188
head.sections.model = Qt.binding(getSectionsModel)
189
head.sections.selectedIndex = Qt.binding(getSelectedIndex)
196
onChatEntryCreated: {
197
// TODO: track using chatId and not participants
198
if (accountId == account.accountId &&
199
firstParticipant && participants[0] == firstParticipant.identifier) {
200
messages.chatEntry = chatEntry
204
for (var i in chatManager.chats) {
205
var chat = chatManager.chats[i]
206
// TODO: track using chatId and not participants
207
if (chat.account.accountId == account.accountId &&
208
firstParticipant && chat.participants[0] == firstParticipant.identifier) {
209
messages.chatEntry = chat
213
messages.chatEntry = null
221
messages.userTyping = false;
226
model: messages.chatEntry ? messages.chatEntry.chatStates : null
228
function processChatState() {
229
if (modelData.state == ChatEntry.ChannelChatStateComposing) {
230
messages.userTyping = true
233
messages.userTyping = false
236
Component.onCompleted: processChatState()
239
onStateChanged: processChatState()
246
width: parent ? parent.width - units.gu(2) : undefined
248
title: messages.title
251
return i18n.tr("Typing..")
253
switch (presenceRequest.type) {
254
case PresenceRequest.PresenceTypeAvailable:
255
return i18n.tr("Online")
256
case PresenceRequest.PresenceTypeOffline:
257
return i18n.tr("Offline")
258
case PresenceRequest.PresenceTypeAway:
259
return i18n.tr("Away")
260
case PresenceRequest.PresenceTypeBusy:
261
return i18n.tr("Busy")
271
sections.model: getSectionsModel()
272
sections.selectedIndex: getSelectedIndex()
62
276
function addAttachmentsToModel(transfer) {
63
277
for (var i in transfer.items) {
208
432
eventModel.writeEvents([event]);
210
var isMMS = attachments.length > 0
211
var isMmsGroupChat = participantIds.length > 1 && telepathyHelper.mmsGroupChat
434
var isMmsGroupChat = participants.length > 1 && telepathyHelper.mmsGroupChat && messages.account.type == AccountEntry.PhoneAccount
212
435
// mms group chat only works if we know our own phone number
213
436
var isSelfContactKnown = account.selfContactId != ""
214
// FIXME: maybe move this to telepathy-ofono itself and treat as just sendMessage on the app?
215
if (isMMS || (isMmsGroupChat && isSelfContactKnown)) {
216
chatManager.sendMMS(participantIds, text, attachments, messages.account.accountId)
218
chatManager.sendMessage(participantIds, text, messages.account.accountId)
437
if (isMmsGroupChat && !isSelfContactKnown) {
438
// TODO: inform the user to enter the phone number of the selected sim card manually
439
// and use it in the telepathy-ofono account as selfContactId.
442
chatManager.sendMessage(messages.account.accountId, participantIds, text, attachments, properties)
222
445
// FIXME: soon it won't be just about SIM cards, so the dialogs need updating
223
if (multipleAccounts && !telepathyHelper.defaultMessagingAccount && !settings.messagesDontAsk) {
446
if (multiplePhoneAccounts && !telepathyHelper.defaultMessagingAccount && !settings.messagesDontAsk && account.type == AccountEntry.PhoneAccount) {
224
447
Qt.inputMethod.hide()
225
448
PopupUtils.open(Qt.createComponent("Dialogs/SetDefaultSIMCardDialog.qml").createObject(messages))
325
585
return Qt.createQmlObject(componentUnion.arg(componentFilters), eventModel)
328
for (var i in accounts) {
329
var account = accounts[i];
588
var filterAccounts = []
590
if (messages.accountsModel.length == 1 && messages.accountsModel[0].type == AccountEntry.GenericAccount) {
591
filterAccounts = [messages.accountsModel[0]]
593
for (var i in telepathyHelper.accounts) {
594
var account = telepathyHelper.accounts[i]
595
if (account.type === AccountEntry.PhoneAccount || account.type === AccountEntry.MultimediaAccount) {
596
filterAccounts.push(account)
601
for (var i in filterAccounts) {
602
var account = filterAccounts[i];
330
603
var filterValue = eventModel.threadIdForParticipants(account.accountId,
331
604
HistoryThreadModel.EventTypeText,
333
account.type === AccountEntry.PhoneAccount ? HistoryThreadModel.MatchPhoneNumber
606
account.type === AccountEntry.PhoneAccount || account.type === AccountEntry.MultimediaAccount ? HistoryThreadModel.MatchPhoneNumber
334
607
: HistoryThreadModel.MatchCaseSensitive);
335
608
if (filterValue === "") {