コード例 #1
0
    def unbanUser(self, userId):
        userData = users.getShortUserById(userId)
        first_name = userData.get('first_name')
        last_name = userData.get('last_name')
        if userId < 0:
            first_name = userData.get('name')
        userName = ""
        if not isinstance(first_name, str) and not isinstance(last_name, str):
            print('name not defined for userData: ' +
                  json.dumps(userData, indent=4))
            return False
        elif isinstance(first_name, str) and isinstance(last_name, str):
            userName = first_name + ' ' + last_name
        elif isinstance(first_name, str):
            userName = first_name
        else:
            userName = last_name

        locString = self.guiDelegate.localize_(
            args=['are_you_sure_for_unblock_username'
                  ], withResult=True) + userName + self.guiDelegate.localize_(
                      args=['are_you_sure_for_unblock_username_tile'],
                      withResult=True)
        dialogsManager = PyDialogsManager()
        index, cancelled = dialogsManager.showYesNoDialogWithMessage(
            locString, "unban_user_button", "cancel")
        if cancelled == True:
            return False
        return self.doUnbanUser(userId)
コード例 #2
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
    def optionsTappedWithPostIdownerIdisNewsViewController(
            self, postId, ownerId, isNewsViewController):
        try:
            dialogsManager = PyDialogsManager()
            items = ['copy_url']
            #if ownerId != vk.userId():
            items.append('report')
            # если новостная лента, скрываем новости источника (опционально)
            if isNewsViewController == True:
                items.append('it_is_not_interesting')
                items.append('hide_source_news')

            index, cancelled = dialogsManager.showRowsDialogWithTitles(items)
            if cancelled:
                return
            if items[index] == 'copy_url':
                self.guiDelegate.copyUrl_(
                    args=['https://vk.com/id' + str(ownerId)])
            elif items[index] == 'report':
                self.report('post', ownerId, postId)
            elif items[index] == 'it_is_not_interesting':
                self.guiDelegate.hideOptionsNode()
                self.ignoreItem('post', ownerId, postId)
            elif items[index] == 'hide_source_news':
                self.guiDelegate.hideOptionsNode()
                self.hideSource(ownerId)
        except Exception as e:
            print('optionsTappedWithPostIdownerId exception: ' + str(e))
コード例 #3
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
 def sendCommentWithTypeownerIdpostIdtext(self, type, ownerId, postId,
                                          text):
     analytics.log('Posts_send_comment')
     response = {}
     try:
         if type == 'wall':
             response = self.wallPostService.sendComment(
                 ownerId, postId, text, 0)
         elif type == 'photo':
             response = self.detailPhotoService.sendComment(
                 ownerId, postId, text, 0)
         elif type == 'video':
             response = self.detailVideoService.sendComment(
                 ownerId, postId, text, 0)
     except Exception as e:
         print(
             'preloadCommentsWithTypeownerIdpostIdcountloaded exception: ' +
             str(e))
     commentId = 0
     if isinstance(response, int):
         response = {'comment_id': response}
     try:
         commentId = response['comment_id']
     except:
         pass
     if commentId == 0:
         dialogsManager = PyDialogsManager()
         dialogsManager.showDialogWithMessage('error_send_comment')
     else:
         try:
             response['user_info'] = users.getShortUserById(vk.userId())
         except:
             pass
     return response
コード例 #4
0
 def exitTapped(self):
     dialogsManager = PyDialogsManager()
     index, cancelled = dialogsManager.showRowsDialogWithTitles(['settings_exit'])
     if index == 0 and not cancelled:
         analytics.log('Settings_do_exit')
         settings.set('access_token', '')
         settings.set('user_id', 0)
         vk.setToken('')
         vk.setUserId(0)
         settings.write()
         managers.shared().screensManager().showAuthorizationViewController()
コード例 #5
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
 def optionsTappedWithVideoIdownerId(self, videoId, ownerId):
     try:
         dialogsManager = PyDialogsManager()
         items = []
         items.append('report')
         index, cancelled = dialogsManager.showRowsDialogWithTitles(items)
         if cancelled:
             return
         self.report('video', ownerId, videoId)
     except Exception as e:
         print('optionsTappedWithVideoIdownerId exception: ' + str(e))
コード例 #6
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
    def report(self, type, ownerId, itemId):
        response = False
        results = 0
        dialogsManager = PyDialogsManager()
        try:
            api = vk.api()
            if type == 'post':
                results = api.wall.reportPost(owner_id=ownerId, post_id=itemId)
            elif type == 'user':
                items = ['p**n', 'spam', 'insult', 'advertisment']
                index, cancelled = dialogsManager.showRowsDialogWithTitles(
                    items)
                if cancelled:
                    return
                type = items[index]
                message, cancelled = dialogsManager.showTextFieldDialogWithText(
                    'enter_report_message')
                if cancelled:
                    return
                results = api.users.report(user_id=ownerId,
                                           type=type,
                                           comment=message)
            elif type == 'photo':
                results = api.photos.report(owner_id=ownerId, photo_id=itemId)
            elif type == 'video':
                message, cancelled = dialogsManager.showTextFieldDialogWithText(
                    'enter_report_message')
                if cancelled:
                    return
                results = api.video.report(owner_id=ownerId,
                                           video_id=itemId,
                                           comment=message)
            elif type == 'post_comment':
                results = api.wall.reportComment(owner_id=ownerId,
                                                 comment_id=itemId)
            elif type == 'photo_comment':
                results = api.photos.reportComment(owner_id=ownerId,
                                                   comment_id=itemId)
            elif type == 'video_comment':
                results = api.video.reportComment(owner_id=ownerId,
                                                  comment_id=itemId)
            else:
                raise ValueError('unsupported type of item for report')
            if isinstance(results, int) and results == 1:
                response = True

        except Exception as e:
            print('posts report exception: ' + str(e))

        if response == False:
            print('report send failed with results: ' + str(results))
            dialogsManager.showDialogWithMessage('error_reporting')
        else:
            dialogsManager.showDialogWithMessage('report_sended_successfully')
            print('report sended successfully for type: ' + str(type))
        pass
コード例 #7
0
 def createPost(self, text):
     results = self.createPostService.createPost(self.ownerId, text)
     postId = 0
     try:
         postId = results['post_id']
     except:
         pass
     if postId == 0:
         dialogsManager = PyDialogsManager()
         dialogsManager.showDialogWithMessage('error_create_post')
     else:
         managers.shared().screensManager(
         ).dismissCreatePostViewController_(args=[True])
     return postId
コード例 #8
0
    def doUnbanUser(self, userId):
        result = 0
        try:
            api = vk.api()
            result = api.account.unban(owner_id=userId)
        except Exception as e:
            print('unbanUser exception: ' + str(e))

        if not isinstance(result, int) or result != 1:
            message = 'error_unban_user' if userId > 0 else 'error_unban_group'
            dialogsManager = PyDialogsManager()
            dialogsManager.showDialogWithMessage(message)
            return False
        return True
コード例 #9
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
 def repostObjectWithIdentifier(self, identifier):
     analytics.log('Posts_repost')
     dialogsManager = PyDialogsManager()
     index, cancelled = dialogsManager.showRowsDialogWithTitles(
         ['repost_for_friends'])
     if cancelled:
         return {}
     if index == 0:
         text, cancelled = dialogsManager.showTextFieldDialogWithText(
             'repost_enter_message')
         if cancelled:
             return {}
         return self.doRepostForFriends(identifier, text)
     return {}
コード例 #10
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
    def hideSource(self, userId):
        results = 0
        try:
            api = vk.api()
            if userId > 0:
                results = api.newsfeed.addBan(user_ids=userId)
            elif userId < 0:
                results = api.newsfeed.addBan(group_ids=abs(userId))
            else:
                raise ValueError('userId on hideSource is 0')
        except Exception as e:
            print('hideSource exception: ' + str(e))

        if not isinstance(results, int) or results != 1:
            dialogsManager = PyDialogsManager()
            dialogsManager.showDialogWithMessage('error_ignore_item')
コード例 #11
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
 def tappedOnCommentWithOwnerIdcommentIdtypeparentItemOwnerId(
         self, ownerId, commentId, type, parentItemOwnerId):
     try:
         items = []
         dialogsManager = PyDialogsManager()
         items.append('report')
         if parentItemOwnerId == vk.userId():
             items.append('comment_delete')
         index, cancelled = dialogsManager.showRowsDialogWithTitles(items)
         if cancelled:
             return
         if index == 0:
             self.report(type, ownerId, commentId)
         elif index == 1:
             self.deleteComment(type, ownerId, commentId, parentItemOwnerId)
     except Exception as e:
         print('tappedOnCommentWithOwnerIdcommentId exception: ' + str(e))
コード例 #12
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
 def optionsTappedWithUserId(self, userId):
     try:
         dialogsManager = PyDialogsManager()
         items = []
         if userId > 0:
             items.append('report')
         items.append('block_user')
         index, cancelled = dialogsManager.showRowsDialogWithTitles(items)
         if cancelled:
             return
         if index == 0 and userId > 0:
             self.report('user', userId, 0)
         else:
             userData = users.getShortUserById(userId)
             first_name = userData.get('first_name')
             last_name = userData.get('last_name')
             if userId < 0:
                 first_name = userData.get('name')
             userName = ""
             if not isinstance(first_name, str) and not isinstance(
                     last_name, str):
                 print('name not defined for userData: ' +
                       json.dumps(userData, indent=4))
                 return
             elif isinstance(first_name, str) and isinstance(
                     last_name, str):
                 userName = first_name + ' ' + last_name
             elif isinstance(first_name, str):
                 userName = first_name
             else:
                 userName = last_name
             locString = self.guiDelegate.localize_(
                 args=['are_you_sure_for_block_username'
                       ], withResult=True) + userName + '?'
             index, cancelled = dialogsManager.showYesNoDialogWithMessage(
                 locString, "ban_user_button", "cancel")
             if cancelled == True:
                 return
             self.blockUser(userId)
     except Exception as e:
         print('optionsTappedWithUserId exception: ' + str(e))
         print(traceback.format_exc())
コード例 #13
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
    def blockUser(self, userId):
        result = 0
        try:
            api = vk.api()
            result = api.account.ban(owner_id=userId)
        except VkAPIError as e:
            if 'already blacklisted' in e.message:
                result = 2
        except Exception as e:
            print('blockUser exception: ' + str(e))
        message = ""
        if isinstance(result, int) and result == 2:
            message = 'already_blacklisted'
        elif not isinstance(result, int) or result != 1:
            message = 'error_ban_user' if userId > 0 else 'error_ban_group'
        else:
            message = 'user_successfully_banned' if userId > 0 else 'group_successfully_banned'

        dialogsManager = PyDialogsManager()
        dialogsManager.showDialogWithMessage(message)
コード例 #14
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
 def deleteComment(self, type, ownerId, commentId, parentItemOwnerId):
     results = 0
     try:
         api = vk.api()
         if type == 'post_comment':
             results = api.wall.deleteComment(owner_id=parentItemOwnerId,
                                              comment_id=commentId)
         elif type == 'photo_comment':
             results = api.photos.deleteComment(owner_id=parentItemOwnerId,
                                                comment_id=commentId)
         elif type == 'video_comment':
             results = api.video.deleteComment(owner_id=parentItemOwnerId,
                                               comment_id=commentId)
     except Exception as e:
         print('deleteComment exception: ' + str(e))
     if not isinstance(results, int) or results != 1:
         dialogsManager = PyDialogsManager()
         dialogsManager.showDialogWithMessage('error_delete_comment')
     else:
         self.guiDelegate.commentDeleted()
コード例 #15
0
ファイル: pypostsviewmodel.py プロジェクト: JasF/vk-ios-app
 def ignoreItem(self, aType, ownerId, itemId):
     results = 0
     if aType == 'post':
         type = 'wall'
     elif aType == 'photo':
         type = 'photo'
     elif aType == 'video':
         type = 'video'
     else:
         raise ValueError('unknown type for ignoreItem: ' + str(aType))
     try:
         api = vk.api()
         results = api.newsfeed.ignoreItem(type=type,
                                           owner_id=ownerId,
                                           item_id=itemId)
         print('ignoreItem result: ' + str(results) + '; ownerId: ' +
               str(ownerId) + '; itemId: ' + str(itemId))
     except Exception as e:
         print('ignoreItem exception: ' + str(e))
     if not isinstance(results, int) or results != 1:
         dialogsManager = PyDialogsManager()
         dialogsManager.showDialogWithMessage('error_ignore_item')
コード例 #16
0
ファイル: pywallviewmodel.py プロジェクト: JasF/vk-ios-app
 def friendButtonTapped(self, friend_status):
     analytics.log('Wall_friend_Button')
     response = {}
     try:
         api = vk.api()
         if self.userId < 0:
             # работа с группой
             return self.joinOrLeaveGroup(friend_status)
         elif friend_status == 1 or friend_status == 3:
             if friend_status == 3:
                 # Пользователь друг или есть входящая заявка
                 dialogsManager = PyDialogsManager()
                 index, cancelled = dialogsManager.showRowsDialogWithTitles(['delete_from_friends'])
                 if cancelled:
                     return -1
             response = api.friends.delete(user_id=self.userId)
             print('friends.delete response: ' + str(response))
             if response.get('success') == 1:
                 return 5 if friend_status == 3 else 0
             return -1
         response = api.friends.add(user_id=self.userId)
     except Exception as e:
         print('wallviewmodel.py friendButtonTapped exception: ' + str(e))
     return response