summaryrefslogtreecommitdiff
path: root/src/api/stream
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-06-13 02:12:30 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-06-13 02:12:30 +0900
commit5880b90f599cfc7eeab714d61f3fc8b9f3be7e0f (patch)
tree44e10eb1357e3cf14a5ede825a0e0b67e22f0c99 /src/api/stream
parentv2086 (diff)
downloadsharkey-5880b90f599cfc7eeab714d61f3fc8b9f3be7e0f.tar.gz
sharkey-5880b90f599cfc7eeab714d61f3fc8b9f3be7e0f.tar.bz2
sharkey-5880b90f599cfc7eeab714d61f3fc8b9f3be7e0f.zip
[API] Refactor and Bug fix
Diffstat (limited to 'src/api/stream')
-rw-r--r--src/api/stream/messaging.ts41
1 files changed, 3 insertions, 38 deletions
diff --git a/src/api/stream/messaging.ts b/src/api/stream/messaging.ts
index 71bf7a34c6..f94625d8e4 100644
--- a/src/api/stream/messaging.ts
+++ b/src/api/stream/messaging.ts
@@ -1,8 +1,7 @@
import * as mongodb from 'mongodb';
import * as websocket from 'websocket';
import * as redis from 'redis';
-import Message from '../models/messaging-message';
-import { publishMessagingStream } from '../event';
+import read from '../common/read-messaging-message';
export default function messagingStream(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any): void {
const otherparty = request.resourceURL.query.otherparty;
@@ -18,42 +17,8 @@ export default function messagingStream(request: websocket.request, connection:
switch (msg.type) {
case 'read':
- if (!msg.id) {
- return;
- }
-
- const id = new mongodb.ObjectID(msg.id);
-
- // Fetch message
- // SELECT _id, user_id, is_read
- const message = await Message.findOne({
- _id: id,
- recipient_id: user._id
- }, {
- fields: {
- _id: true,
- user_id: true,
- is_read: true
- }
- });
-
- if (message == null) {
- return;
- }
-
- if (message.is_read) {
- return;
- }
-
- // Update documents
- await Message.update({
- _id: id
- }, {
- $set: { is_read: true }
- });
-
- // Publish event
- publishMessagingStream(message.user_id, user._id, 'read', id.toString());
+ if (!msg.id) return;
+ read(user._id, otherparty, msg.id);
break;
}
});