示例#1
0
 def _1SetObjAndTime(self, obj, t=None):
     with Acquire(self.oLock):
         if t is None:
             t = time()
         self.time = t
     members0 = obj.contacts
     members = None
     if members0 and len(members0) > 0:
         members = [
             self.client.userClient._1GetObjByLineMid(x.mid, obj=x, time=t)
             for x in members0
         ]
     if members:
         with Acquire(self.oLock):
             self.members = [x.mid for x in members]
     self.gettingObj = False
示例#2
0
 def _2id(self, value):
     with Acquire(self.lock, self.rLock):
         self._3id = value
         r = None
         if self._1rId is not None:
             r = self.rObj
         if r and r != self:
             r.uId = value
示例#3
0
 def _1SetProfileAndTime(self, profile, t=None):
     with Acquire(self.lock, self._1profile.lock, self.oLock):
         if t is None:
             t = time()
         self._1profile.time = t
         self._1profile.name = profile.display_name
         self._1profile.statusMessage = profile.status_message
         self._1profile.picUrl = profile.picture_url
示例#4
0
 def _1SetObjAndTime(self, obj, t=None):
     start = time()
     with Acquire(self.oLock):
         if t is None:
             t = time()
         self.time = t
         self.name = obj.name
     creator0 = obj.creator
     creator = None
     if creator0:
         try:
             creator = self.client.userClient._1GetObjByLineMid(
                 creator0.mid, obj=creator0, time=t)
         except Exception:
             pass
     if creator:
         with Acquire(self.oLock):
             self.creator = creator
     members0 = obj.members
     members = None
     if members0 and len(members0) > 0:
         members = [
             self.client.userClient._1GetObjByLineMid(x.mid, obj=x, time=t)
             for x in members0
         ]
     invitees0 = obj.invitee
     invitees = None
     if invitees0 and len(invitees0) > 0:
         try:
             invitees = [
                 self.client.userClient._1GetObjByLineMid(x.mid,
                                                          obj=x,
                                                          time=t)
                 for x in invitees0
             ]
         except TypeError:
             pass
     if members or invitees:
         with Acquire(self.oLock):
             if members:
                 self.members = [x.mid for x in members]
             if invitees:
                 self.invitees = [x.mid for x in invitees]
     self.gettingObj = False
示例#5
0
 def hasOA(self, value):
     if self._2hasOA != value:
         with Acquire(self.lock, self.client.lock):
             if self._2hasOA != value:
                 self._2hasOA = value
                 if self.id is not None and self.mid is not None and self.client.db is not None:
                     with self.client.GetCursor() as cur:
                         cur.Execute(
                             "UPDATE ChatRooms SET hasOA=%s WHERE lineId=%s OR lineMid=%s",
                             (self._2hasOA, self.id, self.mid))
                         cur.Commit()
             if self._1hasOA != value:
                 self._1hasOA = value
示例#6
0
 def _1SetRId(self, value):
     with Acquire(self.rLock, self.client.lock):
         if value != self._1rId:
             self._1rId = value
             #print("SET RID TO " + str(self._1rId))
             if self.mid:
                 with self.client.GetCursor() as cur:
                     #print("UPDATING USERS")
                     cur.Execute(
                         "UPDATE Users SET rId=%s WHERE id=%s OR lineMid=%s",
                         (value, self._2id, self.mid))
                     #print("UPDATED USERS ROWCOUNT " + str(cur.rowCount))
                     cur.Commit()
示例#7
0
 def _1SetObjAndTime(self, obj, t=None):
     with Acquire(self.lock, self._1profile.lock, self.oLock):
         if t is None:
             t = time()
         self._1profile.time = t
         self._1profile.name = obj.displayName
         self._1profile.statusMessage = obj.statusMessage
         self._1profile.capableBuddy = obj.capableBuddy
         self._1profile.relation = obj.relation
         self._1profile.status = obj.status
         self._1profile.type = obj.type
         self._1profile.picUrl = "http://dl.profile.line.naver.jp" + obj.picturePath
         self._1profile.time = t
     self.gettingObj = False
示例#8
0
 def _1SetUId(self, value):
     with Acquire(self.uLock, self.client.lock):
         if self._1uId != value:
             self._1uId = value
             with self.client.GetCursor() as cur:
                 if self.mid:
                     cur.Execute(
                         "UPDATE ChatRooms SET uId=%s WHERE id=%s OR lineMid=%s",
                         (value, self._2id, self.mid))
                 else:
                     cur.Execute(
                         "UPDATE ChatRooms SET uId=%s WHERE id=%s OR lineId=%s",
                         (value, self._2id, self.id))
                 cur.Commit()
示例#9
0
 def _2id(self, value):
     with Acquire(self.lock, self.uLock):
         self._3id = value
         u = self.uObj
         if u is not None and u._1uId is None:
             u.uId = value
示例#10
0
 def _2id(self):
     with Acquire(self.lock, self.uLock):
         return self._3id
示例#11
0
 def name(self, value):
     with Acquire(self.oLock, self._1profile.lock):
         self._1profile.name = value
示例#12
0
 def profile(self, value):
     with Acquire(self.lock, self.oLock):
         self._1profile = value
示例#13
0
    def Sync(self, obj2=None):
        if obj2 is None:
            obja = None
            if self.client.hasOA and (not IsEmpty(
                    self.id)) and self.id in self.client._1objectsByLineId:
                obja = self.client._1objectsByLineId[self.id]
            objb = None
            if self.client.hasUser and (not IsEmpty(
                    self.mid)) and self.mid in self.client._1objectsByLineMid:
                objb = self.client._1objectsByLineMid[self.mid]
            if obja is self:
                obj2 = objb
            else:
                obj2 = obja
        if obj2 is self:
            return self
        if obj2 is not None:
            with Acquire(self.lock, obj2.lock, self.oLock, obj2.oLock,
                         self.rLock, obj2.rLock):
                if self.chatroomType != obj2.chatroomType:
                    raise Exception(
                        "[Sync] self and obj2 is not of the same type")
                if not IsEmpty(self.id):
                    obj2.id = self.id
                elif not IsEmpty(obj2.id):
                    self.id = obj2.id
                if not IsEmpty(self.mid):
                    obj2.mid = self.mid
                elif not IsEmpty(obj2.mid):
                    self.mid = obj2.mid
                try:
                    with Acquire(self.client.lock):
                        self.client.users.remove(obj2)
                except Exception:
                    pass
                with Acquire(self.rLock, obj2.rLock):
                    r = None
                    if self.rId:
                        r = obj2.rObj
                        obj2.rId = self.rId
                    elif obj2.rId:
                        r = self.rObj
                        self.rId = obj2.rId
                    if r and r.chatroomType != ChatroomType.user:
                        r.uId = self._2id
                if self.rId:
                    with Acquire(self.client.lock):
                        self.client._1objectsByUId[self._2id] = self
                with Acquire(self.oLock, obj2.oLock):
                    if self.time < obj2.time:
                        self.profile = obj2.profile
                    else:
                        obj2.profile = self.profile

        #print("Syncing mid=%s" % self.mid)
        with Acquire(self.client.lock):
            self.client._1objectsUserByMsgId = {
                k: v
                for k, v in self.client._1senderObjectsUserByMsgId.items()
                if v is not obj2 and v is not self
            }
            self.client._1objectsOAByMsgId = {
                k: v
                for k, v in self.client._1senderObjectsOAByMsgId.items()
                if v is not obj2 and v is not self
            }
            self.client._1objectsByLineId[self.id] = self
            self.client._1objectsByLineMid[self.mid] = self
            if self.key and self.key in self.client._1waitingRoom:
                del self.client._1waitingRoom[self.key]
            if obj2.key and obj2.key in self.client._1waitingRoom:
                del self.client._1waitingRoom[obj2.key]
            obj2.key = None
            self.key = None
            #print("Syncing mid=%s to DB" % self.mid)
            if self.client.db is not None and not IsEmpty(
                    self.id) and not IsEmpty(self.mid):
                with self.client.GetCursor() as cur:
                    #print("Syncing mid=%s to DB 2" % self.mid)
                    cur.Execute(
                        "SELECT id, lineId, lineMid FROM Users WHERE lineId=%s OR lineMid=%s ORDER BY lineMid DESC",
                        (self.id, self.mid))
                    fs = cur.FetchAll()
                    lenfs = len(fs)
                    id = None
                    if lenfs == 0:
                        #print("Syncing mid=%s to DB lenfs == 0:" % self.mid)
                        cur.Execute(
                            "INSERT INTO Users(lineId, lineMid) Values(%s,%s) RETURNING id",
                            (
                                self.id,
                                self.mid,
                            ))
                        id = cur.FetchOne()[0]
                        cur.Commit()
                    elif lenfs > 2:
                        #print("Syncing mid=%s to DB lenfs > 2" % self.mid)
                        raise Exception("LENFS > 2 HOW DID THIS EVEN HAPPEN")
                    else:
                        if lenfs == 2:
                            #print("Syncing mid=%s to DB lenfs == 2" % self.mid)
                            cur.Execute("DELETE FROM Users WHERE id=%s",
                                        (fs[1][0], ))
                            cur.Commit()
                        f = fs[0]
                        id = f[0]
                        if IsEmpty(f[2]):
                            #print("Syncing mid=%s to DB IsEmpty(f[2])" % self.mid)
                            cur.Execute(
                                "UPDATE Users SET lineMid=%s WHERE id=%s",
                                (self.mid, id))
                            cur.Commit()
                        elif IsEmpty(f[1]):
                            #print("Syncing mid=%s to DB IsEmpty(f[1])" % self.mid)
                            cur.Execute(
                                "UPDATE Users SET lineId=%s WHERE id=%s",
                                (self.id, id))
                            cur.Commit()

                    self._2id = id
                    cur.Execute(
                        "DELETE FROM SenderLineIdByMsgId WHERE lineId=%s",
                        (self.id, ))
                    cur.Commit()
                    cur.Execute(
                        "DELETE FROM SenderLineMidByMsgId WHERE lineMid=%s",
                        (self.mid, ))
                    cur.Commit()
示例#14
0
 def AskGetObj(self):
     with Acquire(self.lock, self.oLock):
         if not self._1gettingObj:
             self._1gettingObj = True
             return True
         return False
示例#15
0
 def uId(self, value):
     with Acquire(self.uLock):
         if value != self._1uId:
             self._1SetUId(value)
示例#16
0
 def rId(self, value):
     with Acquire(self.rLock):
         if value != self._1rId:
             self._1SetRId(value)
示例#17
0
 def rId(self):
     with Acquire(self.rLock):
         return self._1rId
示例#18
0
 def _1hasOA(self, value):
     if self._2hasOA != value:
         with Acquire(self.lock):
             self._2hasOA = value
示例#19
0
 def time(self, value):
     with Acquire(self.lock):
         self._1time = value
示例#20
0
 def uObj(self):
     with Acquire(self.uLock):
         if self._1uId:
             return self.client.GetObjByRId(self._1uId)
示例#21
0
 def uId(self):
     with Acquire(self.uLock):
         return self._1uId
示例#22
0
 def time(self):
     with Acquire(self.lock):
         return self._1time
示例#23
0
 def AskShouldGetObj(self):
     with Acquire(self.lock, self.oLock):
         if self.shouldGetObj:
             self._1gettingObj = True
             return True
         return False
示例#24
0
 def name(self, value):
     with Acquire(self.lock):
         self._1name = value
示例#25
0
 def members(self, value):
     with Acquire(self.oLock):
         self.time = time()
         self._1members = value
示例#26
0
 def hasUser(self, value):
     if self._2hasUser != value:
         with Acquire(self.lock):
             self._1hasUser = value
             self._2hasUser = value
示例#27
0
    def Sync(self, obj2=None):
        if obj2 is None:
            obja = None
            if self.client.hasOA and (not IsEmpty(
                    self.id)) and self.id in self.client._1objectsByLineId:
                obja = self.client._1objectsByLineId[self.id]
            objb = None
            if self.client.hasUser and (not IsEmpty(
                    self.mid)) and self.mid in self.client._1objectsByLineMid:
                objb = self.client._1objectsByLineMid[self.mid]
            if obja is self:
                obj2 = objb
            else:
                obj2 = obja
        if obj2 is self:
            return self
        if obj2 is not None:
            if self.chatroomType != obj2.chatroomType or not isinstance(
                    obj2, Room):
                raise Exception(
                    "[Sync] self and obj2 is not of the same type. id='%s', mid='%s'"
                    % (self.id or obj2.id, self.mid or obj2.mid))
            with Acquire(self.lock, obj2.lock, self.oLock, obj2.oLock,
                         self.uLock, obj2.uLock):
                if not IsEmpty(self.id):
                    obj2.id = self.id
                elif not IsEmpty(obj2.id):
                    self.id = obj2.id
                if not IsEmpty(self.mid):
                    obj2.mid = self.mid
                elif not IsEmpty(obj2.mid):
                    self.mid = obj2.mid
                hasOA = self._2hasOA or obj2._2hasOA
                self.hasOA = hasOA
                obj2.hasOA = hasOA
                self._1hasOA = hasOA
                obj2._1hasOA = hasOA
                self._2hasOA = hasOA
                obj2._2hasOA = hasOA
                hasUser = self._2hasUser or obj2._2hasUser
                self.hasUser = hasUser
                obj2.hasUser = hasUser
                self._1hasUser = hasUser
                obj2._1hasUser = hasUser
                self._2hasUser = hasUser
                obj2._2hasUser = hasUser
                if self.chatroomType == ChatroomType.room:
                    try:
                        with Acquire(self.client.lock):
                            self.client.rooms.remove(obj2)
                    except Exception:
                        pass
                else:
                    try:
                        with Acquire(self.client.lock):
                            self.client.groups.remove(obj2)
                    except Exception:
                        pass
                with Acquire(self.uLock, obj2.uLock):
                    if self.uId:
                        obj2.uId = self.uId
                        u = obj2.uObj
                        if u:
                            u.rObj = self
                    elif obj2.uId:
                        self.uId = obj2.uId
                        u = self.uObj
                        if u:
                            u.rObj = obj2
                if self.uId:
                    with Acquire(self.client.lock):
                        self.client._1objectsByRId[self._2id] = self
                with Acquire(self.oLock, obj2.oLock):
                    if self.time < obj2.time:
                        self.time = obj2.time
                        self._1members = obj2._1members
                        if self.chatroomType == ChatroomType.group:
                            self._1invitees = obj2._1invitees
                            self._1name = obj2._1name
                    else:
                        obj2.time = self.time
                        obj2._1members = self._1members
                        if obj2.chatroomType == ChatroomType.group:
                            obj2._1invitees = self._1invitees
                            obj2._1name = self._1name

        #print("Syncing mid=%s" % self.mid)
        with Acquire(self.client.lock):
            self.client._1objectsUserByMsgId = {
                k: v
                for k, v in self.client._1objectsUserByMsgId.items()
                if v is not obj2 and v is not self
            }
            self.client._1objectsOAByMsgId = {
                k: v
                for k, v in self.client._1objectsOAByMsgId.items()
                if v is not obj2 and v is not self
            }
            self.client._1objectsByLineId[self.id] = self
            self.client._1objectsByLineMid[self.mid] = self
            if self.key and self.key in self.client._1waitingRoom:
                del self.client._1waitingRoom[self.key]
            if obj2:
                if obj2.key and obj2.key in self.client._1waitingRoom:
                    del self.client._1waitingRoom[obj2.key]
                obj2.key = None
            self.key = None
            #print("Syncing mid=%s to DB" % self.mid)
            if self.client.db is not None and not IsEmpty(
                    self.id) and not IsEmpty(self.mid):
                with self.client.GetCursor() as cur:
                    #print("Syncing mid=%s to DB 2" % self.mid)
                    cur.Execute(
                        "SELECT id, lineId, lineMid FROM ChatRooms WHERE lineId=%s OR lineMid=%s ORDER BY hasOA",
                        (self.id, self.mid))
                    fs = cur.FetchAll()
                    lenfs = len(fs)
                    id = None
                    if lenfs == 0:
                        #print("Syncing mid=%s to DB lenfs == 0:" % self.mid)
                        cur.Execute(
                            "INSERT INTO ChatRooms(lineId, lineMid, type, hasOA, hasUser) Values(%s,%s,%s,%s,%s) RETURNING id",
                            (
                                self.id,
                                self.mid,
                                self.chatroomType,
                                self._2hasOA,
                                self._2hasUser,
                            ))
                        id = cur.FetchOne()[0]
                        cur.Commit()
                    elif lenfs > 2:
                        #print("Syncing mid=%s to DB lenfs > 2" % self.mid)
                        raise Exception("LENFS > 2 HOW DID THIS EVEN HAPPEN")
                    else:
                        if lenfs == 2:
                            #print("Syncing mid=%s to DB lenfs == 2" % self.mid)
                            cur.Execute("DELETE FROM Chatrooms WHERE id=%s",
                                        (fs[1][0], ))
                            cur.Commit()
                        f = fs[0]
                        id = f[0]
                        if IsEmpty(f[2]):
                            #print("Syncing mid=%s to DB IsEmpty(f[2])" % self.mid)
                            cur.Execute(
                                "UPDATE ChatRooms SET lineMid=%s, type=%s, hasOA=%s, hasUser=%s WHERE id=%s",
                                (self.mid, self.chatroomType, self._2hasOA,
                                 self._2hasUser, id))
                            cur.Commit()
                        elif IsEmpty(f[1]):
                            #print("Syncing mid=%s to DB IsEmpty(f[1])" % self.mid)
                            cur.Execute(
                                "UPDATE ChatRooms SET lineId=%s, type=%s, hasOA=%s, hasUser=%s WHERE id=%s",
                                (self.id, self.chatroomType, self._2hasOA,
                                 self._2hasUser, id))
                            cur.Commit()
                        else:
                            #print("Syncing mid=%s to DB f[1] and f[2] exists" % self.mid)
                            cur.Execute(
                                "UPDATE ChatRooms SET type=%s, hasOA=%s, hasUser=%s WHERE id=%s",
                                (self.chatroomType, self._2hasOA,
                                 self._2hasUser, id))
                            cur.Commit()

                    self._2id = id
                    cur.Execute("DELETE FROM LineIdByMsgId WHERE lineId=%s",
                                (self.id, ))
                    cur.Commit()
                    cur.Execute("DELETE FROM LineMidByMsgId WHERE lineMid=%s",
                                (self.mid, ))
                    cur.Commit()
示例#28
0
 def blocked(self):
     if self.time:
         return self._1profile.blocked
     with Acquire(self.oLock, self._1profile.lock):
         return self._1profile.blocked
示例#29
0
 def Leave(self):
     with Acquire(self.lock, self.room.lock):
         if self not in self.room.leavings:
             self.room.leavings.append(self)
         self.SendText(
             "You'll leave the next round. Type '/242 join' to cancel.")
示例#30
0
 def isOA(self):
     if self.time:
         return self._1profile.isOA
     with Acquire(self.oLock, self._1profile.lock):
         return self._1profile.isOA