def message_flag(chat): flags = convert_base(chat.flags) if len(flags) >= 7 and flags[-7] == 1: return 'blocked' # Заблокировано до того момента, пока пользователь не вступит в чат elif len(flags) >= 8 and flags[-8] == 1: return 'repost' # Репост return ''
def system_message(message): flags = convert_base(message.flags) try: if flags[-9] == 1: return True except IndexError: return False
def save(self, force_insert=False, force_update=False): is_new = self.id is None super(ChatMessage, self).save(force_insert, force_update) message_id = self.id if is_new: flags = convert_base(self.flags) if len(flags ) > 4 and flags[-2] == 1: # Если отправленное в комнату if flags[-6] == 1: members = RoomMembers.objects.exclude( user_rel_id=self.user_id).filter(room_rel=self.room) peer_msg_id = message_id for member in members: id = self.id self.pk = None self.user = member.user_rel self.flags = self.flags - 2 # теперь сообщение считается входящим self.peer_msg_id = peer_msg_id if member.joined == False: self.flags = self.flags + 64 super(ChatMessage, self).save(force_insert, force_update) return message_id else: id = self.id self.pk = None self.user, self.peer = self.peer, self.user self.flags = self.flags - 2 # теперь сообщение считается входящим self.peer_msg_id = id super(ChatMessage, self).save(force_insert, force_update) return self.id else: return
def income_or_outgoing_id(chat): flags = convert_base(chat.flags) if len(flags) > 4 and flags[-6] == 1: if len(flags) > 1 and flags[-2] == 1: return chat.user.id return chat.peer_msg.user.id if len(flags) > 1 and flags[-2] == 1: return chat.user.id return chat.peer.id
def income_or_outgoing(chat): flags = convert_base(chat.flags) if len(flags) > 4 and flags[-6] == 1: if len(flags) > 1 and flags[-2] == 1: return fullname(chat.user) return fullname(chat.peer_msg.user) if len(flags) > 1 and flags[-2] == 1: return fullname(chat.user) return fullname(chat.peer)
def income_or_outgoing_image(chat): flags = convert_base(chat.flags) if len(flags) > 4 and flags[-6] == 1: if len(flags) > 1 and flags[-2] == 1: return chat.user.profileavatar.mini_url return chat.peer_msg.user.profileavatar.mini_url if len(flags) > 1 and flags[-2] == 1: return chat.user.profileavatar.mini_url return chat.peer.profileavatar.mini_url
def read_messages(request): dic = { 'status': 200, 'text': '', } ids = request.POST['ids'].split(" ") ids.pop(0) try: if ids: messages = ChatMessage.objects.filter(user=request.user, id__in=ids) for message in messages: message.flags = message.flags - 1 message.save() peer_msg = ChatMessage.objects.get(id=message.peer_msg_id) flags = helper.convert_base(peer_msg.flags) if flags[0] == 1: peer_msg.flags = peer_msg.flags - 1 peer_msg.save() except ChatMessage.DoesNotExist: dic['status'] == 403 dic['text'] == 'Ошибка' return
def unreaded(message): flags = convert_base(message.flags) if flags[len(flags) - 1] == 1: return "unreaded_message" return ""
def is_my(message): flags = convert_base(message.flags) if len(flags) > 1 and flags[-2] == 1: return "is_my" return ""