-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from rodit/auto-download-snaps
Add feature to auto-download snaps.
- Loading branch information
Showing
16 changed files
with
201 additions
and
103 deletions.
There are no files selected for viewing
Binary file not shown.
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
20 changes: 0 additions & 20 deletions
20
app/src/main/java/xyz/rodit/snapmod/features/chatmenu/AutoSaveOption.kt
This file was deleted.
Oops, something went wrong.
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
21 changes: 21 additions & 0 deletions
21
app/src/main/java/xyz/rodit/snapmod/features/chatmenu/ConversationToggleOption.kt
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,21 @@ | ||
package xyz.rodit.snapmod.features.chatmenu | ||
|
||
import xyz.rodit.snapmod.features.FeatureContext | ||
import xyz.rodit.snapmod.util.ConversationManager | ||
import xyz.rodit.snapmod.util.getList | ||
|
||
typealias Manager = (FeatureContext) -> ConversationManager | ||
|
||
class ConversationToggleOption( | ||
context: FeatureContext, | ||
name: String, | ||
textResource: Int, | ||
private val manager: Manager | ||
) : ToggleOption(context, name, textResource) { | ||
|
||
override fun shouldCreate() = !context.config.getList("hidden_chat_options").contains(name) | ||
|
||
override fun isToggled(key: String?) = manager(context).isEnabled(key) | ||
|
||
override fun handleEvent(data: String?) = manager(context).toggle(data) | ||
} |
25 changes: 0 additions & 25 deletions
25
app/src/main/java/xyz/rodit/snapmod/features/chatmenu/PinOption.kt
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
app/src/main/java/xyz/rodit/snapmod/features/chatmenu/StealthOption.kt
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
app/src/main/java/xyz/rodit/snapmod/features/saving/AutoDownloadSnaps.kt
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,43 @@ | ||
package xyz.rodit.snapmod.features.saving | ||
|
||
import xyz.rodit.snapmod.features.Feature | ||
import xyz.rodit.snapmod.features.FeatureContext | ||
import xyz.rodit.snapmod.mappings.* | ||
import xyz.rodit.snapmod.util.PathManager | ||
import xyz.rodit.snapmod.util.after | ||
import xyz.rodit.snapmod.util.toUUIDString | ||
|
||
class AutoDownloadSnaps(context: FeatureContext) : Feature(context) { | ||
|
||
private val ignore = hashSetOf<String>() | ||
|
||
override fun performHooks() { | ||
OperaPageViewController.onDisplayStateChanged.after { | ||
val viewController = OperaPageViewController.wrap(it.thisObject) | ||
if (viewController.state.instance != OperaDisplayState.FULLY_DISPLAYED().instance) return@after | ||
|
||
val params = ParamsMap.wrap(viewController.metadata.instance) | ||
val map = params.map | ||
if (!map.containsKey(MessageStoryKeys.getSnapInSavedState().instance)) return@after | ||
|
||
val messageId = map[MessageStoryKeys.getMessageId().instance] as String? | ||
val conversationId = UUID.wrap(map[ConversationStoryKeys.getConversationId().instance]) | ||
if (messageId == null || conversationId.isNull) return@after | ||
|
||
if (!context.config.getBoolean("auto_download_snaps") | ||
&& !context.autoDownload.isEnabled(conversationId.toUUIDString()) | ||
) return@after | ||
|
||
if (ignore.contains(messageId)) return@after | ||
|
||
ignore.add(messageId) | ||
getMediaInfo(context, params) { info -> | ||
downloadOperaMedia( | ||
context, | ||
PathManager.DOWNLOAD_SNAP, | ||
info | ||
) | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.