native-bridge-datasource.js 12 KB
Newer Older
1 2
// ios用
function callNativeApp(iosKey, jsonData) {
Kim Peace committed
3
  console.debug("callNativeApp called: " + iosKey);
4 5 6 7 8 9 10 11 12
  var result;
  try {
    var key = iosKey;
    var data = jsonData;
    var payload = { key: key, data: data };
    // payloadの形 {"type":"SJbridge","data":{"name":"abc","role":"dev"}}
    // resにObjective-cからのレスポンスが返る
    result = prompt(JSON.stringify(payload));
  } catch (err) {
Kim Peace committed
13
    console.debug("The native context does not exist yet");
14 15 16 17
  }
  return result;
}

18 19 20 21
function parseBoolStringToBool(str) {
  return str == "true" ? true : false;
}

22 23 24
var NativeBridgeDataSource = {};

NativeBridgeDataSource.removeFavoriteGroup = function (groupID) {
25
  if (deviceInfo.isiOS()) {
26 27 28
    const result = callNativeApp(NATIVE_KEY_IOS.removeFavoriteGroup, {
      groupId: groupID,
    });
29
    return parseBoolStringToBool(result);
30 31 32 33 34 35 36 37 38 39
  } else {
    return android.removeFavoriteGroup(groupID);
  }
};

NativeBridgeDataSource.addFavoriteGroup = function (groupID) {
  if (typeof android != "undefined") {
    return android.addFavoriteGroup(groupID);
  } else {
    const result = callNativeApp(NATIVE_KEY_IOS.addFavoriteGroup, {
Kim Peace committed
40
      groupId: groupID,
41
    });
42
    return parseBoolStringToBool(result);
43 44 45 46 47 48 49 50 51 52
  }
};

NativeBridgeDataSource.getRoomType = function () {
  if (typeof android != "undefined") {
    return android.getRoomType();
  } else {
    return parseInt(callNativeApp(NATIVE_KEY_IOS.getRoomType, {}), 10);
  }
};
53 54 55

//ロカールDBからルーム一覧情報を取得
NativeBridgeDataSource.getRoomList = function (roomType, keyWord) {
56
  if (deviceInfo.isiOS()) {
57 58 59 60 61 62
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getRoomList, {
        roomType: roomType,
        keyWord: keyWord,
      })
    );
63
  } else if (deviceInfo.isAndroid()) {
64 65 66 67 68 69
    return JSON.parse(android.getRoomList(roomType, keyWord));
  }
};

//ロカールDBからログインしたユーザのデータを取得する。
NativeBridgeDataSource.getMyInfo = function () {
70
  if (deviceInfo.isiOS()) {
71
    return JSON.parse(callNativeApp(NATIVE_KEY_IOS.getMyInfo, {}));
72
  } else if (deviceInfo.isAndroid()) {
73 74 75 76 77
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getMyInfo());
  }
};

Kim Peace committed
78
NativeBridgeDataSource.getMessagesByRoomID = function (roomID) {
79
  if (deviceInfo.isiOS()) {
80
    return JSON.parse(
Kim Peace committed
81
      callNativeApp(NATIVE_KEY_IOS.getMessages, { roomId: roomID })
82
    );
83
  } else if (deviceInfo.isAndroid()) {
84
    //String形式をJsonに変更してReturn
Kim Peace committed
85
    return JSON.parse(android.getMessageList(roomID));
86 87 88
  }
};

Kim Peace committed
89
NativeBridgeDataSource.getMessagesByMessageID = function (messageID) {
90
  if (deviceInfo.isiOS()) {
91 92
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getMessageListFromMessageId, {
Kim Peace committed
93
        messageId: messageID,
94 95
      })
    );
96
  } else if (deviceInfo.isAndroid()) {
Kim Peace committed
97
    return JSON.parse(android.getMessageListFromMessageId(messageID));
98 99 100 101
  }
};

NativeBridgeDataSource.getFavoriteUsersNotInRoom = function () {
102
  if (deviceInfo.isiOS()) {
103 104 105
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getFavoriteUsersNotInRoom, {})
    );
106
  } else if (deviceInfo.isAndroid()) {
107 108 109 110 111 112
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getFavoriteUsersNotInRoom());
  }
};

NativeBridgeDataSource.getFavoriteUsers = function () {
113
  if (deviceInfo.isiOS()) {
114
    return JSON.parse(callNativeApp(NATIVE_KEY_IOS.getFavoriteUsers, {}));
115
  } else if (deviceInfo.isAndroid()) {
116 117 118 119 120 121
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getFavoriteUsers());
  }
};

NativeBridgeDataSource.getFavoriteGroups = function () {
122
  if (deviceInfo.isiOS()) {
123
    return JSON.parse(callNativeApp(NATIVE_KEY_IOS.getFavoriteGroups, {}));
124
  } else if (deviceInfo.isAndroid()) {
125 126 127 128 129 130
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getFavoriteGroups());
  }
};

NativeBridgeDataSource.getMyGroupUsers = function () {
131
  if (deviceInfo.isiOS()) {
132
    return JSON.parse(callNativeApp(NATIVE_KEY_IOS.getMyGroupUsers, {}));
133
  } else if (deviceInfo.isAndroid()) {
134 135 136 137 138 139
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getMyGroupUsers());
  }
};

NativeBridgeDataSource.getGroupInfo = function (groupId) {
140
  if (deviceInfo.isiOS()) {
141 142 143
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getGroupInfo, { groupId: groupId })
    );
144
  } else if (deviceInfo.isAndroid()) {
145 146 147 148 149 150
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getGroupInfo(groupId));
  }
};

NativeBridgeDataSource.getGroupInfoForAddUser = function (groupId) {
151
  if (deviceInfo.isiOS()) {
152 153 154
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getGroupInfoForAddUser, { groupId: groupId })
    );
155
  } else if (deviceInfo.isAndroid()) {
156 157 158 159 160
    return JSON.parse(android.getGroupInfoForAddUser(groupId));
  }
};

NativeBridgeDataSource.loadSelectedUsers = function () {
161
  if (deviceInfo.isiOS()) {
162
    return JSON.parse(callNativeApp(NATIVE_KEY_IOS.getSelectedUserList, {}));
163
  } else if (deviceInfo.isAndroid()) {
164 165 166 167 168
    return JSON.parse(android.getSelectedUserList());
  }
};

NativeBridgeDataSource.getNameCardData = function (shopMemberId) {
169
  if (deviceInfo.isiOS()) {
170 171 172 173 174
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getNameCardData, {
        shopMemberId: shopMemberId,
      })
    );
175
  } else if (deviceInfo.isAndroid()) {
176 177 178 179 180
    return JSON.parse(android.getNameCardData(shopMemberId));
  }
};

NativeBridgeDataSource.getMyGroupShopMemberByName = function (shopMemberName) {
181
  if (deviceInfo.isiOS()) {
182 183 184 185 186
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getMyGroupShopMemberByName, {
        shopMemberName: shopMemberName,
      })
    );
187
  } else if (deviceInfo.isAndroid()) {
188 189 190 191 192 193 194 195
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getMyGroupShopMemberByName(shopMemberName));
  }
};

NativeBridgeDataSource.getMyGroupShopMemberNotInRoomByName = function (
  shopMemberName
) {
196
  if (deviceInfo.isiOS()) {
197 198 199 200 201
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getMyGroupShopMemberNotInRoomByName, {
        shopMemberName: shopMemberName,
      })
    );
202
  } else if (deviceInfo.isAndroid()) {
203 204 205 206 207 208 209 210
    //String形式をJsonに変更してReturn
    return JSON.parse(
      android.getMyGroupShopMemberNotInRoomByName(shopMemberName)
    );
  }
};

NativeBridgeDataSource.getAllGroupShopMemberByName = function (shopMemberName) {
211
  if (deviceInfo.isiOS()) {
212 213 214 215 216
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getAllGroupShopMemberByName, {
        shopMemberName: shopMemberName,
      })
    );
217
  } else if (deviceInfo.isAndroid()) {
218 219 220 221 222 223 224 225
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getAllGroupShopMemberByName(shopMemberName));
  }
};

NativeBridgeDataSource.getAllGroupShopMemberNotInRoomByName = function (
  shopMemberName
) {
226
  if (deviceInfo.isiOS()) {
227 228 229 230 231
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getAllGroupShopMemberNotInRoomByName, {
        shopMemberName: shopMemberName,
      })
    );
232
  } else if (deviceInfo.isAndroid()) {
233 234 235 236 237 238 239 240
    //String形式をJsonに変更してReturn
    return JSON.parse(
      android.getAllGroupShopMemberNotInRoomByName(shopMemberName)
    );
  }
};

NativeBridgeDataSource.getGroupByName = function (groupName) {
241
  if (deviceInfo.isiOS()) {
242 243 244
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getGroupByName, { groupName: groupName })
    );
245
  } else if (deviceInfo.isAndroid()) {
246 247 248 249 250
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getGroupByName(groupName));
  }
};

Kim Peace committed
251
NativeBridgeDataSource.getUsersInRoom = function (roomID) {
252
  if (deviceInfo.isiOS()) {
253
    return JSON.parse(
Kim Peace committed
254
      callNativeApp(NATIVE_KEY_IOS.getUsersInRoom, { roomId: roomID })
255
    );
256
  } else if (deviceInfo.isAndroid()) {
257
    //String形式をJsonに変更してReturn
Kim Peace committed
258
    return JSON.parse(android.getUsersInRoom(roomID));
259 260 261 262 263
  }
};

// アーカイブ一覧
NativeBridgeDataSource.getArchiveList = function () {
264
  if (deviceInfo.isiOS()) {
265
    return JSON.parse(callNativeApp(NATIVE_KEY_IOS.getArchiveList, {}));
266
  } else if (deviceInfo.isAndroid()) {
267 268 269 270 271 272
    return JSON.parse(android.getArchiveList());
  }
};

// アーカイブ一覧検索
NativeBridgeDataSource.getArchiveByName = function (archiveName) {
273
  if (deviceInfo.isiOS()) {
274 275 276 277 278
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getArchiveByName, {
        archiveName: archiveName,
      })
    );
279
  } else if (deviceInfo.isAndroid()) {
280 281 282 283 284 285
    return JSON.parse(android.getArchiveListByName(archiveName));
  }
};

// アーカイブ詳細
NativeBridgeDataSource.getArchiveDetail = function (archiveId) {
286
  if (deviceInfo.isiOS()) {
287 288 289
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getArchiveDetail, { archiveId: archiveId })
    );
290
  } else if (deviceInfo.isAndroid()) {
291 292 293 294 295
    return JSON.parse(android.getArchiveDetail(archiveId));
  }
};

NativeBridgeDataSource.searchMessages = function (keyword, userList) {
296
  if (deviceInfo.isiOS()) {
297 298 299 300 301 302
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.searchMessages, {
        keyWord: keyword,
        userList: userList,
      })
    );
303
  } else if (deviceInfo.isAndroid()) {
304 305 306 307 308
    return JSON.parse(android.searchMessages(keyword, userList));
  }
};

NativeBridgeDataSource.getMyGroupUsersNotInRoom = function () {
309
  if (deviceInfo.isiOS()) {
310 311 312
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getMyGroupUsersNotInRoom, {})
    );
313
  } else if (deviceInfo.isAndroid()) {
314 315 316 317 318 319 320 321 322
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getMyGroupUsersNotInRoom());
  }
};

NativeBridgeDataSource.getUserInfo = function (shopMemberId) {
  if (shopMemberId == "") {
    return;
  }
323
  if (deviceInfo.isiOS()) {
324 325 326
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getUserInfo, { shopMemberId: shopMemberId })
    );
327
  } else if (deviceInfo.isAndroid()) {
328 329 330 331 332 333
    //String形式をJsonに変更してReturn
    return JSON.parse(android.getUserInfo(shopMemberId));
  }
};

NativeBridgeDataSource.getUserListByLoginId = function (loginIdList) {
334
  if (deviceInfo.isiOS()) {
335 336 337 338 339
    return JSON.parse(
      callNativeApp(NATIVE_KEY_IOS.getUserListByLoginId, {
        loginIdList: loginIdList.join(","),
      })
    );
340
  } else if (deviceInfo.isAndroid()) {
341 342 343 344 345
    return JSON.parse(android.getUserListByLoginId(loginIdList.join(",")));
  }
};

NativeBridgeDataSource.getBeforeRoomType = function () {
346
  if (deviceInfo.isiOS()) {
347 348 349 350 351 352 353
    return callNativeApp(NATIVE_KEY_IOS.getBeforeRoomType, {});
  } else {
    return android.getBeforeRoomType();
  }
};

NativeBridgeDataSource.removeFavoriteUser = function (shopMemberId) {
354
  if (deviceInfo.isiOS()) {
355
    const result = callNativeApp(NATIVE_KEY_IOS.removeFavoriteUser, {
356 357
      shopMemberId: shopMemberId,
    });
358
    return parseBoolStringToBool(result);
359 360 361 362 363 364
  } else {
    return android.removeFavoriteUser(shopMemberId);
  }
};

NativeBridgeDataSource.addFavoriteUser = function (shopMemberId) {
365
  if (deviceInfo.isiOS()) {
366
    const result = callNativeApp(NATIVE_KEY_IOS.addFavoriteUser, {
367 368
      shopMemberId: shopMemberId,
    });
369
    return parseBoolStringToBool(result);
370 371 372 373 374 375
  } else {
    return android.addFavoriteUser(shopMemberId);
  }
};

NativeBridgeDataSource.getJoinCollaborationType = function () {
376
  if (deviceInfo.isiOS()) {
377 378 379 380 381 382 383 384 385 386
    return parseInt(
      callNativeApp(NATIVE_KEY_IOS.getJoinCollaborationType, {}),
      10
    );
  } else {
    return android.getJoinCollaborationType();
  }
};

NativeBridgeDataSource.getUserInfoList = function (shopMemberId) {
387
  if (deviceInfo.isiOS()) {
388 389 390 391
    return callNativeApp(NATIVE_KEY_IOS.getUserInfoList, {
      shopMemberId: shopMemberId,
    });
  } else {
392
    return android.getUserInfoList(shopMemberId);
393 394 395 396
  }
};

NativeBridgeDataSource.createContentView = function () {
397
  if (deviceInfo.isiOS()) {
398 399 400 401 402 403 404
    return parseInt(callNativeApp(NATIVE_KEY_IOS.createContentView, {}));
  } else {
    return android.createContentView();
  }
};

NativeBridgeDataSource.getToMoveGroupId = function () {
405
  if (deviceInfo.isiOS()) {
406 407 408 409 410 411 412
    return callNativeApp(NATIVE_KEY_IOS.getToMoveGroupId, {});
  } else {
    return android.getToMoveGroupId();
  }
};

NativeBridgeDataSource.getHostRequestFlg = function () {
413
  if (deviceInfo.isiOS()) {
414 415 416 417
    return parseInt(callNativeApp(NATIVE_KEY_IOS.getHostRequestFlg, {}), 10);
  } else {
    return android.getHostRequestFlg();
  }
418
};