2021-09-12 13:57:45 +00:00
//
// C o p y r i g h t 2 0 2 1 N e w V e c t o r L t d
//
// L i c e n s e d u n d e r t h e A p a c h e L i c e n s e , V e r s i o n 2 . 0 ( t h e " L i c e n s e " ) ;
// y o u m a y n o t u s e t h i s f i l e e x c e p t i n c o m p l i a n c e w i t h t h e L i c e n s e .
// Y o u m a y o b t a i n a c o p y o f t h e L i c e n s e a t
//
// h t t p : / / w w w . a p a c h e . o r g / l i c e n s e s / L I C E N S E - 2 . 0
//
// U n l e s s r e q u i r e d b y a p p l i c a b l e l a w o r a g r e e d t o i n w r i t i n g , s o f t w a r e
// d i s t r i b u t e d u n d e r t h e L i c e n s e i s d i s t r i b u t e d o n a n " A S I S " B A S I S ,
// W I T H O U T W A R R A N T I E S O R C O N D I T I O N S O F A N Y K I N D , e i t h e r e x p r e s s o r i m p l i e d .
// S e e t h e L i c e n s e f o r t h e s p e c i f i c l a n g u a g e g o v e r n i n g p e r m i s s i o n s a n d
// l i m i t a t i o n s u n d e r t h e L i c e n s e .
//
import Foundation
import Combine
@ available ( iOS 14.0 , * )
class MockTemplateRoomChatService : TemplateRoomChatServiceProtocol {
2021-09-16 21:09:32 +00:00
let roomName : String ? = " New Vector "
static let amadine = TemplateRoomChatMember ( id : " @amadine:matrix.org " , avatarUrl : " !aaabaa:matrix.org " , displayName : " Amadine " )
2021-09-13 08:26:21 +00:00
static let mathew = TemplateRoomChatMember ( id : " @mathew:matrix.org " , avatarUrl : " !bbabb:matrix.org " , displayName : " Mathew " )
2021-09-12 13:57:45 +00:00
static let mockMessages = [
2021-09-20 07:47:28 +00:00
TemplateRoomChatMessage ( id : " !0:matrix.org " , content : . text ( TemplateRoomChatMessageTextContent ( body : " Shall I put it live? " ) ) , sender : amadine , timestamp : Date ( timeIntervalSinceNow : 60 * - 3 ) ) ,
TemplateRoomChatMessage ( id : " !1:matrix.org " , content : . text ( TemplateRoomChatMessageTextContent ( body : " Yea go for it! ...and then let's head to the pub " ) ) , sender : mathew , timestamp : Date ( timeIntervalSinceNow : 60 ) ) ,
TemplateRoomChatMessage ( id : " !2:matrix.org " , content : . text ( TemplateRoomChatMessageTextContent ( body : " Deal. " ) ) , sender : amadine , timestamp : Date ( timeIntervalSinceNow : 60 * - 2 ) ) ,
TemplateRoomChatMessage ( id : " !3:matrix.org " , content : . text ( TemplateRoomChatMessageTextContent ( body : " Ok, Done. 🍻 " ) ) , sender : amadine , timestamp : Date ( timeIntervalSinceNow : 60 * - 1 ) ) ,
2021-09-12 13:57:45 +00:00
]
2021-09-20 07:47:28 +00:00
var roomInitializationStatus : CurrentValueSubject < TemplateRoomChatRoomInitializationStatus , Never >
2021-09-12 13:57:45 +00:00
var chatMessagesSubject : CurrentValueSubject < [ TemplateRoomChatMessage ] , Never >
init ( messages : [ TemplateRoomChatMessage ] = mockMessages ) {
2021-09-20 07:47:28 +00:00
self . roomInitializationStatus = CurrentValueSubject ( . notInitialized )
self . chatMessagesSubject = CurrentValueSubject ( messages )
2021-09-12 13:57:45 +00:00
}
2021-09-20 07:47:28 +00:00
func send ( textMessage : String ) {
let newMessage = TemplateRoomChatMessage ( id : " ! \( chatMessagesSubject . value . count ) :matrix.org " , content : . text ( TemplateRoomChatMessageTextContent ( body : textMessage ) ) , sender : Self . amadine , timestamp : Date ( ) )
2021-09-16 21:09:32 +00:00
self . chatMessagesSubject . value += [ newMessage ]
}
2021-09-20 07:47:28 +00:00
func simulateUpdate ( initializationStatus : TemplateRoomChatRoomInitializationStatus ) {
self . roomInitializationStatus . value = initializationStatus
}
2021-09-23 22:57:54 +00:00
2021-09-12 13:57:45 +00:00
func simulateUpdate ( messages : [ TemplateRoomChatMessage ] ) {
2021-09-23 22:57:54 +00:00
self . chatMessagesSubject . value = messages
2021-09-12 13:57:45 +00:00
}
}