2019-09-18 15:02:21 +09:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
2019-09-23 10:14:20 +09:00
|
|
|
import { Observable } from 'rxjs';
|
2019-09-23 15:17:48 +09:00
|
|
|
import { map, take } from 'rxjs/operators';
|
2019-09-23 10:14:20 +09:00
|
|
|
|
|
|
|
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
|
|
|
|
|
|
|
import {
|
|
|
|
SVC_TYPE_BUDDY,
|
|
|
|
SSVC_TYPE_BUDDY_ADD_REQ,
|
|
|
|
SSVC_TYPE_BUDDY_DEL_REQ,
|
|
|
|
SSVC_TYPE_BUDDY_UPD_REQ
|
|
|
|
} from '../types/service';
|
|
|
|
|
|
|
|
import {
|
|
|
|
BuddyAddRequest,
|
|
|
|
encodeBuddyAdd,
|
2019-09-23 11:47:36 +09:00
|
|
|
decodeBuddyAdd,
|
|
|
|
BuddyAddResponse
|
2019-09-25 13:21:07 +09:00
|
|
|
} from '../models/add';
|
2019-09-23 10:14:20 +09:00
|
|
|
import {
|
|
|
|
BuddyDelRequest,
|
|
|
|
encodeBuddyDel,
|
2019-09-23 11:47:36 +09:00
|
|
|
decodeBuddyDel,
|
|
|
|
BuddyDelResponse
|
2019-09-25 13:21:07 +09:00
|
|
|
} from '../models/del';
|
2019-09-23 10:14:20 +09:00
|
|
|
import {
|
|
|
|
BuddyUpdateRequest,
|
|
|
|
decodeBuddyUpdate,
|
2019-09-23 11:47:36 +09:00
|
|
|
encodeBuddyUpdate,
|
|
|
|
BuddyUpdateResponse
|
2019-09-25 13:21:07 +09:00
|
|
|
} from '../models/update';
|
2019-09-23 10:14:20 +09:00
|
|
|
|
2019-09-18 15:02:21 +09:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class BuddyProtocolService {
|
2019-09-23 10:14:20 +09:00
|
|
|
constructor(private protocolService: ProtocolService) {}
|
|
|
|
|
2019-09-23 11:47:36 +09:00
|
|
|
public buddyAdd(req: BuddyAddRequest): Observable<BuddyAddResponse> {
|
2019-09-23 10:14:20 +09:00
|
|
|
return this.protocolService
|
|
|
|
.call(SVC_TYPE_BUDDY, SSVC_TYPE_BUDDY_ADD_REQ, ...encodeBuddyAdd(req))
|
2019-09-23 15:17:48 +09:00
|
|
|
.pipe(
|
|
|
|
take(1),
|
|
|
|
map(res => decodeBuddyAdd(res))
|
|
|
|
);
|
2019-09-23 10:14:20 +09:00
|
|
|
}
|
|
|
|
|
2019-09-23 11:47:36 +09:00
|
|
|
public buddyDel(req: BuddyDelRequest): Observable<BuddyDelResponse> {
|
2019-09-23 10:14:20 +09:00
|
|
|
return this.protocolService
|
|
|
|
.call(SVC_TYPE_BUDDY, SSVC_TYPE_BUDDY_DEL_REQ, ...encodeBuddyDel(req))
|
2019-09-23 15:17:48 +09:00
|
|
|
.pipe(
|
|
|
|
take(1),
|
|
|
|
map(res => decodeBuddyDel(res))
|
|
|
|
);
|
2019-09-23 10:14:20 +09:00
|
|
|
}
|
|
|
|
|
2019-09-23 11:47:36 +09:00
|
|
|
public buddyUpdate(req: BuddyUpdateRequest): Observable<BuddyUpdateResponse> {
|
2019-09-23 10:14:20 +09:00
|
|
|
return this.protocolService
|
|
|
|
.call(SVC_TYPE_BUDDY, SSVC_TYPE_BUDDY_UPD_REQ, ...encodeBuddyUpdate(req))
|
2019-09-23 15:17:48 +09:00
|
|
|
.pipe(
|
|
|
|
take(1),
|
|
|
|
map(res => decodeBuddyUpdate(res))
|
|
|
|
);
|
2019-09-23 10:14:20 +09:00
|
|
|
}
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|