|
14 | 14 | ContentHome.socialAppId; |
15 | 15 | ContentHome.parentThreadId; |
16 | 16 | ContentHome.modalPopupThreadId; |
| 17 | + ContentHome.originalAppId; |
| 18 | + ContentHome.originalInstanceId; |
17 | 19 | var datastoreWriteKey; |
18 | 20 | var appId; |
19 | 21 | var instanceId; |
|
23 | 25 | datastoreWriteKey = context.datastoreWriteKey; |
24 | 26 | appId = context.appId; |
25 | 27 | instanceId = context.instanceId; |
26 | | - }); |
27 | | - Buildfire.datastore.get('Social', function (err, data) { |
28 | | - console.log('Get data in content section socail App Id------------------', err, data); |
29 | | - if (data && data.data && data.data.socialAppId) { |
30 | | - ContentHome.socialAppId = data.data.socialAppId; |
31 | | - ContentHome.parentThreadId = data.data.parentThreadId; |
32 | | - $scope.$digest(); |
| 28 | + ContentHome.originalAppId = context.appId; |
| 29 | + ContentHome.originalInstanceId = context.instanceId; |
33 | 30 |
|
34 | | - //update the plugin name on social |
35 | | - if (ContentHome.socialAppId && ContentHome.parentThreadId) { |
36 | | - Buildfire.getContext(function (err, context) { |
37 | | - if (err) { |
38 | | - console.error("Error occurred while getting buildfire context"); |
39 | | - } else { |
40 | | - console.log('buildfire get context response::: ', context); |
41 | | - instanceId = context && context.instanceId; |
| 31 | + Buildfire.datastore.get('Social', function (err, data) { |
| 32 | + console.log('Get data in content section socail App Id------------------', err, data); |
| 33 | + if (data && data.data && data.data.socialAppId && data.data.parentThreadId) { |
| 34 | + ContentHome.socialAppId = data.data.socialAppId; |
| 35 | + ContentHome.parentThreadId = data.data.parentThreadId; |
| 36 | + var _storedAppId = data.data.appId; |
| 37 | + var _storedInstanceId = data.data.instanceId; |
| 38 | + $scope.$digest(); |
42 | 39 |
|
43 | | - var updateThreadTitle = function () { |
44 | | - Buildfire.datastore.getWithDynamicData('pluginInfo', function (err, result) { |
45 | | - if (result && result.id) { |
46 | | - pluginTitle = result.data && result.data._buildfire && result.data._buildfire.myDynamicPluginCollection && result.data._buildfire.myDynamicPluginCollection.result && result.data._buildfire.myDynamicPluginCollection.result.length && result.data._buildfire.myDynamicPluginCollection.result[0].data && result.data._buildfire.myDynamicPluginCollection.result[0].data.title; |
47 | | - context.pluginTitle = pluginTitle; |
| 40 | + //update the plugin name on social |
| 41 | + var updateThreadTitle = function () { |
| 42 | + Buildfire.datastore.getWithDynamicData('pluginInfo', function (err, result) { |
| 43 | + if (result && result.id) { |
| 44 | + pluginTitle = result.data && result.data._buildfire && result.data._buildfire.myDynamicPluginCollection && result.data._buildfire.myDynamicPluginCollection.result && result.data._buildfire.myDynamicPluginCollection.result.length && result.data._buildfire.myDynamicPluginCollection.result[0].data && result.data._buildfire.myDynamicPluginCollection.result[0].data.title; |
| 45 | + context.pluginTitle = pluginTitle; |
48 | 46 |
|
49 | | - SocialDataStore.getThreadByUniqueLink(ContentHome.socialAppId, context).then( |
50 | | - function (parentThreadRes) { |
51 | | - console.log('Parent ThreadId -------success----', parentThreadRes); |
52 | | - }, |
53 | | - function (error) { |
54 | | - console.log('Parent thread callback error------', error); |
55 | | - } |
56 | | - ); |
| 47 | + SocialDataStore.getThreadByUniqueLink(ContentHome.socialAppId, context).then( |
| 48 | + function (parentThreadRes) { |
| 49 | + console.log('Parent ThreadId -------success----', parentThreadRes); |
| 50 | + }, |
| 51 | + function (error) { |
| 52 | + console.log('Parent thread callback error------', error); |
57 | 53 | } |
58 | | - }); |
59 | | - }; |
60 | | - updateThreadTitle(); |
61 | | - } |
62 | | - }); |
63 | | - } |
64 | | - console.log('Content------------------------social App id, parent id', ContentHome.socialAppId, ContentHome.parentThreadId); |
65 | | - } |
66 | | - else { |
67 | | - Buildfire.getContext(function (err, context) { |
68 | | - if (err) { |
69 | | - console.error("Error occurred while getting buildfire context"); |
| 54 | + ); |
| 55 | + } |
| 56 | + }); |
| 57 | + }; |
| 58 | + |
| 59 | + /* |
| 60 | + * We want the appId to be saved in the datastore to prevent the duplicate data in the plugin when |
| 61 | + * we clone the app, so we can compare the original appId with the one from buildfire.getContext |
| 62 | + * we also need to compare the instanceId to because we might clone the plugin itself not the app |
| 63 | + * and in this case the appId will remain the same but the instanceId will be changed |
| 64 | + */ |
| 65 | + |
| 66 | + if (!_storedAppId || !_storedInstanceId) { |
| 67 | + Buildfire.datastore.save({ |
| 68 | + socialAppId: ContentHome.socialAppId, |
| 69 | + parentThreadId: ContentHome.parentThreadId, |
| 70 | + appId: ContentHome.originalAppId, |
| 71 | + instanceId: ContentHome.originalInstanceId |
| 72 | + }, 'Social', function (err, data) { |
| 73 | + console.log('Data saved using datastore-------------', err, data); |
| 74 | + }); |
| 75 | + updateThreadTitle(); |
| 76 | + |
| 77 | + } else if (ContentHome.originalAppId != _storedAppId || ContentHome.originalInstanceId != _storedInstanceId) { |
| 78 | + /* |
| 79 | + * check if the context appId is not the same as the one in the datastore |
| 80 | + * or if the current plugin instance is not the same as old one in myDynamicPluginCollection |
| 81 | + * and reset the app |
| 82 | + * */ |
| 83 | + ContentHome.forceResetApp(); |
| 84 | + |
70 | 85 | } else { |
71 | | - console.log('buildfire get context response::: ', context); |
72 | | - instanceId = context && context.instanceId; |
73 | | - addApplication(context); |
| 86 | + updateThreadTitle(); |
74 | 87 | } |
75 | | - }); |
76 | | - } |
| 88 | + |
| 89 | + console.log('Content------------------------social App id, parent id', ContentHome.socialAppId, ContentHome.parentThreadId); |
| 90 | + } |
| 91 | + else { |
| 92 | + addApplication(context); |
| 93 | + }}); |
77 | 94 | }); |
78 | 95 |
|
79 | 96 | function addApplication(context) { |
|
102 | 119 | ContentHome.parentThreadId = parentThreadRes.data.result._id; |
103 | 120 | Buildfire.datastore.save({ |
104 | 121 | socialAppId: response.data.result, |
105 | | - parentThreadId: parentThreadRes.data.result._id |
| 122 | + parentThreadId: parentThreadRes.data.result._id, |
| 123 | + appId : ContentHome.originalAppId, |
| 124 | + instanceId : ContentHome.originalInstanceId |
106 | 125 | }, 'Social', function (err, data) { |
107 | 126 | console.log('Data saved using datastore-------------', err, data); |
108 | 127 | // Buildfire.messaging.sendMessageToWidget({'name': EVENTS.APP_RESET, 'data': data}); |
|
129 | 148 | if (appId && instanceId && datastoreWriteKey) { |
130 | 149 | var context = { |
131 | 150 | appId: appId, |
132 | | - instanceId: instanceId + new Date().getTime(), |
| 151 | + instanceId: instanceId + new Date().getTime(), |
133 | 152 | datastoreWriteKey: datastoreWriteKey |
134 | 153 | }; |
135 | 154 | addApplication(context); |
136 | 155 | } else { |
137 | 156 | Buildfire.getContext(function (err, context) { |
138 | 157 | datastoreWriteKey = context.datastoreWriteKey; |
139 | 158 | appId = context.appId; |
140 | | - instanceId = context.instanceId + new Date().getTime(); |
| 159 | + instanceId = context.instanceId + new Date().getTime(); |
141 | 160 | addApplication(context); |
142 | 161 | }); |
143 | 162 | } |
|
146 | 165 | }); |
147 | 166 | }; |
148 | 167 |
|
| 168 | + ContentHome.forceResetApp = function () { |
| 169 | + // resetting the app when the app or plugin is cloned |
| 170 | + Buildfire.getContext(function (err, context) { |
| 171 | + datastoreWriteKey = context.datastoreWriteKey; |
| 172 | + appId = context.appId; |
| 173 | + instanceId = context.instanceId; |
| 174 | + addApplication(context); |
| 175 | + }); |
| 176 | + }; |
| 177 | + |
149 | 178 | ContentHome.height = window.innerHeight; |
150 | 179 | ContentHome.noMore = false; |
151 | 180 | console.log('inside init method of content controller:::::::: '); |
|
0 commit comments