Skip to content

Commit 18cdd2d

Browse files
author
SamSchott
authored
Merge pull request #59 from SamSchott/develop
develop
2 parents f3a1cae + cc80dfb commit 18cdd2d

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

maestral/sync/monitor.py

+19-22
Original file line numberDiff line numberDiff line change
@@ -1459,22 +1459,19 @@ def notify_user(self, changes):
14591459
return
14601460

14611461
# find out who changed the file(s), get the name if its only a single user
1462-
1463-
user_name = None
1464-
1465-
if all(getattr(x, "sharing_info", None) for x in changes.entries):
1466-
# all files are in shared folder, see if the user IDs are the same
1467-
dbid0 = changes.entries[0].sharing_info.modified_by
1468-
if all(x.sharing_info.modified_by == dbid0 for x in changes.entries):
1462+
try:
1463+
dbid_list = [md.sharing_info.modified_by for md in changes.entries]
1464+
if all(dbid == dbid_list[0] for dbid in dbid_list):
14691465
# all files have been modified by the same user
1470-
if dbid0 == CONF.get("account", "account_id"):
1466+
if dbid_list[0] == CONF.get("account", "account_id"):
14711467
user_name = "You"
14721468
else:
1473-
account_info = self.client.get_account_info(dbid0)
1469+
account_info = self.client.get_account_info(dbid_list[0])
14741470
user_name = account_info.name.display_name
1475-
elif not any(getattr(x, "sharing_info", None) for x in changes.entries):
1476-
# all files were changed by current user
1477-
user_name = "You"
1471+
else:
1472+
user_name = None
1473+
except AttributeError:
1474+
user_name = None
14781475

14791476
# notify user
14801477
if n_changed == 1:
@@ -1484,25 +1481,25 @@ def notify_user(self, changes):
14841481

14851482
if isinstance(md, DeletedMetadata):
14861483
# file has been deleted from remote
1487-
self.notify.send("{0} removed {1}".format(user_name, file_name))
1484+
change_type = "removed"
14881485
elif isinstance(md, FileMetadata):
14891486
if self.get_local_rev(md.path_lower):
14901487
is_new_file = False
14911488
else:
14921489
revs = self.client.list_revisions(md.path_lower, limit=2)
14931490
is_new_file = len(revs.entries) == 1
1494-
if is_new_file:
1495-
# file has been added to remote
1496-
self.notify.send("{0} added {1}".format(user_name, file_name))
1497-
else:
1498-
# file has been modified on remote
1499-
self.notify.send("{0} changed {1}".format(user_name, file_name))
1491+
change_type = "added" if is_new_file else "changed"
1492+
15001493
elif isinstance(md, FolderMetadata):
1501-
self.notify.send("{0} added {1}".format(user_name, file_name))
1494+
change_type = "added"
1495+
1496+
if user_name:
1497+
self.notify.send("{0} {1} {2}".format(user_name, change_type, file_name))
1498+
else:
1499+
self.notify.send("{0} {1}".format(file_name, change_type))
15021500

15031501
elif n_changed > 1:
1504-
# for multiple changes, display user name if all equal and type
1505-
# of change of "deleted"
1502+
# for multiple changes, display user name if all equal
15061503
if all(isinstance(x, DeletedMetadata) for x in changes.entries):
15071504
change_type = "removed"
15081505
else:

0 commit comments

Comments
 (0)