Initial Commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
Creating a new repository on the command line
|
||||
touch README.md
|
||||
git init
|
||||
|
||||
git add README.md
|
||||
git commit -m "first commit"
|
||||
git remote add origin https://git.theonasanyas.com/agboola/MessagingApp_Functions.git
|
||||
git push -u origin main
|
||||
Pushing an existing repository from the command line
|
||||
git remote add origin https://git.theonasanyas.com/agboola/MessagingApp_Functions.git
|
||||
git push -u origin main
|
||||
@@ -0,0 +1,30 @@
|
||||
# See https://www.dartlang.org/guides/libraries/private-files
|
||||
|
||||
# Files and directories created by pub
|
||||
.dart_tool/
|
||||
.packages
|
||||
build/
|
||||
# If you're building an application, you may want to check-in your pubspec.lock
|
||||
pubspec.lock
|
||||
|
||||
# Directory created by dartdoc
|
||||
# If you don't generate documentation locally you can remove this line.
|
||||
doc/api/
|
||||
|
||||
# dotenv environment variables file
|
||||
.env*
|
||||
|
||||
# Avoid committing generated Javascript files:
|
||||
*.dart.js
|
||||
*.info.json # Produced by the --dump-info flag.
|
||||
*.js # When generated by dart2js. Don't specify *.js if your
|
||||
# project includes source files written in JavaScript.
|
||||
*.js_
|
||||
*.js.deps
|
||||
*.js.map
|
||||
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
|
||||
# Directory used by Appwrite CLI for local development
|
||||
.appwrite
|
||||
@@ -0,0 +1,46 @@
|
||||
# conversations_upd_function
|
||||
|
||||
## 🧰 Usage
|
||||
|
||||
### GET /ping
|
||||
|
||||
- Returns a "Pong" message.
|
||||
|
||||
**Response**
|
||||
|
||||
Sample `200` Response:
|
||||
|
||||
```text
|
||||
Pong
|
||||
```
|
||||
|
||||
### GET, POST, PUT, PATCH, DELETE /
|
||||
|
||||
- Returns a "Learn More" JSON response.
|
||||
|
||||
**Response**
|
||||
|
||||
Sample `200` Response:
|
||||
|
||||
```json
|
||||
{
|
||||
"motto": "Build like a team of hundreds_",
|
||||
"learn": "https://appwrite.io/docs",
|
||||
"connect": "https://appwrite.io/discord",
|
||||
"getInspired": "https://builtwith.appwrite.io"
|
||||
}
|
||||
```
|
||||
|
||||
## ⚙️ Configuration
|
||||
|
||||
| Setting | Value |
|
||||
| ----------------- | --------------- |
|
||||
| Runtime | Dart (2.17) |
|
||||
| Entrypoint | `lib/main.dart` |
|
||||
| Build Commands | `dart pub get` |
|
||||
| Permissions | `any` |
|
||||
| Timeout (Seconds) | 15 |
|
||||
|
||||
## 🔒 Environment Variables
|
||||
|
||||
No environment variables required.
|
||||
@@ -0,0 +1 @@
|
||||
include: package:lints/recommended.yaml
|
||||
@@ -0,0 +1,96 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:dart_appwrite/dart_appwrite.dart';
|
||||
|
||||
late Databases _database;
|
||||
|
||||
var _usersDbId;
|
||||
var _conversationDbId;
|
||||
var _documentId;
|
||||
var _databaseId;
|
||||
|
||||
Future<dynamic> main(final context) async {
|
||||
try {
|
||||
final client = Client()
|
||||
.setEndpoint(
|
||||
Platform.environment['APPWRITE_FUNCTION_API_ENDPOINT'] ?? '')
|
||||
.setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'] ?? '')
|
||||
.setKey(context.req.headers['x-appwrite-key'] ?? '');
|
||||
|
||||
_database = Databases(client);
|
||||
_conversationDbId = Platform.environment['APPWRITE_COLLECTION_ID'];
|
||||
_usersDbId = Platform.environment['APPWRITE_USERS_ID'];
|
||||
|
||||
String trigger = context.req.headers['x-appwrite-trigger'];
|
||||
if (trigger == 'event') {
|
||||
List<dynamic> _members = context.req.bodyJson['members'];
|
||||
_documentId = context.req.bodyJson['\$id'];
|
||||
_databaseId = context.req.bodyJson['\$databaseId'];
|
||||
|
||||
for (var _member in _members) {
|
||||
var _membersReduced =
|
||||
_members.where((_data) => _data != _member).toList();
|
||||
await createConversation(_member, _membersReduced);
|
||||
}
|
||||
}
|
||||
} on AppwriteException catch (e) {
|
||||
context.error('error message - ${e.message}');
|
||||
} on Exception catch (e) {
|
||||
context.error('error message - ${e.toString()}');
|
||||
}
|
||||
return context.res.empty();
|
||||
}
|
||||
|
||||
dynamic createConversation(var member, var _members) async {
|
||||
//
|
||||
for (var _member in _members) {
|
||||
List<dynamic> _chatIdMap = [];
|
||||
List<dynamic> _detailMap = [];
|
||||
|
||||
var _userDetail = await _database.getDocument(
|
||||
databaseId: _databaseId, collectionId: _usersDbId, documentId: _member);
|
||||
|
||||
var _imageUrl = _userDetail.data['image'];
|
||||
var _name = _userDetail.data['name'];
|
||||
|
||||
dynamic _conversationDetail;
|
||||
try {
|
||||
_conversationDetail = await _database.getDocument(
|
||||
databaseId: _databaseId,
|
||||
collectionId: _conversationDbId,
|
||||
documentId: member);
|
||||
} on AppwriteException catch (e) {
|
||||
e.message;
|
||||
} on Exception catch (e) {
|
||||
e.toString();
|
||||
}
|
||||
|
||||
if (_conversationDetail != null) {
|
||||
_chatIdMap = _conversationDetail.data['chatId'];
|
||||
_detailMap = _conversationDetail.data['details'];
|
||||
|
||||
await _database.deleteDocument(
|
||||
databaseId: _databaseId,
|
||||
collectionId: _conversationDbId,
|
||||
documentId: member,
|
||||
);
|
||||
}
|
||||
|
||||
String _data = '{"name": "$_name","image": "$_imageUrl","unseenCount": 1}';
|
||||
_chatIdMap.add(_documentId);
|
||||
_detailMap.add(_data);
|
||||
|
||||
Map<dynamic, dynamic> _conversationMap = {
|
||||
"chatId": _chatIdMap,
|
||||
"details": _detailMap
|
||||
};
|
||||
await _database.createDocument(
|
||||
databaseId: _databaseId,
|
||||
collectionId: _conversationDbId,
|
||||
documentId: member,
|
||||
data: _conversationMap,
|
||||
);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
name: starter_template
|
||||
version: 1.0.0
|
||||
|
||||
environment:
|
||||
sdk: ^2.17.0
|
||||
|
||||
dependencies:
|
||||
dart_appwrite: 8.0.0
|
||||
|
||||
dev_dependencies:
|
||||
lints: ^2.0.0
|
||||
@@ -0,0 +1,30 @@
|
||||
# See https://www.dartlang.org/guides/libraries/private-files
|
||||
|
||||
# Files and directories created by pub
|
||||
.dart_tool/
|
||||
.packages
|
||||
build/
|
||||
# If you're building an application, you may want to check-in your pubspec.lock
|
||||
pubspec.lock
|
||||
|
||||
# Directory created by dartdoc
|
||||
# If you don't generate documentation locally you can remove this line.
|
||||
doc/api/
|
||||
|
||||
# dotenv environment variables file
|
||||
.env*
|
||||
|
||||
# Avoid committing generated Javascript files:
|
||||
*.dart.js
|
||||
*.info.json # Produced by the --dump-info flag.
|
||||
*.js # When generated by dart2js. Don't specify *.js if your
|
||||
# project includes source files written in JavaScript.
|
||||
*.js_
|
||||
*.js.deps
|
||||
*.js.map
|
||||
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
|
||||
# Directory used by Appwrite CLI for local development
|
||||
.appwrite
|
||||
@@ -0,0 +1,46 @@
|
||||
# mesaages_upd_function
|
||||
|
||||
## 🧰 Usage
|
||||
|
||||
### GET /ping
|
||||
|
||||
- Returns a "Pong" message.
|
||||
|
||||
**Response**
|
||||
|
||||
Sample `200` Response:
|
||||
|
||||
```text
|
||||
Pong
|
||||
```
|
||||
|
||||
### GET, POST, PUT, PATCH, DELETE /
|
||||
|
||||
- Returns a "Learn More" JSON response.
|
||||
|
||||
**Response**
|
||||
|
||||
Sample `200` Response:
|
||||
|
||||
```json
|
||||
{
|
||||
"motto": "Build like a team of hundreds_",
|
||||
"learn": "https://appwrite.io/docs",
|
||||
"connect": "https://appwrite.io/discord",
|
||||
"getInspired": "https://builtwith.appwrite.io"
|
||||
}
|
||||
```
|
||||
|
||||
## ⚙️ Configuration
|
||||
|
||||
| Setting | Value |
|
||||
| ----------------- | --------------- |
|
||||
| Runtime | Dart (2.17) |
|
||||
| Entrypoint | `lib/main.dart` |
|
||||
| Build Commands | `dart pub get` |
|
||||
| Permissions | `any` |
|
||||
| Timeout (Seconds) | 15 |
|
||||
|
||||
## 🔒 Environment Variables
|
||||
|
||||
No environment variables required.
|
||||
@@ -0,0 +1 @@
|
||||
include: package:lints/recommended.yaml
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:dart_appwrite/dart_appwrite.dart';
|
||||
|
||||
late Databases _database;
|
||||
|
||||
var _usersDbId;
|
||||
var _conversationDbId;
|
||||
var _documentId;
|
||||
var _databaseId;
|
||||
|
||||
Future<dynamic> main(final context) async {
|
||||
try {
|
||||
final client = Client()
|
||||
.setEndpoint(
|
||||
Platform.environment['APPWRITE_FUNCTION_API_ENDPOINT'] ?? '')
|
||||
.setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'] ?? '')
|
||||
.setKey(context.req.headers['x-appwrite-key'] ?? '');
|
||||
|
||||
_database = Databases(client);
|
||||
} on AppwriteException catch (e) {
|
||||
context.error('error message - ${e.message}');
|
||||
} on Exception catch (e) {
|
||||
context.error('error message - ${e.toString()}');
|
||||
}
|
||||
|
||||
return context.res.empty();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
name: starter_template
|
||||
version: 1.0.0
|
||||
|
||||
environment:
|
||||
sdk: ^2.17.0
|
||||
|
||||
dependencies:
|
||||
dart_appwrite: 8.0.0
|
||||
|
||||
dev_dependencies:
|
||||
lints: ^2.0.0
|
||||
Reference in New Issue
Block a user