Skip to content

Commit

Permalink
feat: Features Tips Channel @NagramTips
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Feb 11, 2024
1 parent 1a45e06 commit c4fdd8d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5363,8 +5363,10 @@ void setOpenProgress(float progress) {

if (new Random().nextInt(100) < 50)
PrivacyUtil.postCheckAll(getParentActivity(), currentAccount);
else if (new Random().nextInt(100) < 20)
else if (new Random().nextInt(100) < 20) {
UpdateUtil.postCheckFollowChannel(getParentActivity(), currentAccount);
UpdateUtil.postCheckFollowTipsChannel(getParentActivity(), currentAccount);
}

updateStoriesVisibility(false);
return fragmentView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
import tw.nekomimi.nekogram.utils.GsonUtil;
import tw.nekomimi.nekogram.utils.ShareUtil;

import static tw.nekomimi.nekogram.utils.UpdateUtil.channelUsernameTips;

@SuppressLint("RtlHardcoded")
public class NekoSettingsActivity extends BaseFragment {

Expand All @@ -85,6 +87,7 @@ public class NekoSettingsActivity extends BaseFragment {

private int aboutRow;
private int channelRow;
private int channelTipsRow;
// private int fdroidRow;
// private int googlePlayRow;
private int sourceCodeRow;
Expand Down Expand Up @@ -185,6 +188,8 @@ public void startDocumentSelectActivity() {
presentFragment(new NekoExperimentalSettingsActivity());
} else if (position == channelRow) {
MessagesController.getInstance(currentAccount).openByUserName("nagram_channel", this, 1);
} else if (position == channelTipsRow) {
MessagesController.getInstance(currentAccount).openByUserName(channelUsernameTips, this, 1);
} else if (position == translationRow) {
Browser.openUrl(getParentActivity(), "https://hosted.weblate.org/engage/nekox/");
// } else if (position == fdroidRow) {
Expand Down Expand Up @@ -400,6 +405,7 @@ private void updateRows() {

aboutRow = rowCount++;
channelRow = rowCount++;
channelTipsRow = rowCount++;
// fdroidRow = rowCount++;
/*if (ExternalGcm.checkPlayServices()) {
googlePlayRow = rowCount++;
Expand Down Expand Up @@ -504,6 +510,8 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
// textCell.setText(LocaleController.getString("AppLinkFDroid", R.string.AppLinkFDroid), true);
// } else if (position == googlePlayRow) {
// textCell.setText(LocaleController.getString("GooglePlay", R.string.GooglePlay), true);
} else if (position == channelTipsRow) {
textCell.setTextAndValue(LocaleController.getString("TipsChannel", R.string.TipsChannel), "@" + channelUsernameTips, true);
} else if (position == sourceCodeRow) {
textCell.setText(LocaleController.getString("SourceCode", R.string.SourceCode), true);
} else if (position == translationRow) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.telegram.ui.ActionBar.AlertDialog
object UpdateUtil {

const val channelUsername = "nagram_channel"
const val channelUsernameTips = "NagramTips"

@JvmStatic
fun postCheckFollowChannel(ctx: Context, currentAccount: Int) = UIUtil.runOnIoDispatcher {
Expand Down Expand Up @@ -77,4 +78,64 @@ object UpdateUtil {

}

@JvmStatic
fun postCheckFollowTipsChannel(ctx: Context, currentAccount: Int) = UIUtil.runOnIoDispatcher {

if (MessagesController.getMainSettings(currentAccount).getBoolean("update_channel_tip_skip", false)) return@runOnIoDispatcher

val messagesCollector = MessagesController.getInstance(currentAccount)
val connectionsManager = ConnectionsManager.getInstance(currentAccount)
val messagesStorage = MessagesStorage.getInstance(currentAccount)
val updateChannel = messagesCollector.getUserOrChat(channelUsernameTips)

if (updateChannel is TLRPC.Chat) checkFollowTipsChannel(ctx, currentAccount, updateChannel) else {
connectionsManager.sendRequest(TLRPC.TL_contacts_resolveUsername().apply {
username = channelUsernameTips
}) { response: TLObject?, error: TLRPC.TL_error? ->
if (error == null) {
val res = response as TLRPC.TL_contacts_resolvedPeer
val chat = res.chats.find { it.username == channelUsernameTips } ?: return@sendRequest
messagesCollector.putChats(res.chats, false)
messagesStorage.putUsersAndChats(res.users, res.chats, false, true)
checkFollowTipsChannel(ctx, currentAccount, chat)
}
}
}

}

private fun checkFollowTipsChannel(ctx: Context, currentAccount: Int, channel: TLRPC.Chat) {
if (!channel.left || channel.kicked) {
return
}

UIUtil.runOnUIThread {

val messagesCollector = MessagesController.getInstance(currentAccount)
val userConfig = UserConfig.getInstance(currentAccount)

val builder = AlertDialog.Builder(ctx)

builder.setTitle(LocaleController.getString("FCTitle", R.string.FCTitle))
builder.setMessage(LocaleController.getString("TipsInfo", R.string.TipsInfo))

builder.setPositiveButton(LocaleController.getString("ChannelJoin", R.string.ChannelJoin)) { _, _ ->
messagesCollector.addUserToChat(channel.id, userConfig.currentUser, 0, null, null, null)
Browser.openUrl(ctx, "https://t.me/$channelUsernameTips")
}

builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null)

builder.setNeutralButton(LocaleController.getString("DoNotRemindAgain", R.string.DoNotRemindAgain)) { _, _ ->
MessagesController.getMainSettings(currentAccount).edit().putBoolean("update_channel_tip_skip", true).apply()
}

try {
builder.show()
} catch (ignored: Exception) {}

}

}

}
2 changes: 2 additions & 0 deletions TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,7 @@
<string name="DisableMarkdown">禁用 Markdown</string>
<string name="SendWithMarkdown">启用 Markdown</string>
<string name="DisableClickProfileGalleryView">禁用点按切换头像</string>
<string name="TipsInfo">要关注我们的功能介绍频道吗 ?</string>
<string name="TipsChannel">功能介绍频道</string>
<string name="ShowSmallGIF">GIF 显示得更小</string>
</resources>
2 changes: 2 additions & 0 deletions TMessagesProj/src/main/res/values/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,7 @@
<string name="DisableMarkdown">Disable Markdown</string>
<string name="SendWithMarkdown">Send with markdown</string>
<string name="DisableClickProfileGalleryView">Disable flip avatars by tapping</string>
<string name="TipsInfo">Want to follow our features tips channel?</string>
<string name="TipsChannel">Features Tips Channel</string>
<string name="ShowSmallGIF">Show Small Gif</string>
</resources>

0 comments on commit c4fdd8d

Please sign in to comment.