Skip to content

Commit

Permalink
add open HKEPC raw url option
Browse files Browse the repository at this point in the history
use native bottom sheet on favourites tab
  • Loading branch information
gaplo917 committed May 14, 2023
1 parent ba7c73d commit c1e2b1b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 29 deletions.
80 changes: 57 additions & 23 deletions src/es6/core/controller/LikesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import * as HKEPC from '../../data/config/hkepc'
import { FindMessageRequest } from '../model/requests'
import { searchMultipleKeyword } from '../../utils/search'
import * as Controllers from './PostDetailController'
import { Bridge, Channel } from '../bridge'

export class LikesController {
static get STATE() {
Expand All @@ -29,6 +31,7 @@ export class LikesController {

constructor($scope, AuthService, $state, ngToast, MessageService, $sanitize, $ionicActionSheet) {
this.scope = $scope
this.state = $state
this.ngToast = ngToast
this.pageSize = 5
this.sanitize = $sanitize
Expand Down Expand Up @@ -116,31 +119,62 @@ export class LikesController {
this.scope.$emit(FindMessageRequest.NAME, new FindMessageRequest(postId, messageId))
}

goToMessage(message) {
this.state.go(Controllers.PostDetailController.STATE, {
topicId: message.post.topicId,
postId: message.post.id,
page: message.post.page,
delayRender: 0,
focus: message.id,
})
}

onMore(message) {
// Show the action sheet
this.ionicActionSheet.show({
buttons: [{ text: '開啟' }, { text: '開啟 HKEPC 原始連結' }],
titleText: '分享連結',
destructiveText: '從我的最愛移除',
cancelText: '取消',
cancel: () => {
// add cancel code..
return true
},
buttonClicked: (index) => {
if (index === 0) {
window.location.href = `/tab/topics/${message.post.topicId}/posts/${message.post.id}/page/${message.post.page}`
} else {
window.open(HKEPC.forum.findMessage(message.post.id, message.id))
if (Bridge.isAvailable()) {
Bridge.callHandler(
Channel.actionSheet,
{
buttons: ['前往帖子', '開啟 HKEPC 原始連結', `從我的最愛移除`],
titleText: '更多功能',
cancelText: '取消',
},
(index) => {
if (index === 0) {
this.goToMessage(message)
} else if (index === 1) {
window.open(HKEPC.forum.findMessage(message.post.id, message.id), '_system', 'location=yes')
} else if (index === 2) {
this.messageService.remove(message)
this.messages = this.messages.filter((m) => m.id !== message.id)
}
}
return true
},
destructiveButtonClicked: (index) => {
this.messageService.remove(message)
this.messages = this.messages.filter((m) => m.id !== message.id)
return true
},
})
)
} else {
// Show the action sheet
this.ionicActionSheet.show({
buttons: [{ text: '開啟' }, { text: '開啟 HKEPC 原始連結' }],
titleText: '分享連結',
destructiveText: '從我的最愛移除',
cancelText: '取消',
cancel: () => {
// add cancel code..
return true
},
buttonClicked: (index) => {
if (index === 0) {
this.goToMessage(message)
} else {
window.open(HKEPC.forum.findMessage(message.post.id, message.id), '_system', 'location=yes')
}
return true
},
destructiveButtonClicked: (index) => {
this.messageService.remove(message)
this.messages = this.messages.filter((m) => m.id !== message.id)
return true
},
})
}
}

loadLazyImage(uid, imageSrc) {
Expand Down
13 changes: 8 additions & 5 deletions src/es6/core/controller/PostDetailController.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ export class PostDetailController extends IRLifecycleOwner {
{
buttons: [
'分享到 ...',
'開啟 HKEPC 原始連結',
`${this.reversePostOrder ? '關閉' : '開啟'}倒轉看帖`,
`${this.filterOnlyAuthorId ? '關閉' : '開啟'}只看 ${message.author.name} 的帖`,
'關注此主題的新回覆',
Expand All @@ -594,33 +595,35 @@ export class PostDetailController extends IRLifecycleOwner {
url: HKEPC.forum.findMessage(message.post.id, message.id),
})
} else if (index === 1) {
window.open(HKEPC.forum.findMessage(message.post.id, message.id), '_system', 'location=yes')
} else if (index === 2) {
this.reversePostOrder = !this.reversePostOrder
if (this.reversePostOrder) this.ngToast.success('<i class="ion-ios-checkmark"> 已開啟倒轉看帖功能!</i>')
else ngToast.success('<i class="ion-ios-checkmark"> 已關閉倒轉看帖功能!</i>')

this.doRefresh()
} else if (index === 2) {
} else if (index === 3) {
this.filterOnlyAuthorId = this.filterOnlyAuthorId === undefined ? message.author.uid : undefined
if (this.filterOnlyAuthorId !== undefined)
ngToast.success(`<i class="ion-ios-checkmark"> 只看 ${message.author.name} 的帖!</i>`)
else ngToast.success(`<i class="ion-ios-checkmark"> 已關閉只看 ${message.author.name} 的帖!</i>`)

this.doRefresh()
} else if (index === 3) {
} else if (index === 4) {
apiService
.subscribeNewReply(this.postId)
.safeApply(scope, () => {
ngToast.success('<i class="ion-ios-checkmark"> 成功關注此主題,你將能夠接收到新回覆的通知!</i>')
})
.subscribe()
} else if (index === 4) {
} else if (index === 5) {
apiService
.addFavPost(this.postId)
.safeApply(scope, () => {
ngToast.success('<i class="ion-ios-checkmark"> 成功收藏此主題!</i>')
})
.subscribe()
} else if (index === 5) {
} else if (index === 6) {
// this feature is made for apple review team, sosad
this.state.go(Controllers.CMUsersController.STATE, {
prefill: JSON.stringify({
Expand All @@ -631,7 +634,7 @@ export class PostDetailController extends IRLifecycleOwner {
message.isMatchedFilter = true
message.filterMode = '1'
message.filterReason = '(已隱藏|原因:帖子內容問題)'
} else if (index === 6) {
} else if (index === 7) {
this.onReport(message)
}
}
Expand Down
2 changes: 1 addition & 1 deletion www/templates/tab-likes.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<div class="item item-avatar">
<img ng-src="{{::message.author.image}}" />
<button class="button button-icon ion-ios-arrow-down fright" ng-click="vm.onMore(message)"></button>
<button class="button button-icon ion-android-more-vertical on-more-button fright" ng-click="vm.onMore(message)"></button>

<h2 ng-bind="::message.author.name"></h2>
<p>{{::message.createdAt}}</p>
Expand Down

0 comments on commit c1e2b1b

Please sign in to comment.