Skip to content

Commit

Permalink
add User.sent_dms to track the DMs we've sent to a user
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Aug 14, 2024
1 parent 405bd06 commit eb9b28f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
)
OBJECT_EXPIRE_AGE = timedelta(days=90)

# Types of DMs that we send
DMS = (
'follow_request_from_bridged_user',
'replied_to_bridged_user',
'welcome',
)

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -190,6 +197,9 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
# reset_protocol_properties.
enabled_protocols = ndb.StringProperty(repeated=True, choices=list(PROTOCOLS.keys()))

# DMs that we've attempted to send to this user
sent_dms = ndb.StringProperty(repeated=True, choices=DMS)

created = ndb.DateTimeProperty(auto_now_add=True)
updated = ndb.DateTimeProperty(auto_now=True)

Expand Down Expand Up @@ -495,6 +505,7 @@ def enable():
user = self.key.get()
if to_proto.LABEL not in user.enabled_protocols:
user.enabled_protocols.append(to_proto.LABEL)
add(user.sent_dms, 'welcome')
user.put()
nonlocal added
added = True
Expand Down
2 changes: 2 additions & 0 deletions tests/test_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ def test_activitypub_follow_bsky_bot_user_enables_protocol(self, mock_get, mock_
# check results
user = ActivityPub.get_by_id('https://inst/alice')
self.assertTrue(user.is_enabled(ATProto))
self.assertEqual(['welcome'], user.sent_dms)

self.assertEqual(1, len(user.copies))
self.assertEqual('atproto', user.copies[0].protocol)
Expand Down Expand Up @@ -504,6 +505,7 @@ def test_atproto_follow_ap_bot_user_enables_protocol(self, mock_get, mock_post):

user = ATProto.get_by_id('did:plc:alice')
self.assertTrue(user.is_enabled(ActivityPub))
self.assertEqual(['welcome'], user.sent_dms)

headers = {
'Content-Type': 'application/json',
Expand Down

0 comments on commit eb9b28f

Please sign in to comment.