@@ -141,7 +141,6 @@ type Msg struct {
141
141
URN urns.URN `db:"urn_urn" json:"urn"`
142
142
URNAuth null.String `db:"urn_auth" json:"urn_auth,omitempty"`
143
143
OrgID OrgID `db:"org_id" json:"org_id"`
144
- TopupID TopupID `db:"topup_id" json:"-"`
145
144
FlowID FlowID `db:"flow_id" json:"-"`
146
145
147
146
// extra data from handling added to the courier payload
@@ -184,14 +183,11 @@ func (m *Msg) ChannelUUID() assets.ChannelUUID { return m.m.ChannelUUID }
184
183
func (m * Msg ) URN () urns.URN { return m .m .URN }
185
184
func (m * Msg ) URNAuth () null.String { return m .m .URNAuth }
186
185
func (m * Msg ) OrgID () OrgID { return m .m .OrgID }
187
- func (m * Msg ) TopupID () TopupID { return m .m .TopupID }
188
186
func (m * Msg ) FlowID () FlowID { return m .m .FlowID }
189
187
func (m * Msg ) ContactID () ContactID { return m .m .ContactID }
190
188
func (m * Msg ) ContactURNID () * URNID { return m .m .ContactURNID }
191
189
func (m * Msg ) IsResend () bool { return m .m .IsResend }
192
190
193
- func (m * Msg ) SetTopup (topupID TopupID ) { m .m .TopupID = topupID }
194
-
195
191
func (m * Msg ) SetChannel (channel * Channel ) {
196
192
m .channel = channel
197
193
if channel != nil {
@@ -255,7 +251,6 @@ func NewIncomingIVR(cfg *runtime.Config, orgID OrgID, call *Call, in *flows.MsgI
255
251
m .ChannelID = call .ChannelID ()
256
252
257
253
m .OrgID = orgID
258
- m .TopupID = NilTopupID
259
254
m .CreatedOn = createdOn
260
255
261
256
// add any attachments
@@ -288,7 +283,6 @@ func NewOutgoingIVR(cfg *runtime.Config, orgID OrgID, call *Call, out *flows.Msg
288
283
m .URN = out .URN ()
289
284
290
285
m .OrgID = orgID
291
- m .TopupID = NilTopupID
292
286
m .CreatedOn = createdOn
293
287
m .SentOn = & createdOn
294
288
@@ -354,7 +348,6 @@ func newOutgoingMsg(rt *runtime.Runtime, org *Org, channel *Channel, contact *fl
354
348
m .OrgID = org .ID ()
355
349
m .ContactID = ContactID (contact .ID ())
356
350
m .BroadcastID = broadcastID
357
- m .TopupID = NilTopupID
358
351
m .Text = out .Text ()
359
352
m .HighPriority = false
360
353
m .Direction = DirectionOut
@@ -451,7 +444,6 @@ func NewIncomingMsg(cfg *runtime.Config, orgID OrgID, channel *Channel, contactI
451
444
m .MsgType = MsgTypeFlow
452
445
m .ContactID = contactID
453
446
m .OrgID = orgID
454
- m .TopupID = NilTopupID
455
447
m .CreatedOn = createdOn
456
448
457
449
// add any attachments
@@ -483,8 +475,7 @@ SELECT
483
475
channel_id,
484
476
contact_id,
485
477
contact_urn_id,
486
- org_id,
487
- topup_id
478
+ org_id
488
479
FROM
489
480
msgs_msg
490
481
WHERE
@@ -521,7 +512,6 @@ SELECT
521
512
m.contact_id,
522
513
m.contact_urn_id,
523
514
m.org_id,
524
- m.topup_id,
525
515
u.identity AS "urn_urn",
526
516
u.auth AS "urn_auth"
527
517
FROM
@@ -626,18 +616,18 @@ const insertMsgSQL = `
626
616
INSERT INTO
627
617
msgs_msg(uuid, text, high_priority, created_on, modified_on, queued_on, sent_on, direction, status, attachments, metadata,
628
618
visibility, msg_type, msg_count, error_count, next_attempt, failed_reason, channel_id,
629
- contact_id, contact_urn_id, org_id, topup_id, flow_id, broadcast_id)
619
+ contact_id, contact_urn_id, org_id, flow_id, broadcast_id)
630
620
VALUES(:uuid, :text, :high_priority, :created_on, now(), now(), :sent_on, :direction, :status, :attachments, :metadata,
631
621
:visibility, :msg_type, :msg_count, :error_count, :next_attempt, :failed_reason, :channel_id,
632
- :contact_id, :contact_urn_id, :org_id, :topup_id, : flow_id, :broadcast_id)
622
+ :contact_id, :contact_urn_id, :org_id, :flow_id, :broadcast_id)
633
623
RETURNING
634
624
id as id,
635
625
now() as modified_on,
636
626
now() as queued_on
637
627
`
638
628
639
629
// UpdateMessage updates a message after handling
640
- func UpdateMessage (ctx context.Context , tx Queryer , msgID flows.MsgID , status MsgStatus , visibility MsgVisibility , msgType MsgType , flow FlowID , topup TopupID , attachments []utils.Attachment , logUUIDs []ChannelLogUUID ) error {
630
+ func UpdateMessage (ctx context.Context , tx Queryer , msgID flows.MsgID , status MsgStatus , visibility MsgVisibility , msgType MsgType , flow FlowID , attachments []utils.Attachment , logUUIDs []ChannelLogUUID ) error {
641
631
_ , err := tx .ExecContext (ctx ,
642
632
`UPDATE
643
633
msgs_msg
@@ -646,12 +636,11 @@ func UpdateMessage(ctx context.Context, tx Queryer, msgID flows.MsgID, status Ms
646
636
visibility = $3,
647
637
msg_type = $4,
648
638
flow_id = $5,
649
- topup_id = $6,
650
- attachments = $7,
651
- log_uuids = array_cat(log_uuids, $8)
639
+ attachments = $6,
640
+ log_uuids = array_cat(log_uuids, $7)
652
641
WHERE
653
642
id = $1` ,
654
- msgID , status , visibility , msgType , flow , topup , pq .Array (attachments ), pq .Array (logUUIDs ))
643
+ msgID , status , visibility , msgType , flow , pq .Array (attachments ), pq .Array (logUUIDs ))
655
644
656
645
if err != nil {
657
646
return errors .Wrapf (err , "error updating msg: %d" , msgID )
@@ -1121,19 +1110,6 @@ func (b *BroadcastBatch) CreateMessages(ctx context.Context, rt *runtime.Runtime
1121
1110
}
1122
1111
}
1123
1112
1124
- // allocate a topup for these message if org uses topups
1125
- topup , err := AllocateTopups (ctx , rt .DB , rt .RP , oa .Org (), len (msgs ))
1126
- if err != nil {
1127
- return nil , errors .Wrapf (err , "error allocating topup for broadcast messages" )
1128
- }
1129
-
1130
- // if we have an active topup, assign it to our messages
1131
- if topup != NilTopupID {
1132
- for _ , m := range msgs {
1133
- m .SetTopup (topup )
1134
- }
1135
- }
1136
-
1137
1113
// insert them in a single request
1138
1114
err = InsertMessages (ctx , rt .DB , msgs )
1139
1115
if err != nil {
@@ -1184,14 +1160,13 @@ func (b *BroadcastBatch) updateTicket(ctx context.Context, db Queryer, oa *OrgAs
1184
1160
const sqlUpdateMsgForResending = `
1185
1161
UPDATE msgs_msg m
1186
1162
SET channel_id = r.channel_id::int,
1187
- topup_id = r.topup_id::int,
1188
1163
status = 'P',
1189
1164
error_count = 0,
1190
1165
failed_reason = NULL,
1191
1166
queued_on = r.queued_on::timestamp with time zone,
1192
1167
sent_on = NULL,
1193
1168
modified_on = NOW()
1194
- FROM (VALUES(:id, :channel_id, :topup_id, : queued_on)) AS r(id, channel_id, topup_id , queued_on)
1169
+ FROM (VALUES(:id, :channel_id, :queued_on)) AS r(id, channel_id, queued_on)
1195
1170
WHERE m.id = r.id::bigint`
1196
1171
1197
1172
const sqlUpdateMsgResendFailed = `
@@ -1211,7 +1186,6 @@ func ResendMessages(ctx context.Context, db Queryer, rp *redis.Pool, oa *OrgAsse
1211
1186
1212
1187
for _ , msg := range msgs {
1213
1188
var ch * flows.Channel
1214
- var err error
1215
1189
urnID := msg .ContactURNID ()
1216
1190
1217
1191
if urnID != nil {
@@ -1243,11 +1217,6 @@ func ResendMessages(ctx context.Context, db Queryer, rp *redis.Pool, oa *OrgAsse
1243
1217
msg .m .FailedReason = ""
1244
1218
msg .m .IsResend = true // mark message as being a resend so it will be queued to courier as such
1245
1219
1246
- // allocate a new topup for this message if org uses topups
1247
- msg .m .TopupID , err = AllocateTopups (ctx , db , rp , oa .Org (), 1 )
1248
- if err != nil {
1249
- return nil , errors .Wrapf (err , "error allocating topup for message resending" )
1250
- }
1251
1220
resends = append (resends , msg .m )
1252
1221
resent = append (resent , msg )
1253
1222
} else {
0 commit comments