示例#1
0
 def create(cls, follower, followee):
     from server.models.message import Message
     existing = Follow.read(follower, followee)
     if existing:
         return existing
     newFollow = Follow(
         follower=follower.id,
         followee=followee.id,
     )
     newFollow.id = Follow.makeId(follower.id, followee.id)
     newFollow.store(core.connect())
     json = {
         "fromId": "shiftspace",
         "toId": followee.id,
         "title":
         "%s has started following your shifts!" % (follower.userName),
         "text":
         "%s has started following your shifts!" % (follower.userName),
         "meta": "follow",
         "content": {
             "followerId": follower.id
         }
     }
     Message.create(**json)
     return newFollow
示例#2
0
 def shareWith(self, userIds, fromUser=None):
     from server.models.message import Message
     from server.models.ssuser import SSUser
     users = core.fetch(keys=userIds)
     if fromUser:
         userName = fromUser.userName
     else:
         userName = SSUser.read(self.createdBy).userName
     for user in users:
         json = {
             "fromId":
             self.createdBy,
             "toId":
             user["_id"],
             "title":
             "%s has shared a shift with you!" % userName,
             "text":
             "%s has shared a shift titled '%s' with you!" %
             (userName, self.summary),
             "meta":
             "share",
             "content": {
                 "type": "shift",
                 "_id": self.id,
                 "href": self.href,
                 "summary": self.summary
             }
         }
         Message.create(**json)
示例#3
0
 def create(cls, userId, shiftId, text, subscribe=False):
     from server.models.ssuser import SSUser
     from server.models.shift import Shift
     from server.models.message import Message
     # first try the public feed
     theShift = Shift.load(core.connect("shiftspace/shared"), shiftId)
     shiftAuthor = SSUser.load(core.connect(), theShift.createdBy)
     theUser = SSUser.load(core.connect(), userId)
     server = core.server()
     # create the comment db if necessary
     dbexists = True
     if not theShift.hasThread():
         server.create(Comment.db(shiftId))
         dbexists = False
     # get the db
     db = core.connect(Comment.db(shiftId))
     # if db just created, sync the views and subscribe shift author
     if not dbexists:
         Comment.by_created.sync(db)
         Comment.all_subscribed.sync(db)
         shiftAuthor.subscribe(theShift)
     # subscribe the user making the comment
     if not theUser.isSubscribed(theShift) and subscribe:
         theUser.subscribe(theShift)
     # create comment and comment stub
     json = {
         "createdBy": userId,
         "shiftId": shiftId,
         "shiftAuthor": theShift.createdBy,
         "text": text,
         }
     newComment = Comment(**utils.clean(json))
     newComment.store(db)
     subscribers = theShift.subscribers()
     # make a private copy
     # TODO: need to think about the implications of a private copy here - David
     newComment.copyTo(SSUser.privateDb(theUser.id))
     # send each subscriber a message
     if len(subscribers) > 0:
         # TODO: needs to be optimized with a fast join - David
         for subscriber in subscribers:
             if subscriber != userId:
                 astr = ((subscriber == theShift.createdBy) and "your") or ("%s's" % shiftAuthor.userName)
                 json = {
                     "fromId": userId,
                     "toId": subscriber,
                     "title": "%s just commented on %s shift!" % (theUser.userName, astr),
                     "text": "%s just commented on %s shift!" % (theUser.userName, astr),
                     "meta": "comment"
                     }
                 Message.create(**utils.clean(json))
     # TODO: don't replicate if peer - David 11/21/09
     core.replicate(Comment.db(shiftId), "shiftspace/shared")
     return newComment
示例#4
0
 def create(cls, userId, shiftId, text, subscribe=False):
     from server.models.ssuser import SSUser
     from server.models.shift import Shift
     from server.models.message import Message
     # first try the public feed
     theShift = Shift.load(core.connect("shiftspace/shared"), shiftId)
     shiftAuthor = SSUser.load(core.connect(), theShift.createdBy)
     theUser = SSUser.load(core.connect(), userId)
     server = core.sharedServer()
     # create the comment db if necessary
     dbexists = True
     if not theShift.hasThread():
         server.create(Comment.db(shiftId))
         dbexists = False
     # get the db
     db = core.connect(Comment.db(shiftId))
     # if db just created, sync the views and subscribe shift author
     if not dbexists:
         Comment.by_created.sync(db)
         Comment.all_subscribed.sync(db)
         shiftAuthor.subscribe(theShift)
     # subscribe the user making the comment
     if not theUser.isSubscribed(theShift) and subscribe:
         theUser.subscribe(theShift)
     # create comment and comment stub
     json = {
         "createdBy": userId,
         "shiftId": shiftId,
         "shiftAuthor": theShift.createdBy,
         "text": text,
         }
     newComment = Comment(**utils.clean(json))
     newComment.store(db)
     subscribers = theShift.subscribers()
     # make a private copy
     # TODO: need to think about the implications of a private copy here - David
     newComment.copyTo(SSUser.privateDb(theUser.id))
     # send each subscriber a message
     if len(subscribers) > 0:
         # TODO: needs to be optimized with a fast join - David
         for subscriber in subscribers:
             if subscriber != userId:
                 astr = ((subscriber == theShift.createdBy) and "your") or ("%s's" % shiftAuthor.userName)
                 json = {
                     "fromId": userId,
                     "toId": subscriber,
                     "title": "%s just commented on %s shift!" % (theUser.userName, astr),
                     "text": "%s just commented on %s shift!" % (theUser.userName, astr),
                     "meta": "comment"
                     }
                 Message.create(**utils.clean(json))
     # TODO: don't replicate if peer - David 11/21/09
     core.replicate(Comment.db(shiftId), "shiftspace/shared")
     return newComment
示例#5
0
    def inviteUser(self, aUser, otherUser):
        from server.models.permission import Permission
        from server.models.message import Message

        Permission.create(aUser.id, self.id, otherUser.id, 0)
        json = {
            "fromId": aUser.id,
            "toId": otherUser.id,
            "title": "%s invited you to join the group %s!" % (aUser.userName, self.longName),
            "text": "%s invited you to join the group %s!" % (aUser.userName, self.longName),
            "meta": "invite",
            "content": {"type": "group", "_id": self.id},
        }
        Message.create(**json)
示例#6
0
 def inviteUser(self, aUser, otherUser):
     from server.models.permission import Permission
     from server.models.message import Message
     Permission.create(aUser.id, self.id, otherUser.id, 0)
     json = {
         "fromId": aUser.id,
         "toId": otherUser.id,
         "title": "%s invited you to join the group %s!" % (aUser.userName, self.longName),
         "text": "%s invited you to join the group %s!" % (aUser.userName, self.longName),
         "meta": "invite",
         "content": {
             "type": "group",
             "_id": self.id
             }
         }
     Message.create(**json)
示例#7
0
 def shareWith(self, userIds, fromUser=None):
     from server.models.message import Message
     from server.models.ssuser import SSUser
     users = core.fetch(keys=userIds)
     if fromUser:
         userName = fromUser.userName
     else:
         userName = SSUser.read(self.createdBy).userName
     for user in users:
         json = {
             "fromId": self.createdBy,
             "toId": user["_id"],
             "title": "%s has shared a shift with you!" % userName,
             "text": "%s has shared a shift titled '%s' with you!" % (userName, self.summary),
             "meta": "share",
             "content": {
                 "type": "shift",
                 "_id": self.id,
                 "href": self.href,
                 "summary": self.summary
                 }
         }
         Message.create(**json)
示例#8
0
 def create(cls, follower, followee):
     from server.models.message import Message
     existing = Follow.read(follower, followee)
     if existing:
         return existing
     newFollow = Follow(
         follower = follower.id,
         followee = followee.id,
         )
     newFollow.id = Follow.makeId(follower.id, followee.id)
     newFollow.store(core.connect())
     json = {
         "fromId": "shiftspace",
         "toId": followee.id,
         "title": "%s has started following your shifts!" % (follower.userName),
         "text": "%s has started following your shifts!" % (follower.userName),
         "meta": "follow",
         "content": {
             "followerId": follower.id
             }
         }
     Message.create(**json)
     return newFollow