From ed18d3cc2283ea15c6909df9bfbc16027c0ab003 Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Tue, 21 Nov 2017 12:40:48 +0900
Subject: [PATCH] #935

---
 src/web/app/common/mios.ts        |  1 +
 src/web/app/desktop/tags/home.tag | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/web/app/common/mios.ts b/src/web/app/common/mios.ts
index 838be9c370..96dac70f61 100644
--- a/src/web/app/common/mios.ts
+++ b/src/web/app/common/mios.ts
@@ -198,6 +198,7 @@ export default class MiOS extends EventEmitter {
 			fetchme(cachedMe.token, freshData => {
 				Object.assign(cachedMe, freshData);
 				cachedMe.trigger('updated');
+				cachedMe.trigger('refreshed');
 			});
 		} else {
 			// Get token from cookie
diff --git a/src/web/app/desktop/tags/home.tag b/src/web/app/desktop/tags/home.tag
index fb244941a7..c751117517 100644
--- a/src/web/app/desktop/tags/home.tag
+++ b/src/web/app/desktop/tags/home.tag
@@ -193,11 +193,16 @@
 
 		this.home = [];
 
+		this.bakeHomeData = () => JSON.stringify(this.I.client_settings.home);
+		this.bakedHomeData = this.bakeHomeData();
+
 		this.on('mount', () => {
 			this.refs.tl.on('loaded', () => {
 				this.trigger('loaded');
 			});
 
+			this.I.on('refreshed', this.onMeRefreshed);
+
 			this.I.client_settings.home.forEach(widget => {
 				try {
 					this.setWidget(widget);
@@ -256,6 +261,8 @@
 		});
 
 		this.on('unmount', () => {
+			this.I.off('refreshed', this.onMeRefreshed);
+
 			this.home.forEach(widget => {
 				widget.unmount();
 			});
@@ -266,6 +273,12 @@
 			}
 		});
 
+		this.onMeRefreshed = () => {
+			if (this.bakedHomeData != this.bakeHomeData()) {
+				alert('別の場所でホームが編集されました。ページを再度読み込みすると編集が反映されます。');
+			}
+		};
+
 		this.setWidget = (widget, prepend = false) => {
 			const el = document.createElement(`mk-${widget.name}-home-widget`);
 
@@ -366,7 +379,6 @@
 			this.api('i/update_home', {
 				home: data
 			}).then(() => {
-				this.I.client_settings.home = data;
 				this.I.update();
 			});
 		};
-- 
GitLab