Skip to content

Commit

Permalink
Merge pull request #5355 from nyaruka/msg_is_android
Browse files Browse the repository at this point in the history
Add `Msg.is_android` field
  • Loading branch information
rowanseymour authored Jul 5, 2024
2 parents 97265c6 + fe8186d commit e3a39e7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion temba/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def get_country(self, obj):
return str(obj.country) if obj.country else None

def get_device(self, obj):
if not obj.is_android():
if not obj.is_android:
return None

return {
Expand Down
5 changes: 3 additions & 2 deletions temba/channels/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ def generate_secret(cls, length=64):
code = generate_secret(length)
return code

@property
def is_android(self) -> bool:
"""
Is this an Android channel
Expand Down Expand Up @@ -646,7 +647,7 @@ def release(self, user, *, trigger_sync: bool = True):
self.save(update_fields=("is_active", "config", "modified_by", "modified_on"))

# trigger the orphaned channel
if trigger_sync and self.is_android() and registration_id:
if trigger_sync and self.is_android and registration_id:
self.trigger_sync(registration_id)

# any triggers associated with our channel get archived and released
Expand Down Expand Up @@ -679,7 +680,7 @@ def trigger_sync(self, registration_id=None): # pragma: no cover
Sends a FCM command to trigger a sync on the client
"""

assert self.is_android(), "can only trigger syncs on Android channels"
assert self.is_android, "can only trigger syncs on Android channels"

from .tasks import sync_channel_fcm_task

Expand Down
2 changes: 1 addition & 1 deletion temba/channels/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def get_context_data(self, **kwargs):
context["msg_count"] = channel.get_msg_count()
context["ivr_count"] = channel.get_ivr_count()

if channel.is_android():
if channel.is_android:
context["latest_sync_events"] = channel.sync_events.order_by("-created_on")[:10]

if not channel.is_new():
Expand Down
10 changes: 10 additions & 0 deletions temba/msgs/migrations/0266_msg_is_android.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated by Django 5.0.6 on 2024-07-05 13:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [("msgs", "0265_broadcast_template_variables")]

operations = [migrations.AddField(model_name="msg", name="is_android", field=models.BooleanField(null=True))]
1 change: 1 addition & 0 deletions temba/msgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ class Msg(models.Model):
direction = models.CharField(max_length=1, choices=DIRECTION_CHOICES)
status = models.CharField(max_length=1, choices=STATUS_CHOICES, default=STATUS_PENDING, db_index=True)
visibility = models.CharField(max_length=1, choices=VISIBILITY_CHOICES, default=VISIBILITY_VISIBLE)
is_android = models.BooleanField(null=True)
labels = models.ManyToManyField("Label", related_name="msgs")

# the number of actual messages the channel sent this as (outgoing only)
Expand Down
1 change: 1 addition & 0 deletions temba/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def _create_msg(
status=status or (Msg.STATUS_PENDING if direction == Msg.DIRECTION_IN else Msg.STATUS_INITIALIZING),
msg_type=msg_type,
visibility=visibility,
is_android=channel and channel.is_android,
external_id=external_id,
high_priority=high_priority,
created_on=created_on or timezone.now(),
Expand Down

0 comments on commit e3a39e7

Please sign in to comment.