Skip to content

Commit

Permalink
make User.sent_dms per-protocol by changing its type to Target
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Aug 14, 2024
1 parent eb9b28f commit eedc77f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
)
OBJECT_EXPIRE_AGE = timedelta(days=90)

# Types of DMs that we send
# Types of DMs that we send. Used in User.sent_dms
DMS = (
'follow_request_from_bridged_user',
'replied_to_bridged_user',
Expand Down Expand Up @@ -197,8 +197,10 @@ 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)
# DMs that we've attempted to send to this user. Target.protocol is the
# protocol we sent the DM about (and the bot account it came from),
# Target.uri is the type of DM.
sent_dms = ndb.StructuredProperty(Target, repeated=True, choices=DMS)

created = ndb.DateTimeProperty(auto_now_add=True)
updated = ndb.DateTimeProperty(auto_now=True)
Expand Down Expand Up @@ -505,7 +507,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')
add(user.sent_dms, Target(protocol=to_proto.LABEL, uri='welcome'))
user.put()
nonlocal added
added = True
Expand Down
5 changes: 3 additions & 2 deletions tests/test_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +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([Target(protocol='atproto', uri='welcome')], user.sent_dms)

self.assertEqual(1, len(user.copies))
self.assertEqual('atproto', user.copies[0].protocol)
Expand Down Expand Up @@ -505,7 +505,8 @@ 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)
self.assertEqual([Target(protocol='activitypub', uri='welcome')],
user.sent_dms)

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

0 comments on commit eedc77f

Please sign in to comment.