diff --git a/status/statusgo_backend_new/chat.nim b/status/statusgo_backend_new/chat.nim index fabca41..c630512 100644 --- a/status/statusgo_backend_new/chat.nim +++ b/status/statusgo_backend_new/chat.nim @@ -1,13 +1,66 @@ -import json +import json, sequtils, sugar import core, utils import response_type export response_type +proc saveChat*( + chatId: string, + chatType: int, + active: bool = true, + color: string = "#000000", + ensName: string = "", + profile: string = "", + joined: int64 = 0 + ): RpcResponse[JsonNode] {.raises: [Exception].} = + # TODO: ideally status-go/stimbus should handle some of these fields instead of having the client + # send them: lastMessage, unviewedMEssagesCount, timestamp, lastClockValue, name? + return callPrivateRPC("saveChat".prefix, %* [ + { + "lastClockValue": 0, # TODO: + "color": color, + "name": (if ensName != "": ensName else: chatId), + "lastMessage": nil, # TODO: + "active": active, + "profile": profile, + "id": chatId, + "unviewedMessagesCount": 0, # TODO: + "chatType": chatType.int, + "timestamp": 1588940692659, # TODO: + "joined": joined + } + ]) + proc getChats*(): RpcResponse[JsonNode] {.raises: [Exception].} = let payload = %* [] result = callPrivateRPC("chats".prefix, payload) proc createPublicChat*(chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} = let payload = %* [{"ID": chatId}] - result = callPrivateRPC("createPublicChat".prefix, payload) \ No newline at end of file + result = callPrivateRPC("createPublicChat".prefix, payload) + +proc createOneToOneChat*(chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} = + let payload = %* [{"ID": chatId}] + result = callPrivateRPC("createOneToOneChat".prefix, payload) + +proc leaveGroupChat*(chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} = + result = callPrivateRPC("leaveGroupChat".prefix, %* [nil, chatId, true]) + +proc deactivateChat*(chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} = + callPrivateRPC("deactivateChat".prefix, %* [{ "ID": chatId }]) + +proc clearChatHistory*(chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} = + callPrivateRPC("deleteMessagesByChatID".prefix, %* [chatId]) + +proc sendImages*(chatId: string, images: var seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} = + let imagesJson = %* images.map(image => %* + { + "chatId": chatId, + "contentType": 7, # TODO how do we unhardcode this + "imagePath": image, + # TODO is this still needed + # "ensName": preferredUsername, + "text": "Update to latest version to see a nice image here!" + } + ) + callPrivateRPC("sendChatMessages".prefix, %* [imagesJson]) \ No newline at end of file diff --git a/status/statusgo_backend_new/chatCommands.nim b/status/statusgo_backend_new/chatCommands.nim new file mode 100644 index 0000000..f84ab57 --- /dev/null +++ b/status/statusgo_backend_new/chatCommands.nim @@ -0,0 +1,21 @@ +import json +import core, utils +import response_type + +proc acceptRequestAddressForTransaction*(messageId: string, address: string): RpcResponse[JsonNode] {.raises: [Exception].} = + callPrivateRPC("acceptRequestAddressForTransaction".prefix, %* [messageId, address]) + +proc declineRequestAddressForTransaction*(messageId: string): RpcResponse[JsonNode] {.raises: [Exception].} = + callPrivateRPC("declineRequestAddressForTransaction".prefix, %* [messageId]) + +proc declineRequestTransaction*(messageId: string): RpcResponse[JsonNode] {.raises: [Exception].} = + callPrivateRPC("declineRequestTransaction".prefix, %* [messageId]) + +proc requestAddressForTransaction*(chatId: string, fromAddress: string, amount: string, tokenAddress: string): RpcResponse[JsonNode] {.raises: [Exception].} = + callPrivateRPC("requestAddressForTransaction".prefix, %* [chatId, fromAddress, amount, tokenAddress]) + +proc requestTransaction*(chatId: string, fromAddress: string, amount: string, tokenAddress: string): RpcResponse[JsonNode] {.raises: [Exception].} = + callPrivateRPC("requestTransaction".prefix, %* [chatId, amount, tokenAddress, fromAddress]) + +proc acceptRequestTransaction*(transactionHash: string, messageId: string, signature: string): RpcResponse[JsonNode] {.raises: [Exception].} = + callPrivateRPC("acceptRequestTransaction".prefix, %* [transactionHash, messageId, signature])