Skip to content

Commit

Permalink
support viewing "online" mail in protonmail's messages view mode #102
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Feb 6, 2019
1 parent e573903 commit 49a5262
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 127 deletions.
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"html-to-text": "4.0.0",
"image-processing-js": "0.0.3",
"js-base64": "2.5.1",
"keytar": "4.3.3",
"keytar": "4.4.0",
"memory-streams": "0.1.3",
"mime-types": "2.1.21",
"msgpack-lite": "0.1.26",
Expand All @@ -123,17 +123,17 @@
},
"devDependencies": {
"@angular-devkit/build-optimizer": "0.13.0",
"@angular/animations": "7.2.3",
"@angular/common": "7.2.3",
"@angular/compiler": "7.2.3",
"@angular/compiler-cli": "7.2.3",
"@angular/core": "7.2.3",
"@angular/forms": "7.2.3",
"@angular/http": "7.2.3",
"@angular/language-service": "7.2.3",
"@angular/platform-browser": "7.2.3",
"@angular/platform-browser-dynamic": "7.2.3",
"@angular/router": "7.2.3",
"@angular/animations": "7.2.4",
"@angular/common": "7.2.4",
"@angular/compiler": "7.2.4",
"@angular/compiler-cli": "7.2.4",
"@angular/core": "7.2.4",
"@angular/forms": "7.2.4",
"@angular/http": "7.2.4",
"@angular/language-service": "7.2.4",
"@angular/platform-browser": "7.2.4",
"@angular/platform-browser-dynamic": "7.2.4",
"@angular/router": "7.2.4",
"@angularclass/hmr": "2.1.3",
"@email-securely-app/import-sort-style": "0.1.0",
"@expo/spawn-async": "1.4.0",
Expand Down Expand Up @@ -255,7 +255,7 @@
"stylus-loader": "3.0.2",
"to-string-loader": "1.1.5",
"ts-node": "8.0.2",
"tsconfig-paths": "3.7.0",
"tsconfig-paths": "3.8.0",
"tsconfig-paths-webpack-plugin": "3.2.0",
"tslint": "5.12.1",
"tslint-consistent-codestyle": "1.15.0",
Expand All @@ -264,7 +264,7 @@
"typescript": "3.3.1",
"uglifyjs-webpack-plugin": "2.1.1",
"url-loader": "1.1.2",
"webpack": "4.29.1",
"webpack": "4.29.2",
"webpack-cli": "3.2.3",
"webpack-dev-server": "3.1.14",
"webpack-merge": "4.2.1",
Expand Down
46 changes: 33 additions & 13 deletions src/electron-preload/webview/protonmail/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {angularJsHttpResponseTypeGuard, isLoggedIn} from "src/electron-preload/w
import {buildDbPatch, buildDbPatchEndpoint} from "src/electron-preload/webview/protonmail/api/build-db-patch";
import {curryFunctionMembers, isEntityUpdatesPatchNotEmpty} from "src/shared/util";
import {fillInputValue, getLocationHref, resolveDomElements, resolveIpcMainApi, submitTotpToken} from "src/electron-preload/webview/util";
import {resolveProviderApi} from "src/electron-preload/webview/protonmail/lib/provider-api";

const _logger = curryFunctionMembers(WebviewConstants.WEBVIEW_LOGGERS.protonmail, "[api/index]");
const twoFactorCodeElementId = "twoFactorCode";
Expand All @@ -34,13 +35,19 @@ const endpoints: ProtonmailApi = {
logger.info();

// TODO reduce the "mailFolderId" value that contains a minimum items count
const $state: { go: (v: string, d: Record<string, string>) => Promise<void> } | undefined
= window.angular && window.angular.element(document).data().$injector.get("$state");
const $state: undefined | {
go: (
path: string,
params?: Partial<Record<"label" | "id" | "messageID", string>>,
) => Promise<void>;
} = window.angular && window.angular.element(document).data().$injector.get("$state");

if (!$state) {
throw new Error(`Failed to resolve "$state" service`);
}

const api = await resolveProviderApi();
const messagesViewMode = api.mailSettingsModel.get().ViewMode === api.constants.MESSAGE_VIEW_MODE;
const {system, custom} = input.mail.mailFolderIds.reduce(
(accumulator: { system: typeof input.mail.mailFolderIds, custom: typeof input.mail.mailFolderIds }, id) => {
if (id in PROTONMAIL_MAILBOX_ROUTE_NAMES) {
Expand All @@ -57,13 +64,20 @@ const endpoints: ProtonmailApi = {
if (custom.length) {
const [folderId] = custom;

await $state.go("secured.label", {
label: folderId,
});
await $state.go("secured.label.element", {
id: mailConversationId,
messageID: mailId,
});
if (messagesViewMode) {
await $state.go(`secured.label.element`, {
id: mailId,
label: folderId,
});
} else {
await $state.go("secured.label", {
label: folderId,
});
await $state.go("secured.label.element", {
id: mailConversationId,
messageID: mailId,
});
}

return null;
}
Expand All @@ -82,10 +96,16 @@ const endpoints: ProtonmailApi = {
throw new Error(`Failed to resolve folder route name`);
}

await $state.go(`secured.${folderRouteName}.element`, {
id: mailConversationId,
messageID: mailId,
});
if (messagesViewMode) {
await $state.go(`secured.${folderRouteName}.element`, {
id: mailId,
});
} else {
await $state.go(`secured.${folderRouteName}.element`, {
id: mailConversationId,
messageID: mailId,
});
}

return null;
})()),
Expand Down
17 changes: 17 additions & 0 deletions src/electron-preload/webview/protonmail/lib/provider-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ import {resolveIpcMainApi} from "src/electron-preload/webview/util";
// TODO consider executing direct $http calls
// in order to not depend on Protonmail WebClient's AngularJS factories/services
export interface ProviderApi {
constants: {
MESSAGE_VIEW_MODE: 1;
CONVERSATION_VIEW_MODE: 0;
};
$http: ng.IHttpService;
url: {
build: (module: string) => () => string;
};
lazyLoader: {
app: () => Promise<void>;
};
mailSettingsModel: {
get: () => {
ViewMode:
| ProviderApi["constants"]["MESSAGE_VIEW_MODE"]
| ProviderApi["constants"]["CONVERSATION_VIEW_MODE"];
};
};
messageModel: (message: Rest.Model.Message) => {
clearTextBody: () => Promise<string>;
};
Expand Down Expand Up @@ -93,7 +104,13 @@ export async function resolveProviderApi(): Promise<ProviderApi> {
// so app gets protonmail breaking changes noticed on early stage

return {
constants: {
// TODO TS: get rid of type casting
MESSAGE_VIEW_MODE: 1 as ProviderApi["constants"]["MESSAGE_VIEW_MODE"],
CONVERSATION_VIEW_MODE: 0 as ProviderApi["constants"]["CONVERSATION_VIEW_MODE"],
},
lazyLoader,
mailSettingsModel: resolveService<ProviderApi["mailSettingsModel"]>(injector, "mailSettingsModel"),
$http: resolveService<ProviderApi["$http"]>(injector, "$http"),
url: resolveService<ProviderApi["url"]>(injector, "url"),
messageModel: resolveService<ProviderApi["messageModel"]>(injector, "messageModel"),
Expand Down
Loading

0 comments on commit 49a5262

Please sign in to comment.