139
141
function getSelectedIndex() {
140
142
if (newMessage) {
141
// if this is a new message, just pre select the the
143
// if this is a new message, just pre select the the
142
144
// default phone account for messages if available
143
145
if (multiplePhoneAccounts && telepathyHelper.defaultMessagingAccount) {
144
146
for (var i in messages.accountsModel) {
301
303
multiRecipient.forceActiveFocus()
304
function sendMessageSanityCheck(text, participantIds, attachments, properties) {
305
// if MMS is enabled, we don't have to check for anything here
306
if (telepathyHelper.mmsEnabled ) {
310
// if the account is not a phone one, we can also send the message
311
if (messages.account.type != AccountEntry.PhoneAccount) {
315
// we need to check if there will be an overload for sending the message
316
var accounts = telepathyHelper.accountOverload(messages.account)
317
for (var i in accounts) {
318
var account = accounts[i]
319
if (account.active) {
324
// now we are here with a phone account that doesn't support MMS
325
// we check if MMS is required or not
326
// for now it is only required in two cases: attachments and MMS groups
327
// so if chatType is not Room and the attachment list is empty, we can send
328
if (messages.chatType != ChatEntry.ChatTypeRoom && attachments.length == 0) {
332
// last but not least, show a warning to the user saying he needs to enable MMS to send the message
334
props["title"] = i18n.tr("MMS support required")
335
props["text"] = i18n.tr("MMS support is required to send this message.\nPlease enable it in Settings->Enable MMS messages")
336
PopupUtils.open(Qt.createComponent("Dialogs/InformationDialog.qml").createObject(messages), messages, props)
340
306
function sendMessage(text, participantIds, attachments, properties) {
341
307
if (typeof(properties) === 'undefined') {
345
// check if at least one account is selected
346
if (!messages.account) {
347
Qt.inputMethod.hide()
348
// workaround for bug #1461861
349
messages.focus = false
352
if (telepathyHelper.flightMode) {
353
properties["title"] = i18n.tr("You have to disable flight mode")
354
properties["text"] = i18n.tr("It is not possible to send messages in flight mode")
355
} else if (multiplePhoneAccounts) {
356
properties["title"] = i18n.tr("No SIM card selected")
357
properties["text"] = i18n.tr("You need to select a SIM card")
358
} else if (telepathyHelper.phoneAccounts.all.length > 0 && telepathyHelper.phoneAccounts.active.length == 0) {
359
properties["title"] = i18n.tr("No SIM card")
360
properties["text"] = i18n.tr("Please insert a SIM card and try again.")
362
properties["text"] = i18n.tr("It is not possible to send the message")
363
properties["title"] = i18n.tr("Failed to send the message")
365
PopupUtils.open(Qt.createComponent("Dialogs/InformationDialog.qml").createObject(messages), messages, properties)
369
if (!sendMessageSanityCheck(text, participantIds, attachments, properties)) {
373
311
if (messages.threads.length > 0) {
374
312
properties["chatType"] = messages.chatType
375
313
properties["threadId"] = messages.threadId
405
343
// if the last outgoing message used a different accountId, add an
406
344
// information event and quit the loop
345
var thread = eventModel.threadForProperties(messages.account.accountId,
346
HistoryEventModel.EventTypeText,
348
messages.account.usePhoneNumbers ? HistoryEventModel.MatchPhoneNumber : HistoryEventModel.MatchCaseSensitive,
350
if (!checkThreadInFilters(thread.accountId, thread.threadId)) {
351
addNewThreadToFilter(thread.accountId, thread)
354
messages.threadId = thread.threadId
407
355
eventModel.writeTextInformationEvent(messages.account.accountId,
408
356
messages.threadId,
409
357
newParticipantsIds,
422
370
// and insert it into the history service
424
372
// FIXME: we need to review this case. In case of account overload, this will be saved in the wrong thread
425
// also, we probably need to create the thread here
375
var thread = eventModel.threadForProperties(messages.account.accountId,
376
HistoryEventModel.EventTypeText,
378
messages.account.usePhoneNumbers ? HistoryEventModel.MatchPhoneNumber : HistoryEventModel.MatchCaseSensitive,
380
if (!checkThreadInFilters(thread.accountId, thread.threadId)) {
381
addNewThreadToFilter(thread.accountId, thread)
383
messages.threadId = thread.threadId
427
386
var timestamp = new Date()
428
387
var tmpEventId = timestamp.toISOString()
918
877
processPendingEvents()
922
id: mmsBroadcastChecker
924
property var props: null
926
function isMMSBroadcast(text, participantIds, attachments, properties) {
927
var account = messages.account
928
// if we don't have the account or if it is not a phone one, it is
929
// not an MMS broadcast
930
if (!account || account.type != AccountEntry.PhoneAccount) {
934
// if chatType is Room, this is not a broadcast
935
if (chatType == ChatEntry.ChatTypeRoom) {
939
// if there is only one participant, it is also not a broadcast
940
if (participantIds.length == 1) {
944
// if there is no attachments, that's not going via MMS
945
if (attachments.length == 0) {
949
// if there is an active account overload, assume it is going to be used
950
// and thus this won't be an MMS broadcast
951
var accounts = telepathyHelper.accountOverload(account).length
952
for (var i in accounts) {
953
if (accounts[i].active) {
958
// if none of the cases above match, this is an MMS broadcast
962
function checkForBroadcastAndSend(text, participantIds, attachments, properties) {
963
props = {"text" : text,
964
"participantIds" : participantIds,
965
"attachments" : attachments,
966
"properties" : properties
969
if (isMMSBroadcast(text, participantIds, attachments, properties)) {
970
var popup = PopupUtils.open(Qt.resolvedUrl("MMSBroadcastDialog.qml"), mmsBroadcastChecker, {})
971
popup.accepted.connect(onPopupAccepted)
975
// if this is not an MMS broadcast, just send the message
976
messages.sendMessage(text, participantIds, attachments, properties)
981
function onPopupAccepted() {
982
if (messages.sendMessage(props["text"],
983
props["participantIds"],
984
props["attachments"],
985
props["properties"])) {
992
880
// These fake items are used to track if there are instances loaded
993
881
// on the second column because we have no access to the page stack
1536
1423
if (item.contentType.toLowerCase() === "application/smil") {
1539
if (startsWith(item.contentType.toLowerCase(),"video/")) {
1540
videoSize += FileOperations.size(item.filePath)
1542
1426
attachment.push(item.name)
1543
1427
attachment.push(item.contentType)
1544
1428
attachment.push(item.filePath)
1545
1429
newAttachments.push(attachment)
1547
if (videoSize > 307200 && !settings.messagesDontShowFileSizeWarning) {
1548
// FIXME we are guessing here if the handler will try to send it over an overloaded account
1549
// FIXME: this should be revisited when changing the MMS group implementation
1550
var isPhone = (account && account.type == AccountEntry.PhoneAccount)
1552
// check if an account overload might be used
1553
var accounts = telepathyHelper.accountOverload(account)
1554
for (var i in accounts) {
1555
var tmpAccount = accounts[i]
1556
if (tmpAccount.active) {
1563
PopupUtils.open(Qt.createComponent("Dialogs/FileSizeWarningDialog.qml").createObject(messages))
1567
1432
var recipients = participantIds.length > 0 ? participantIds :
1568
1433
multiRecipient.recipients
1571
1436
properties["x-canonical-tmp-files"] = true
1574
// if sendMessage succeeds it means the message was either sent or
1575
// injected into the history service so the user can retry later
1576
if (mmsBroadcastChecker.checkForBroadcastAndSend(text, recipients, newAttachments, properties)) {
1439
sendMessageValidator.validateMessageAndSend(text, recipients, newAttachments, properties)
1579
1441
if (eventModel.filter == null) {
1580
1442
reloadFilters = !reloadFilters
1447
SendMessageValidator {
1448
id: sendMessageValidator
1450
onMessageSent: composeBar.reset()
1585
1453
KeyboardRectangle {