forked from TelegramMessenger/Telegram-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply referral code #24
Open
bkg866
wants to merge
10
commits into
development
Choose a base branch
from
apply_referral_code
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,315
−155
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b8ff7c8
subscribe ongoing
2d42381
subscribe feature
ada0bfe
updated icons into media players
173b739
applied refaral code
faa8955
apply referral code
ba1f960
applied referral code feature
9fef51c
added reward screen new UI and it's functionality
cf5bb49
Update WEVApplyReferalControllerNode.swift
57e4442
apply new UI tint color
9318626
updated it to prod environment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
submodules/ContactListUI/Sources/Model/WEVSubscribeActivity.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// WEVSubscribeActivity.swift | ||
// _idx_ContactListUI_AE77A1D0_ios_min13.0 | ||
// | ||
// Created by Apple on 11/11/22. | ||
// | ||
|
||
import Foundation | ||
// This file was generated from JSON Schema using quicktype, do not modify it directly. | ||
// To parse the JSON, add this file to your project and do: | ||
// | ||
// let projectRegionCrews = try? newJSONDecoder().decode(ProjectRegionCrews.self, from: jsonData) | ||
|
||
import Foundation | ||
|
||
// MARK: - ProjectRegionCrews | ||
struct WEVSubscribeActivity: Codable { | ||
let kind, etag: String | ||
let items: [Item] | ||
let nextPageToken: String | ||
let pageInfo: PageInfo | ||
} | ||
|
||
// MARK: - Item | ||
struct Item: Codable { | ||
let kind, etag, id: String | ||
let snippet: Snippet | ||
let contentDetails: ContentDetails | ||
} | ||
|
||
// MARK: - ContentDetails | ||
struct ContentDetails: Codable { | ||
let upload: Upload | ||
} | ||
|
||
// MARK: - Upload | ||
struct Upload: Codable { | ||
let videoID: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case videoID = "videoId" | ||
} | ||
} | ||
|
||
// MARK: - Snippet | ||
struct Snippet: Codable { | ||
let publishedAt: Date | ||
let channelID, title, snippetDescription: String | ||
let thumbnails: Thumbnails | ||
let type: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case publishedAt | ||
case channelID = "channelId" | ||
case title | ||
case snippetDescription = "description" | ||
case thumbnails, type | ||
} | ||
} | ||
|
||
// MARK: - Thumbnails | ||
struct Thumbnails: Codable { | ||
let thumbnailsDefault, medium, high: Default | ||
let standard: Default? | ||
let maxres: Default? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case thumbnailsDefault = "default" | ||
case medium, high, standard, maxres | ||
} | ||
} | ||
|
||
// MARK: - Default | ||
struct Default: Codable { | ||
let url: String | ||
let width, height: Int | ||
} | ||
|
||
// MARK: - PageInfo | ||
struct PageInfo: Codable { | ||
let totalResults, resultsPerPage: Int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// WEVChannel.swift | ||
// _idx_ContactListUI_1D7887AF_ios_min13.0 | ||
// | ||
// Created by Apple on 15/09/22. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
// MARK: - Crew | ||
struct WevUser: Codable { | ||
let userId: Int64 | ||
let firstname: String? | ||
let lastname: String? | ||
let username: String? | ||
let phone: String? | ||
let referralcode: String? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case userId = "user_id" | ||
case firstname = "first_name" | ||
case lastname = "last_name" | ||
case username = "username" | ||
case phone = "phone" | ||
case referralcode = "referral_code" | ||
} | ||
} | ||
/** | ||
* Generate a random referral code | ||
*/ | ||
class referalCode { | ||
static let digits = [ | ||
"0", | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5", | ||
"6", | ||
"7", | ||
"8", | ||
"9" | ||
]; | ||
|
||
static let letters = [ | ||
"A", | ||
"B", | ||
"C", | ||
"D", | ||
"E", | ||
"F", | ||
"G", | ||
"H", | ||
"I", | ||
"J", | ||
"K", | ||
"L", | ||
"M", | ||
"N", | ||
"O", | ||
"P", | ||
"Q", | ||
"R", | ||
"S", | ||
"T", | ||
"U", | ||
"V", | ||
"W", | ||
"X", | ||
"Y", | ||
"Z", | ||
]; | ||
|
||
static func generateRefferalCode() -> String { | ||
var code = "" | ||
for _ in 0..<4 { | ||
code += letters.randomElement() ?? "" | ||
} | ||
for _ in 0..<1 { | ||
code += digits.randomElement() ?? "" | ||
} | ||
return code | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,8 +61,8 @@ public class WEVDiscoverRootNode: ASDisplayNode { | |
var arrWatchLater: [WatchLaterVideo] = [] | ||
var arrSubscribedVideos: [SubscribedVideo] = [] | ||
|
||
private let supabaseUrl = LJConfig.SupabaseKeys.supabaseUrl | ||
private let supabaseKey = LJConfig.SupabaseKeys.supabaseKey | ||
private let supabaseUrl = LJConfig.SupabaseKeys.supabaseUrlDev | ||
private let supabaseKey = LJConfig.SupabaseKeys.supabaseKeyDev | ||
|
||
/// 根据状态返回该显示的视频 | ||
private var showDataArray: [WEVVideoModel] { | ||
|
@@ -205,7 +205,7 @@ public class WEVDiscoverRootNode: ASDisplayNode { | |
view.presentationData = self.presentationData | ||
view.filterAction = {[weak self] in | ||
guard let self = self else {return} | ||
let vc = WEVDiscoverFilterViewController(allChannel: WEVChannel.allCases, selectedArray: self.selectedChannelArray) | ||
/*let vc = WEVDiscoverFilterViewController(allChannel: WEVChannel.allCases, selectedArray: self.selectedChannelArray) | ||
vc.selectedArray = self.selectedChannelArray | ||
vc.didSelected = {[weak self] channelArray in | ||
guard let self = self else {return} | ||
|
@@ -225,8 +225,23 @@ public class WEVDiscoverRootNode: ASDisplayNode { | |
//fetch filter data | ||
self.selectedChannelArray = channelArray | ||
self.scrollViewLoadData(isHeadRefesh: true) | ||
}*/ | ||
let push: (ViewController) -> Void = { [weak self] c in | ||
guard let strongSelf = self, let navigationController = strongSelf.controller?.navigationController as? NavigationController else { | ||
return | ||
} | ||
var updatedControllers = navigationController.viewControllers | ||
for controller in navigationController.viewControllers.reversed() { | ||
if controller !== strongSelf && !(controller is TabBarController) { | ||
updatedControllers.removeLast() | ||
} else { | ||
break | ||
} | ||
} | ||
updatedControllers.append(c) | ||
navigationController.setViewControllers(updatedControllers, animated: true) | ||
} | ||
self.controller.present(vc, animated: true, completion: nil) | ||
push(WEVSubscribeController(context: self.context)) | ||
} | ||
|
||
view.cancelAction = {[weak self] in | ||
|
@@ -558,7 +573,20 @@ public class WEVDiscoverRootNode: ASDisplayNode { | |
}) | ||
|
||
self.backgroundColor = presentationData.theme.chatList.backgroundColor | ||
|
||
} | ||
|
||
private func getUserPeer(engine: TelegramEngine, peerId: EnginePeer.Id) -> Signal<EnginePeer?, NoError> { | ||
return engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) | ||
|> mapToSignal { peer -> Signal<EnginePeer?, NoError> in | ||
guard let peer = peer else { | ||
return .single(nil) | ||
} | ||
if case let .secretChat(secretChat) = peer { | ||
return engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: secretChat.regularPeerId)) | ||
} else { | ||
return .single(peer) | ||
} | ||
} | ||
} | ||
|
||
func twitchRealTimeSync() { | ||
|
@@ -1566,6 +1594,59 @@ extension WEVDiscoverRootNode: UICollectionViewDataSource { | |
} | ||
} | ||
} | ||
extension WEVDiscoverRootNode { | ||
|
||
func fetchTelegramUserInfo() { | ||
let _ = (getUserPeer(engine: self.context.engine, peerId: self.context.account.peerId) | ||
|> deliverOnMainQueue).start(next: { [weak self] peer in | ||
guard let strongSelf = self else { | ||
return | ||
} | ||
|
||
if case let .user(peer) = peer { | ||
print(peer.lastName ?? "") | ||
strongSelf.doSaveUserData(peer: peer) | ||
} | ||
}) | ||
} | ||
|
||
func doSaveUserData(peer: TelegramUser) { | ||
Task { | ||
await saveUserData(peer: peer) | ||
} | ||
} | ||
|
||
func saveUserData(peer: TelegramUser) async { | ||
//check client is not a nil | ||
guard let client = await self.controller.database else { | ||
return | ||
} | ||
do { | ||
|
||
let cuurentUser = try await client | ||
.from("user") | ||
.select() | ||
.eq(column: "user_id", value: "\(peer.id.id._internalGetInt64Value())") | ||
.execute() | ||
.decoded(to: [WevUser].self) | ||
|
||
//if referralcode is there use existing otherwise create a new code | ||
let refralCode = cuurentUser.first?.referralcode ?? referalCode.generateRefferalCode() | ||
|
||
let _ = try await client.from("user") | ||
.upsert( | ||
values: WevUser(userId: peer.id.id._internalGetInt64Value(), firstname: peer.firstName, lastname: peer.lastName, username: peer.username, phone: peer.phone, referralcode: refralCode), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bkg866 - this will be a problem unless we can lock down tables with RLS. |
||
onConflict: "user_id", | ||
returning: .representation, | ||
ignoreDuplicates: false | ||
) | ||
.execute() | ||
.json() | ||
} catch { | ||
print(error.localizedDescription) | ||
} | ||
} | ||
} | ||
extension WEVDiscoverRootNode { | ||
/// 搜索状态 | ||
enum SearchStatus { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just use client? here instead of guard let dance. should be currentUser